ufutx-love-h5-public/src/plugins/wxShare.js

69 lines
2.5 KiB
JavaScript
Raw Normal View History

2026-04-02 18:12:53 +08:00
import wx from 'weixin-js-sdk'
import store from '@/store'
// import { $toastText } from '@/config/toast'
const base = {}
base.install = function(Vue, options) {
Vue.prototype.$shareList = function(imgUrl, link, desc, title) {
// 分享
let share_title = ``
if (!localStorage.getItem('from_openid') || (localStorage.getItem('from_openid') && localStorage.getItem('from_openid').length < 20)) {
share_title = ''
} else if (store.state.app.info.nickname && store.state.app.info.nickname.length > 4) {
share_title = store.state.app.info.nickname.substring(0, 4) + '..推送'
} else {
share_title = store.state.app.info.nickname + '推送'
}
wx.config(store.state.app.configData)
wx.ready(function() {
wx.hideMenuItems({
menuList: [] // 屏蔽复制链接
})
wx.updateAppMessageShareData({
title: desc !== '欢迎和我预约' ? share_title + '《' + title + '》' : `${title}】商家预约`, // 分享标题
desc: desc, // 分享描述
link: link, // 分享链接
imgUrl: imgUrl, // 分享图标
success: function() {
console.log('分享成功')
},
cancel: function() {
console.log('分享失败')
}
})
// 微信分享菜单测试
wx.updateTimelineShareData({
title: share_title + '《' + title + '》', // 分享标题
desc: desc, // 分享描述
link: link, // 分享链接
imgUrl: imgUrl, // 分享图标
success: function() {
console.log('分享成功')
},
cancel: function() {
console.log('分享失败')
}
})
wx.onMenuShareAppMessage({
title: share_title + '《' + title + '》', // 分享标题
desc: desc, // 分享描述
link: link, // 分享链接;在微信上分享时,该链接的域名必须与企业某个应用的可信域名一致
imgUrl: imgUrl, // 分享图标
success: function() {
console.log('分享成功-企业') // 用户确认分享后执行的回调函数
},
cancel: function() {
// 用户取消分享后执行的回调函数
}
})
})
wx.error(function(err) {
// $toastText('网络异常,请稍后重试')
console.log(JSON.stringify(err), '7777777777777')
// alert(JSON.stringify(err))
})
}
}
export default base