|
@@ -5,19 +5,17 @@ import Vue from 'vue'
|
|
|
import {WechatPlugin} from 'vux'
|
|
|
Vue.use(WechatPlugin);
|
|
|
|
|
|
-class WechatShare
|
|
|
-{
|
|
|
- constructor(data,surl)
|
|
|
- {
|
|
|
+class WechatShare {
|
|
|
+ constructor(data, surl) {
|
|
|
let sign_url = encodeURIComponent(surl.split('#')[0]);
|
|
|
let host = window.location.protocol + '//' + window.location.host;
|
|
|
- let url = host+"/mobile/index.php?act=mshop&op=signurl&client_type=ajax&sign_url="+sign_url+"&callback=";
|
|
|
+ alert(sign_url);
|
|
|
+ let url = host + "/mobile/index.php?act=mshop&op=signurl&client_type=ajax&sign_url=" + sign_url + "&callback=";
|
|
|
|
|
|
let pThis = this;
|
|
|
- this.getJSONP(url, function (res)
|
|
|
- {
|
|
|
- if(res.code !== 200) {
|
|
|
- alert(res.message);
|
|
|
+ this.getJSONP(url, function (res) {
|
|
|
+ if (res.code !== 200) {
|
|
|
+ // alert(res.message);
|
|
|
return;
|
|
|
}
|
|
|
let sign = res.datas;
|
|
@@ -25,9 +23,8 @@ class WechatShare
|
|
|
nonceStr = sign.noncestr,
|
|
|
signature = sign.signature,
|
|
|
appid = sign.appid;
|
|
|
-
|
|
|
Vue.wechat.config({
|
|
|
- debug: false,
|
|
|
+ debug: true,
|
|
|
appId: appid,
|
|
|
timestamp: timestamp,
|
|
|
nonceStr: nonceStr,
|
|
@@ -49,8 +46,7 @@ class WechatShare
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- getJSONP(url, callback)
|
|
|
- {
|
|
|
+ getJSONP(url, callback) {
|
|
|
let cn = "callback" + (+new Date()),
|
|
|
s = document.createElement("script");
|
|
|
s.type = "text/javascript";
|
|
@@ -59,8 +55,7 @@ class WechatShare
|
|
|
let heads = document.head || document.getElementsByTagName('head')[0];
|
|
|
let sp = heads.appendChild(s);
|
|
|
|
|
|
- setTimeout(function ()
|
|
|
- { //利用计时器 变成异步
|
|
|
+ setTimeout(function () { //利用计时器 变成异步
|
|
|
window[cn] = function (data) {
|
|
|
try {
|
|
|
s.onload = s.onreadystatechange = function () {
|
|
@@ -81,10 +76,8 @@ class WechatShare
|
|
|
}, 0);
|
|
|
}
|
|
|
|
|
|
- register(data)
|
|
|
- {
|
|
|
- Vue.wechat.ready(function ()
|
|
|
- {
|
|
|
+ register(data) {
|
|
|
+ Vue.wechat.ready(function () {
|
|
|
//分享朋友圈 / 2.2 监听“分享到朋友圈”按钮点击、自定义分享内容及分享结果接口
|
|
|
Vue.wechat.onMenuShareTimeline({
|
|
|
title: data.title, // 分享标
|
|
@@ -118,8 +111,8 @@ class WechatShare
|
|
|
});
|
|
|
})
|
|
|
}
|
|
|
- unregister()
|
|
|
- {
|
|
|
+
|
|
|
+ unregister() {
|
|
|
}
|
|
|
}
|
|
|
|