feat: 功能
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
|
||||
import api from '@/api/http'
|
||||
import { setToken, getRefreshToken } from '@/utils/auth'
|
||||
import { API_BASE } from '@/api/config'
|
||||
// 使用公共配置
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
|
||||
const SERVER_BASE = API_BASE.APP_MEMBER
|
||||
|
||||
@@ -191,6 +192,17 @@ export async function resetPasswordBySms(mobile, newPassword, smsCode) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息(C端)
|
||||
* GET /member/user/get
|
||||
*
|
||||
* @returns {Promise<Object>} 用户信息对象
|
||||
*/
|
||||
export async function getUserInfo() {
|
||||
const { data } = await api.get(`${SERVER_BASE}/user/get`)
|
||||
return data || {}
|
||||
}
|
||||
|
||||
/**
|
||||
* “手机+验证码+密码注册”组合流程(基于短信登录即注册 + 设置密码)
|
||||
* 说明:
|
||||
@@ -235,4 +247,5 @@ export default {
|
||||
sendResetPasswordCode,
|
||||
resetPasswordBySms,
|
||||
registerWithMobileCodePassword,
|
||||
getUserInfo,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import request from '@/api/http'
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source'
|
||||
import { getAccessToken } from '@/utils/auth'
|
||||
import { API_BASE } from '@/api/config'
|
||||
// 使用公共配置
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
|
||||
const SERVER_BASE_AI = API_BASE.ADMIN_AI
|
||||
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
import http from '@/api/http'
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source'
|
||||
import { getAuthHeader } from '@/utils/token-manager'
|
||||
import { API_BASE } from '@/api/config'
|
||||
import { getAuthHeader } from '@gold/utils/token-manager'
|
||||
// 使用公共配置和 API 服务创建器
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
import { createApiService } from '@gold/api/services'
|
||||
// 初始化公共 hook 的 API 服务
|
||||
import { setApiService } from '@gold/hooks/web/useVoiceText'
|
||||
|
||||
// 使用本地代理前缀 /tikhub,开发环境通过 Vite 代理到 https://api.tikhub.io
|
||||
const SERVER_BASE = API_BASE.TIKHUB
|
||||
// 注意:API_BASE.TIKHUB 不存在,应该使用 TIKHUB_APP
|
||||
const SERVER_BASE = API_BASE.TIKHUB_APP || API_BASE.TIKHUB || ''
|
||||
|
||||
// 创建公共 API 服务实例
|
||||
const apiService = createApiService({
|
||||
http,
|
||||
getAuthHeader,
|
||||
baseUrl: SERVER_BASE,
|
||||
})
|
||||
|
||||
// 设置全局 API 服务(供 useVoiceText hook 使用)
|
||||
setApiService(apiService)
|
||||
|
||||
export const CommonService = {
|
||||
videoToCharacters(data) {
|
||||
return http.post(`${SERVER_BASE}/videoToCharacters2`, data)
|
||||
return apiService.videoToCharacters(data)
|
||||
},
|
||||
callWorkflow(data) {
|
||||
return http.post(`${SERVER_BASE}/callWorkflow`, data)
|
||||
return apiService.callWorkflow(data)
|
||||
},
|
||||
|
||||
// 流式调用 workflow
|
||||
|
||||
@@ -1,34 +1,14 @@
|
||||
/**
|
||||
* API 基础配置
|
||||
* 统一管理所有 API 的基础 URL
|
||||
*
|
||||
* 注意:此文件已迁移到公共模块 @gold/config/api
|
||||
* 为了保持向后兼容,这里重新导出公共配置
|
||||
* 新代码建议直接使用 @gold/config/api
|
||||
*/
|
||||
|
||||
const BASE_URL = import.meta.env.VITE_BASE_URL || ''
|
||||
// 从公共模块导入
|
||||
export { API_BASE, getApiUrl } from '@gold/config/api'
|
||||
|
||||
/**
|
||||
* API 基础路径配置
|
||||
*/
|
||||
export const API_BASE = {
|
||||
// 会员端 API
|
||||
APP: `${BASE_URL}`,
|
||||
// 具体模块路径
|
||||
ADMIN_AI: `${BASE_URL}/admin-api/ai`,
|
||||
APP_MEMBER: `${BASE_URL}/member`,
|
||||
|
||||
// 特殊路径
|
||||
TIKHUB_APP: `${BASE_URL}/api/tikHup`,
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整的 API 路径
|
||||
* @param {string} module - 模块名称 (如 'ADMIN_AI', 'APP_MEMBER')
|
||||
* @param {string} path - 接口路径 (如 '/chat/conversation/create-my')
|
||||
* @returns {string} 完整的 API URL
|
||||
*/
|
||||
export function getApiUrl(module, path) {
|
||||
const base = API_BASE[module] || API_BASE.ADMIN
|
||||
return `${base}${path.startsWith('/') ? path : '/' + path}`
|
||||
}
|
||||
|
||||
export default API_BASE
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ async function example1() {
|
||||
// ========== 方式二:从具体文件导入(兼容旧代码) ==========
|
||||
import { ChatMessageApi } from '@/api/chat'
|
||||
import { CommonService } from '@/api/common'
|
||||
import { API_BASE } from '@/api/config'
|
||||
// 使用公共配置
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
|
||||
async function example2() {
|
||||
// 原有方式仍然可用
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import { getAuthHeader } from '@/utils/token-manager'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { getAuthHeader, clearAllTokens } from '@gold/utils/token-manager'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
/**
|
||||
* 不需要 token 的接口白名单
|
||||
@@ -57,6 +59,10 @@ http.interceptors.response.use(
|
||||
if (data && typeof data.code === 'number' && (data.code === 0 || data.code === 200)) {
|
||||
return data
|
||||
} else {
|
||||
// code 不为 0 时,检查是否为401
|
||||
if (data && typeof data.code === 'number' && data.code === 401) {
|
||||
handle401Error()
|
||||
}
|
||||
// code 不为 0 时,抛出错误
|
||||
const error = new Error(data?.message || data?.msg || '请求失败')
|
||||
error.code = data?.code
|
||||
@@ -65,11 +71,56 @@ http.interceptors.response.use(
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
// 处理 HTTP 状态码 401
|
||||
if (error.response && error.response.status === 401) {
|
||||
handle401Error()
|
||||
}
|
||||
// 统一错误处理:输出关键信息,便于排查 403 等问题
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* 处理 401 未授权错误
|
||||
* 清空 token 并退出登录
|
||||
*
|
||||
* 注意:使用防抖机制避免多个请求同时401时重复处理
|
||||
*/
|
||||
function handle401Error() {
|
||||
// 避免重复处理(防止多个请求同时401导致多次调用)
|
||||
if (handle401Error.processed) {
|
||||
return
|
||||
}
|
||||
|
||||
handle401Error.processed = true
|
||||
|
||||
// 1. 清空所有 token
|
||||
try {
|
||||
clearAllTokens() // 统一使用 token-manager 的清空函数
|
||||
} catch (e) {
|
||||
console.error('清空 token 失败:', e)
|
||||
}
|
||||
|
||||
// 2. 退出登录状态(清空用户信息)
|
||||
try {
|
||||
const userStore = useUserStore()
|
||||
// logout() 会清空用户信息和本地存储
|
||||
userStore.logout()
|
||||
} catch (e) {
|
||||
console.error('退出登录失败:', e)
|
||||
}
|
||||
|
||||
// 3. 提示用户(延迟显示,避免在清空过程中显示)
|
||||
setTimeout(() => {
|
||||
message.warning('登录已过期,请重新登录', 3)
|
||||
}, 100)
|
||||
|
||||
// 4. 延迟重置标志,避免短时间内重复处理
|
||||
setTimeout(() => {
|
||||
handle401Error.processed = false
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
export default http
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import http from '@/api/http'
|
||||
import { InterfaceType, MethodType, InterfaceUrlMap, ParamType } from './types'
|
||||
import qs from 'qs'
|
||||
import { API_BASE } from '@/api/config'
|
||||
// 使用公共配置
|
||||
import { API_BASE } from '@gold/config/api'
|
||||
|
||||
// 使用本地代理前缀 /tikhub,开发环境通过 Vite 代理到 https://api.tikhub.io
|
||||
const SERVER_TIKHUB = API_BASE.TIKHUB_APP
|
||||
|
||||
Reference in New Issue
Block a user