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