From efa27756a855313c5ae4655e4ad54c289fcb94f5 Mon Sep 17 00:00:00 2001 From: zpc Date: Mon, 7 Jul 2025 14:01:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E4=BA=AB=E3=80=81?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/platform/BasePlatform.js | 2 +- common/platform/H5Platform.js | 22 +- common/platform/NewWebAppPlatform.js | 40 +- common/platform/WebAppPlatform.js | 10 - common/webapp.js | 81 +- components/detail-lucky/detail-lucky.vue | 2 +- components/page-container/page-container.vue | 46 +- pages/shouye/detail.vue | 32 +- pages/shouye/detail_wuxian.vue | 30 +- pages/user/login.vue | 65 +- pages/user/tui-guang.vue | 1145 +++++++++-------- uni_modules/uni-share/changelog.md | 18 + .../uni-share/js_sdk/uni-image-menu.js | 204 +++ uni_modules/uni-share/js_sdk/uni-share.js | 98 ++ uni_modules/uni-share/package.json | 80 ++ uni_modules/uni-share/readme.md | 95 ++ 16 files changed, 1327 insertions(+), 643 deletions(-) create mode 100644 uni_modules/uni-share/changelog.md create mode 100644 uni_modules/uni-share/js_sdk/uni-image-menu.js create mode 100644 uni_modules/uni-share/js_sdk/uni-share.js create mode 100644 uni_modules/uni-share/package.json create mode 100644 uni_modules/uni-share/readme.md diff --git a/common/platform/BasePlatform.js b/common/platform/BasePlatform.js index 4d28840..a77adb1 100644 --- a/common/platform/BasePlatform.js +++ b/common/platform/BasePlatform.js @@ -259,7 +259,7 @@ class BasePlatform { * 获取功能权限 */ getPermission(functionName) { - return true; + return false; } } diff --git a/common/platform/H5Platform.js b/common/platform/H5Platform.js index ca4e1de..02c6d91 100644 --- a/common/platform/H5Platform.js +++ b/common/platform/H5Platform.js @@ -1,7 +1,7 @@ import BasePlatform from './BasePlatform'; import eruda from 'eruda'; import { parseQueryString } from '@/common/util'; - +// import UniShare from 'uni_modules/uni-share/js_sdk/uni-share.js'; class H5Platform extends BasePlatform { @@ -66,16 +66,26 @@ class H5Platform extends BasePlatform { url }) { console.log(`H5分享:${title} - ${desc}`); + if (url.indexOf("http") == -1) { + url = window.location.origin + url; + } // 调用浏览器原生分享(如果可用) if (navigator.share) { - return navigator.share({ - title, + navigator.share({ + title: title, text: desc, - url - }); + url: url + }) + .then(() => console.log('分享成功')) + .catch((error) => console.log('分享失败:', error)); + return; } + uni.setClipboardData({ + data: url + }); + this.$c.msg("链接已复制,快去分享吧~") // 降级方案 - alert(`请手动分享:${url}`); + // alert(`请手动分享:${url}`); } /** diff --git a/common/platform/NewWebAppPlatform.js b/common/platform/NewWebAppPlatform.js index 8622dfd..a64e875 100644 --- a/common/platform/NewWebAppPlatform.js +++ b/common/platform/NewWebAppPlatform.js @@ -1,6 +1,6 @@ import BasePlatform from './BasePlatform'; import H5Platform from './H5Platform'; -import { webAppPay } from '@/common/webapp.js' +import { webAppPay, webAppShare } from '@/common/webapp.js' import { parseQueryString } from '@/common/util' function versionToNumber(versionString) { @@ -13,6 +13,7 @@ class NewWebAppPlatform extends H5Platform { this.code = 'WEB_APP_ANDROID'; this.env = 'web_app'; this.app_version = 100; + this.app_os = null; let location = window.location.href; const params = parseQueryString(location); @@ -26,15 +27,38 @@ class NewWebAppPlatform extends H5Platform { } if (params['os'] != null) { - uni.setStorageSync('app_os', params['os']); + let app_os = params['os']; + uni.setStorageSync('app_os', app_os); + this.app_os = app_os; } + if (this.app_os == null) { + + + if (uni.getStorageSync('app_version') != null) { + let _appversion = uni.getStorageSync('app_version') ?? "1.0.0"; + if (_appversion.indexOf(".") > -1) { + _appversion = versionToNumber(_appversion); + this.app_version = _appversion; + } + + } + if (uni.getStorageSync('app_os') != null) { + this.app_os = uni.getStorageSync('app_os'); + } + console.log('加载数据', uni.getStorageSync('app_version'), uni.getStorageSync('app_os')); + } + } share({ title, desc, image, url }) { - console.log(`H5分享:${title} - ${desc}`); - // 调用浏览器原生分享(如果可用) - if (navigator.share) { - return navigator.share({ title, text: desc, url }); + console.log(`APP分享:${title} - ${desc} - ${image} - ${url}`); + if (this.app_version == 100) { + uni.setClipboardData({ + data: url + }); + this.$c.msg("链接已复制,快去分享吧~"); + return; } + return webAppShare(title, desc, image, url); // 降级方案 // alert(`请手动分享:${url}`); } @@ -112,11 +136,9 @@ class NewWebAppPlatform extends H5Platform { wxLogin: 101 }; let _functionVersion = appPermission[functionName]; - - if (_functionVersion != null) { //如果当前app权限大于等于功能权限版本,则返回true - console.log('验证功能权限', functionName, _functionVersion, this.app_version, this.app_version >= _functionVersion); + console.log('验证功能权限' + functionName, "功能要求版本:" + _functionVersion, "当前app版本:" + this.app_version, "当前功能是否满足:" + (this.app_version >= _functionVersion)); return this.app_version >= _functionVersion; } return false; diff --git a/common/platform/WebAppPlatform.js b/common/platform/WebAppPlatform.js index 8fb4afb..1b32b49 100644 --- a/common/platform/WebAppPlatform.js +++ b/common/platform/WebAppPlatform.js @@ -26,16 +26,6 @@ class WebAppPlatform extends H5Platform { this.code = 'WEB_APP'; 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}`); - } - downloadFile(url) { return new Promise((resolve, reject) => { try { diff --git a/common/webapp.js b/common/webapp.js index 792bf90..83f746f 100644 --- a/common/webapp.js +++ b/common/webapp.js @@ -100,4 +100,83 @@ export const sendWxAppLogin = () => { } }); }); -} \ No newline at end of file +} + +/** + * 分享 + * @param {*} title 标题 + * @param {*} desc 描述 + * @param {*} image 图片 + * @param {*} url 链接 + * @returns + */ +export const webAppShare = (title, desc, image, url) => { + if (!window.ydsApp) { + reject('ydsApp未加载'); + return; + } + let shareUrl = url; + if (shareUrl.indexOf('http') == -1) { + shareUrl = window.location.origin + url; + } + + let shareData = { + content: { //公共的分享参数配置 类型(type)、链接(herf)、标题(title)、summary(描述)、imageUrl(缩略图) + type: 0, + href: shareUrl, + title: title, + summary: desc, + imageUrl: image + "?imageMogr2/thumbnail/108x108" + }, + menus: [{ + "img": "/static/app-plus/sharemenu/icon_wechat.png", + "text": "微信好友", + "share": { //当前项的分享参数配置。可覆盖公共的配置如下:分享到微信小程序,配置了type=5 + "provider": "weixin", + "scene": "WXSceneSession" + } + }, { + "img": "/static/app-plus/sharemenu/wx_quan.png", + "text": "微信朋友圈", + "share": { + "provider": "weixin", + "scene": "WXSceneTimeline" + } + }, + { + "img": "/static/app-plus/sharemenu/mp_app.png", + "text": "微信小程序", + "share": { + provider: "weixin", + scene: "WXSceneSession", + type: 5, + miniProgram: { + id: 'gh_04b8832df741', + path: url, + webUrl: shareUrl, + type: 0 + }, + } + }, + { + "img": "/static/app-plus/sharemenu/copy.png", + "text": "复制", + "share": "copyurl" + }, + { + "img": "/static/app-plus/sharemenu/more.png", + "text": "更多", + "share": "shareSystem" + } + ], + cancelText: "取消分享", + } + + ydsApp.postMessage({ + data: { + action: 'share', + data: shareData, + } + }) +} + diff --git a/components/detail-lucky/detail-lucky.vue b/components/detail-lucky/detail-lucky.vue index 2cf7e89..644e809 100644 --- a/components/detail-lucky/detail-lucky.vue +++ b/components/detail-lucky/detail-lucky.vue @@ -29,7 +29,7 @@ export default { return { chaoShenIndex: -1, prizeList: null, - mode: mode, + // mode: mode, }; }, computed: { diff --git a/components/page-container/page-container.vue b/components/page-container/page-container.vue index ed0e12e..eab8243 100644 --- a/components/page-container/page-container.vue +++ b/components/page-container/page-container.vue @@ -1,24 +1,16 @@