74 lines
1.5 KiB
Vue
74 lines
1.5 KiB
Vue
<script>
|
|
export default {
|
|
onLaunch: function() {
|
|
console.log('App Launch')
|
|
this.checkNetworkStatus()
|
|
|
|
},
|
|
onShow: function() {
|
|
console.log('App Show')
|
|
this.checkNetworkStatus()
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
},
|
|
methods: {
|
|
// 检查网络状态
|
|
checkNetworkStatus() {
|
|
uni.getNetworkType({
|
|
success: (res) => {
|
|
console.log('网络类型:', res.networkType)
|
|
if (res.networkType === 'none') {
|
|
uni.showModal({
|
|
title: '网络连接失败',
|
|
content: '请检查您的网络连接后重试',
|
|
showCancel: false,
|
|
confirmText: '知道了'
|
|
})
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
console.error('获取网络状态失败:', err)
|
|
}
|
|
})
|
|
|
|
// 监听网络状态变化
|
|
uni.onNetworkStatusChange((res) => {
|
|
console.log('网络状态变化:', res)
|
|
if (!res.isConnected) {
|
|
uni.showToast({
|
|
title: '网络连接已断开',
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: '网络连接已恢复',
|
|
icon: 'success',
|
|
duration: 2000
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
/*每个页面公共css */
|
|
@import '@/uni_modules/uni-scss/index.scss';
|
|
/* #ifndef APP-NVUE */
|
|
@import '@/static/customicons.css';
|
|
// 设置整个项目的背景色
|
|
page {
|
|
background-color: #f5f5f5;
|
|
}
|
|
|
|
/* #endif */
|
|
.example-info {
|
|
font-size: 14px;
|
|
color: #333;
|
|
padding: 10px;
|
|
}
|
|
</style>
|