113 lines
3.0 KiB
Vue
113 lines
3.0 KiB
Vue
<script>
|
||
import config from './config'
|
||
import store from '@/store'
|
||
import { getToken } from '@/utils/auth'
|
||
|
||
export default {
|
||
globalData: {
|
||
config: {}
|
||
},
|
||
onLaunch: function() {
|
||
this.initApp(),
|
||
// 初始化 tabBar 文本
|
||
this.updateTabBarText()
|
||
|
||
// 监听语言变化事件
|
||
uni.$on('languageChanged', () => {
|
||
this.updateTabBarText()
|
||
})
|
||
},
|
||
// onShow: function() {
|
||
// // 检查应用状态,确保从后台恢复时状态一致
|
||
// this.checkAppState()
|
||
// },
|
||
onDestroy() {
|
||
// 移除事件监听器
|
||
uni.$off('languageChanged')
|
||
},
|
||
methods: {
|
||
// 初始化应用
|
||
initApp() {
|
||
// 初始化应用配置
|
||
this.initConfig()
|
||
// 检查用户登录状态
|
||
//#ifdef H5
|
||
this.checkLogin()
|
||
//#endif
|
||
},
|
||
initConfig() {
|
||
this.globalData.config = config
|
||
},
|
||
checkLogin() {
|
||
if (!getToken()) {
|
||
console.log('checkLogin 检查登录状态,token不存在')
|
||
|
||
this.$tab.reLaunch('/pages/login')
|
||
}
|
||
},
|
||
// checkAppState() {
|
||
// // 检查Token状态和页面导航栈状态
|
||
// console.log('应用从后台切换到前台,检查应用状态')
|
||
|
||
// // 获取当前页面路径,判断是否在登录页
|
||
// const pages = getCurrentPages()
|
||
// const currentPage = pages[pages.length - 1]
|
||
// const currentPagePath = currentPage ? currentPage.route : ''
|
||
|
||
// // 如果当前页面是登录页,则不检查token
|
||
// if (currentPagePath === 'pages/login') {
|
||
// console.log('当前已在登录页面,不进行token检查')
|
||
// return
|
||
// }
|
||
|
||
// // 检查Token状态
|
||
// if (!getToken()) {
|
||
// console.log('Token不存在,提示并跳转到登录页')
|
||
// uni.showToast({
|
||
// icon: 'none',
|
||
// title: '登录已过期,请重新登录'
|
||
// })
|
||
// setTimeout(() => {
|
||
// uni.reLaunch({ url: '/pages/login' })
|
||
// }, 1500)
|
||
// } else {
|
||
// console.log('Token存在,不做操作')
|
||
// }
|
||
|
||
|
||
// },
|
||
updateTabBarText() {
|
||
// 使用 nextTick 确保 DOM 更新完成
|
||
this.$nextTick(() => {
|
||
try {
|
||
// 设置工作台 tabBar 项
|
||
uni.setTabBarItem({
|
||
index: 0,
|
||
text: this.$t('tabBar.workbench')
|
||
})
|
||
|
||
// 设置任务 tabBar 项
|
||
uni.setTabBarItem({
|
||
index: 1,
|
||
text: this.$t('tabBar.task')
|
||
})
|
||
|
||
// 设置我的 tabBar 项
|
||
uni.setTabBarItem({
|
||
index: 2,
|
||
text: this.$t('tabBar.mine')
|
||
})
|
||
} catch (error) {
|
||
console.error('更新 tabBar 文本失败:', error)
|
||
}
|
||
})
|
||
}
|
||
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
@import '@/static/scss/index.scss'
|
||
</style>
|