From 06617de98440af1869cfbf4f4c1ffc37548a4904 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sun, 22 Jun 2025 19:09:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E5=AF=B9=E6=8E=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/SqlSugarRepository.cs | 113 +++++++++++------- .../Dtos/SessionCreateAndUpdateInput.cs | 2 +- .../Services/AiChatService.cs | 32 ++--- .../Entities/SessionAggregateRoot.cs | 2 +- Yi.Ai.Vue3/.env.development | 6 +- Yi.Ai.Vue3/.env.production | 6 +- Yi.Ai.Vue3/src/api/chat/index.ts | 4 +- Yi.Ai.Vue3/src/api/model/index.ts | 2 +- Yi.Ai.Vue3/src/api/session/index.ts | 10 +- Yi.Ai.Vue3/src/api/session/types.ts | 4 +- Yi.Ai.Vue3/src/api/user/index.ts | 2 +- .../src/components/LoginDialog/index.vue | 2 +- .../pages/chat/layouts/chatWithId/index.vue | 1 + Yi.Ai.Vue3/src/stores/modules/chat.ts | 4 +- Yi.Ai.Vue3/src/stores/modules/session.ts | 15 ++- Yi.Ai.Vue3/src/utils/request.ts | 5 +- Yi.Ai.Vue3/types/components.d.ts | 6 + Yi.Ai.Vue3/types/import_meta.d.ts | 1 + Yi.Ai.Vue3/vite.config.ts | 22 +++- 19 files changed, 143 insertions(+), 96 deletions(-) diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs index 7468ee9b..12239daf 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs @@ -15,14 +15,15 @@ using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.SqlSugarCore.Repositories { - public class SqlSugarRepository : ISqlSugarRepository, IRepository where TEntity : class, IEntity, new() + public class SqlSugarRepository : ISqlSugarRepository, IRepository + where TEntity : class, IEntity, new() { public ISqlSugarClient _Db => AsyncContext.Run(async () => await GetDbContextAsync()); public ISugarQueryable _DbQueryable => _Db.Queryable(); private readonly ISugarDbContextProvider _dbContextProvider; - + /// /// 异步查询执行器 /// @@ -58,22 +59,26 @@ namespace Yi.Framework.SqlSugarCore.Repositories #region Abp模块 - public virtual async Task FindAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task FindAsync(Expression> predicate, + bool includeDetails = true, CancellationToken cancellationToken = default) { return await GetFirstAsync(predicate); } - public virtual async Task GetAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task GetAsync(Expression> predicate, + bool includeDetails = true, CancellationToken cancellationToken = default) { return await GetFirstAsync(predicate); } - public virtual async Task DeleteAsync(Expression> predicate, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteAsync(Expression> predicate, bool autoSave = false, + CancellationToken cancellationToken = default) { await this.DeleteAsync(predicate); } - public virtual async Task DeleteDirectAsync(Expression> predicate, CancellationToken cancellationToken = default) + public virtual async Task DeleteDirectAsync(Expression> predicate, + CancellationToken cancellationToken = default) { await this.DeleteAsync(predicate); } @@ -103,60 +108,71 @@ namespace Yi.Framework.SqlSugarCore.Repositories throw new NotImplementedException(); } - public virtual async Task> GetListAsync(Expression> predicate, bool includeDetails = false, CancellationToken cancellationToken = default) + public virtual async Task> GetListAsync(Expression> predicate, + bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetListAsync(predicate); } - public virtual async Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task InsertAsync(TEntity entity, bool autoSave = false, + CancellationToken cancellationToken = default) { return await InsertReturnEntityAsync(entity); } - public virtual async Task InsertManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task InsertManyAsync(IEnumerable entities, bool autoSave = false, + CancellationToken cancellationToken = default) { await InsertRangeAsync(entities.ToList()); } - public virtual async Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task UpdateAsync(TEntity entity, bool autoSave = false, + CancellationToken cancellationToken = default) { await UpdateAsync(entity); return entity; } - public virtual async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, + CancellationToken cancellationToken = default) { await UpdateRangeAsync(entities.ToList()); } - public virtual async Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteAsync(TEntity entity, bool autoSave = false, + CancellationToken cancellationToken = default) { await DeleteAsync(entity); } - public virtual async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, + CancellationToken cancellationToken = default) { await DeleteAsync(entities.ToList()); } - public virtual async Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) + public virtual async Task> GetListAsync(bool includeDetails = false, + CancellationToken cancellationToken = default) { return await GetListAsync(); } public virtual async Task GetCountAsync(CancellationToken cancellationToken = default) { - return await this.CountAsync(_=>true); + return await this.CountAsync(_ => true); } - public virtual async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) + public virtual async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, + bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetPageListAsync(_ => true, skipCount, maxResultCount); } + #endregion #region 内置DB快捷操作 + public virtual async Task> AsDeleteable() { return (await GetDbSimpleClientAsync()).AsDeleteable(); @@ -171,7 +187,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories { return (await GetDbSimpleClientAsync()).AsInsertable(insertObj); } - + public virtual async Task> AsInsertable(TEntity[] insertObjs) { return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs); @@ -211,9 +227,11 @@ namespace Yi.Framework.SqlSugarCore.Repositories { return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs); } + #endregion #region SimpleClient模块 + public virtual async Task CountAsync(Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).CountAsync(whereExpression); @@ -230,7 +248,6 @@ namespace Yi.Framework.SqlSugarCore.Repositories { return await (await GetDbSimpleClientAsync()).DeleteAsync(deleteObj); } - } public virtual async Task DeleteAsync(List deleteObjs) @@ -250,13 +267,13 @@ namespace Yi.Framework.SqlSugarCore.Repositories { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) { - return await (await GetDbSimpleClientAsync()).AsUpdateable().SetColumns(nameof(ISoftDelete.IsDeleted), true).Where(whereExpression).ExecuteCommandAsync() > 0; + return await (await GetDbSimpleClientAsync()).AsUpdateable() + .SetColumns(nameof(ISoftDelete.IsDeleted), true).Where(whereExpression).ExecuteCommandAsync() > 0; } else { return await (await GetDbSimpleClientAsync()).DeleteAsync(whereExpression); } - } public virtual async Task DeleteByIdAsync(dynamic id) @@ -264,6 +281,11 @@ namespace Yi.Framework.SqlSugarCore.Repositories if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) { var entity = await GetByIdAsync(id); + if (entity is null) + { + return false; + } + //反射赋值 ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, entity); return await UpdateAsync(entity); @@ -284,6 +306,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories { return false; } + //反射赋值 entities.ForEach(e => ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e)); return await UpdateRangeAsync(entities); @@ -292,7 +315,6 @@ namespace Yi.Framework.SqlSugarCore.Repositories { return await (await GetDbSimpleClientAsync()).DeleteByIdAsync(ids); } - } public virtual async Task GetByIdAsync(dynamic id) @@ -301,7 +323,6 @@ namespace Yi.Framework.SqlSugarCore.Repositories } - public virtual async Task GetFirstAsync(Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).GetFirstAsync(whereExpression); @@ -317,14 +338,19 @@ namespace Yi.Framework.SqlSugarCore.Repositories return await (await GetDbSimpleClientAsync()).GetListAsync(whereExpression); } - public virtual async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize) + public virtual async Task> GetPageListAsync(Expression> whereExpression, + int pageNum, int pageSize) { - return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel() { PageIndex = pageNum, PageSize = pageSize }); + return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, + new PageModel() { PageIndex = pageNum, PageSize = pageSize }); } - public virtual async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize, Expression>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc) + public virtual async Task> GetPageListAsync(Expression> whereExpression, + int pageNum, int pageSize, Expression>? orderByExpression = null, + OrderByType orderByType = OrderByType.Asc) { - return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType); + return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, + new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType); } public virtual async Task GetSingleAsync(Expression> whereExpression) @@ -379,30 +405,31 @@ namespace Yi.Framework.SqlSugarCore.Repositories public virtual async Task UpdateAsync(TEntity updateObj) { - if (typeof(TEntity).IsAssignableTo())//带版本号乐观锁更新 + if (typeof(TEntity).IsAssignableTo()) //带版本号乐观锁更新 { try { - int num = await (await GetDbSimpleClientAsync()) + int num = await (await GetDbSimpleClientAsync()) .Context.Updateable(updateObj).ExecuteCommandWithOptLockAsync(true); - return num>0; + return num > 0; } catch (VersionExceptions ex) { - - throw new AbpDbConcurrencyException($"{ex.Message}[更新失败:ConcurrencyStamp不是最新版本],entityInfo:{updateObj}", ex); + throw new AbpDbConcurrencyException( + $"{ex.Message}[更新失败:ConcurrencyStamp不是最新版本],entityInfo:{updateObj}", ex); } } + return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj); } - public virtual async Task UpdateAsync(Expression> columns, Expression> whereExpression) + public virtual async Task UpdateAsync(Expression> columns, + Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).UpdateAsync(columns, whereExpression); } - public virtual async Task UpdateRangeAsync(List updateObjs) { return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(updateObjs); @@ -411,30 +438,36 @@ namespace Yi.Framework.SqlSugarCore.Repositories #endregion } - public class SqlSugarRepository : SqlSugarRepository, ISqlSugarRepository, IRepository where TEntity : class, IEntity, new() + public class SqlSugarRepository : SqlSugarRepository, ISqlSugarRepository, + IRepository where TEntity : class, IEntity, new() { - public SqlSugarRepository(ISugarDbContextProvider sugarDbContextProvider) : base(sugarDbContextProvider) + public SqlSugarRepository(ISugarDbContextProvider sugarDbContextProvider) : base( + sugarDbContextProvider) { } - public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteAsync(TKey id, bool autoSave = false, + CancellationToken cancellationToken = default) { await DeleteByIdAsync(id); } - public virtual async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false, + CancellationToken cancellationToken = default) { await DeleteByIdsAsync(ids.Select(x => (object)x).ToArray()); } - public virtual async Task FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task FindAsync(TKey id, bool includeDetails = true, + CancellationToken cancellationToken = default) { return await GetByIdAsync(id); } - public virtual async Task GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task GetAsync(TKey id, bool includeDetails = true, + CancellationToken cancellationToken = default) { return await GetByIdAsync(id); } } -} +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/SessionCreateAndUpdateInput.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/SessionCreateAndUpdateInput.cs index 46fbd2fd..c41d956f 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/SessionCreateAndUpdateInput.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/SessionCreateAndUpdateInput.cs @@ -4,5 +4,5 @@ public class SessionCreateAndUpdateInput { public string SessionTitle { get; set; } public string SessionContent { get; set; } - public string Remark { get; set; } + public string? Remark { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AiChatService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AiChatService.cs index d0b49f2f..64c8ce4d 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AiChatService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AiChatService.cs @@ -89,7 +89,7 @@ public class AiChatService : ApplicationService var history = new List(); foreach (var aiChatContextDto in input.Messages) { - if (aiChatContextDto.Role == "ai") + if (aiChatContextDto.Role == "system") { history.Add(ChatMessage.CreateAssistantMessage(aiChatContextDto.Content)); } @@ -100,23 +100,23 @@ public class AiChatService : ApplicationService } var gateWay = LazyServiceProvider.GetRequiredService(); - var completeChatResponse = gateWay.CompleteChatAsync(input.Model, history, cancellationToken); - await using var writer = new StreamWriter(response.Body, Encoding.UTF8, leaveOpen: true); - await foreach (var data in completeChatResponse) - { - var model = MapToMessage(input.Model, data); - var message = JsonConvert.SerializeObject(model, new JsonSerializerSettings - { - ContractResolver = new CamelCasePropertyNamesContractResolver() - }); - - await writer.WriteLineAsync($"data: {message}\n"); - await writer.FlushAsync(cancellationToken); // 确保立即推送数据 - } + // var completeChatResponse = gateWay.CompleteChatAsync(input.Model, history, cancellationToken); + // await using var writer = new StreamWriter(response.Body, Encoding.UTF8, leaveOpen: true); + // await foreach (var data in completeChatResponse) + // { + // var model = MapToMessage(input.Model, data); + // var message = JsonConvert.SerializeObject(model, new JsonSerializerSettings + // { + // ContractResolver = new CamelCasePropertyNamesContractResolver() + // }); + // + // await writer.WriteLineAsync($"data: {message}\n"); + // await writer.FlushAsync(cancellationToken); // 确保立即推送数据 + // } //断开连接 - await writer.WriteLineAsync($"data: done\n"); - await writer.FlushAsync(cancellationToken); // 确保立即推送数据 + // await writer.WriteLineAsync("data: done\n"); + // await writer.FlushAsync(cancellationToken); // 确保立即推送数据 if (CurrentUser.IsAuthenticated && input.SessionId.HasValue) { diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/SessionAggregateRoot.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/SessionAggregateRoot.cs index daa57d21..6d290364 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/SessionAggregateRoot.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/SessionAggregateRoot.cs @@ -10,5 +10,5 @@ public class SessionAggregateRoot : FullAuditedAggregateRoot public Guid UserId { get; set; } public string SessionTitle { get; set; } public string SessionContent { get; set; } - public string Remark { get; set; } + public string? Remark { get; set; } } \ No newline at end of file diff --git a/Yi.Ai.Vue3/.env.development b/Yi.Ai.Vue3/.env.development index d7ce0a49..6059351c 100644 --- a/Yi.Ai.Vue3/.env.development +++ b/Yi.Ai.Vue3/.env.development @@ -11,10 +11,8 @@ VITE_WEB_ENV = 'development' VITE_WEB_BASE_API = '/dev-api' # 本地接口 -# VITE_API_URL = http://122.51.75.95:6039 - VITE_API_URL=http://129.211.24.7:6039 -# VITE_API_URL = https://ccnetcore.com -# VITE_API_URL = https://mp.pandarobot.chat +VITE_API_URL = http://localhost:19001/api/app +#VITE_API_URL = http://ccnetcore.com:19001/api/app # SSO单点登录url SSO_SEVER_URL='http://localhost:18001' diff --git a/Yi.Ai.Vue3/.env.production b/Yi.Ai.Vue3/.env.production index 55f18341..c32394bd 100644 --- a/Yi.Ai.Vue3/.env.production +++ b/Yi.Ai.Vue3/.env.production @@ -10,12 +10,12 @@ VITE_WEB_ENV = 'production' # 生产环境 VITE_WEB_BASE_API = '/prod-api' +# 本地接口 +VITE_API_URL = http://ccnetcore.com:19001/api/app + # 是否在打包时开启压缩,支持 gzip 和 brotli VITE_BUILD_COMPRESS = gzip -# VITE_API_URL = http://122.51.75.95:6039 -# VITE_API_URL = http://129.211.24.7:6039 -VITE_API_URL = https://mp.pandarobot.chat # SSO单点登录url SSO_SEVER_URL='https://ccnetcore.com' # SSO单点登录项目标识 diff --git a/Yi.Ai.Vue3/src/api/chat/index.ts b/Yi.Ai.Vue3/src/api/chat/index.ts index 774214fa..ae92da0b 100644 --- a/Yi.Ai.Vue3/src/api/chat/index.ts +++ b/Yi.Ai.Vue3/src/api/chat/index.ts @@ -2,7 +2,7 @@ import type { ChatMessageVo, GetChatListParams, SendDTO } from './types'; import { get, post } from '@/utils/request'; // 发送消息 -export const send = (data: SendDTO) => post('/prod-api/ai-chat/send', data); +export const send = (data: SendDTO) => post('/ai-chat/send', data); // export const send = (data: SendDTO) => post('/chat/send', data); // 新增对应会话聊天记录 @@ -13,5 +13,5 @@ export function addChat(data: ChatMessageVo) { // 获取当前会话的聊天记录 export function getChatList(params: GetChatListParams) { // return get('/system/message/list', params); - return get('/prod-api/message', params); + return get('/message', params); } diff --git a/Yi.Ai.Vue3/src/api/model/index.ts b/Yi.Ai.Vue3/src/api/model/index.ts index 57847f6e..68f20748 100644 --- a/Yi.Ai.Vue3/src/api/model/index.ts +++ b/Yi.Ai.Vue3/src/api/model/index.ts @@ -4,5 +4,5 @@ import { get } from '@/utils/request'; // 获取当前用户的模型列表 export function getModelList() { // return get('/system/model/modelList'); - return get('/prod-api/ai-chat/model'); + return get('/ai-chat/model'); } diff --git a/Yi.Ai.Vue3/src/api/session/index.ts b/Yi.Ai.Vue3/src/api/session/index.ts index 27905ada..9f703b94 100644 --- a/Yi.Ai.Vue3/src/api/session/index.ts +++ b/Yi.Ai.Vue3/src/api/session/index.ts @@ -9,21 +9,21 @@ import { del, get, post, put } from '@/utils/request'; // 获取会话列表 export function get_session_list(params: GetSessionListParams) { // return get('/system/session/list', params); - return get('/prod-api/session', params); + return get('/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(`/prod-api/session/${id}`); + return get(`/session/${id}`); } // 删除会话 export function delete_session(ids: string[]) { - return del(`/prod-api/session/${ids}`); + return del(`/session/${ids[0]}`); } diff --git a/Yi.Ai.Vue3/src/api/session/types.ts b/Yi.Ai.Vue3/src/api/session/types.ts index 797c0de5..4a2b11ce 100644 --- a/Yi.Ai.Vue3/src/api/session/types.ts +++ b/Yi.Ai.Vue3/src/api/session/types.ts @@ -28,11 +28,11 @@ export interface GetSessionListParams { /** * 当前页数 */ - pageNum?: number; + skipCount?: number; /** * 分页大小 */ - pageSize?: number; + maxResultCount?: number; /** * 请求参数 */ diff --git a/Yi.Ai.Vue3/src/api/user/index.ts b/Yi.Ai.Vue3/src/api/user/index.ts index e2115e54..5e98d50d 100644 --- a/Yi.Ai.Vue3/src/api/user/index.ts +++ b/Yi.Ai.Vue3/src/api/user/index.ts @@ -2,5 +2,5 @@ import { get } from '@/utils/request'; // 获取用户信息 export function getUserInfo() { - return get('/prod-api/ai-chat/account'); + return get('/ai-chat/account'); } diff --git a/Yi.Ai.Vue3/src/components/LoginDialog/index.vue b/Yi.Ai.Vue3/src/components/LoginDialog/index.vue index 62559a36..4007e37d 100644 --- a/Yi.Ai.Vue3/src/components/LoginDialog/index.vue +++ b/Yi.Ai.Vue3/src/components/LoginDialog/index.vue @@ -128,7 +128,7 @@ function handleThirdPartyLogin() {
- YiXin-Ai + 意心-Ai
diff --git a/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue b/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue index 5abceb18..eb5e166e 100644 --- a/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue +++ b/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue @@ -108,6 +108,7 @@ function handleDataChunk(chunk: AnyObject) { // 另一种思考中形式,content中有 的格式 // 一开始匹配到 开始,匹配到 结束,并处理标签中的内容为思考内容 + console.log(chunk.choices,"chunk.choices") const parsedChunk = chunk.choices?.[0].delta.content; if (parsedChunk) { const thinkStart = parsedChunk.includes(''); diff --git a/Yi.Ai.Vue3/src/stores/modules/chat.ts b/Yi.Ai.Vue3/src/stores/modules/chat.ts index d6df4d44..0467f1c6 100644 --- a/Yi.Ai.Vue3/src/stores/modules/chat.ts +++ b/Yi.Ai.Vue3/src/stores/modules/chat.ts @@ -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) { diff --git a/Yi.Ai.Vue3/src/stores/modules/session.ts b/Yi.Ai.Vue3/src/stores/modules/session.ts index 5f856bf6..2416bf65 100644 --- a/Yi.Ai.Vue3/src/stores/modules/session.ts +++ b/Yi.Ai.Vue3/src/stores/modules/session.ts @@ -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]); diff --git a/Yi.Ai.Vue3/src/utils/request.ts b/Yi.Ai.Vue3/src/utils/request.ts index 8f3925ff..0d5157f3 100644 --- a/Yi.Ai.Vue3/src/utils/request.ts +++ b/Yi.Ai.Vue3/src/utils/request.ts @@ -11,6 +11,7 @@ interface BaseResponse { data: T; msg: string; } + // 扩展请求函数类型声明 declare module 'hook-fetch' { interface HookFetchDefaults { @@ -19,8 +20,7 @@ declare module 'hook-fetch' { } } export const request = hookFetch.create({ - // 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({ if (typeof response.result?.code === 'number') { return response; } - // 非标准格式 → 包装为标准格式 return { ...response, diff --git a/Yi.Ai.Vue3/types/components.d.ts b/Yi.Ai.Vue3/types/components.d.ts index 813c541f..15e68aac 100644 --- a/Yi.Ai.Vue3/types/components.d.ts +++ b/Yi.Ai.Vue3/types/components.d.ts @@ -12,6 +12,9 @@ declare module 'vue' { DeepThinking: typeof import('./../src/components/DeepThinking/index.vue')['default'] ElAvatar: typeof import('element-plus/es')['ElAvatar'] ElButton: typeof import('element-plus/es')['ElButton'] + ElCard: typeof import('element-plus/es')['ElCard'] + ElCollapse: typeof import('element-plus/es')['ElCollapse'] + ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem'] ElContainer: typeof import('element-plus/es')['ElContainer'] ElDivider: typeof import('element-plus/es')['ElDivider'] ElEmpty: typeof import('element-plus/es')['ElEmpty'] @@ -22,6 +25,9 @@ declare module 'vue' { ElImage: typeof import('element-plus/es')['ElImage'] ElInput: typeof import('element-plus/es')['ElInput'] ElMain: typeof import('element-plus/es')['ElMain'] + ElTable: typeof import('element-plus/es')['ElTable'] + ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] + ElTag: typeof import('element-plus/es')['ElTag'] ElTooltip: typeof import('element-plus/es')['ElTooltip'] FilesSelect: typeof import('./../src/components/FilesSelect/index.vue')['default'] IconSelect: typeof import('./../src/components/IconSelect/index.vue')['default'] diff --git a/Yi.Ai.Vue3/types/import_meta.d.ts b/Yi.Ai.Vue3/types/import_meta.d.ts index 7ac88368..caa83c90 100644 --- a/Yi.Ai.Vue3/types/import_meta.d.ts +++ b/Yi.Ai.Vue3/types/import_meta.d.ts @@ -6,6 +6,7 @@ interface ImportMetaEnv { readonly VITE_WEB_ENV: string; readonly VITE_WEB_BASE_API: string; readonly VITE_API_URL: string; + readonly VITE_BUILD_COMPRESS: string; } declare interface ImportMeta { diff --git a/Yi.Ai.Vue3/vite.config.ts b/Yi.Ai.Vue3/vite.config.ts index beeddf28..0673c143 100644 --- a/Yi.Ai.Vue3/vite.config.ts +++ b/Yi.Ai.Vue3/vite.config.ts @@ -25,13 +25,23 @@ export default defineConfig((cnf) => { }, server: { + port: 17001, + open: true, proxy: { - // 代理所有以 /prod-api 开头的请求 - "/prod-api": { - target: "https://ccnetcore.com", // 接口域名 - changeOrigin: true, // 改变源 - secure: false, // 如果目标服务器使用 HTTPS 且证书无效,需要设置为 false - }, + [env.VITE_WEB_BASE_API]: { + target: env.VITE_API_URL, + changeOrigin: true, + rewrite: (path) => path.replace(`${[env.VITE_WEB_BASE_API]}`, ""), + + //查看真实代理url + bypass(req, res, options) { + //@ts-ignore + const proxyUrl = new URL(options.rewrite(req.url) || '',(options.target)as string)?.href || ''; + console.log(proxyUrl); + req.headers['x-req-proxyUrl'] = proxyUrl + res.setHeader('x-res-proxyUrl',proxyUrl) + }, + } }, },