acdr-ui/dist/dev/mp-weixin/sheep/platform/share.js.map

1 line
9.7 KiB
Plaintext
Raw Normal View History

2024-09-19 07:20:14 +08:00
{"version":3,"file":"share.js","sources":["../../../../../src/sheep/platform/share.js"],"sourcesContent":["import $store from '@/sheep/store'\r\nimport $platform from '@/sheep/platform'\r\nimport $router from '@/sheep/router'\r\nimport $url from '@/sheep/url'\r\nimport BrokerageApi from '@/sheep/api/trade/brokerage'\r\n// #ifdef H5\r\nimport $wxsdk from '@/sheep/libs/sdk-h5-weixin'\r\n// #endif\r\n\r\n// 设置分享的平台渠道: 1=H5,2=微信公众号网页,3=微信小程序,4=App,...按需扩展\r\nconst platformMap = ['H5', 'WechatOfficialAccount', 'WechatMiniProgram', 'App']\r\n\r\n// 设置分享方式: 1=直接转发,2=海报,3=复制链接,...按需扩展\r\nconst fromMap = ['forward', 'poster', 'link']\r\n\r\n// TODO 芋艿:分享的接入\r\n// 设置分享信息参数\r\nconst getShareInfo = (\r\n scene = {\r\n title: '', // 自定义分享标题\r\n desc: '', // 自定义描述\r\n image: '', // 自定义分享图片\r\n params: {}, // 自定义分享参数\r\n },\r\n poster = {\r\n // 自定义海报数据\r\n type: 'user',\r\n },\r\n) => {\r\n const shareInfo = {\r\n title: '', // 分享标题\r\n desc: '', // 描述\r\n image: '', // 分享图片\r\n path: '', // 分享页面+参数\r\n link: '', // 分享Url+参数\r\n query: '', // 分享参数\r\n poster, // 海报所需数据\r\n }\r\n\r\n const app = $store('app')\r\n const shareConfig = app.platform.share\r\n\r\n // 自动拼接分享用户参数\r\n const query = buildSpmQuery(scene.params)\r\n shareInfo.query = query\r\n\r\n // 配置分享链接地址\r\n shareInfo.link = buildSpmLink(query, shareConfig.linkAddress)\r\n // 配置页面地址带参数\r\n shareInfo.path = buildSpmPath(query)\r\n\r\n // 配置转发参数\r\n if (shareConfig.methods.includes('forward')) {\r\n // TODO puhui999: forward 这块有点问题\r\n if (shareConfig.forwardInfo.title === '' || shareConfig.forwardInfo.image === '') {\r\n console.log('请在平台设置中配置转发信息')\r\n }\r\n // 设置自定义分享信息\r\n shareInfo.title = scene.title || shareConfig.forwardInfo.title\r\n shareInfo.image = $url.cdn(scene.image || shareConfig.forwardInfo.image)\r\n shareInfo.desc = scene.desc || shareConfig.forwardInfo.subtitle\r\n shareInfo.path = buildSpmPath(scene.path, query)\r\n }\r\n\r\n return shareInfo\r\n}\r\n\r\n/**\r\n * 构造 spm 分享参数\r\n *\r\n * @param params json 格式其中包含1shareId 分享用户的编号2page 页面类型3query 页面 ID参数4platform 平台类型5from 分享来源类型。\r\n * @return 分享串 `spm=${shareId}.${page}.${query}.${platform}.${from}`\r\n */\r\nconst buildSpmQuery = (params) => {\r\n const user = $store('user')\r\n let shareId = '0' // 设置分享者用户ID\r\n if (typeof params.shareId === 'undefined') {\r\n if (user.isLogin) {\r\n shareId = user.userInfo.id\r\n }\r\n }\r\n let page = '1' // 页面类型: 1=首页(默认),2=商品,3=拼团商品,4=秒杀商品,5=邀请参团,6=分销邀请...按需扩展\r\n if (typeof params.page !== 'undefined') {\r\n page = params.page\r\n }\r\n let query = '0' // 设置页面ID: 如商品ID、拼团ID等\r\n if (typeof params.query !== 'undefined') {\r\n query = params.query\r\n }\r\n const platform = platformMap.indexOf($platform.name) + 1\r\n let from = '1'\r\n if (typeof params.from !== 'undefined') {\r\n from = platformMap.indexOf(params.from) + 1\r\n }\r\n // spmParams = ... 可按需扩展\r\n return `spm=${shareId}.${page}.${query}.${platform}.${from}`\r\n}\r\n\r\n// 构造页面分享参数: 所有的分享都先到首页进行 spm 参数解析\r\nconst buildSpmPath = (query) => {\r\n // 默认是主页,页面 page例如 pages/index/index根路径前不要填加 /\r\n // 不能携带参数参数请放在scene字段里如果不填写这个字段默认跳主页面。scancode_time为系统保留参数不允许配置\r\n return `pages/index/index`\r\n}\r\n\r\n// <20><>