From a4e47cdf7ba59f14a9f71d8d820a770fe4552790 Mon Sep 17 00:00:00 2001 From: nesxy Date: Wed, 14 Aug 2019 01:57:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E5=BE=AE=E4=BF=A1=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/wxShare.js | 184 +++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 93 deletions(-) diff --git a/src/models/wxShare.js b/src/models/wxShare.js index c4cffe3..8376fbd 100644 --- a/src/models/wxShare.js +++ b/src/models/wxShare.js @@ -5,108 +5,106 @@ import wxShareModel from "../models/wxShare-model.js"; import homeApi from "../models/home-model.js"; //微信分享功能 -Vue.prototype.wxShare = function(params) { - var params = params || {}; +Vue.prototype.wxShare = function (params) { +var params = params || {}; - wxShareModel.getShare(params).then(response => { - if (response.code != 0) { - return; +wxShareModel.getShare(params).then(response => { + if (response.code != 0) { + return; + } + + var jsApiSignConfig = response.response.jsApiSignConfig; + var shareConfig = response.response.shareConfig; + var couponNo = response.response.couponNo + wx.config({ + debug: false, // 开启调试模式,开发时可以开启 + appId: jsApiSignConfig.appId, // 必填,公众号的唯一标识 由接口返回 + timestamp: jsApiSignConfig.timestamp, // 必填,生成签名的时间戳 由接口返回 + nonceStr: jsApiSignConfig.nonceStr, // 必填,生成签名的随机串 由接口返回 + signature: jsApiSignConfig.signature, // 必填,签名 由接口返回 + jsApiList: [ + "onMenuShareAppMessage", + "onMenuShareTimeline", + "onMenuShareQQ", + "onMenuShareWeibo", + "onMenuShareQZone" + ] + }); + var urlParams = ''; + let uuniqueId = this.$cookies.get('1hjz_mall_unique_id') + if (couponNo !== undefined && couponNo !== null && couponNo !== "") { + urlParams = '?batchNo=' + couponNo + } + if (uuniqueId !== undefined && uuniqueId !== null && uuniqueId !== "") { + if (urlParams.length > 0) { + urlParams += '&uniqueId=' + uuniqueId + } else { + urlParams = '?uniqueId=' + uuniqueId } - var jsApiSignConfig = response.response.jsApiSignConfig; - var shareConfig = response.response.shareConfig; - var couponNo = response.response.couponNo - wx.config({ - debug: false, // 开启调试模式,开发时可以开启 - appId: jsApiSignConfig.appId, // 必填,公众号的唯一标识 由接口返回 - timestamp: jsApiSignConfig.timestamp, // 必填,生成签名的时间戳 由接口返回 - nonceStr: jsApiSignConfig.nonceStr, // 必填,生成签名的随机串 由接口返回 - signature: jsApiSignConfig.signature, // 必填,签名 由接口返回 - jsApiList: [ - "onMenuShareAppMessage", - "onMenuShareTimeline", - "onMenuShareQQ", - "onMenuShareWeibo", - "onMenuShareQZone" - ] + } + wx.ready(() => { + //获取“分享给朋友”按钮点击状态及自定义分享内容接口 + wx.onMenuShareAppMessage({ + // 分享给朋友 + title: shareConfig.title, // 分享标题 + desc: shareConfig.desc, // 分享描述 + link: shareConfig.url + urlParams, // 分享链接 默认以当前链接 + imgUrl: shareConfig.img, // 分享图标 + success: function (res) {} + }); + //转发到朋友圈 + wx.onMenuShareTimeline({ + title: shareConfig.title, // 分享标题 + desc: shareConfig.desc, // 分享描述 + link: shareConfig.url + urlParams, // 分享链接 默认以当前链接 + imgUrl: shareConfig.img, // 分享图标 + success: function (res) {} + }); + //微信分享qq + wx.onMenuShareQQ({ + title: shareConfig.title, // 分享标题 + desc: shareConfig.desc, // 分享描述 + link: shareConfig.url + urlParams, // 分享链接 默认以当前链接 + imgUrl: shareConfig.img, // 分享图标 + success: function (res) {} }); - var urlParams = ''; - let uuniqueId = this.$cookies.get('1hjz_mall_unique_id') - if(couponNo !== undefined && couponNo !== null && couponNo !== ""){ - urlParams = '?batchNo='+ couponNo - } - if(uuniqueId !== undefined && uuniqueId !== null && uuniqueId !== ""){ - if(urlParams.length > 0){ - urlParams+='&uniqueId='+ uuniqueId - } else{ - urlParams = '?uniqueId='+ uuniqueId - } - - } - wx.ready(() => { - //获取“分享给朋友”按钮点击状态及自定义分享内容接口 - wx.onMenuShareAppMessage({ - // 分享给朋友 - title: shareConfig.title, // 分享标题 - desc: shareConfig.desc, // 分享描述 - link: shareConfig.url+urlParams, // 分享链接 默认以当前链接 - imgUrl: shareConfig.img, // 分享图标 - success: function(res) { - } - }); - //转发到朋友圈 - wx.onMenuShareTimeline({ - title: shareConfig.title, // 分享标题 - desc: shareConfig.desc, // 分享描述 - link: shareConfig.url+urlParams, // 分享链接 默认以当前链接 - imgUrl: shareConfig.img, // 分享图标 - success: function(res) {} - }); - //微信分享qq - wx.onMenuShareQQ({ - title: shareConfig.title, // 分享标题 - desc: shareConfig.desc, // 分享描述 - link: shareConfig.url+urlParams, // 分享链接 默认以当前链接 - imgUrl: shareConfig.img, // 分享图标 - success: function(res) {} - }); - //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 - wx.onMenuShareWeibo({ - title: shareConfig.title, // 分享标题 - desc: shareConfig.desc, // 分享描述 - link: shareConfig.url+urlParams, // 分享链接 默认以当前链接 - imgUrl: shareConfig.img, // 分享图标 - success: function(res) {} - }); + //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 + wx.onMenuShareWeibo({ + title: shareConfig.title, // 分享标题 + desc: shareConfig.desc, // 分享描述 + link: shareConfig.url + urlParams, // 分享链接 默认以当前链接 + imgUrl: shareConfig.img, // 分享图标 + success: function (res) {} + }); - //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口(即将废弃) - wx.onMenuShareQZone({ - title: shareConfig.title, // 分享标题 - desc: shareConfig.desc, // 分享描述 - link: shareConfig.url+urlParams, // 分享链接 默认以当前链接 - imgUrl: shareConfig.img, // 分享图标 - success: function(res) {} - }); - if (localStorage.getItem("latitude") == null) { - wx.getLocation({ - type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' - success: function(res) { + //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口(即将废弃) + wx.onMenuShareQZone({ + title: shareConfig.title, // 分享标题 + desc: shareConfig.desc, // 分享描述 + link: shareConfig.url + urlParams, // 分享链接 默认以当前链接 + imgUrl: shareConfig.img, // 分享图标 + success: function (res) {} + }); + if (localStorage.getItem("latitude") == null) { + wx.getLocation({ + type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' + success: function (res) { localStorage.setItem("latitude", res.latitude); localStorage.setItem("longitude", res.longitude); - }, - cancel: function() { + }, + cancel: function () { alter("拒绝定位"); - } - }); - } else { - - } - alert("lat:"+localStorage.getItem("latitude")+ ";lng:"+localStorage.getItem("longitude")); - wx.error(function(res) { - console.log("wx-js初始化: " + res); - }); + } }); + } else { + + } + alert("lat:" + localStorage.getItem("latitude") + ";lng:" + localStorage.getItem("longitude")); + wx.error(function (res) { + alter("wx-js初始化: " + res); }); }); -}; \ No newline at end of file +}); +}