更新脚手架!
This commit is contained in:
69
src/plugins/wxshare.js
Normal file
69
src/plugins/wxshare.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import wx from 'weixin-js-sdk';
|
||||
import axios from "axios";
|
||||
import { Toast } from "vant";
|
||||
|
||||
const imgUrl = new URL(`../assets/images/share.jpg`, import.meta.url).href
|
||||
const linkUrl = import.meta.env.VITE_HOST + import.meta.env.VITE_FOLDER
|
||||
|
||||
export function wxShare(option) {
|
||||
let url = location.href.split('#')[0];
|
||||
// qiween: https://www.qiween.com/wxapi/api/jsconfig
|
||||
// 信蜂: https://wx.xfhd.net/wxapi/api/jsconfig?appid=wx41d80a1bb01f658d
|
||||
axios.get('https://wx.xfhd.net/wxapi/api/jsconfig?appid=wx41d80a1bb01f658d', {
|
||||
params: { url }
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('分享配置:', {
|
||||
'title': option.title,
|
||||
'desc': option.desc,
|
||||
'link': linkUrl + option.link
|
||||
});
|
||||
|
||||
let data = res.data;
|
||||
wx.config({
|
||||
debug: false, // 开启调试模式
|
||||
appId: data.appId, // 必填,公众号的唯一标识
|
||||
timestamp: data.timestamp, // 必填,生成签名的时间戳
|
||||
nonceStr: data.nonceStr, // 必填,生成签名的随机串
|
||||
signature: data.signature, // 必填,签名,见附录1
|
||||
jsApiList: [
|
||||
'checkJsApi',
|
||||
'chooseImage',
|
||||
'closeWindow',
|
||||
'chooseWXPay',
|
||||
'scanQRCode',
|
||||
'showMenuItems',
|
||||
'onMenuShareAppMessage',
|
||||
'onMenuShareTimeline',
|
||||
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
|
||||
})
|
||||
wx.ready(function () {
|
||||
wx.hideMenuItems({
|
||||
menuList: ["menuItem:copyUrl", "menuItem:share:appMessage", "menuItem:share:timeline"] // 屏蔽复制链接
|
||||
});
|
||||
wx.onMenuShareTimeline({
|
||||
link: linkUrl + option.link, // 分享链接
|
||||
title: option.title, // 分享标题
|
||||
desc: option.desc, // 分享描述
|
||||
imgUrl: imgUrl, // 分享图标
|
||||
success() {// 用户成功分享后执行的回调函数
|
||||
Toast('分享成功')
|
||||
},
|
||||
});
|
||||
wx.onMenuShareAppMessage({
|
||||
link: linkUrl + option.link, // 分享链接
|
||||
title: option.title, // 分享标题
|
||||
desc: option.desc, // 分享描述
|
||||
imgUrl: imgUrl, // 分享图标
|
||||
success() {// 用户成功分享后执行的回调函数
|
||||
Toast('分享成功')
|
||||
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user