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