-
Notifications
You must be signed in to change notification settings - Fork 14
/
App.vue
101 lines (97 loc) · 2.76 KB
/
App.vue
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
93
94
95
96
97
98
99
100
101
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
</style>
<script>
import { login, inviteTrack } from "./request"
export default {
onLaunch: async function(e) {
console.log(e)
console.log('App Launch');
var openid = uni.getStorageSync('openid');
this.globalData.inviteOpenid = e.query.openid;
if (openid) {
console.log('获取到本地openid')
this.globalData.openid = openid;
this.inviteTrack(e.query.openid, openid, e.query.id, false);
} else {
// 登录
console.log('登录')
const [loginError, loginRes] = await uni.login();
console.log(loginError, loginRes)
// 发送 res.code 到后台换取 openId, sessionKey, unionId
if (loginRes && loginRes.code){
const res = await login({code: loginRes.code})
this.globalData.openid = res.result.data.user.openid;
uni.setStorageSync('openid', res.result.data.user.openid);
this.inviteTrack(e.query.openid, this.globalData.openid, e.query.id, false);
}else{
console.log('登录失败')
}
}
},
onShow: function() {
console.log('App Show');
},
onHide: function() {
console.log('App Hide');
},
globalData: {
api: {
login: 'https://3e08f5fc-25d1-41dc-9dab-418a7fb3e2dd.bspapp.com/http/api/login',
cover: 'https://3e08f5fc-25d1-41dc-9dab-418a7fb3e2dd.bspapp.com/http/api/cover',
coverDetail: 'https://3e08f5fc-25d1-41dc-9dab-418a7fb3e2dd.bspapp.com/http/api/cover/detail',
lookVideo: 'https://3e08f5fc-25d1-41dc-9dab-418a7fb3e2dd.bspapp.com/http/api/look/video',
inviteTrack: 'https://3e08f5fc-25d1-41dc-9dab-418a7fb3e2dd.bspapp.com/http/api/invite/track',
},
openid: '',
inviteOpenid:'',
inviteStatus: null,
},
methods: {
shareConfig(){
var messages = [
{
title: '送你个性微信红包封面,发红包时可用',
path: '/pages/index/index?openid=' + this.globalData.openid,
},
];
return messages[Math.floor(Math.random()*messages.length)];
},
shareTimelineConfig(){
var messages = [
{
title: '送你个性微信红包封面,发红包时可用',
query: 'openid=' + this.globalData.openid,
path: '/pages/index/index'
},
];
return messages[Math.floor(Math.random()*messages.length)];
},
//邀请上报
inviteTrack(inviteOpenid, openid, id, adinvite){
console.log('邀请上报')
console.log(inviteOpenid, openid)
if(inviteOpenid && openid && inviteOpenid != openid){
wx.request({
url: this.globalData.api.inviteTrack,
method: "POST",
data: {
inviteOpenid,
openid,
id,
adinvite,
},
success: (res) => {
console.log(res)
this.globalData.inviteStatus = res.data.data
}
});
}
},
}
};
</script>
<style>
/*每个页面公共css */
</style>