oa-base/App.vue

81 lines
1.6 KiB
Vue
Raw Normal View History

2024-06-18 07:55:32 +00:00
<script>
2024-12-04 08:33:24 +00:00
2024-10-28 07:31:46 +00:00
export default {
data() {
return {
// 上一次网络状态
lastNetworkStatus: null
}
},
methods: {
// 判断是否是第一次安装APP并且打开
2024-12-04 08:33:24 +00:00
isFirstOpen() {
2024-10-28 07:31:46 +00:00
let isFirstOpen = uni.getStorageSync('isFirstOpen')
if (!isFirstOpen) {
uni.setStorageSync('isFirstOpen', true)
return true
}
return false
2024-06-18 07:55:32 +00:00
},
2024-10-28 07:31:46 +00:00
networkStatusChange(res) {
2024-12-04 08:33:24 +00:00
console.log(res)
2024-10-28 07:31:46 +00:00
if (res.isConnected) {
// 如果是第一次安装进入,并且网络状态为有网络,则跳转到主页
if (this.isFirstOpen()) {
uni.redirectTo({
url: '/pages/index/index'
})
}
// 如果上一次网络状态为无网络,且当前网络状态为有网络,则跳转到首页
if (this.lastNetworkStatus === false) {
uni.showModal({
title: "提示",
content: "当前设备网络发生更改,是否刷新页面?",
2024-12-17 06:06:42 +00:00
showCancel: true,
2024-10-28 07:31:46 +00:00
success: function (res) {
2024-12-17 06:06:42 +00:00
if (res.confirm || res.cancel) {
2024-10-28 07:31:46 +00:00
uni.redirectTo({
url: '/pages/index/index'
})
}
},
});
}
} else {
uni.redirectTo({
url: '/pages/networko/index'
})
}
this.lastNetworkStatus = res.isConnected
}
},
onLaunch: function () {
2024-12-04 08:33:24 +00:00
console.log('onLaunch')
2024-10-28 07:31:46 +00:00
},
onShow: function () {
uni.onNetworkStatusChange(this.networkStatusChange);
uni.getNetworkType({
success: (res) => {
if (res.networkType === 'none') {
uni.redirectTo({
url: '/pages/networko/index'
})
2024-07-09 10:55:32 +00:00
}
2024-10-28 07:31:46 +00:00
}
})
2024-12-04 08:33:24 +00:00
2024-10-28 07:31:46 +00:00
},
onHide: function () {
2024-07-09 09:36:30 +00:00
uni.offNetworkStatusChange(this.networkStatusChange)
2024-06-18 07:55:32 +00:00
}
2024-10-28 07:31:46 +00:00
}
2024-04-11 06:31:44 +00:00
</script>
<style>
2024-10-28 07:31:46 +00:00
/*每个页面公共css */
2024-04-11 06:31:44 +00:00
</style>