Browse Source

首页分享

feature/feature-compatible
fengchengzhi 7 years ago
parent
commit
51e0f1516b
2 changed files with 46 additions and 21 deletions
  1. 49
      src/models/wxShare.js
  2. 18
      src/view/home.vue

49
src/models/wxShare.js

@ -2,13 +2,41 @@
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'
//微信分享功能 //微信分享功能
Vue.prototype.wxShareL = function(link) {
var wxconfigApi = 'http://1hjz.3ncto.com.cn/mall/web/share/config';
axios.get(wxconfigApi).then(function(response) {
//Vue.prototype.wxShareL = function(link,params) {
//// homeApi.getGoods(params).then(res => {})
//// getGoods : (params) =>
//// utilsModel
//// .config(homeApi.getGoods)
//// .request({
//// params : params,
//// }),
// var getNews = function(params) =>
// utilsModel
// .config({
// method: 'GET',
// url: '/mall/web/share/config',
// })
// .request({
// params : params,
// })
// getNews(params).then(res => {
// console.log(res)
// })
//}
Vue.prototype.wxShare = function(params) {
//var params = params || {}
var wxconfigApi = 'http://192.168.40.82:8808/mall/web/share/config';
console.log(params)
// /mall/web/share/config?merchantNo=2&source=0 //首页
// /mall/web/share/config?merchantNo=2&source=1
// /mall/web/share/config?couponNO=2&source=1
axios.get(wxconfigApi,{params:params}).then(function(response) {
var response = response var response = response
var jsApiSignConfig = response.data.data.jsApiSignConfig var jsApiSignConfig = response.data.data.jsApiSignConfig
var shareConfig = response.data.data.shareConfig var shareConfig = response.data.data.shareConfig
@ -24,6 +52,7 @@ Vue.prototype.wxShareL = function(link) {
console.log('jsApiSignConfig',jsApiSignConfig) console.log('jsApiSignConfig',jsApiSignConfig)
console.log('shareConfig',shareConfig) console.log('shareConfig',shareConfig)
wx.ready(() => { wx.ready(() => {
//获取“分享给朋友”按钮点击状态及自定义分享内容接口 //获取“分享给朋友”按钮点击状态及自定义分享内容接口
wx.onMenuShareAppMessage({ // 分享给朋友 wx.onMenuShareAppMessage({ // 分享给朋友
@ -40,14 +69,4 @@ Vue.prototype.wxShareL = function(link) {
console.log(error); console.log(error);
}); });
// wx.ready(() => {
// var imgUrl = 'http://www.yihaojiazheng.cn/mall/web/share/config'
// wx.onMenuShareAppMessage({ // 分享给朋友
// title: title, // 分享标题
// desc: desc, // 分享描述
// link: link, // 分享链接 默认以当前链接
// imgUrl: imgUrl, // 分享图标
// })
// })
} }

18
src/view/home.vue

@ -107,28 +107,31 @@
watch: { watch: {
$route(to,from){ $route(to,from){
this.getdefaultAddress() this.getdefaultAddress()
},
defaultCity (val,old){
// console.log(this.merchantNo)
this.wxShare({"merchantNo":this.merchantNo,"source":0,"url":encodeURIComponent(location.href)})
} }
}, },
computed: { computed: {
}, },
created() { created() {
// this.wxShare()
this.wxShareL()
}, },
methods: { methods: {
//
getName (){ getName (){
let arr = this.addressValue[2].split('&') || '' let arr = this.addressValue[2].split('&') || ''
this.districtId = arr[0] this.districtId = arr[0]
this.merchantNo = arr[2] this.merchantNo = arr[2]
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)
}, },
getCityName (){ getCityName (){
let name = localStorage.getItem("cityName")||'' let name = localStorage.getItem("cityName")||''
// console.log(name)
if(!name){ if(!name){
this.merchantNo = 2 this.merchantNo = 2
return return
@ -200,11 +203,14 @@
}, },
// //
getdefaultAddress (){ getdefaultAddress (){
let StorageData = localStorage.getItem("cityName")||''
homeApi.getdefaultAddress().then(res => { homeApi.getdefaultAddress().then(res => {
// console.log('',res) // console.log('',res)
if ( res.code == 0 ){ if ( res.code == 0 ){
if ( !res.data ){ if ( !res.data ){
this.show = true
if ( !StorageData ){
this.show = true
}
this.merchantNo = 2 this.merchantNo = 2
} else { } else {
this.defaultCity = res.data.districtName || '' this.defaultCity = res.data.districtName || ''
@ -227,7 +233,7 @@
// //
this.getdefaultAddress() this.getdefaultAddress()
this.getAddress() this.getAddress()
this.wxShare({"merchantNo":this.merchantNo,"source":0,"url":encodeURIComponent(location.href)})
}, },
destroyed () { destroyed () {

Loading…
Cancel
Save