blob: d9657e6c9b673e1bd9a6cd8d9b96946c32842716 [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<script>
2 export default {
3 globalData: {
4 msg: {}
5 },
6 onLaunch() {
7 let that = this
8 uni.getSystemInfo({
9 success(res) {
10 uni.setStorageSync('platform', res.platform)
11 }
12 })
13 //锁定竖屏
14 // #ifdef APP-PLUS
15
16 //获取版本号
17 let v = plus.runtime.version
18 let c = plus.runtime.versionCode
19 let version = v + '(' + c + ')'
20 that.globalData.version = version
21
22 //获取uuid
23 plus.device.getInfo({
24 success(res) {
25 let uuid = res.uuid
26 that.globalData.clientid = uuid
27 }
28 })
29
30 //锁定屏幕
31 plus.screen.lockOrientation("portrait-primary")
32
33 //引入插件
34 const KJJPush = uni.requireNativePlugin('KJ-JPush');
35 //设置应用角标,android只支持华为手机 或者使用 plus.runtime.setBadgeNumber(0);
36 KJJPush.setApplicationIconBadgeNumber(0);
37
38 let platform = uni.getStorageSync('platform')
39 if (platform == 'ios') {
40 //ios重置极光推送服务器的角标
41 KJJPush.ios_resetJPushBadge();
42 }
43
44 //清除所有通知消息
45 KJJPush.clearAllNotifications();
46 //判断用户(应用设置界面)是否允许接收通知
47 KJJPush.isNotificationEnabled(result => {
48 var str = JSON.stringify(result);
49 // '0'未开启通知 '1'已开启
50 if (str == '0') {
51 uni.showModal({
52 title: '提示',
53 content: '您还未开启通知,可能无法获取推送消息,是否现在去开启?',
54 success: function(res) {
55 if (res.confirm) {
56 KJJPush.openSettingsForNotification();
57 }
58 }
59 });
60 }
61 });
62
63 let uid = uni.getStorageSync("uid")
64 //设置Alias
65 KJJPush.setAlias(uid ? uid : 'tourist', 1, result => {
66 //console.log("setAlias:" + JSON.stringify(result));
67 });
68
69 //监听推送打开通知,(前台、后台、ios app完全退出)都可以监听
70 KJJPush.addNotifyMessageOpened(result => {
71
72 console.log(result)
73 var str = JSON.stringify(result);
74 // uni.showModal({
75 // title: '推送通知测试',
76 // content: str,
77 // success: function(res) {}
78 // });
79 });
80 //监听自定义推送消息
81 KJJPush.addCustomizeNotifyMessage(result => {
82 var str = JSON.stringify(result);
83 // uni.showModal({
84 // title: 'KJ-JPush',
85 // content: str,
86 // showCancel: false,
87 // success: function(res) {}
88 // });
89 });
90 //监听推送消息
91 // KJJPush.addNotifyMessage(result => {
92 // console.log(result)
93 // var str = JSON.stringify(result);
94 // uni.showModal({
95 // title: '推送通知',
96 // content: str,
97 // success: function(res) {
98 // if (res.confirm) {
99 // KJJPush.clearAllNotifications();
100 // KJJPush.ios_resetJPushBadge();
101 // }
102 // }
103 // });
104 // });
105
106 // #endif
107
108 //判断token是否过期
109 let token = uni.getStorageSync("token")
110 //let isFirstTimeEnterApp = uni.getStorageSync("isFirstTimeEnterApp")
111 //console.log(token)
112 //console.log("isFirstTimeEnterApp",isFirstTimeEnterApp)
113 if (!token) {
114 //if (isFirstTimeEnterApp) { //判断是否第一次进入App 先入引导页
115 uni.reLaunch({
116 url: "/pages/sub_basic/login/index"
117 })
118 //}
119 } else {
120 let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
121 let curRoute = ''
122 if(routes.length != 0){
123 curRoute = routes[routes.length - 1].route //获取当前页面路由
124 }
125 //console.log(routes)
126 that.$u.post("/v1/infor", {}).then((res) => {
127 if (res.token) {
128 uni.setStorageSync("token", res.token)
129 }
130 if(curRoute != 'pages/sub_tabbar/index'){
131 uni.switchTab({
132 url: "/pages/sub_tabbar/index"
133 })
134 }
135
136 }).catch(res => {
137 uni.setStorageSync('token','')
138 if(routes.length != 0 || curRoute != 'pages/sub_basic/login/index'){
139 uni.reLaunch({
140 url: "/pages/sub_basic/login/index"
141 })
142 }
143
144 })
145 }
146 uni.onNetworkStatusChange(function(res) {
147 if (res.networkType == '4g') {
148 uni.showToast({
149 title: "您已切换至4g网络,请注意流量使用情况",
150 icon: "none",
151 duration: 1500
152 })
153 } else if (res.networkType == 'wifi') {
154 uni.showToast({
155 title: "您已切换至wifi网络",
156 icon: "none",
157 duration: 1500
158 })
159 } else
160 if (!res.isConnected || res.networkType == '2g' || res.networkType == 'none') {
161 let routes = getCurrentPages()
162 let curRoute = routes[routes.length - 1].route
163 if (curRoute == 'pages/sub_basic/login/index' || curRoute == 'pages/sub_basic/register/index' || curRoute == 'pages/sub_basic/forgetPwd/index') {
164
165 } else {
166 uni.navigateTo({
167 url: "/pages/sub_basic/network/index"
168 })
169 }
170 }
171 });
172 },
173
174 }
175</script>
176
177<style lang="scss">
178 /* #ifndef APP-NVUE */
179 @import "uview-ui/index.scss";
180 @import "/static/css/iconfont.css";
181
182 /*覆盖文本编辑器里面的图片的大小*/
183 uni-rich-text {
184 img {
185 max-width: 100% !important;
186 }
187 }
188
189 .status_bar {
190 height: var(--status-bar-height);
191 width: 100%;
192 }
193
194 page {
195 background-color: #F3F3F3;
196 }
197
198 /* #endif */
199
200
201
202 /*每个页面公共css */
203</style>