昨天需要给旧项目增加一个详情页面,然后弄好了。接着老板需要实现分享功能,这个功能在之前已经做好了,但是分享出来的链接点进去不是被分享的页面,其实就是分享的链接给固定了在首页。后面查看文档,结合代码,自己链接改了。
部分代码
// 微信分享设置
app.$wx.dynamicShare = () => {
const normal = {
title: document.title,
desc: '',
link: '',
};
const dyshare = app.$route.meta.share || normal;
return {
title: dyshare.title, // 分享标题
desc: dyshare.desc, // 分享详情
// link: `${location.href.replace(/#\/.*/ig, '')}`, // 分享链接
link: `${location.href.indexOf('detail') > 0 ? location.href : location.href.replace(/#\/.*/ig, '')}`,
img_url: 'https://file-qy.mall-to.com/learn/element/learn_share_logo.jpg', // 分享图标
};
};
上面的link属性,注释掉的是原来的代码,因为我增加的是detail这个页面,分享的时候判断该链接有无这个字符串,有就跳转到该页面,没有就跳转到首页。
我说一下我这么做的想法,我不想破坏他之前的写法,因为该项目除了detai这个页面分享出去,其他都会进入到首页,假如我把全部改成分享后链接点进去都是被分享的页面,就只能看到当前被分享的页面,无法进入其他页面,因为这个是没有导航的。
不过应该可以使用beforRounterEnter(to,from,next)来判断进是从哪里进入的,通过判断from.name或者是from.path属性来控制返回的跳转,如果有,点击返回就返回到上一页,如果没有就返回到首页(未通过验证嘻嘻)。
后面老板又提了一个要求,隐藏部分分享按钮,然后通过查找微信文档,部分可隐藏,部分不可以隐藏。
微信分享文档界面操作
所有分享菜单项附录3
企业微信分享文档界面操作
所有分享菜单项附录3
贴一下部分代码
wx.config配置
Axios.get(`${process.auth}/wechat/jsconfig`, {
params: {
uuid,
url: `${location.origin}${location.pathname}${location.search}`,
},
})
.then((res) => {
const config = res.data;
wx.config({
debug: false,
appId: config.appId,
timestamp: config.timestamp,
nonceStr: config.nonceStr,
signature: config.signature,
jsApiList: config.jsApiList,
});
}).catch(() => {});
我们是通过接口获取wx.config的参数
wx.ready函数
wx.ready(() => {
//hideMenuItems配置批量隐藏菜单项
wx.hideMenuItems({
menuList: [
'menuItem:openWithSafari',
'menuItem:openWithQQBrowser',
'menuItem:share:qq',
'menuItem:share:weiboApp',
'menuItem:share:facebook',
'menuItem:share:QZone',
'menuItem:setFont',
'menuItem:favorite',
],
});
});
其他具体接入配置自行百度,笔者充当工作笔记[抱歉]。