64 lines
1.7 KiB
Vue
64 lines
1.7 KiB
Vue
<script>
|
||
// #ifdef VUE3
|
||
import { initDictData } from '@/utils/dict'
|
||
// #endif
|
||
|
||
export default {
|
||
onLaunch: function() {
|
||
console.log('App Launch')
|
||
|
||
// TODO: 测试用 - 临时设置 token,测试完成后删除此代码
|
||
// #ifdef VUE3
|
||
// 如果还没有 token,则设置一个测试 token
|
||
const token = uni.getStorageSync('token')
|
||
if (!token) {
|
||
const testToken = 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImNkYjJlNjM0LTM5M2MtNDk3MC1iNDQ3LTViNGVmYTQ1NzQwYiJ9.oMAFItV_sRDGWu44EwQqT7K6VP7Bz43n-dm00V2UPOwtN0FtFw_4u9TPa993VDcDM0zxDVI_sxS5cjcKcgl1GA'
|
||
uni.setStorageSync('token', testToken)
|
||
console.log('已设置测试 token:', testToken)
|
||
}
|
||
|
||
// 初始化字典数据
|
||
initDictData().catch(err => {
|
||
console.error('初始化字典数据失败:', err)
|
||
})
|
||
// #endif
|
||
|
||
// 检测初始网络状态
|
||
this.checkNetworkStatus()
|
||
|
||
// 监听网络状态变化
|
||
uni.onNetworkStatusChange((res) => {
|
||
if (res.isConnected === false || res.networkType === 'none') {
|
||
uni.$uv.toast('网络连接不可用,请检查网络设置')
|
||
}
|
||
})
|
||
},
|
||
onShow: function() {
|
||
console.log('App Show')
|
||
// 每次显示时检测网络状态
|
||
this.checkNetworkStatus()
|
||
},
|
||
onHide: function() {
|
||
console.log('App Hide')
|
||
},
|
||
methods: {
|
||
checkNetworkStatus() {
|
||
uni.getNetworkType({
|
||
success: (res) => {
|
||
if (res.networkType === 'none') {
|
||
uni.$uv.toast('网络连接不可用,请检查网络设置')
|
||
}
|
||
},
|
||
fail: (err) => {
|
||
console.error('获取网络状态失败:', err)
|
||
uni.$uv.toast('无法检测网络状态,请检查网络连接')
|
||
}
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
@import '@climblee/uv-ui/index.scss';
|
||
</style> |