-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.vue
executable file
·81 lines (72 loc) · 2.1 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
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
</style>
<script>
export default {
onLaunch: function() {
console.log('App Launch');
},
onShow: function() {
const self = this
// Deal with page loaded at first time.
// Check login!
let memberToken = uni.getStorageSync(self.$store.state.setting.member_token_key)
if (! memberToken) {
// Close other pages and redirect
uni.redirectTo({
url: '/pages/account/signin'
})
} else {
// Request to check
self.$apiRequest({
url: self.$apiList.accountInfo,
method: 'GET',
header: {
Authorization: `Bearer ${memberToken}`
}
}).then((res) => {
// console.log(res.data);
if (res.code == 0 && res.data) {
// res.data format is {mobile: "13185826384", email: null, name: null}
// Recover store info
self.$store.commit('member/setHasLogin', true)
self.$store.commit('member/setMemberToken', memberToken)
} else {
// clear invalid token
uni.removeStorageSync(self.$store.state.setting.member_token_key)
// redirect
uni.redirectTo({
url: '/pages/account/signin'
})
}
}).catch((err) => {
uni.redirectTo({
url: '/pages/account/signin'
})
})
}
},
onHide: function() {
console.log('App Hide');
}
};
</script>
<style lang="scss">
/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
font-family: uniicons;
src: url('/static/uni.ttf');
}
/* #endif */
body {
background-color: #F1F5F8;
}
button.primary {
background-color: #0faeff;
}
button.warn {
background-color: #FFA200;
}
</style>