mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
update: mobile 聊天记录获取最新数据
This commit is contained in:
@@ -34,6 +34,9 @@ export function getChatHistory(agentId: string, sessionId: string) {
|
|||||||
ignoreAuth: false,
|
ignoreAuth: false,
|
||||||
toast: 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.report = reportOptions.find(item => item.value === formData.value.chatHistoryConf)?.name
|
||||||
displayNames.value.language = formData.value.ttsLanguage
|
|
||||||
|
|
||||||
isVisibleReport.value = formData.value.memModelId !== 'Memory_nomem'
|
isVisibleReport.value = formData.value.memModelId !== 'Memory_nomem'
|
||||||
|
|
||||||
|
|||||||
@@ -285,7 +285,6 @@ onLoad((options) => {
|
|||||||
if (options?.sessionId && options?.agentId) {
|
if (options?.sessionId && options?.agentId) {
|
||||||
sessionId.value = options.sessionId
|
sessionId.value = options.sessionId
|
||||||
agentId.value = options.agentId
|
agentId.value = options.agentId
|
||||||
loadChatHistory()
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error('缺少必要参数')
|
console.error('缺少必要参数')
|
||||||
@@ -293,6 +292,10 @@ onLoad((options) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
loadChatHistory()
|
||||||
|
})
|
||||||
|
|
||||||
// 页面销毁时清理音频资源
|
// 页面销毁时清理音频资源
|
||||||
onUnload(() => {
|
onUnload(() => {
|
||||||
if (audioContext.value) {
|
if (audioContext.value) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { ChatSession } from '@/api/chat-history/types'
|
|||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { getChatSessions } from '@/api/chat-history/chat-history'
|
import { getChatSessions } from '@/api/chat-history/chat-history'
|
||||||
import { t } from '@/i18n'
|
import { t } from '@/i18n'
|
||||||
|
import { deepClone } from '@/utils'
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'ChatHistory',
|
name: 'ChatHistory',
|
||||||
@@ -43,7 +44,7 @@ const sessionList = ref<ChatSession[]>([])
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const loadingMore = ref(false)
|
const loadingMore = ref(false)
|
||||||
const hasMore = ref(true)
|
const hasMore = ref(true)
|
||||||
const currentPage = ref(1)
|
const currentPage = ref(0)
|
||||||
const pageSize = 10
|
const pageSize = 10
|
||||||
|
|
||||||
// 使用传入的智能体ID
|
// 使用传入的智能体ID
|
||||||
@@ -52,10 +53,8 @@ const currentAgentId = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 加载聊天会话列表
|
// 加载聊天会话列表
|
||||||
async function loadChatSessions(page = 1, isRefresh = false) {
|
async function loadChatSessions(page = 1, isUpdate = false) {
|
||||||
try {
|
try {
|
||||||
console.log(t('chatHistory.getChatSessions'), { page, isRefresh })
|
|
||||||
|
|
||||||
// 检查是否有当前选中的智能体
|
// 检查是否有当前选中的智能体
|
||||||
if (!currentAgentId.value) {
|
if (!currentAgentId.value) {
|
||||||
console.warn(t('chatHistory.noSelectedAgent'))
|
console.warn(t('chatHistory.noSelectedAgent'))
|
||||||
@@ -76,7 +75,10 @@ async function loadChatSessions(page = 1, isRefresh = false) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (page === 1) {
|
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 {
|
else {
|
||||||
sessionList.value.push(...(response.list || []))
|
sessionList.value.push(...(response.list || []))
|
||||||
@@ -170,10 +172,15 @@ function goToChatDetail(session: ChatSession) {
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 智能体已简化为默认
|
// 智能体已简化为默认
|
||||||
|
|
||||||
loadChatSessions(1)
|
loadChatSessions(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
if (currentPage.value !== 0) {
|
||||||
|
loadChatSessions(1, true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 暴露方法给父组件
|
// 暴露方法给父组件
|
||||||
defineExpose({
|
defineExpose({
|
||||||
refresh,
|
refresh,
|
||||||
|
|||||||
@@ -300,3 +300,36 @@ export function debounce<T extends AnyFunction>(
|
|||||||
|
|
||||||
return debounced
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user