feat: 完成对接接口

This commit is contained in:
ccnetcore
2025-06-22 19:09:13 +08:00
parent 6459d7c024
commit 06617de984
19 changed files with 143 additions and 96 deletions

View File

@@ -2,7 +2,7 @@ import type { ChatMessageVo, GetChatListParams, SendDTO } from './types';
import { get, post } from '@/utils/request';
// 发送消息
export const send = (data: SendDTO) => post<null>('/prod-api/ai-chat/send', data);
export const send = (data: SendDTO) => post<null>('/ai-chat/send', data);
// export const send = (data: SendDTO) => post<null>('/chat/send', data);
// 新增对应会话聊天记录
@@ -13,5 +13,5 @@ export function addChat(data: ChatMessageVo) {
// 获取当前会话的聊天记录
export function getChatList(params: GetChatListParams) {
// return get<ChatMessageVo[]>('/system/message/list', params);
return get<ChatMessageVo[]>('/prod-api/message', params);
return get<ChatMessageVo[]>('/message', params);
}

View File

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

View File

@@ -9,21 +9,21 @@ import { del, get, post, put } from '@/utils/request';
// 获取会话列表
export function get_session_list(params: GetSessionListParams) {
// return get<ChatSessionVo[]>('/system/session/list', params);
return get<ChatSessionVo[]>('/prod-api/session', params);
return get<ChatSessionVo[]>('/session', params);
}
// 创建会话
export function create_session(data: CreateSessionDTO) {
return post('/prod-api/session', data);
return post('/session', data);
}
// 更新会话
export function update_session(data: ChatSessionVo) {
return put('/prod-api/session', data);
return put(`/session/${data.id}`, data);
}
// 会话详情
export function get_session(id: string) {
return get<ChatSessionVo>(`/prod-api/session/${id}`);
return get<ChatSessionVo>(`/session/${id}`);
}
// 删除会话
export function delete_session(ids: string[]) {
return del(`/prod-api/session/${ids}`);
return del(`/session/${ids[0]}`);
}

View File

@@ -28,11 +28,11 @@ export interface GetSessionListParams {
/**
* 当前页数
*/
pageNum?: number;
skipCount?: number;
/**
* 分页大小
*/
pageSize?: number;
maxResultCount?: number;
/**
* 请求参数
*/

View File

@@ -2,5 +2,5 @@ import { get } from '@/utils/request';
// 获取用户信息
export function getUserInfo() {
return get<any>('/prod-api/ai-chat/account');
return get<any>('/ai-chat/account');
}

View File

@@ -128,7 +128,7 @@ function handleThirdPartyLogin() {
<div class="left-section">
<div class="logo-wrap">
<img :src="logoPng" class="logo-img">
<span class="logo-text">YiXin-Ai</span>
<span class="logo-text">意心-Ai</span>
</div>
<div class="ad-banner">
<SvgIcon name="p-bangong" class-name="animate-up-down" />

View File

@@ -108,6 +108,7 @@ function handleDataChunk(chunk: AnyObject) {
// 另一种思考中形式content中有 <think></think> 的格式
// 一开始匹配到 <think> 开始,匹配到 </think> 结束,并处理标签中的内容为思考内容
console.log(chunk.choices,"chunk.choices")
const parsedChunk = chunk.choices?.[0].delta.content;
if (parsedChunk) {
const thinkStart = parsedChunk.includes('<think>');

View File

@@ -56,8 +56,8 @@ export const useChatStore = defineStore('chat', () => {
sessionId,
userId: userStore.userInfo?.userId as number,
});
if (res.rows) {
setChatMap(sessionId, res.rows);
if (res.data.items) {
setChatMap(sessionId, res.data.items);
}
}
catch (error) {

View File

@@ -60,16 +60,15 @@ export const useSessionStore = defineStore('session', () => {
try {
const params: GetSessionListParams = {
userId: userStore.userInfo?.userId as number,
pageNum: page,
pageSize: pageSize.value,
skipCount: page,
maxResultCount: pageSize.value,
isAsc: 'desc',
orderByColumn: 'createTime',
};
const resArr = await get_session_list(params);
// 预处理会话分组 并添加前缀图标
const res = processSessions(resArr.rows);
const res = processSessions(resArr.data.items);
const allSessions = new Map(sessionList.value.map(item => [item.id, item])); // 现有所有数据
res.forEach(item => allSessions.set(item.id, { ...item })); // 更新/添加数据
@@ -126,7 +125,7 @@ export const useSessionStore = defineStore('session', () => {
// msg: "操作成功",
// data: "1935711019560206338"
// };
console.log('create_session---res--',res)
console.log('create_session---res--', res);
// 创建会话后立刻查询列表会话
// 1. 先找到被修改会话在 sessionList 中的索引(假设 sessionList 是按服务端排序的完整列表)
const targetIndex = sessionList.value.findIndex(session => session.id === `${res.data}`);
@@ -138,13 +137,12 @@ export const useSessionStore = defineStore('session', () => {
// 3. 刷新目标页数据
await requestSessionList(targetPage, true);
// 并将当前勾选信息设置为新增的会话信息
const newSessionRes = await get_session(`${res.data}`);
const newSessionRes = await get_session(`${res.data.id}`);
setCurrentSession(newSessionRes.data);
// 跳转聊天页
router.replace({
name: 'chatWithId',
params: { id: `${res.data}` },
params: { id: `${res.data.id}` },
});
}
catch (error) {
@@ -180,6 +178,7 @@ export const useSessionStore = defineStore('session', () => {
// 删除会话(供组件调用)
const deleteSessions = async (ids: string[]) => {
try {
//todo cc这里删除返回空的body结果炸了报错堆栈都没有
await delete_session(ids);
// 1. 先找到被修改会话在 sessionList 中的索引(假设 sessionList 是按服务端排序的完整列表)
const targetIndex = sessionList.value.findIndex(session => session.id === ids[0]);

View File

@@ -11,6 +11,7 @@ interface BaseResponse<T = any> {
data: T;
msg: string;
}
// 扩展请求函数类型声明
declare module 'hook-fetch' {
interface HookFetchDefaults {
@@ -19,8 +20,7 @@ declare module 'hook-fetch' {
}
}
export const request = hookFetch.create<BaseResponse>({
// baseURL: import.meta.env.VITE_API_URL,
baseURL: '', // 留空或使用'/'
baseURL: import.meta.env.VITE_WEB_BASE_API,
headers: {
'Content-Type': 'application/json',
},
@@ -33,7 +33,6 @@ export const request = hookFetch.create<BaseResponse>({
if (typeof response.result?.code === 'number') {
return response;
}
// 非标准格式 → 包装为标准格式
return {
...response,