hookehuyr

测试分享模块-路由入口页面

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