|
@@ -0,0 +1,84 @@
|
|
|
+let isload = false
|
|
|
+let wx = global.wx
|
|
|
+
|
|
|
+function toConfigure () {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ global.$.ajax({
|
|
|
+ url: '//www.4dage.com/wechat/jssdk/share',
|
|
|
+ type: 'get',
|
|
|
+ data: {
|
|
|
+ uri: location.href.split('#')[0],
|
|
|
+ name: '四维开发测试'
|
|
|
+ },
|
|
|
+ dataType: 'jsonp',
|
|
|
+ jsonpCallback: 'success_jsonp',
|
|
|
+ success: function (data, textStatus) {
|
|
|
+ wx.config({
|
|
|
+ debug: false,
|
|
|
+ appId: data.appId,
|
|
|
+ timestamp: data.timestamp,
|
|
|
+ nonceStr: data.nonceStr,
|
|
|
+ signature: data.signature,
|
|
|
+ jsApiList: ['checkJsApi', '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']
|
|
|
+ })
|
|
|
+ resolve()
|
|
|
+ },
|
|
|
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
|
+ reject(new Error('jsonp.error:' + textStatus))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function setup ({ title, link, imgUrl, desc }) {
|
|
|
+ imgUrl = imgUrl.trim()
|
|
|
+ if (!(imgUrl.indexOf('http') === 0)) {
|
|
|
+ if (imgUrl.indexOf('//') === 0) {
|
|
|
+ imgUrl = 'https:' + imgUrl
|
|
|
+ } else {
|
|
|
+ imgUrl = location.origin + imgUrl
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let defaultFn = () => { }
|
|
|
+ let defaultChar = ''
|
|
|
+ wx.onMenuShareTimeline({ title, link, imgUrl, desc })
|
|
|
+ wx.onMenuShareAppMessage({ title, desc, link, imgUrl, type: defaultChar, dataUrl: defaultChar })
|
|
|
+ wx.onMenuShareWeibo({ title, desc, link, imgUrl, success: defaultFn, cancel: defaultFn })
|
|
|
+ wx.onMenuShareQZone({ title, desc, link, imgUrl, success: defaultFn, cancel: defaultFn })
|
|
|
+ wx.onMenuShareQQ({ title, desc, link, imgUrl, success: defaultFn, cancel: defaultFn })
|
|
|
+ wx.error(function (e) { })
|
|
|
+}
|
|
|
+
|
|
|
+export default async (args) => {
|
|
|
+ // 需要引入 https://res.wx.qq.com/open/js/jweixin-1.2.0.js
|
|
|
+ if (typeof wx !== 'undefined') {
|
|
|
+ if (!isload) {
|
|
|
+ await toConfigure()
|
|
|
+ await new Promise(resolve => {
|
|
|
+ wx.ready(function () {
|
|
|
+ isload = true
|
|
|
+ resolve(1)
|
|
|
+ })
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ isload = true
|
|
|
+ resolve()
|
|
|
+ }, 1000)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ setup(args)
|
|
|
+ }
|
|
|
+}
|