fix:修复bug

This commit is contained in:
2025-10-14 19:20:26 +08:00
parent 30e298d9d2
commit 4408673438
21 changed files with 1153 additions and 549 deletions
+13 -15
View File
@@ -56,37 +56,35 @@ export default {
}
},
onShow() {
this.checkLoginStatus()
this.loadUserInfo()
},
methods: {
async loadUserInfo() {
try {
const res = await getUserInfo()
if (res.code === 200) {
if (res.code === 401 || res.code === 40101) {
// 无提示跳转至登录
try {
const pages = getCurrentPages()
const current = pages && pages.length ? pages[pages.length - 1] : null
const route = current && current.route ? ('/' + current.route) : '/pages/index/index'
const query = current && current.options ? Object.keys(current.options).map(k => `${k}=${encodeURIComponent(current.options[k])}`).join('&') : ''
const redirect = encodeURIComponent(query ? `${route}?${query}` : route)
uni.reLaunch({ url: `/pages/login/index?redirect=${redirect}` })
} catch (e) {
uni.reLaunch({ url: '/pages/login/index' })
}
} else if (res.code === 200) {
this.userInfo = res.data
this.isLogin = true
} else {
this.isLogin = false
uni.showToast({
title: '获取用户信息失败',
icon: 'none'
})
}
} catch (error) {
console.error('加载用户信息失败:', error)
this.isLogin = false
}
},
checkLoginStatus() {
const token = uni.getStorageSync('token')
this.isLogin = !!token
if (!this.isLogin) {
uni.redirectTo({
url: '/pages/login/index'
})
}
},
navigateTo(url) {
uni.navigateTo({ url })
},