1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| import wx from "weixin-js-sdk";
import { request } from '../js/request';
const requestget = new request();
let href; var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { href = encodeURIComponent(window.location.href); } else { href = window.location.href; } requestget.Get({ url: '/getWxConfig', data: { "url": href } }).then((data) => { weixinConfigData = data.data; wx.config({ debug: false, appId: weixinConfigData.appid, timestamp: weixinConfigData.timestamp, nonceStr: weixinConfigData.noncestr, signature: weixinConfigData.signature, jsApiList: [ 'checkJsApi', 'updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'translateVoice', 'startRecord', 'stopRecord', 'onRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard' ] }); }).catch((e) => {
}) }
class wechatShareApi { wxShare(param) { wx.ready(function () { wx.updateAppMessageShareData({ desc: param.descContent, title: param.shareTitle, link: param.lineLink, imgUrl: param.imgUrl, trigger: function (res) { }, success: function (res) {
}, cancel: function (res) { }, fail: function (res) { } });
wx.updateTimelineShareData({ desc: param.descContent, title: param.friendTitle == undefined ? param.shareTitle : param.friendTitle, link: param.lineLink, imgUrl: param.imgUrl, trigger: function (res) { }, success: function (res) {
}, cancel: function (res) { }, fail: function (res) { } });
}); } } export { wechatShareApi }
3.在指定组件中引入公共微信分享方法文件`wechat.js`;就可以调用分享方法 import {wechatShareApi} from "../assets/js/wechat" const weApi = new wechatShareApi();
weApi.wxShare({ shareTitle: "这是微信分享的标题", descContent: "这是微信分享的描述文案", lineLink: location.href, imgUrl: "这是微信分享的图片" })
|