share.js
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import wx from 'weixin-js-sdk'
import axios from '@/utils/axios';
const fn = (to) => {
// 路由名
let ruleName = location.href.split('#/')[1].split('?')[0];
const icon = 'https://cdn.lifeat.cn/webappgroup/betterLifelogo.png'
const shareInfoMap = {
'client/index': {
title: '童声无界',
desc: '引导页',
icon
},
'client/chooseSchool': {
title: '选择幼儿园',
desc: '引导页',
icon
},
default: {
title: to.name,
desc: window.location.href,
icon
},
}
let infoMap = shareInfoMap[ruleName] ? shareInfoMap[ruleName] : shareInfoMap['default'];
// console.warn(ruleName);
console.warn(infoMap);
console.warn(wx);
console.warn(axios);
}
export default fn
// 这个判断后加的为了减少请求次数,据后端说有次数限制,当需要分享的页面才去请求接口。
// if (shareInfoMap[ruleName]) {
// // request 是封装的请求
// request.post('/wxmp/sign/jsSdk', {
// url: location.href,
// }).then(res => {
// let { timestamp, nonceStr, signature, appId } = res;
// wx.config({
// debug: false,
// appId,
// timestamp,
// nonceStr,
// signature,
// jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData']
// });
// wx.error(function (errres) {
// console.info(errres)
// })
// wx.ready(() => { //需在用户可能点击分享按钮前就先调用
// console.info('ready')
// //分享朋友
// wx.updateAppMessageShareData({
// title: infoMap.title, // 分享标题
// desc: infoMap.desc, // 分享描述
// link: location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
// imgUrl: infoMap.icon, // 分享图标
// success: function () {
// console.info("成功")
// // 设置成功
// },
// fail: function (erres) {
// console.info('失败:', erres)
// }
// })
// //分享到 朋友圈
// wx.updateTimelineShareData({
// title: infoMap.title, // 分享标题
// link: location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
// imgUrl: infoMap.icon, // 分享图标
// success: function () {
// console.info("成功")
// // 设置成功
// },
// fail: function (erres) {
// console.info('失败:', erres)
// }
// })
// });
// }).catch(err => {
// console.info('err:', err)
// })
// }