This commit is contained in:
2025-09-09 14:43:04 +08:00
parent c191002cc6
commit 6ab8f89770
14 changed files with 722 additions and 1731 deletions
+6 -23
View File
@@ -155,38 +155,21 @@ export const saveProfileData = (profileData) => {
/**
* 清理登录流程中的临时数据
* @deprecated 使用 http/utils/auth-helper.js 中的 clearTempLoginData 替代
*/
export const clearTempLoginData = () => {
// 清理临时数据,保留重要的用户信息
uni.removeStorageSync(STORAGE_KEYS.WX_LOGIN_CODE)
console.log('清理临时登录数据')
const { clearTempLoginData } = require('../http/utils/auth-helper.js')
clearTempLoginData()
}
/**
* 检查并验证token有效性
* @returns {Promise<boolean>} token是否有效
* @deprecated 使用 http/utils/auth-helper.js 中的 validateToken 替代
*/
export const validateToken = async () => {
const token = uni.getStorageSync(STORAGE_KEYS.TOKEN)
if (!token) {
return false
}
try {
// 调用一个简单的API来验证token
const { getUserInfo } = await import('@/http/api/profile.js')
await getUserInfo({
custom: {
loading: false,
toast: false
}
})
return true
} catch (error) {
console.log('Token验证失败:', error)
return false
}
const { validateToken } = await import('../http/utils/auth-helper.js')
return await validateToken()
}
/**
+9 -17
View File
@@ -188,38 +188,30 @@ export class WechatAuth {
/**
* 清除所有登录信息
* @deprecated 使用 http/utils/auth-helper.js 中的 clearAuthData 替代
*/
static clearLoginInfo() {
try {
uni.removeStorageSync(HTTP_CONFIG.storageKeys.token)
uni.removeStorageSync(HTTP_CONFIG.storageKeys.refreshToken)
uni.removeStorageSync(HTTP_CONFIG.storageKeys.userInfo)
console.log('登录信息清除成功')
} catch (error) {
console.error('清除登录信息失败:', error)
}
const { clearAuthData } = require('../http/utils/auth-helper.js')
clearAuthData()
}
/**
* 跳转到登录页面
* @deprecated 使用 http/utils/auth-helper.js 中的 navigateToLogin 替代
*/
static navigateToLogin() {
uni.reLaunch({
url: HTTP_CONFIG.loginPage
})
const { navigateToLogin } = require('../http/utils/auth-helper.js')
navigateToLogin()
}
/**
* 检查登录状态并处理
* @returns {boolean} 是否已登录
* @deprecated 使用 http/utils/auth-helper.js 中的 checkLoginStatus 替代
*/
static checkLoginStatus() {
if (!this.isLoggedIn()) {
console.log('用户未登录,跳转到登录页')
this.navigateToLogin()
return false
}
return true
const { checkLoginStatus } = require('../http/utils/auth-helper.js')
return checkLoginStatus()
}
/**