|
@@ -86,6 +86,7 @@ const fetchUserInfo = async () => {
|
|
|
try {
|
|
try {
|
|
|
const token = uni.getStorageSync('token')
|
|
const token = uni.getStorageSync('token')
|
|
|
if (!token) return
|
|
if (!token) return
|
|
|
|
|
+ uni.showLoading({ title: '加载中...' })
|
|
|
const response = await uni.request({
|
|
const response = await uni.request({
|
|
|
url: 'https://wx.baiyun.work/user_info',
|
|
url: 'https://wx.baiyun.work/user_info',
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
@@ -95,8 +96,17 @@ const fetchUserInfo = async () => {
|
|
|
},
|
|
},
|
|
|
data: {}
|
|
data: {}
|
|
|
})
|
|
})
|
|
|
|
|
+ uni.hideLoading()
|
|
|
console.log('User info response:', response)
|
|
console.log('User info response:', response)
|
|
|
const resp = response.data as any
|
|
const resp = response.data as any
|
|
|
|
|
+ if (response.statusCode === 401) {
|
|
|
|
|
+ // Token 无效,清除并跳转登录
|
|
|
|
|
+ uni.removeStorageSync('token')
|
|
|
|
|
+ uni.removeStorageSync('role')
|
|
|
|
|
+ user.value = {}
|
|
|
|
|
+ uni.reLaunch({ url: '/pages/login/login' })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
if (resp && resp.code === 200 && resp.data) {
|
|
if (resp && resp.code === 200 && resp.data) {
|
|
|
user.value = resp.data
|
|
user.value = resp.data
|
|
|
// 保存到本地存储
|
|
// 保存到本地存储
|
|
@@ -107,6 +117,7 @@ const fetchUserInfo = async () => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
|
|
+ uni.hideLoading()
|
|
|
console.error('Fetch user info error:', err)
|
|
console.error('Fetch user info error:', err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|