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