import { WXconfirm } from '@/api/wxconfirm' import store from '@/store' // import { removeUrlParam } from '@/util/index' // import { Toast } from 'mint-ui' const wx = require('weixin-js-sdk') export const wxpermission = (state, fn) => { console.log('微信鉴权') console.log(window.location.href) let curUrl = window.location.href if (curUrl.split('#').length >= 2) { curUrl = window.location.href.split('#')[0] } // Toast({ // message: curUrl, // position: 'center', // duration: 5 * 1000 // }) let params = { url: curUrl, auth_id: store.getters.authId } WXconfirm(params).then(res => { console.log(res) wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: res.appId, // 必填,公众号的唯一标识 timestamp: res.timestamp, // 必填,生成签名的时间戳 nonceStr: res.noncestr, // 必填,生成签名的随机串 signature: res.signature, // 必填,签名,见附录1 jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'translateVoice', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'scanQRCode', 'chooseWXPay', 'addCard', 'chooseCard', 'openCard'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }) wx.ready(() => { fn() if (state === 0) { wx.hideMenuItems({ menuList: ['menuItem:share:appMessage', 'menuItem:share:timeline', 'menuItem:copyUrl', 'menuItem:share:qq', 'menuItem:share:weiboApp', 'menuItem:favorite', 'menuItem:share:facebook', 'menuItem:share:QZone', 'menuItem:originPage', 'menuItem:openWithQQBrowser', 'menuItem:openWithSafari', 'menuItem:share:email', 'menuItem:share:brand', 'menuItem:editTag'] // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3 }) } // const shareData = { // title: '凯歌健康券', // imgUrl: 'http://www.icaremgt.com/img/logo_03.png', // desc: '致力于各个服务机构与用户', // link: removeUrlParam('code') // } // initWXShare(shareData) }) }) } export const initWXShare = (shareData) => { wx.onMenuShareAppMessage({ title: shareData.title, // 分享标题 desc: shareData.desc, // 分享描述 link: shareData.link, // 分享链接 imgUrl: shareData.imgUrl, // 分享图标 type: 'link', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }) wx.onMenuShareTimeline({ title: shareData.title, // 分享标题 desc: shareData.desc, // 分享描述 link: shareData.link, // 分享链接 imgUrl: shareData.imgUrl, // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }) }