App.vue
3.4 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<script>
import common from '@/utils/common.js'
import http from '@/utils/http.js'
import app_config from '@/utils/app.js'
import loginHelper from '@/utils/loginHelper.js'
import {
transformImageCodeToUri
} from "@/utils/image_utils.js";
export default {
data() {
return {
common,
timer: null
}
},
onLaunch: async function() {
console.log('App Launch')
// #ifdef APP-PLUS
plus.screen.lockOrientation("portrait-primary") //关闭横屏
var code = common.getChannelCode();
app_config.app_info.PromoterId = code;
console.log(app_config.app_info.PromoterId);
// #endif
//获取导航栏高度
uni.getSystemInfo({
success: (e) => {
// #ifdef APP-PLUS
if (e.statusBarHeight === 0) {
common.statusBarH = 33
} else {
common.statusBarH = e.statusBarHeight
}
// #endif
// #ifdef H5
common.statusBarH = 10
// #endif
// #ifdef MP-WEIXIN
common.statusBarH = e.statusBarHeight + 20
// #endif
// if (e.platform === 'android' || e.platform === 'ios') {
// common.customBarH = e.statusBarHeight + 55
// } else {
// common.customBarH = e.statusBarHeight + 50
// }
}
})
//获取配置
// let local_ic = await uni.getStorageSync('info_config_key')
// if (local_ic.length > 0) {
// common.info_config = JSON.parse(local_ic)
// }
// console.debug('---0000------', common.info_config)
// let ic_res = await http.gql({
// query: 'query{info_config}'
// })
// let info_config = ic_res.data.info_config
// if (info_config) {
// common.info_config = info_config
// await uni.setStorageSync('info_config_key', JSON.stringify(info_config))
// console.log(common.info_config);
// } else {
// console.debug('---获取后台配置失败---')
// }
},
onShow: function() {
console.log('App Show')
// 检查当前上网环境
uni.getNetworkType({
complete: function(res) {
if (res.networkType == "none") {
setTimeout(() => {
uni.showToast({
icon: "none",
title: "网络异常,请检查网络设置!",
duration: 2000,
position: "bottom",
});
}, 200);
}
},
});
this.antoLogin();
this.timer = setInterval(this.antoLogin, 9 * 60 * 1000)
},
onHide: function() {
console.log('App Hide')
clearInterval(this.timer)
},
methods: {
async antoLogin() {
var appToken = loginHelper.getAppToken() || ""
console.log("antoLogin " + JSON.stringify(appToken))
if (appToken) {
var mac_code = uni.getSystemInfoSync().deviceId
var time = new Date().getTime() + ""
let query_data = `mutation{
ydn_auto_login(token:${JSON.stringify(appToken)},mac_code:${JSON.stringify(mac_code)},t:${JSON.stringify(time)})
}`;
console.log(query_data)
let result = await http.gql({
query: query_data
})
console.log(result)
if (result && result.data && result.data.ydn_auto_login) {
if (!result.data.ydn_auto_login.Error) {
result.data.ydn_auto_login.Result.FaceImageCode = transformImageCodeToUri(result.data
.ydn_auto_login.Result
.FaceImageCode);
loginHelper.login(result.data.ydn_auto_login
.Result,result.data.ydn_auto_login.AppToken)
} else {
loginHelper.logout()
}
}
} else {
loginHelper.logout()
}
}
}
}
</script>
<style>
/*每个页面公共css */
</style>