优化
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
|
||||
import api from '@/api/http'
|
||||
// 直接使用实例(最简单、最可靠)
|
||||
import tokenManager from '@gold/utils/token-manager'
|
||||
// 使用公共配置
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
import router from '@/router'
|
||||
import { getUserInfo,clearUserInfoCache } from './userinfo'
|
||||
|
||||
const SERVER_BASE = API_BASE.APP_MEMBER
|
||||
|
||||
/**
|
||||
* 保存 token 的辅助函数
|
||||
* @param {Object} info - 包含 accessToken 和 refreshToken 的对象
|
||||
* 保存token
|
||||
* @param {Object} info - 包含accessToken和refreshToken的对象
|
||||
*/
|
||||
function saveTokens(info) {
|
||||
if (!info?.accessToken && !info?.refreshToken) {
|
||||
@@ -24,62 +23,50 @@ function saveTokens(info) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清除用户信息缓存
|
||||
*/
|
||||
async function clearUserCache() {
|
||||
function clearUserCache() {
|
||||
try {
|
||||
const { clearUserInfoCache } = await import('@gold/hooks/web/useUserInfo')
|
||||
clearUserInfoCache()
|
||||
} catch (e) {
|
||||
// 清除缓存失败不影响登录流程
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信场景枚举(请与后端配置保持一致)
|
||||
* - MEMBER_LOGIN: 会员短信登录场景
|
||||
* - MEMBER_UPDATE_PASSWORD: 已登录用户修改密码(短信校验)场景
|
||||
* - MEMBER_RESET_PASSWORD: 未登录用户忘记密码重置(短信校验)场景
|
||||
* 如有"注册"独立场景,可在此添加:MEMBER_REGISTER: 13
|
||||
*/
|
||||
// 短信场景枚举
|
||||
export const SMS_SCENE = {
|
||||
MEMBER_LOGIN: 1,
|
||||
MEMBER_UPDATE_PASSWORD: 3,
|
||||
MEMBER_RESET_PASSWORD: 4,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信模板编码常量
|
||||
*/
|
||||
// 短信模板编码
|
||||
export const SMS_TEMPLATE_CODE = {
|
||||
USER_REGISTER: 'muye-user-code',
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号密码登录
|
||||
* POST /member/auth/login
|
||||
*
|
||||
* @param {string} mobile - 手机号(必填)
|
||||
* @param {string} password - 密码(必填,长度 4-16)
|
||||
* @returns {Promise<Object>} data.data: { accessToken, refreshToken, expiresTime, userInfo }
|
||||
* @param {string} mobile - 手机号
|
||||
* @param {string} password - 密码
|
||||
* @returns {Promise<Object>} 登录信息
|
||||
*/
|
||||
export async function loginByPassword(mobile, password) {
|
||||
const { data } = await api.post(`${SERVER_BASE}/auth/login`, { mobile, password })
|
||||
const info = data || {}
|
||||
saveTokens(info)
|
||||
await clearUserCache()
|
||||
clearUserCache()
|
||||
return info
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
* POST /member/auth/send-sms-code
|
||||
*
|
||||
* @param {string} mobile - 手机号(登录/忘记密码等需要;修改密码场景可不传)
|
||||
* @param {number} scene - 短信场景(见 SMS_SCENE)
|
||||
* @param {string} templateCode - 模板编码(可选,如 'muye-user-code')
|
||||
* @returns {Promise<Object>} 后端通用响应结构
|
||||
* @param {string} mobile - 手机号
|
||||
* @param {number} scene - 短信场景
|
||||
* @param {string} templateCode - 模板编码
|
||||
* @returns {Promise<Object>} 响应数据
|
||||
*/
|
||||
export async function sendSmsCode(mobile, scene, templateCode) {
|
||||
const body = { scene }
|
||||
@@ -91,13 +78,11 @@ export async function sendSmsCode(mobile, scene, templateCode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验短信验证码(可选前置校验,一般直接在业务接口 use)
|
||||
* POST /member/auth/validate-sms-code
|
||||
*
|
||||
* @param {string} mobile - 手机号(必填)
|
||||
* @param {string} code - 验证码(必填,4-6 位数字)
|
||||
* @param {number} scene - 短信场景(必填,见 SMS_SCENE)
|
||||
* @returns {Promise<Object>} 后端通用响应结构
|
||||
* 校验短信验证码
|
||||
* @param {string} mobile - 手机号
|
||||
* @param {string} code - 验证码
|
||||
* @param {number} scene - 短信场景
|
||||
* @returns {Promise<Object>} 响应数据
|
||||
*/
|
||||
export async function validateSmsCode(mobile, code, scene) {
|
||||
const { data } = await api.post(`${SERVER_BASE}/auth/validate-sms-code`, { mobile, code, scene })
|
||||
@@ -105,63 +90,52 @@ export async function validateSmsCode(mobile, code, scene) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机+验证码登录(首次即自动注册)
|
||||
* POST /member/auth/sms-login
|
||||
*
|
||||
* @param {string} mobile - 手机号(必填)
|
||||
* @param {string} code - 短信验证码(必填)
|
||||
* @returns {Promise<Object>} data.data: { accessToken, refreshToken, expiresTime, userInfo }
|
||||
* 手机+验证码登录
|
||||
* @param {string} mobile - 手机号
|
||||
* @param {string} code - 短信验证码
|
||||
* @returns {Promise<Object>} 登录信息
|
||||
*/
|
||||
export async function loginBySms(mobile, code) {
|
||||
const { data } = await api.post(`${SERVER_BASE}/auth/sms-login`, { mobile, code })
|
||||
const info = data || {}
|
||||
saveTokens(info)
|
||||
await clearUserCache()
|
||||
clearUserCache()
|
||||
return info
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新令牌
|
||||
* POST /member/auth/refresh-token?refreshToken=xxx
|
||||
*
|
||||
* @returns {Promise<Object>} data.data: { accessToken, refreshToken, expiresTime, userInfo }
|
||||
* @returns {Promise<Object>} 新的token信息
|
||||
*/
|
||||
export async function refreshToken() {
|
||||
const rt = tokenManager.getRefreshToken()
|
||||
if (!rt) throw new Error('缺少 refresh_token')
|
||||
|
||||
const { data } = await api.post(`${SERVER_BASE}/auth/refresh-token`, null, { params: { refreshToken: rt } })
|
||||
|
||||
// 检查业务状态码
|
||||
if (data?.code === 401) {
|
||||
// 401: refreshToken 无效或过期
|
||||
tokenManager.clearTokens()
|
||||
await clearUserCache()
|
||||
router.push('/login')
|
||||
|
||||
const authError = new Error('登录已过期,请重新登录')
|
||||
if (!rt) {
|
||||
const authError = new Error('缺少 refresh_token')
|
||||
authError.code = 401
|
||||
authError.needRelogin = true
|
||||
throw authError
|
||||
}
|
||||
|
||||
if (data?.code !== 0 && data?.code !== 200) {
|
||||
throw new Error(data?.message || data?.msg || '刷新token失败')
|
||||
const { data,code,message } = await api.post(`${SERVER_BASE}/auth/refresh-token`, null, { params: { refreshToken: rt } })
|
||||
|
||||
if (code === 401) {
|
||||
tokenManager.clearTokens()
|
||||
clearUserCache()
|
||||
return router.push('/login')
|
||||
}
|
||||
if (code !== 0 && code !== 200) {
|
||||
throw new Error(message || '刷新token失败')
|
||||
}
|
||||
|
||||
const info = data || {}
|
||||
saveTokens(info)
|
||||
await clearUserCache()
|
||||
clearUserCache()
|
||||
return info
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录态下:发送"修改密码"验证码
|
||||
* - 场景:SMS_SCENE.MEMBER_UPDATE_PASSWORD
|
||||
* - 特性:后端会以当前登录用户的手机号为准,无需传 mobile
|
||||
* POST /member/auth/send-sms-code
|
||||
*
|
||||
* @returns {Promise<Object>} 后端通用响应结构
|
||||
* 发送修改密码验证码
|
||||
* @returns {Promise<Object>} 响应数据
|
||||
*/
|
||||
export async function sendUpdatePasswordCode() {
|
||||
const { data } = await api.post(`${SERVER_BASE}/auth/send-sms-code`, {
|
||||
@@ -171,12 +145,10 @@ export async function sendUpdatePasswordCode() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录态下:通过短信验证码修改密码
|
||||
* PUT /member/user/update-password
|
||||
*
|
||||
* @param {string} newPassword - 新密码(必填,4-16 位)
|
||||
* @param {string} smsCode - 短信验证码(必填,4-6 位数字)
|
||||
* @returns {Promise<Object>} 后端通用响应结构
|
||||
* 通过短信验证码修改密码
|
||||
* @param {string} newPassword - 新密码
|
||||
* @param {string} smsCode - 短信验证码
|
||||
* @returns {Promise<Object>} 响应数据
|
||||
*/
|
||||
export async function updatePasswordBySmsCode(newPassword, smsCode) {
|
||||
const { data } = await api.put(`${SERVER_BASE}/user/update-password`, {
|
||||
@@ -187,12 +159,9 @@ export async function updatePasswordBySmsCode(newPassword, smsCode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 未登录:发送"忘记密码"验证码
|
||||
* - 场景:SMS_SCENE.MEMBER_RESET_PASSWORD
|
||||
* POST /member/auth/send-sms-code
|
||||
*
|
||||
* @param {string} mobile - 手机号(必填)
|
||||
* @returns {Promise<Object>} 后端通用响应结构
|
||||
* 发送重置密码验证码
|
||||
* @param {string} mobile - 手机号
|
||||
* @returns {Promise<Object>} 响应数据
|
||||
*/
|
||||
export async function sendResetPasswordCode(mobile) {
|
||||
const { data } = await api.post(`${SERVER_BASE}/auth/send-sms-code`, {
|
||||
@@ -203,13 +172,11 @@ export async function sendResetPasswordCode(mobile) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 未登录:通过手机验证码重置密码(忘记密码)
|
||||
* PUT /member/user/reset-password
|
||||
*
|
||||
* @param {string} mobile - 手机号(必填)
|
||||
* @param {string} newPassword - 新密码(必填,4-16 位)
|
||||
* @param {string} smsCode - 短信验证码(必填,4-6 位数字)
|
||||
* @returns {Promise<Object>} 后端通用响应结构
|
||||
* 通过手机验证码重置密码
|
||||
* @param {string} mobile - 手机号
|
||||
* @param {string} newPassword - 新密码
|
||||
* @param {string} smsCode - 短信验证码
|
||||
* @returns {Promise<Object>} 响应数据
|
||||
*/
|
||||
export async function resetPasswordBySms(mobile, newPassword, smsCode) {
|
||||
const { data } = await api.put(`${SERVER_BASE}/user/reset-password`, {
|
||||
@@ -221,41 +188,27 @@ export async function resetPasswordBySms(mobile, newPassword, smsCode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息(C端)
|
||||
* GET /member/user/get
|
||||
*
|
||||
* 获取用户信息
|
||||
* @returns {Promise<Object>} 用户信息对象
|
||||
*/
|
||||
export async function getUserInfo() {
|
||||
const { data } = await api.get(`${SERVER_BASE}/user/get`)
|
||||
return data || {}
|
||||
export function getUserInfoAuth() {
|
||||
return getUserInfo()
|
||||
}
|
||||
|
||||
/**
|
||||
* "手机+验证码+密码注册"组合流程(基于短信登录即注册 + 设置密码)
|
||||
* 说明:
|
||||
* - 1) 发送登录场景验证码(可选:若已拿到 code 可跳过)
|
||||
* - 2) 短信登录:首次会自动注册并返回 token
|
||||
* - 3) 登录态下发送"修改密码"验证码
|
||||
* - 4) 用短信验证码设置密码
|
||||
*
|
||||
* @param {string} mobile - 手机号(必填)
|
||||
* @param {string} loginCode - 第一次登录使用的短信验证码(必填)
|
||||
* @param {string} newPassword - 注册后设置的新密码(必填)
|
||||
* @param {string} updatePwdCode - 设置密码用到的短信验证码(必填)
|
||||
* 手机+验证码+密码注册流程
|
||||
* @param {string} mobile - 手机号
|
||||
* @param {string} loginCode - 登录验证码
|
||||
* @param {string} newPassword - 新密码
|
||||
* @param {string} updatePwdCode - 设置密码验证码
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function registerWithMobileCodePassword(mobile, loginCode, newPassword, updatePwdCode) {
|
||||
// 2) 短信登录(首次即注册)
|
||||
await loginBySms(mobile, loginCode)
|
||||
|
||||
// 4) 用短信验证码设置密码
|
||||
await updatePasswordBySmsCode(newPassword, updatePwdCode)
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出一个默认对象,便于统一引入
|
||||
*/
|
||||
// 默认导出
|
||||
export default {
|
||||
SMS_SCENE,
|
||||
SMS_TEMPLATE_CODE,
|
||||
@@ -269,5 +222,5 @@ export default {
|
||||
sendResetPasswordCode,
|
||||
resetPasswordBySms,
|
||||
registerWithMobileCodePassword,
|
||||
getUserInfo,
|
||||
};
|
||||
getUserInfo: getUserInfoAuth,
|
||||
}
|
||||
|
||||
6
frontend/app/web-gold/src/api/bailian.js
Normal file
6
frontend/app/web-gold/src/api/bailian.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import http from './http'
|
||||
import { createBaiLianService } from '@gold/api/services/bailian'
|
||||
|
||||
const defaultService = createBaiLianService(http)
|
||||
|
||||
export default defaultService
|
||||
@@ -1,38 +1,27 @@
|
||||
/**
|
||||
* 应用层 API 服务
|
||||
* 封装应用特定的 API 调用,使用 mono 级别的服务
|
||||
*/
|
||||
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source'
|
||||
// 直接使用实例(最简单、最可靠)
|
||||
import tokenManager from '@gold/utils/token-manager'
|
||||
import { TikHubService } from '@gold/api/services'
|
||||
import BaiLianService from './bailian'
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
|
||||
/**
|
||||
* TikHub API 基础路径
|
||||
*/
|
||||
// 百炼API基础路径
|
||||
const TIKHUB_BASE = API_BASE.TIKHUB_APP || API_BASE.TIKHUB || ''
|
||||
|
||||
/**
|
||||
* 应用层通用服务
|
||||
*/
|
||||
// 应用层通用服务
|
||||
export const CommonService = {
|
||||
/**
|
||||
* 视频转字符(音频转文字)
|
||||
* 直接使用 mono 级别的 TikHub 服务
|
||||
*/
|
||||
videoToCharacters(data) {
|
||||
return TikHubService.videoToCharacters(data)
|
||||
return BaiLianService.videoToCharacters(data)
|
||||
},
|
||||
|
||||
/**
|
||||
* 调用工作流
|
||||
*/
|
||||
callWorkflow(data) {
|
||||
return TikHubService.callWorkflow(data)
|
||||
return BaiLianService.callWorkflow(data)
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 流式调用工作流(SSE)
|
||||
*/
|
||||
@@ -49,7 +38,7 @@ export const CommonService = {
|
||||
|
||||
let retryCount = 0
|
||||
const maxRetries = 0
|
||||
|
||||
|
||||
return fetchEventSource(`${TIKHUB_BASE}/callWorkflow`, {
|
||||
method: 'post',
|
||||
headers: {
|
||||
@@ -81,5 +70,3 @@ export const CommonService = {
|
||||
}
|
||||
|
||||
export default CommonService
|
||||
|
||||
|
||||
|
||||
@@ -1,76 +1,27 @@
|
||||
/**
|
||||
* 应用层 HTTP 客户端
|
||||
* 支持自定义拦截器的可扩展版本
|
||||
* - 提供 createHttpClient 工厂函数
|
||||
* - 业务代码可以创建自己的 http 实例并添加拦截器
|
||||
*/
|
||||
|
||||
import { createClientAxios } from '@gold/api/axios/client'
|
||||
import createClientAxios from '@gold/api/axios/client'
|
||||
import { refreshToken } from '@/api/auth'
|
||||
import router from '@/router'
|
||||
|
||||
/**
|
||||
* 创建应用层 HTTP 客户端实例
|
||||
* 创建HTTP客户端实例
|
||||
* @param {Object} options - 配置选项
|
||||
* @param {Function} options.on401 - 401 错误处理回调
|
||||
* @param {Function} options.on403 - 403 错误处理回调
|
||||
* @returns {AxiosInstance} HTTP 客户端实例
|
||||
* @param {Function} options.on401 - 401错误处理回调
|
||||
* @param {Function} options.on403 - 403错误处理回调
|
||||
* @returns {AxiosInstance} HTTP客户端实例
|
||||
*/
|
||||
export function createHttpClient(options = {}) {
|
||||
const { on401, on403 } = options
|
||||
|
||||
const httpClient = createClientAxios({
|
||||
return createClientAxios({
|
||||
baseURL: '/',
|
||||
timeout: 180000,
|
||||
refreshTokenFn: refreshToken,
|
||||
on401: async (error) => {
|
||||
if (on401) {
|
||||
await on401(error)
|
||||
return
|
||||
}
|
||||
router.push('/login')
|
||||
},
|
||||
on403: (error) => {
|
||||
on403 ? on403(error) : router.push('/login')
|
||||
},
|
||||
on401: on401 || ((error) => router.push('/login')),
|
||||
on403: on403 || ((error) => router.push('/login')),
|
||||
})
|
||||
|
||||
return httpClient
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的 HTTP 客户端实例
|
||||
* 业务代码可以:
|
||||
* 1. 直接使用 http 实例
|
||||
* 2. 调用 createHttpClient() 创建自定义实例
|
||||
* 3. 在自定义实例上添加拦截器
|
||||
*/
|
||||
// 默认HTTP客户端实例
|
||||
const http = createHttpClient()
|
||||
|
||||
export default http
|
||||
|
||||
/**
|
||||
* 使用示例:
|
||||
*
|
||||
* 1. 直接使用默认实例
|
||||
* import http from '@/api/http'
|
||||
* await http.post('/api/data')
|
||||
*
|
||||
* 2. 创建自定义实例并添加拦截器
|
||||
* import { createHttpClient } from '@/api/http'
|
||||
*
|
||||
* const myHttp = createHttpClient()
|
||||
* myHttp.interceptors.request.use((config) => {
|
||||
* config.headers['X-Custom-Header'] = 'value'
|
||||
* return config
|
||||
* })
|
||||
*
|
||||
* 3. 自定义 401 处理
|
||||
* const myHttp = createHttpClient({
|
||||
* on401: (error) => {
|
||||
* console.log('自定义 401 处理')
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
|
||||
|
||||
export default http
|
||||
154
frontend/app/web-gold/src/api/userinfo.js
Normal file
154
frontend/app/web-gold/src/api/userinfo.js
Normal file
@@ -0,0 +1,154 @@
|
||||
import http from './http'
|
||||
import { ref } from 'vue'
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
import tokenManager from '@gold/utils/token-manager'
|
||||
|
||||
// 缓存配置
|
||||
const CACHE_KEY = 'USER_INFO_CACHE'
|
||||
const CACHE_DURATION = 5 * 60 * 1000
|
||||
|
||||
/**
|
||||
* 使用useUserInfo构造用户信息管理
|
||||
* @param {Object} options - 配置选项
|
||||
* @param {string} options.baseUrl - API基础URL
|
||||
* @returns {Object} 包含fetchUserInfo、loading、error、userInfo的对象
|
||||
*/
|
||||
export function useUserInfo(options = {}) {
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const userInfo = ref(null)
|
||||
|
||||
const baseUrl = options.baseUrl || API_BASE.APP_MEMBER
|
||||
const apiUrl = `${baseUrl}/user/get`
|
||||
|
||||
/**
|
||||
* 获取Authorization头
|
||||
* @returns {string}
|
||||
*/
|
||||
const getAuthHeader = () => {
|
||||
const token = tokenManager.getAccessToken()
|
||||
if (token) {
|
||||
return `Bearer ${token}`
|
||||
}
|
||||
|
||||
try {
|
||||
const manualToken = sessionStorage.getItem('DEV_MANUAL_TOKEN')
|
||||
if (manualToken) {
|
||||
return `Bearer ${manualToken}`
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略错误
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的用户信息
|
||||
* @returns {Object|null} 缓存的用户信息或null
|
||||
*/
|
||||
const getCachedUserInfo = () => {
|
||||
try {
|
||||
const cached = sessionStorage.getItem(CACHE_KEY)
|
||||
if (!cached) return null
|
||||
|
||||
const { data, timestamp } = JSON.parse(cached)
|
||||
const now = Date.now()
|
||||
|
||||
if (now - timestamp > CACHE_DURATION) {
|
||||
sessionStorage.removeItem(CACHE_KEY)
|
||||
return null
|
||||
}
|
||||
|
||||
console.log('[UserInfo] 使用本地缓存')
|
||||
return data
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储用户信息到本地
|
||||
* @param {Object} userInfoData - 用户信息
|
||||
*/
|
||||
const setCachedUserInfo = (userInfoData) => {
|
||||
try {
|
||||
const cacheData = {
|
||||
data: userInfoData,
|
||||
timestamp: Date.now()
|
||||
}
|
||||
sessionStorage.setItem(CACHE_KEY, JSON.stringify(cacheData))
|
||||
console.log('[UserInfo] 更新本地缓存')
|
||||
} catch (e) {
|
||||
console.error('缓存用户信息失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @returns {Promise<Object>} 用户信息对象
|
||||
*/
|
||||
const fetchUserInfo = async () => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
const cachedUserInfo = getCachedUserInfo()
|
||||
if (cachedUserInfo) {
|
||||
userInfo.value = cachedUserInfo
|
||||
return cachedUserInfo
|
||||
}
|
||||
|
||||
const authHeader = getAuthHeader()
|
||||
const response = await http.get(apiUrl, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(authHeader && { Authorization: authHeader }),
|
||||
},
|
||||
})
|
||||
|
||||
const data = response.data?.data || response.data
|
||||
if (data) {
|
||||
setCachedUserInfo(data)
|
||||
userInfo.value = data
|
||||
return data
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err
|
||||
console.error('获取用户信息失败:', err)
|
||||
throw err
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
fetchUserInfo,
|
||||
loading,
|
||||
error,
|
||||
userInfo,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 清除用户信息缓存
|
||||
*/
|
||||
export function clearUserInfoCache() {
|
||||
try {
|
||||
sessionStorage.removeItem(CACHE_KEY)
|
||||
console.log('[UserInfo] 清除缓存')
|
||||
} catch (e) {
|
||||
console.error('清除缓存失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接获取用户信息
|
||||
* @param {Object} options - 配置选项
|
||||
* @returns {Promise<Object>} 用户信息对象
|
||||
*/
|
||||
export async function getUserInfo(options = {}) {
|
||||
const hook = useUserInfo(options)
|
||||
return await hook.fetchUserInfo()
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { ref, computed, watch } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getJSON, setJSON, remove } from '@/utils/storage'
|
||||
import tokenManager from '@gold/utils/token-manager'
|
||||
import { getUserInfo, clearUserInfoCache } from '@gold/hooks/web/useUserInfo'
|
||||
import { getUserInfo, clearUserInfoCache } from '@/api/userinfo'
|
||||
|
||||
const STORAGE_KEY = 'user_store_v1'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user