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