shareIOU.vue
2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<template>
<v-layout id="shareIOU" column justify-center align-center>
<v-card id="mainBlock" flat>
<div>分享本页面给微信好友或朋友圈</div>
<div>或者</div>
<div>让让对方扫一扫二维码</div>
<div class="qr" v-html="img">
</div>
</v-card>
</v-layout>
</template>
<script>
export default {
async asyncData({store, query, app, redirect, route}) {
console.log(route)
let {data} = await app.$axios.get(`/iou/shareInfo?id=${query.id}&userId=${store.state.user.id}`)
if (data.success) {
return {img: data.img, url: data.url}
} else {
store.dispatch('displayMessage', data.msg)
redirect(301, '/')
}
},
data: () => ({
info:{},
ticket: {}
}),
computed: {
userInfo() {
return this.$store.state.user
}
},
async mounted() {
const u = navigator.userAgent
console.log(u)
const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
console.log(isiOS)
let {data} = await this.$axios.post(`/wechatTicket`, {
userId: this.$store.state.user.id,
href: isiOS ? this.$store.state.firstUrl : window.location.href
})
if (data.success) {
window.wx.config({
debug: true,
appId: data.config.appId, // 必填,公众号的唯一标识
timestamp: data.config.timestamp, // 必填,生成签名的时间戳
nonceStr: data.config.nonceStr, // 必填,生成签名的随机串
signature: data.config.signature,// 必填,签名
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表
})
const shareConfig = {
title: `${this.userInfo.name}邀请您确认借条`, // 分享标题
link: `https://www.51liuliang.cc/netiou/shareRedirect?id=${this.$route.query.id}`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: this.userInfo.headimgurl, // 分享图标
success: function () {},
cancel: function () {}
}
window.wx.ready(() => {
window.wx.onMenuShareTimeline(shareConfig)
window.wx.onMenuShareAppMessage(shareConfig)
})
window.wx.error(function(res){
console.log(res)
})
}
},
}
</script>
<style lang="scss" scoped>
#shareIOU {
#mainBlock {
width: 100vw;
background-color: transparent;
text-align: center;
font-size: 1.3rem;
font-weight: bold;
.qr {
width: 60%;
background-color: #fff;
margin: 1rem 20%;
svg {
vertical-align: bottom;
}
}
}
}
</style>