diff --git a/main/manager-mobile/src/api/chat-history/chat-history.ts b/main/manager-mobile/src/api/chat-history/chat-history.ts index 89c3f1ef..dc7000ef 100644 --- a/main/manager-mobile/src/api/chat-history/chat-history.ts +++ b/main/manager-mobile/src/api/chat-history/chat-history.ts @@ -34,6 +34,9 @@ export function getChatHistory(agentId: string, sessionId: string) { ignoreAuth: false, toast: false, }, + cacheFor: { + expire: -1, + }, }) } diff --git a/main/manager-mobile/src/pages/agent/edit.vue b/main/manager-mobile/src/pages/agent/edit.vue index cc1844d2..964ad0b2 100644 --- a/main/manager-mobile/src/pages/agent/edit.vue +++ b/main/manager-mobile/src/pages/agent/edit.vue @@ -283,7 +283,6 @@ function updateDisplayNames() { // 角色音色特殊处理 displayNames.value.report = reportOptions.find(item => item.value === formData.value.chatHistoryConf)?.name - displayNames.value.language = formData.value.ttsLanguage isVisibleReport.value = formData.value.memModelId !== 'Memory_nomem' diff --git a/main/manager-mobile/src/pages/chat-history/detail.vue b/main/manager-mobile/src/pages/chat-history/detail.vue index e60bd93b..ae2d3d41 100644 --- a/main/manager-mobile/src/pages/chat-history/detail.vue +++ b/main/manager-mobile/src/pages/chat-history/detail.vue @@ -285,7 +285,6 @@ onLoad((options) => { if (options?.sessionId && options?.agentId) { sessionId.value = options.sessionId agentId.value = options.agentId - loadChatHistory() } else { console.error('缺少必要参数') @@ -293,6 +292,10 @@ onLoad((options) => { } }) +onShow(() => { + loadChatHistory() +}) + // 页面销毁时清理音频资源 onUnload(() => { if (audioContext.value) { diff --git a/main/manager-mobile/src/pages/chat-history/index.vue b/main/manager-mobile/src/pages/chat-history/index.vue index b922ccdd..b4cf6d97 100644 --- a/main/manager-mobile/src/pages/chat-history/index.vue +++ b/main/manager-mobile/src/pages/chat-history/index.vue @@ -3,6 +3,7 @@ import type { ChatSession } from '@/api/chat-history/types' import { computed, onMounted, ref } from 'vue' import { getChatSessions } from '@/api/chat-history/chat-history' import { t } from '@/i18n' +import { deepClone } from '@/utils' defineOptions({ name: 'ChatHistory', @@ -43,7 +44,7 @@ const sessionList = ref([]) const loading = ref(false) const loadingMore = ref(false) const hasMore = ref(true) -const currentPage = ref(1) +const currentPage = ref(0) const pageSize = 10 // 使用传入的智能体ID @@ -52,10 +53,8 @@ const currentAgentId = computed(() => { }) // 加载聊天会话列表 -async function loadChatSessions(page = 1, isRefresh = false) { +async function loadChatSessions(page = 1, isUpdate = false) { try { - console.log(t('chatHistory.getChatSessions'), { page, isRefresh }) - // 检查是否有当前选中的智能体 if (!currentAgentId.value) { console.warn(t('chatHistory.noSelectedAgent')) @@ -76,7 +75,10 @@ async function loadChatSessions(page = 1, isRefresh = false) { }) if (page === 1) { - sessionList.value = response.list || [] + const oldSessionList = deepClone(sessionList.value) + oldSessionList.splice(0, 10) + oldSessionList.unshift(...(response.list || [])) + sessionList.value = isUpdate ? oldSessionList : response.list || [] } else { sessionList.value.push(...(response.list || [])) @@ -170,10 +172,15 @@ function goToChatDetail(session: ChatSession) { onMounted(async () => { // 智能体已简化为默认 - loadChatSessions(1) }) +onShow(() => { + if (currentPage.value !== 0) { + loadChatSessions(1, true) + } +}) + // 暴露方法给父组件 defineExpose({ refresh, diff --git a/main/manager-mobile/src/utils/index.ts b/main/manager-mobile/src/utils/index.ts index 8ac842c8..4017494a 100644 --- a/main/manager-mobile/src/utils/index.ts +++ b/main/manager-mobile/src/utils/index.ts @@ -300,3 +300,36 @@ export function debounce( return debounced } + +type DeepCloneTarget = string | number | boolean | null | undefined | object + +/** + * 深拷贝方法 + * @param target 要拷贝的目标 + * @returns 拷贝后的新对象 + */ +export function deepClone(target: T): T { + if (target === null || typeof target !== 'object') { + return target + } + + if (target instanceof Date) { + return new Date(target.getTime()) as any + } + + if (Array.isArray(target)) { + return target.map(item => deepClone(item)) as any + } + + if (target instanceof Object) { + const clonedObj = {} as T + for (const key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + (clonedObj as any)[key] = deepClone((target as any)[key]) + } + } + return clonedObj + } + + return target +}