diff --git a/src/models/wxShare-model.js b/src/models/wxShare-model.js new file mode 100644 index 0000000..10ea5c6 --- /dev/null +++ b/src/models/wxShare-model.js @@ -0,0 +1,12 @@ + +import utilsModel from './utils-model' +import wxShareApi from '../api/wxShare' + +export default { + getShare : (params) => + utilsModel + .config(wxShareApi.getShare) + .request({ + params : params, + }), +} \ No newline at end of file diff --git a/src/models/wxShare.js b/src/models/wxShare.js index abee7cf..e1e9a42 100644 --- a/src/models/wxShare.js +++ b/src/models/wxShare.js @@ -2,30 +2,20 @@ import Vue from 'vue' import wx from 'weixin-js-sdk' import axios from 'axios' -import utilsModel from './utils-model' -import wxShareApi from '../api/wxShare' +import wxShareModel from "../models/wxShare-model.js"; +import homeApi from "../models/home-model.js"; //微信分享功能 -//Vue.prototype.wxShareL = function(link,params) { -//// homeApi.getGoods(params).then(res => {}) -//// getGoods : (params) => -//// utilsModel -//// .config(homeApi.getGoods) -//// .request({ -//// params : params, -//// }), -// -//} - Vue.prototype.wxShare = function(params) { - var wxconfigApi = 'http://1hjz.3ncto.com.cn/mall/web/share/config'; - axios.get(wxconfigApi,{params:params}).then(function(response) { - - var response = response - console.log('1111',response) - var jsApiSignConfig = response.data.data.jsApiSignConfig - var shareConfig = response.data.data.shareConfig + var params = params || {} + wxShareModel.getShare(params).then(response => { + console.log(response) + if ( response.code != 0 ){ + return; + } + var jsApiSignConfig = response.data.jsApiSignConfig + var shareConfig = response.data.shareConfig wx.config({ debug: false, // 开启调试模式,开发时可以开启 @@ -85,13 +75,85 @@ Vue.prototype.wxShare = function(params) { } }); }) - - - - }) - .catch(function(error) { - console.log(error); - }); -} \ No newline at end of file +} + + +//Vue.prototype.wxShares = function(params) { +// var wxconfigApi = 'http://1hjz.3ncto.com.cn/mall/web/share/config'; +// axios.get(wxconfigApi,{params:params}).then(function(response) { +// +// var response = response +// console.log('1111',response) +// var jsApiSignConfig = response.data.data.jsApiSignConfig +// var shareConfig = response.data.data.shareConfig +// +// 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, // 分享链接 默认以当前链接 +// imgUrl: shareConfig.img, // 分享图标 +// success: function(res){ +// } +// }) +// //转发到朋友圈 +// wx.onMenuShareTimeline({ +// title: shareConfig.title, // 分享标题 +// desc: shareConfig.desc, // 分享描述 +// link: shareConfig.url, // 分享链接 默认以当前链接 +// imgUrl: shareConfig.img, // 分享图标 +// success: function(res){ +// } +// }); +// //微信分享qq +// wx.onMenuShareQQ({ +// title: shareConfig.title, // 分享标题 +// desc: shareConfig.desc, // 分享描述 +// link: shareConfig.url, // 分享链接 默认以当前链接 +// imgUrl: shareConfig.img, // 分享图标 +// success: function(res){ +// } +// }); +// +// //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 +// wx.onMenuShareWeibo({ +// title: shareConfig.title, // 分享标题 +// desc: shareConfig.desc, // 分享描述 +// link: shareConfig.url, // 分享链接 默认以当前链接 +// imgUrl: shareConfig.img, // 分享图标 +// success: function(res){ +// } +// }); +// +// //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口(即将废弃) +// wx.onMenuShareQZone({ +// title: shareConfig.title, // 分享标题 +// desc: shareConfig.desc, // 分享描述 +// link: shareConfig.url, // 分享链接 默认以当前链接 +// imgUrl: shareConfig.img, // 分享图标 +// success: function(res){ +// } +// }); +// }) +// +// +// +// +// }) +// .catch(function(error) { +// console.log(error); +// }); +// +//} \ No newline at end of file diff --git a/src/view/home.vue b/src/view/home.vue index 9698a75..1e4578d 100644 --- a/src/view/home.vue +++ b/src/view/home.vue @@ -76,8 +76,8 @@ return { show: false, defaultCity: '天河区', - merchantNo: '', //商户编号 - districtId: '', //区id + merchantNo: 2, //商户编号 + districtId: '440106000', //区id addressData: [], addressValue: [], bannerImgList:[], //轮播图 @@ -108,18 +108,12 @@ $route(to,from){ this.getdefaultAddress() }, - defaultCity (val,old){ - this.ShareWenXin() - } +// defaultCity (val,old){ +// this.ShareWenXin() +// } }, - computed: { - - }, - created() { - - }, methods: { - //获取城市名称 + //监听地区选择的完成按钮 getName (){ let arr = this.addressValue[2].split('&') || '' this.districtId = arr[0] @@ -127,21 +121,26 @@ this.getGoodsList() //加载商品列表 this.defaultCity = arr[1] this.show = false - localStorage.setItem('cityName',this.addressValue) + localStorage.setItem('cityName',this.addressValue) + this.ShareWenXin() }, + //获取本地存储上的地区信息 getCityName (){ let name = localStorage.getItem("cityName")||'' if(!name){ - this.merchantNo = 2 return } + //440000000&广东省,440100000&广州市,440106000&天河区&2 + console.log(name) let arr = name.split(',') this.addressValue = arr let cityNameArr = arr[2].split('&') - let cityName = cityNameArr[1] - this.defaultCity = cityName + //let cityName = cityNameArr[1] + this.districtId = cityNameArr[0] + this.defaultCity = cityNameArr[1] this.merchantNo = cityNameArr[2] }, + //获取城市名称 change (name) { this.addressValue = name }, @@ -202,36 +201,32 @@ }, //获取默认地址信息 getdefaultAddress (){ - let StorageData = localStorage.getItem("cityName")||'' + homeApi.getdefaultAddress().then(res => { - // console.log('默认地址信息',res) if ( res.code == 0 ){ + //如果获取的信息不存在 将从本地存储上拿 if ( !res.data ){ - if ( !StorageData ){ - this.show = true - } - this.merchantNo = 2 + this.show = true + this.getCityName () } else { - this.defaultCity = res.data.districtName || '' - this.districtId = res.data.districtId || '' - this.merchantNo = res.data.merchantNo || 2 + this.defaultCity = res.data.districtName + this.districtId = res.data.districtId + this.merchantNo = res.data.merchantNo this.addressValue = [] this.addressValue.push(res.data.provinceId) this.addressValue.push(res.data.cityId) this.addressValue.push(res.data.districtId) + localStorage.setItem('cityName',this.addressValue) } } else { this.$vux.toast.text(res.msg,"middle"); } this.getGoodsList() - this.getCityName () + }); }, ShareWenXin (){ var merchantNo = this.merchantNo - if ( !merchantNo ){ - merchantNo = 2 - } this.wxShare({"merchantNo":merchantNo,"source":0,"url":encodeURIComponent(location.href)}) } }, @@ -239,6 +234,7 @@ //异步加载 this.getdefaultAddress() this.getAddress() + this.ShareWenXin() }, destroyed () { diff --git a/src/view/month-card.vue b/src/view/month-card.vue index f347efa..6aa6db3 100644 --- a/src/view/month-card.vue +++ b/src/view/month-card.vue @@ -124,7 +124,8 @@ console.log(result.msg); } }); - + + }, // 立即使用优惠券 @@ -184,10 +185,9 @@ } }, mounted() { - // 初始化 this.handleInit(); - + this.wxShare({"couponNo":this.batchNo,"source":20,"url":encodeURIComponent(location.href)}) } } diff --git a/src/view/poster.vue b/src/view/poster.vue index d9ff9be..e999a85 100644 --- a/src/view/poster.vue +++ b/src/view/poster.vue @@ -244,11 +244,11 @@ var sourceType = this.getParam("sourceType") var merchantNo = this.getParam("merchantNo") if ( sourceType == 2 ){ //指定优惠券 - this.wxShare({"couponNo":coupon,"source":1,"url":encodeURIComponent(location.href)}) + this.wxShare({"couponNo":coupon,"source":10,"url":encodeURIComponent(location.href)}) } else if( sourceType == 1) { //通过商户默认推荐 - this.wxShare({"merchantNo":merchantNo,"source":1,"url":encodeURIComponent(location.href)}) + this.wxShare({"merchantNo":merchantNo,"source":10,"url":encodeURIComponent(location.href)}) } else { - this.wxShare({"merchantNo":this.merchantNo,"source":1,"url":encodeURIComponent(location.href)}) + this.wxShare({"merchantNo":this.merchantNo,"source":10,"url":encodeURIComponent(location.href)}) } }