From deb4471299e5f3bb95224482e5211e0783c2092e Mon Sep 17 00:00:00 2001 From: zpc Date: Wed, 25 Jun 2025 16:52:08 +0800 Subject: [PATCH] yds --- App.vue | 5 ++ common/env.js | 2 +- common/platform/AppPlatform.js | 4 +- common/platform/H5Platform.js | 3 +- common/platform/NewWebAppPlatform.js | 87 +++++++++++++++++++++++++++ common/platform/PlatformFactory.js | 52 ++++++++++------ common/util.js | 61 ++++++++++++++++++- common/webapp.js | 80 ++++++++++++++++++++++++ common/ydsmixin.js | 31 ++++++++++ index.html | 1 + main.js | 18 +++--- manifest.json | 2 +- pages.json | 2 +- pages/other/about.vue | 7 ++- static/tab/c1.png | Bin 1253 -> 1441 bytes uni.scss | 3 +- 16 files changed, 322 insertions(+), 36 deletions(-) create mode 100644 common/platform/NewWebAppPlatform.js create mode 100644 common/webapp.js create mode 100644 common/ydsmixin.js diff --git a/App.vue b/App.vue index 5853906..f3833f9 100644 --- a/App.vue +++ b/App.vue @@ -132,6 +132,11 @@ uni-tabbar { z-index: 97 !important; } +uni-tabbar .uni-tabbar__icon img{ + height: 24px !important; + width: 24px !important; +} + /* 引入字体 */ @font-face { font-family: "YouSheBiaoTiHei"; diff --git a/common/env.js b/common/env.js index a1b2027..adaa76e 100644 --- a/common/env.js +++ b/common/env.js @@ -41,7 +41,7 @@ const testing = { // 根据环境变量选择对应配置 -let currentEnv = production;//production;//testing;//production_wz; +let currentEnv = testing;//production;//testing;//production_wz; // 衍生配置 const config = { ...currentEnv, diff --git a/common/platform/AppPlatform.js b/common/platform/AppPlatform.js index c4a99da..5b4670d 100644 --- a/common/platform/AppPlatform.js +++ b/common/platform/AppPlatform.js @@ -28,7 +28,7 @@ class AppPlatform extends BasePlatform { async appData() { this.getConfig().then(res => { console.log("AppLaunch", res); - if (res.isCheck) { + if (res.buildVersion=="105") { console.log("开启审核模式开启审核模式开启审核模式开启审核模式开启审核模式开启审核模式开启审核模式"); uni.setTabBarItem({ index: 0, @@ -334,7 +334,7 @@ class AppPlatform extends BasePlatform { uni.removeStorageSync('userinfo'); that.getConfig().then(res => { console.log("AppLaunch", res); - if (!res.isCheck) { + if (res.buildVersion == "105") { uni.switchTab({ url: '/pages/shouye/index' }); diff --git a/common/platform/H5Platform.js b/common/platform/H5Platform.js index e0672b2..ca4e1de 100644 --- a/common/platform/H5Platform.js +++ b/common/platform/H5Platform.js @@ -11,6 +11,7 @@ class H5Platform extends BasePlatform { this.env = 'h5'; // 简单初始化 let erudaInstance = uni.getStorageSync("erudaInstance"); + if (erudaInstance != null && erudaInstance != "") { this.startDeb(); } @@ -169,7 +170,7 @@ class H5Platform extends BasePlatform { window.location.href = url; } } - + // if (window.location.pathname == "/" || window.location.pathname == "/pages/index/index") { // uni.switchTab({ // url: '/pages/shouye/index' diff --git a/common/platform/NewWebAppPlatform.js b/common/platform/NewWebAppPlatform.js new file mode 100644 index 0000000..935093e --- /dev/null +++ b/common/platform/NewWebAppPlatform.js @@ -0,0 +1,87 @@ +import BasePlatform from './BasePlatform'; +import H5Platform from './H5Platform'; +import { webAppPay } from '@/common/webapp.js' + + +class NewWebAppPlatform extends H5Platform { + constructor() { + super(); + this.code = 'WEB_APP_ANDROID'; + this.env = 'web_app'; + } + share({ title, desc, image, url }) { + console.log(`H5分享:${title} - ${desc}`); + // 调用浏览器原生分享(如果可用) + if (navigator.share) { + return navigator.share({ title, text: desc, url }); + } + // 降级方案 + // alert(`请手动分享:${url}`); + } + pay({ + data + }, event) { + console.log(this, event); + return new Promise(async (resolve, reject) => { + const res = await webAppPay(data); + if (!res) { + uni.showToast({ + title: '取消支付', + icon: 'none', + duration: 500, + success: () => { + /* 取消订单 */ + resolve('cancel') + } + }); + return; + } + uni.showToast({ + title: '支付成功', + icon: 'success', + duration: 500, + success: () => { + resolve('success') + } + }) + }); + } + downloadFile(url) { + return new Promise((resolve, reject) => { + try { + // 创建一个隐藏的a标签 + const a = document.createElement('a'); + a.href = url; + a.download = url.split('/').pop() || 'download'; // 使用URL中的文件名或默认名称 + a.style.display = 'none'; + document.body.appendChild(a); + a.click(); // 触发下载 + document.body.removeChild(a); // 清理DOM + resolve({ success: true }); + } catch (error) { + console.error('下载失败:', error); + // 降级方案,直接打开 + window.location.href = url; + resolve({ success: false, error: error.message }); + } + }); + } + /** + * 重写获取用户中心菜单列表,添加微信小程序特有菜单 + * @returns {Array} 菜单项数组 + */ + getUserMenuList() { + // 获取基础菜单列表 + const baseMenuList = super.getUserMenuList(); + + // 添加客服菜单项(仅微信小程序) + + + // 将客服菜单插入到第二个位置 + return [...baseMenuList.slice(0, baseMenuList.length - 1), ...baseMenuList.slice(baseMenuList.length - 1)]; + } + getVersion() { + return uni.getStorageSync('version') == '' ? '1.0.0' : uni.getStorageSync('version'); + } +} +export default NewWebAppPlatform; \ No newline at end of file diff --git a/common/platform/PlatformFactory.js b/common/platform/PlatformFactory.js index b463d5b..141177c 100644 --- a/common/platform/PlatformFactory.js +++ b/common/platform/PlatformFactory.js @@ -9,6 +9,7 @@ import IOSPlatform from './IOSPlatform'; //#ifdef WEB import H5Platform from './H5Platform'; import WebAppPlatform from './WebAppPlatform'; +import NewWebAppPlatform from './NewWebAppPlatform'; //#endif class PlatformFactory { static create() { @@ -24,7 +25,7 @@ class PlatformFactory { //#endif // 判断 App 环境 //#ifdef APP - + return new AppPlatform(); //#endif @@ -33,36 +34,53 @@ class PlatformFactory { // if(window.location.href.includes('cb2039d0e35094521ae46a1d11b0ddd1')){ // return new WebAppPlatform(); // } - console.log(window.location.href); - //window.location.search - let is_web_app = uni.getStorageSync('is_web_app'); - let search = window.location.search; + let is_web_app = this.checkIsWebApp(); + let is_new_web_app = this.checkIsNewWebApp(); - if (search != null && search != '') { - const searchParams = new URLSearchParams(window.location.search); - const code = searchParams.get('_p'); - if (code && code == 'cb2039d0e35094521ae46a1d11b0ddd1') { - uni.setStorageSync('is_web_app', true); - is_web_app = true; - } - } - if (uni.getStorageSync('is_web_app') != null && uni.getStorageSync('is_web_app') != '') { - is_web_app = true; - } if (is_web_app) { return new WebAppPlatform(); } + if (is_new_web_app) { + return new NewWebAppPlatform(); + } return new H5Platform(); //#endif // 默认返回 return new BasePlatform(); } + + static checkIsWebApp() { + return this.checkPlatformType('is_web_app'); + } + + static checkIsNewWebApp() { + return this.checkPlatformType('is_new_web_app','cb20xad0e35094521ae46a1d1fb0ddd1'); + } + + static checkPlatformType(storageKey, codeValue = 'cb2039d0e35094521ae46a1d11b0ddd1') { + let isPlatformType = uni.getStorageSync(storageKey); + let search = window.location.search; + + if (search != null && search != '') { + const searchParams = new URLSearchParams(window.location.search); + const code = searchParams.get('_p'); + if (code && code == codeValue) { + uni.setStorageSync(storageKey, true); + isPlatformType = true; + } + } + if (uni.getStorageSync(storageKey) != null && uni.getStorageSync(storageKey) != '') { + isPlatformType = true; + } + + return isPlatformType; + } } // 使用示例 const platform = PlatformFactory.create(); -// console.log(platform.env,"获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台"); +// console.log(platform.env,"获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台获取平台"); export { platform }; \ No newline at end of file diff --git a/common/util.js b/common/util.js index f822bcb..e43ee58 100644 --- a/common/util.js +++ b/common/util.js @@ -48,4 +48,63 @@ export function msg(msg) { duration, position, }); -}; \ No newline at end of file +}; +/** + * 生成GUID + * @returns {string} 返回格式为'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'的GUID + */ +export function generateGUID() { + return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function(c) { + const r = Math.random() * 16 | 0; + const v = c === 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); +} +/** + * 生成指定长度的随机GUID + * @param {Number} length 指定GUID的长度 + * @returns {string} 返回指定长度的随机GUID + */ +export function generateGUIDWithLength(length = 32) { + let guid = ''; + const characters = 'abcdef0123456789'; + + // 生成指定长度的随机字符 + for (let i = 0; i < length; i++) { + guid += characters.charAt(Math.floor(Math.random() * characters.length)); + } + + // 如果长度大于等于36,则添加破折号使其格式类似标准GUID + if (length >= 36) { + return guid.substring(0, 8) + '-' + + guid.substring(8, 12) + '-' + + guid.substring(12, 16) + '-' + + guid.substring(16, 20) + '-' + + guid.substring(20, 32) + + guid.substring(32); + } + + return guid; +} +/** + * 生成固定长度的随机字符串 + * @param {Number} length 字符串长度,默认为16 + * @param {Boolean} includeSpecial 是否包含特殊字符,默认为false + * @returns {string} 返回生成的随机字符串 + */ +export function generateRandomString(length = 16, includeSpecial = false) { + let result = ''; + let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + + // 如果需要包含特殊字符 + if (includeSpecial) { + characters += '!@#$%^&*()_+~`|}{[]:;?><,./-='; + } + + const charactersLength = characters.length; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + + return result; +} \ No newline at end of file diff --git a/common/webapp.js b/common/webapp.js new file mode 100644 index 0000000..9e1d0c8 --- /dev/null +++ b/common/webapp.js @@ -0,0 +1,80 @@ +import { generateRandomString } from '@/common/util.js' +document.addEventListener('UniAppJSBridgeReady', function () { + // alert('aaa1') + ydsApp.getEnv(function (res) { + console.log('当前环境:' + JSON.stringify(res)); + ydsApp.postMessage({ + data: { + action: 'load', + } + }); + }); + +}); +const _ydsApp = { + callback: {} +} +window.yds_postMessage = function (data) { + // 检查data是否为字符串类型 + console.log('yds_postMessageyds_postMessageyds_postMessageyds_postMessage', data); + if (typeof data === 'string') { + try { + data = JSON.parse(data); + } catch (e) { + console.log('数据解析失败:', e); + return; // 解析失败,退出函数 + } + } + + if (data.action == "pay") { + if (_ydsApp.callback[data.callback]) { + _ydsApp.callback[data.callback](data.data); + delete _ydsApp.callback[data.callback]; + return; + } + console.log('回调不存在'); + } +} +//返回按钮 +window.yds_backPress = function () { + uni.navigateBack(); +} +export const home = () => { + if (window.ydsApp) { + console.log('加载webapp-成功'); + } else { + console.log('加载webapp-未加载'); + } + +} + +export const webAppPay = (orderInfo) => { + return new Promise((resolve, reject) => { + if (!window.ydsApp) { + reject('ydsApp未加载'); + return; + } + let callback = generateRandomString(16); + _ydsApp.callback[callback] = resolve; + ydsApp.postMessage({ + data: { + action: 'pay', + data: orderInfo, + callback: callback + } + }); + }); +} + +export const webAppPageUrl = (url, isHome) => { + if (!window.ydsApp) { + reject('ydsApp未加载'); + return; + } + ydsApp.postMessage({ + data: { + action: 'pageUrl', + data: { page: url, isHome: isHome }, + } + }) +} \ No newline at end of file diff --git a/common/ydsmixin.js b/common/ydsmixin.js new file mode 100644 index 0000000..385b14d --- /dev/null +++ b/common/ydsmixin.js @@ -0,0 +1,31 @@ +import { webAppPageUrl } from '@/common/webapp.js'; +let home = ["pages/hegui/hegui", + "pages/shouye/index", + "pages/mall/index", + "pages/infinite/index", + "pages/user/index" +]; +const ydsMixin = { + onShow() { + //#ifdef H5 + try { + var pages = getCurrentPages(); + if (pages && pages.length > 0) { + let tempPage = pages[pages.length - 1]; + // tempPage.route + let isHome = home.includes(tempPage.route); + console.log('当前页面位置', tempPage.route, isHome); + webAppPageUrl(tempPage.route, isHome); + } + } catch (e) { + console.log('ydsMixin-onShow-error', e); + } + + //#endif + }, + methods: { + + } +} + +export default ydsMixin; \ No newline at end of file diff --git a/index.html b/index.html index 70a57c2..d823612 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,7 @@ var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)')) document.write('') + diff --git a/main.js b/main.js index b586873..6f197d4 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,10 @@ import Vue from 'vue' import App from './App' import Mixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js' import common from '@/common/common.js' +// #ifdef H5 +import { home } from '@/common/webapp.js' +import ydsMixin from '@/common/ydsmixin.js' +// #endif import { gotopage } from '@/common/gotopage.js' @@ -42,19 +46,15 @@ Vue.prototype.req = RequestManager.request Vue.prototype.$request = RequestManager // #ifdef H5 -function loadScript(url) { - var script = document.createElement('script') - script.type = 'text/javascript' - script.src = url - document.head.appendChild(script) -} - -loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js') +home(); // #endif Vue.config.productionTip = false -Vue.mixin(Mixin) +Vue.mixin(Mixin); +// #ifdef H5 +Vue.mixin(ydsMixin); +// #endif App.mpType = 'app' const app = new Vue({ diff --git a/manifest.json b/manifest.json index 8034b15..6a57b02 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "友达赏王者", - "appid" : "__UNI__2E6CB39", + "appid" : "__UNI__0BC0425", "description" : "", "versionName" : "1.0.2", "versionCode" : 102, diff --git a/pages.json b/pages.json index acd5ed5..8dffb59 100644 --- a/pages.json +++ b/pages.json @@ -453,7 +453,7 @@ "borderStyle": "black", "backgroundColor": "#FFFFFF", "iconWidth": "24px", - "iconHeight": "24px", + // "iconHeight": "10px", "list": [ { "pagePath": "pages/shouye/index", diff --git a/pages/other/about.vue b/pages/other/about.vue index ce5eadc..4af538d 100644 --- a/pages/other/about.vue +++ b/pages/other/about.vue @@ -30,7 +30,9 @@ 日志状态: {{ logEnabled ? '已开启' : '已关闭' }} - + + 环境: {{ $platform.env }}--{{ $platform.code }} + @@ -65,7 +67,8 @@ export default { isTestMode: false, logEnabled: false, version: '', - domain: '' + domain: '', + env: '' } }, onLoad() { diff --git a/static/tab/c1.png b/static/tab/c1.png index b60654b40b471fe81548914b37750d622bc0cc67..0459fcd0b52dd9ac637109bbb5bf7bf2396ca2cc 100644 GIT binary patch literal 1441 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSK$uZf!>a+Pp*=Gsq9nr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