!126 分享相关完善

Merge pull request !126 from puhui999/master
This commit is contained in:
芋道源码
2024-12-01 08:58:39 +00:00
committed by Gitee
9 changed files with 54 additions and 32 deletions
+15 -4
View File
@@ -60,12 +60,11 @@
/**
* 模板组件 - 提供页面公共组件,属性,方法
*/
import { computed, reactive, ref } from 'vue';
import { computed } from 'vue';
import sheep from '@/sheep';
import { isEmpty } from 'lodash-es';
import { onShow } from '@dcloudio/uni-app';
// #ifdef MP-WEIXIN
import { onShareAppMessage } from '@dcloudio/uni-app';
import { onShareAppMessage, onShareTimeline, onShow } from '@dcloudio/uni-app';
// #endif
const props = defineProps({
@@ -191,7 +190,11 @@
});
// #ifdef MP-WEIXIN
// 微信小程序分享
uni.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline'],
});
// 微信小程序分享好友
onShareAppMessage(() => {
return {
title: shareInfo.value.title,
@@ -199,6 +202,14 @@
imageUrl: shareInfo.value.image,
};
});
// 微信小程序分享朋友圈
onShareTimeline(() => {
return {
title: shareInfo.value.title,
query: shareInfo.value.path,
imageUrl: shareInfo.value.image,
};
});
// #endif
onShow(() => {
+12 -6
View File
@@ -47,19 +47,18 @@ const getShareInfo = (
// 配置分享链接地址
shareInfo.link = buildSpmLink(query, shareConfig.linkAddress);
// 配置页面地址带参数
shareInfo.path = buildSpmPath(query);
shareInfo.path = buildSpmPath();
// 配置转发参数
if (shareConfig.methods.includes('forward')) {
// TODO puhui999: forward 这块有点问题
if (shareConfig.forwardInfo.title === '' || shareConfig.forwardInfo.image === '') {
console.log('请在平台设置中配置转发信息');
console.log('请在平台设置中配置默认转发信息');
}
// 设置自定义分享信息
shareInfo.title = scene.title || shareConfig.forwardInfo.title;
shareInfo.image = $url.cdn(scene.image || shareConfig.forwardInfo.image);
shareInfo.desc = scene.desc || shareConfig.forwardInfo.subtitle;
shareInfo.path = buildSpmPath(scene.path, query);
shareInfo.path = buildSpmPath(query);
}
return shareInfo;
@@ -100,7 +99,7 @@ const buildSpmQuery = (params) => {
const buildSpmPath = (query) => {
// 默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /
// 不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置
return `pages/index/index`;
return typeof query === 'undefined' ? `pages/index/index` : `pages/index/index?${query}`;
};
// 构造分享链接
@@ -148,7 +147,7 @@ const decryptSpm = (spm) => {
shareParams.page = '/pages/goods/seckill';
query = shareParamsArray[2].split(',');
shareParams.query = {
id: query[1],
id: query[0],
};
break;
case '5':
@@ -158,6 +157,13 @@ const decryptSpm = (spm) => {
id: shareParamsArray[2],
};
break;
case '6':
// 积分商品
shareParams.page = '/pages/goods/point';
shareParams.query = {
id: shareParamsArray[2],
};
break;
}
shareParams.platform = platformMap[shareParamsArray[3] - 1];
shareParams.from = fromMap[shareParamsArray[4] - 1];
+6 -1
View File
@@ -71,13 +71,18 @@ const app = defineStore({
};
this.platform = {
share: {
methods: ['poster', 'link'],
methods: ['forward', 'poster', 'link'],
linkAddress: 'http://127.0.0.1:3000', // TODO 芋艿:可以考虑改到 .env 那
posterInfo: {
user_bg: '/static/img/shop/config/user-poster-bg.png',
goods_bg: '/static/img/shop/config/goods-poster-bg.png',
groupon_bg: '/static/img/shop/config/groupon-poster-bg.png',
},
forwardInfo: {
title: '',
image: '',
desc: '',
},
},
bind_mobile: 0,
};