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: {}, |
guangchao.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 5 | verno:'', |
| 6 | vername:'', |
| 7 | version:'' |
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 | |
| 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.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 69 | let uid = uni.getStorageSync("userid") |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 70 | //设置Alias |
| 71 | KJJPush.setAlias(uid ? uid : 'tourist', 1, result => { |
guangchao.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 72 | console.log("setAlias:" + JSON.stringify(result)); |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 73 | }); |
| 74 | |
| 75 | //监听推送打开通知,(前台、后台、ios app完全退出)都可以监听 |
| 76 | KJJPush.addNotifyMessageOpened(result => { |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 77 | console.log(result) |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 78 | }); |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 79 | // #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.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 89 | url: "/pages/sub_basic/login" |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 90 | }) |
| 91 | //} |
| 92 | } else { |
| 93 | let routes = getCurrentPages(); // 获取当前打开过的页面路由数组 |
| 94 | let curRoute = '' |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 95 | if (routes.length != 0) { |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 96 | 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.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 103 | if (curRoute != 'pages/sub_tabbar/index') { |
| 104 | let hands = uni.getStorageSync("hands") |
| 105 | if (hands) { |
| 106 | uni.setStorageSync("login", 2) |
| 107 | uni.reLaunch({ |
guangchao.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 108 | url: "/pages/sub_mine/lock" |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 109 | }) |
| 110 | } else { |
| 111 | uni.switchTab({ |
| 112 | url: "/pages/sub_tabbar/index" |
| 113 | }) |
| 114 | } |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 115 | } |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 116 | |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 117 | }).catch(res => { |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 118 | uni.setStorageSync('token', '') |
guangchao.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 119 | if (routes.length != 0 || curRoute != 'pages/sub_basic/login') { |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 120 | uni.reLaunch({ |
guangchao.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 121 | url: "/pages/sub_basic/login" |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 122 | }) |
| 123 | } |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 124 | |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 125 | }) |
| 126 | } |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 127 | |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 128 | 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.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 145 | 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.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 151 | } else { |
| 152 | uni.navigateTo({ |
guangchao.xu | 6cdd45e | 2021-04-16 17:44:30 +0800 | [diff] [blame] | 153 | url: "/pages/sub_basic/network" |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 154 | }) |
| 155 | } |
| 156 | } |
| 157 | }); |
| 158 | }, |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 159 | onShow() { |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 160 | |
guangchao.xu | c43cf97 | 2021-01-18 13:37:55 +0800 | [diff] [blame] | 161 | } |
guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame] | 162 | } |
| 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> |