|
|
|
@ -16,98 +16,94 @@ export default { |
|
|
|
|
title: '嗨森逛分享', // 分享标题
|
|
|
|
|
link:"", // 分享链接
|
|
|
|
|
imgUrl: 'https://hsg.dctpay.com/filesystem/wxApplets/logo.png', // 分享图标
|
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
resVerifyWx:null, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
//分享
|
|
|
|
|
doShare() { |
|
|
|
|
async doShare() { |
|
|
|
|
|
|
|
|
|
const app = getApp(); |
|
|
|
|
|
|
|
|
|
let that = this;
|
|
|
|
|
// let theUrl = window.location.href;
|
|
|
|
|
that.localPath = window.location.href; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that.shareLink = app.globalData.h5url + '?accountId=0000016&key=&code=' + that.localPath.split('#')[1]; |
|
|
|
|
|
|
|
|
|
that.$set(this.shareH5,"link",that.shareLink) |
|
|
|
|
|
|
|
|
|
console.log(that.shareLink,"that.shareLink"); |
|
|
|
|
let datas = { |
|
|
|
|
url: that.localPath.split('#')[0] |
|
|
|
|
} |
|
|
|
|
/* https://hsg.dctpay.com/hsgH5/index.html?code=081Zb4ml2gamsb4L3nnl2UArrO1Zb4mc&state=1#/physical-merchants/classify/goods-search/goods-search?goodsLabel=%E9%9B%B6%E5%85%83%E8%B4%AD */ |
|
|
|
|
let api = require('../Utils/Api'); |
|
|
|
|
that.resVerifyWx = await api.verifyWx(datas); |
|
|
|
|
console.log(that.resVerifyWx,"doshare"); |
|
|
|
|
that.h5ShareMethod(); |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
//获取当前路由
|
|
|
|
|
getCurrentRouteYm() { |
|
|
|
|
let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
|
|
|
|
|
console.log(currentRoutes[currentRoutes.length - 1]); |
|
|
|
|
let route = currentRoutes[currentRoutes.length - 1]; |
|
|
|
|
return decodeURIComponent(route.$page.fullPath) |
|
|
|
|
}, |
|
|
|
|
h5ShareMethod(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let api = require('../Utils/Api'); |
|
|
|
|
let that = this; |
|
|
|
|
if(!that.resVerifyWx){ |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
let wx = require('weixin-js-sdk'); |
|
|
|
|
api.verifyWx(datas).then(res => { |
|
|
|
|
if (res.return_code == '000000') { |
|
|
|
|
// console.log(that.resVerifyWx,"h5ShareMethod");
|
|
|
|
|
if (that.resVerifyWx.return_code == '000000') { |
|
|
|
|
wx.config({ |
|
|
|
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
|
|
appId: res.return_data.appId, // 必填,公众号的唯一标识
|
|
|
|
|
timestamp: res.return_data.timestamp, // 必填,生成签名的时间戳
|
|
|
|
|
nonceStr: res.return_data.nonceStr, // 必填,生成签名的随机串
|
|
|
|
|
signature: res.return_data.signature, // 必填,签名,见附录1
|
|
|
|
|
appId: that.resVerifyWx.return_data.appId, // 必填,公众号的唯一标识
|
|
|
|
|
timestamp: that.resVerifyWx.return_data.timestamp, // 必填,生成签名的时间戳
|
|
|
|
|
nonceStr: that.resVerifyWx.return_data.nonceStr, // 必填,生成签名的随机串
|
|
|
|
|
signature: that.resVerifyWx.return_data.signature, // 必填,签名,见附录1
|
|
|
|
|
jsApiList: [ |
|
|
|
|
'updateAppMessageShareData', |
|
|
|
|
'updateTimelineShareData', |
|
|
|
|
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后, |
|
|
|
|
config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。 |
|
|
|
|
对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。 */ |
|
|
|
|
wx.ready(function() { //需在用户可能点击分享按钮前就先调用
|
|
|
|
|
|
|
|
|
|
/* 分享给朋友 */ |
|
|
|
|
wx.updateAppMessageShareData(that.shareH5); |
|
|
|
|
|
|
|
|
|
/* 自定义“分享到朋友圈” */ |
|
|
|
|
wx.updateTimelineShareData(that.shareH5); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: res.return_msg, |
|
|
|
|
title: that.resVerifyWx.return_msg, |
|
|
|
|
duration: 2000, |
|
|
|
|
icon: 'none' |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
//获取当前路由
|
|
|
|
|
getCurrentRouteYm() { |
|
|
|
|
let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
|
|
|
|
|
console.log(currentRoutes[currentRoutes.length - 1]); |
|
|
|
|
let route = currentRoutes[currentRoutes.length - 1]; |
|
|
|
|
return decodeURIComponent(route.$page.fullPath) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
onLoad() { |
|
|
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
// #ifdef H5
|
|
|
|
|
this.doShare() |
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
this.doShare(); |
|
|
|
|
}) |
|
|
|
|
// #endif
|
|
|
|
|
}, |
|
|
|
|
onShow(){ |
|
|
|
|
// #ifdef H5
|
|
|
|
|
this.$nextTick(()=>{ |
|
|
|
|
this.h5ShareMethod(); |
|
|
|
|
}) |
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
// onShow(){
|
|
|
|
|
// this.$nextTick(()=>{
|
|
|
|
|
// console.log(this.shareLink,this.shareH5,"this.shareLink---share--onshows")
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
/* 小程序分享 */ |
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
onShareAppMessage(res) { |
|
|
|
|