OfficeSystem/App.vue
2025-11-19 13:42:44 +08:00

64 lines
1.7 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>