update: mobile 聊天记录获取最新数据

This commit is contained in:
zhuoqinglian
2026-04-10 16:11:04 +08:00
parent 784ba359f2
commit 2cd9484c54
5 changed files with 53 additions and 8 deletions
@@ -34,6 +34,9 @@ export function getChatHistory(agentId: string, sessionId: string) {
ignoreAuth: false,
toast: false,
},
cacheFor: {
expire: -1,
},
})
}
@@ -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'
@@ -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) {
@@ -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<ChatSession[]>([])
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,
+33
View File
@@ -300,3 +300,36 @@ export function debounce<T extends AnyFunction>(
return debounced
}
type DeepCloneTarget = string | number | boolean | null | undefined | object
/**
* 深拷贝方法
* @param target 要拷贝的目标
* @returns 拷贝后的新对象
*/
export function deepClone<T extends DeepCloneTarget>(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
}