OfficeSystem/App.vue

64 lines
1.7 KiB
Vue
Raw Normal View History

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