-
Notifications
You must be signed in to change notification settings - Fork 149
/
App.vue
59 lines (57 loc) · 1.45 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
<script>
/* 本项目为开源项目,作者微信:zheng593446899,如有问题可联系*/
import { login, inviteTrack } from "./request"
export default {
onLaunch: async function(e) {
console.log(e)
console.log('App Launch');
var openid = uni.getStorageSync('openid');
if (openid) {
this.globalData.openid = openid;
this.inviteTrack(e.query.openid, openid, e.query.id)
} else {
// 登录
const [loginError, loginRes] = await uni.login();
// 发送 res.code 到后台换取 openId, sessionKey, unionId
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)
}
},
onShow: function() {
console.log('App Show');
},
onHide: function() {
console.log('App Hide');
},
globalData: {
openid: '',
},
methods: {
shareConfig(){
var messages = [
{
title: '送你个性微信红包封面,发红包时可用',
path: '/pages/index/index?openid=' + this.globalData.openid,
},
];
return messages[Math.floor(Math.random()*messages.length)];
},
//邀请上报
inviteTrack(inviteOpenid, openid, id){
if(inviteOpenid && openid && inviteOpenid != openid){
console.log(inviteOpenid, openid)
inviteTrack({
inviteOpenid,
openid,
id,
})
}
},
}
};
</script>
<style>
/*每个页面公共css */
</style>