62 lines
1.5 KiB
Vue
62 lines
1.5 KiB
Vue
<script>
|
||
import config from './config'
|
||
import store from '@/store'
|
||
import { getToken } from '@/utils/auth'
|
||
|
||
export default {
|
||
onLaunch: function() {
|
||
this.initApp()
|
||
},
|
||
onShow: function() {
|
||
// 检查应用状态,确保从后台恢复时状态一致
|
||
this.checkAppState()
|
||
},
|
||
methods: {
|
||
// 初始化应用
|
||
initApp() {
|
||
// 初始化应用配置
|
||
this.initConfig()
|
||
// 检查用户登录状态
|
||
//#ifdef H5
|
||
this.checkLogin()
|
||
//#endif
|
||
},
|
||
initConfig() {
|
||
this.globalData.config = config
|
||
},
|
||
checkLogin() {
|
||
if (!getToken()) {
|
||
this.$tab.reLaunch('/pages/login')
|
||
}
|
||
},
|
||
checkAppState() {
|
||
|
||
|
||
// 检查Token状态和页面导航栈状态
|
||
console.log('应用从后台切换到前台,检查应用状态')
|
||
// 检查Token状态
|
||
if (!getToken()) {
|
||
console.log('Token不存在,提示并跳转到登录页')
|
||
uni.showToast({
|
||
icon: 'none',
|
||
title: '登录已过期,请重新登录'
|
||
})
|
||
setTimeout(() => {
|
||
uni.reLaunch({ url: loginPage })
|
||
}, 1500)
|
||
} else {
|
||
console.log('Token存在,不做操作')
|
||
}
|
||
|
||
// 注意:应用从后台切换到前台的逻辑已在permission.js中处理
|
||
// 这里不需要重复处理,保留此方法以便未来扩展
|
||
}
|
||
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
@import '@/static/scss/index.scss'
|
||
</style>
|