Browse Source

分享

feature/feature-compatible
fengchengzhi 7 years ago
parent
commit
ab15b635da
5 changed files with 133 additions and 63 deletions
  1. 12
      src/models/wxShare-model.js
  2. 118
      src/models/wxShare.js
  3. 54
      src/view/home.vue
  4. 6
      src/view/month-card.vue
  5. 6
      src/view/poster.vue

12
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,
}),
}

118
src/models/wxShare.js

@ -2,30 +2,20 @@
import Vue from 'vue' import Vue from 'vue'
import wx from 'weixin-js-sdk' import wx from 'weixin-js-sdk'
import axios from 'axios' 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) { 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({ wx.config({
debug: false, // 开启调试模式,开发时可以开启 debug: false, // 开启调试模式,开发时可以开启
@ -85,13 +75,85 @@ Vue.prototype.wxShare = function(params) {
} }
}); });
}) })
}) })
.catch(function(error) {
console.log(error);
});
}
}
//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);
// });
//
//}

54
src/view/home.vue

@ -76,8 +76,8 @@
return { return {
show: false, show: false,
defaultCity: '天河区', defaultCity: '天河区',
merchantNo: '', //
districtId: '', //id
merchantNo: 2, //
districtId: '440106000', //id
addressData: [], addressData: [],
addressValue: [], addressValue: [],
bannerImgList:[], // bannerImgList:[], //
@ -108,18 +108,12 @@
$route(to,from){ $route(to,from){
this.getdefaultAddress() this.getdefaultAddress()
}, },
defaultCity (val,old){
this.ShareWenXin()
}
// defaultCity (val,old){
// this.ShareWenXin()
// }
}, },
computed: {
},
created() {
},
methods: { methods: {
//
//
getName (){ getName (){
let arr = this.addressValue[2].split('&') || '' let arr = this.addressValue[2].split('&') || ''
this.districtId = arr[0] this.districtId = arr[0]
@ -127,21 +121,26 @@
this.getGoodsList() // this.getGoodsList() //
this.defaultCity = arr[1] this.defaultCity = arr[1]
this.show = false this.show = false
localStorage.setItem('cityName',this.addressValue)
localStorage.setItem('cityName',this.addressValue)
this.ShareWenXin()
}, },
//
getCityName (){ getCityName (){
let name = localStorage.getItem("cityName")||'' let name = localStorage.getItem("cityName")||''
if(!name){ if(!name){
this.merchantNo = 2
return return
} }
//440000000&广,440100000&广,440106000&&2
console.log(name)
let arr = name.split(',') let arr = name.split(',')
this.addressValue = arr this.addressValue = arr
let cityNameArr = arr[2].split('&') 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] this.merchantNo = cityNameArr[2]
}, },
//
change (name) { change (name) {
this.addressValue = name this.addressValue = name
}, },
@ -202,36 +201,32 @@
}, },
// //
getdefaultAddress (){ getdefaultAddress (){
let StorageData = localStorage.getItem("cityName")||''
homeApi.getdefaultAddress().then(res => { homeApi.getdefaultAddress().then(res => {
// console.log('',res)
if ( res.code == 0 ){ if ( res.code == 0 ){
//
if ( !res.data ){ if ( !res.data ){
if ( !StorageData ){
this.show = true
}
this.merchantNo = 2
this.show = true
this.getCityName ()
} else { } 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 = []
this.addressValue.push(res.data.provinceId) this.addressValue.push(res.data.provinceId)
this.addressValue.push(res.data.cityId) this.addressValue.push(res.data.cityId)
this.addressValue.push(res.data.districtId) this.addressValue.push(res.data.districtId)
localStorage.setItem('cityName',this.addressValue)
} }
} else { } else {
this.$vux.toast.text(res.msg,"middle"); this.$vux.toast.text(res.msg,"middle");
} }
this.getGoodsList() this.getGoodsList()
this.getCityName ()
}); });
}, },
ShareWenXin (){ ShareWenXin (){
var merchantNo = this.merchantNo var merchantNo = this.merchantNo
if ( !merchantNo ){
merchantNo = 2
}
this.wxShare({"merchantNo":merchantNo,"source":0,"url":encodeURIComponent(location.href)}) this.wxShare({"merchantNo":merchantNo,"source":0,"url":encodeURIComponent(location.href)})
} }
}, },
@ -239,6 +234,7 @@
// //
this.getdefaultAddress() this.getdefaultAddress()
this.getAddress() this.getAddress()
this.ShareWenXin()
}, },
destroyed () { destroyed () {

6
src/view/month-card.vue

@ -124,7 +124,8 @@
console.log(result.msg); console.log(result.msg);
} }
}); });
}, },
// 使 // 使
@ -184,10 +185,9 @@
} }
}, },
mounted() { mounted() {
// //
this.handleInit(); this.handleInit();
this.wxShare({"couponNo":this.batchNo,"source":20,"url":encodeURIComponent(location.href)})
} }
} }
</script> </script>

6
src/view/poster.vue

@ -244,11 +244,11 @@
var sourceType = this.getParam("sourceType") var sourceType = this.getParam("sourceType")
var merchantNo = this.getParam("merchantNo") var merchantNo = this.getParam("merchantNo")
if ( sourceType == 2 ){ // 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) { // } 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 { } else {
this.wxShare({"merchantNo":this.merchantNo,"source":1,"url":encodeURIComponent(location.href)})
this.wxShare({"merchantNo":this.merchantNo,"source":10,"url":encodeURIComponent(location.href)})
} }
} }

Loading…
Cancel
Save