手持机

This commit is contained in:
张怡蓉
2025-08-20 14:08:19 +08:00
parent 0e9da3259f
commit d4e53370bf
15 changed files with 354 additions and 62 deletions

View File

@@ -4,10 +4,13 @@
import { getToken } from '@/utils/auth'
export default {
globalData: {
config: {}
},
onLaunch: function() {
this.initApp()
},
onShow: function() {
onShow: function() {
// 检查应用状态,确保从后台恢复时状态一致
this.checkAppState()
},
@@ -30,27 +33,36 @@
}
},
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中处理
// 这里不需要重复处理,保留此方法以便未来扩展
}
// 检查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存在,不做操作')
}
}
}
}