blob: 9ed2cc60bf5c3ad955239453eebc44d869a24f36 [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<script>
2 export default {
3 globalData: {
guangchao.xuc43cf972021-01-18 13:37:55 +08004 msg: {},
guangchao.xu6cdd45e2021-04-16 17:44:30 +08005 verno:'',
6 vername:'',
7 version:''
guangchao.xu070005a2020-12-07 09:56:40 +08008 },
9 onLaunch() {
10 let that = this
guangchao.xuc43cf972021-01-18 13:37:55 +080011
guangchao.xu50e42382021-01-04 17:53:47 +080012 //获取平台信息
guangchao.xu070005a2020-12-07 09:56:40 +080013 uni.getSystemInfo({
14 success(res) {
15 uni.setStorageSync('platform', res.platform)
16 }
17 })
guangchao.xu070005a2020-12-07 09:56:40 +080018 // #ifdef APP-PLUS
guangchao.xuc43cf972021-01-18 13:37:55 +080019
guangchao.xu070005a2020-12-07 09:56:40 +080020 //获取版本号
21 let v = plus.runtime.version
22 let c = plus.runtime.versionCode
23 let version = v + '(' + c + ')'
24 that.globalData.version = version
guangchao.xuc43cf972021-01-18 13:37:55 +080025 that.globalData.vername = v
26 that.globalData.verno = c
guangchao.xu070005a2020-12-07 09:56:40 +080027
guangchao.xu50e42382021-01-04 17:53:47 +080028 //获取设备uuid
guangchao.xu070005a2020-12-07 09:56:40 +080029 plus.device.getInfo({
30 success(res) {
31 let uuid = res.uuid
32 that.globalData.clientid = uuid
33 }
34 })
35
36 //锁定屏幕
37 plus.screen.lockOrientation("portrait-primary")
38
39 //引入插件
40 const KJJPush = uni.requireNativePlugin('KJ-JPush');
41 //设置应用角标,android只支持华为手机 或者使用 plus.runtime.setBadgeNumber(0);
42 KJJPush.setApplicationIconBadgeNumber(0);
43
44 let platform = uni.getStorageSync('platform')
45 if (platform == 'ios') {
46 //ios重置极光推送服务器的角标
47 KJJPush.ios_resetJPushBadge();
48 }
49
50 //清除所有通知消息
51 KJJPush.clearAllNotifications();
52 //判断用户(应用设置界面)是否允许接收通知
53 KJJPush.isNotificationEnabled(result => {
54 var str = JSON.stringify(result);
55 // '0'未开启通知 '1'已开启
56 if (str == '0') {
57 uni.showModal({
58 title: '提示',
59 content: '您还未开启通知,可能无法获取推送消息,是否现在去开启?',
60 success: function(res) {
61 if (res.confirm) {
62 KJJPush.openSettingsForNotification();
63 }
64 }
65 });
66 }
67 });
68
guangchao.xu6cdd45e2021-04-16 17:44:30 +080069 let uid = uni.getStorageSync("userid")
guangchao.xu070005a2020-12-07 09:56:40 +080070 //设置Alias
71 KJJPush.setAlias(uid ? uid : 'tourist', 1, result => {
guangchao.xu6cdd45e2021-04-16 17:44:30 +080072 console.log("setAlias:" + JSON.stringify(result));
guangchao.xu070005a2020-12-07 09:56:40 +080073 });
74
75 //监听推送打开通知,(前台、后台、ios app完全退出)都可以监听
76 KJJPush.addNotifyMessageOpened(result => {
guangchao.xu070005a2020-12-07 09:56:40 +080077 console.log(result)
guangchao.xu070005a2020-12-07 09:56:40 +080078 });
guangchao.xu070005a2020-12-07 09:56:40 +080079 // #endif
80
81 //判断token是否过期
82 let token = uni.getStorageSync("token")
83 //let isFirstTimeEnterApp = uni.getStorageSync("isFirstTimeEnterApp")
84 //console.log(token)
85 //console.log("isFirstTimeEnterApp",isFirstTimeEnterApp)
86 if (!token) {
87 //if (isFirstTimeEnterApp) { //判断是否第一次进入App 先入引导页
88 uni.reLaunch({
guangchao.xu6cdd45e2021-04-16 17:44:30 +080089 url: "/pages/sub_basic/login"
guangchao.xu070005a2020-12-07 09:56:40 +080090 })
91 //}
92 } else {
93 let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
94 let curRoute = ''
guangchao.xuc43cf972021-01-18 13:37:55 +080095 if (routes.length != 0) {
guangchao.xu070005a2020-12-07 09:56:40 +080096 curRoute = routes[routes.length - 1].route //获取当前页面路由
97 }
98 //console.log(routes)
99 that.$u.post("/v1/infor", {}).then((res) => {
100 if (res.token) {
101 uni.setStorageSync("token", res.token)
102 }
guangchao.xuc43cf972021-01-18 13:37:55 +0800103 if (curRoute != 'pages/sub_tabbar/index') {
104 let hands = uni.getStorageSync("hands")
105 if (hands) {
106 uni.setStorageSync("login", 2)
107 uni.reLaunch({
guangchao.xu6cdd45e2021-04-16 17:44:30 +0800108 url: "/pages/sub_mine/lock"
guangchao.xuc43cf972021-01-18 13:37:55 +0800109 })
110 } else {
111 uni.switchTab({
112 url: "/pages/sub_tabbar/index"
113 })
114 }
guangchao.xu070005a2020-12-07 09:56:40 +0800115 }
guangchao.xuc43cf972021-01-18 13:37:55 +0800116
guangchao.xu070005a2020-12-07 09:56:40 +0800117 }).catch(res => {
guangchao.xuc43cf972021-01-18 13:37:55 +0800118 uni.setStorageSync('token', '')
guangchao.xu6cdd45e2021-04-16 17:44:30 +0800119 if (routes.length != 0 || curRoute != 'pages/sub_basic/login') {
guangchao.xu070005a2020-12-07 09:56:40 +0800120 uni.reLaunch({
guangchao.xu6cdd45e2021-04-16 17:44:30 +0800121 url: "/pages/sub_basic/login"
guangchao.xu070005a2020-12-07 09:56:40 +0800122 })
123 }
guangchao.xuc43cf972021-01-18 13:37:55 +0800124
guangchao.xu070005a2020-12-07 09:56:40 +0800125 })
126 }
guangchao.xuc43cf972021-01-18 13:37:55 +0800127
guangchao.xu070005a2020-12-07 09:56:40 +0800128 uni.onNetworkStatusChange(function(res) {
129 if (res.networkType == '4g') {
130 uni.showToast({
131 title: "您已切换至4g网络,请注意流量使用情况",
132 icon: "none",
133 duration: 1500
134 })
135 } else if (res.networkType == 'wifi') {
136 uni.showToast({
137 title: "您已切换至wifi网络",
138 icon: "none",
139 duration: 1500
140 })
141 } else
142 if (!res.isConnected || res.networkType == '2g' || res.networkType == 'none') {
143 let routes = getCurrentPages()
144 let curRoute = routes[routes.length - 1].route
guangchao.xu6cdd45e2021-04-16 17:44:30 +0800145 if (curRoute == 'pages/sub_basic/login' || curRoute == 'pages/sub_basic/register' || curRoute ==
146 'pages/sub_basic/forgetPwd') {
147 uni.showToast({
148 title:'暂无可用网络。请开启网络',
149 icon:'none'
150 })
guangchao.xu070005a2020-12-07 09:56:40 +0800151 } else {
152 uni.navigateTo({
guangchao.xu6cdd45e2021-04-16 17:44:30 +0800153 url: "/pages/sub_basic/network"
guangchao.xu070005a2020-12-07 09:56:40 +0800154 })
155 }
156 }
157 });
158 },
guangchao.xuc43cf972021-01-18 13:37:55 +0800159 onShow() {
guangchao.xu070005a2020-12-07 09:56:40 +0800160
guangchao.xuc43cf972021-01-18 13:37:55 +0800161 }
guangchao.xu070005a2020-12-07 09:56:40 +0800162 }
163</script>
164
165<style lang="scss">
166 /* #ifndef APP-NVUE */
167 @import "uview-ui/index.scss";
168 @import "/static/css/iconfont.css";
169
170 /*覆盖文本编辑器里面的图片的大小*/
171 uni-rich-text {
172 img {
173 max-width: 100% !important;
174 }
175 }
176
177 .status_bar {
178 height: var(--status-bar-height);
179 width: 100%;
180 }
181
182 page {
183 background-color: #F3F3F3;
184 }
185
186 /* #endif */
187
188
189
190 /*每个页面公共css */
191</style>