From d497c2ff49c8ab7382345f0415c1b23482f12503 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Sat, 25 Oct 2025 15:25:15 +0800 Subject: [PATCH] fenxiang --- utils/util.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/utils/util.js b/utils/util.js index ab24828..afbd137 100755 --- a/utils/util.js +++ b/utils/util.js @@ -6,6 +6,8 @@ const HOSTARR = { // 'production': 'https://leyitest.ali251.langye.net', }; // 审核状态 + +const jwx = require('jweixin-module') const HOST = HOSTARR[process.env .NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];// @@ -109,7 +111,8 @@ const wxH5AuthLogin = (cb) => { // 可以根据需要添加其他字段,如 WeChatOpenID 等 } uni.setStorageSync(user_info_key, userInfo) - cb(userInfo) + cb(userInfo) + shareIndex() } else { console.error('登录失败: token为空') uni.showToast({ title: '登录失败,请重试', icon: 'none' }) @@ -134,7 +137,60 @@ const wxH5AuthLogin = (cb) => { window.location.href = authUrl } } - + +// 分享 + +const shareIndex = (cb) => { + console.log("开始分享配置",location.href.split('#')[0]) + let link = HOST+"/h5/"; + request({ + api: `/api/mobile/user/wx-jssdk`, + method: 'GET', + data:{ + url:location.href.split('#')[0] + }, + utilSuccess: (res) => { + jwx.config({ + debug: false, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。 + appId: res.appId, + jsApiList: res.jsApiList, + nonceStr: res.nonceStr, + signature: res.signature, + timestamp: res.timestamp, + }) + jwx.ready(() => { + jwx.updateAppMessageShareData({ + title: '中共苏州独立支部旧址', // 分享标题 + link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 + desc: '点击查看', + imgUrl: HOST+'/h5/share.jpg', // 分享图标 + success: () => { + console.log( + 'updateAppMessageShareData-success' + ) + }, + + }); + jwx.updateTimelineShareData({ + title: '中共苏州独立支部旧址', // 分享标题 + desc: '点击查看', + link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 + imgUrl: HOST+'/h5/share.jpg', // 分享图标 + success: () => { + console.log( + 'updateTimelineShareData-success' + ) + } + }); + }) + }, + utilFail: (err) => { + console.error('分享配置失败:', err) + // uni.showToast({ title: '分享配置失败', icon: 'none' }) + } + }) + +} const getUserProfile = (cb) => { cb = cb || function() {}