feat: 前端接口代理

This commit is contained in:
Gsh
2025-06-19 23:45:22 +08:00
parent bc91a8cff2
commit a89e11d132
12 changed files with 133 additions and 7 deletions

View File

@@ -2,7 +2,8 @@ import type { ChatMessageVo, GetChatListParams, SendDTO } from './types';
import { get, post } from '@/utils/request';
// 发送消息
export const send = (data: SendDTO) => post<null>('/chat/send', data);
export const send = (data: SendDTO) => post<null>('/prod-api/ai/send', data);
// export const send = (data: SendDTO) => post<null>('/chat/send', data);
// 新增对应会话聊天记录
export function addChat(data: ChatMessageVo) {

View File

@@ -3,5 +3,6 @@ import { get } from '@/utils/request';
// 获取当前用户的模型列表
export function getModelList() {
return get<GetSessionListVO[]>('/system/model/modelList');
// return get<GetSessionListVO[]>('/system/model/modelList');
return get<GetSessionListVO[]>('/prod-api/ai/model');
}

View File

@@ -49,7 +49,6 @@ router.beforeEach(
// // resetRouter(); // 预留
// return next();
// }
console.log(`to---`,to)
// 4、判断访问页面是否在路由白名单地址[静态路由]中,如果存在直接放行。
if (ROUTER_WHITE_LIST.includes(to.path))
return next();

View File

@@ -18,6 +18,7 @@ export const useModelStore = defineStore('model', () => {
const requestModelList = async () => {
try {
const res = await getModelList();
console.log('res', res);
modelList.value = res.data;
}
catch (error) {

View File

@@ -120,6 +120,13 @@ export const useSessionStore = defineStore('session', () => {
try {
const res = await create_session(data);
// TODO: 模拟请求
// const res = {
// code: 200,
// msg: "操作成功",
// data: "1935711019560206338"
// };
console.log('create_session---res--',res)
// 创建会话后立刻查询列表会话
// 1. 先找到被修改会话在 sessionList 中的索引(假设 sessionList 是按服务端排序的完整列表)
const targetIndex = sessionList.value.findIndex(session => session.id === `${res.data}`);

View File

@@ -12,12 +12,37 @@ interface BaseResponse {
rows: never;
}
// 修改 BaseResponse 类型,使其兼容裸数组
type BaseResponse<T = any> =
| { code: number; data: T; msg: string } // 标准格式
| T[]; // 裸数组格式
export const request = hookFetch.create<BaseResponse, 'data' | 'rows'>({
baseURL: import.meta.env.VITE_API_URL,
// baseURL: import.meta.env.VITE_API_URL,
baseURL: '', // 留空或使用'/'
headers: {
'Content-Type': 'application/json',
},
plugins: [sseTextDecoderPlugin({ json: true, prefix: 'data:' })],
plugins: [
sseTextDecoderPlugin({ json: true, prefix: 'data:' }),
{
name: 'adapt-array-response',
afterResponse: async (response) => {
// 如果是数组格式,手动包裹成 { data: [...] }
if (Array.isArray(response.result)) {
return {
...response,
result: {
code: 200,
msg: 'success',
data: response.result,
},
};
}
return response;
},
},
],
});
function jwtPlugin(): HookFetchPlugin<BaseResponse> {