fix: paginate chat detail messages

This commit is contained in:
2026-07-30 15:09:05 +08:00
parent 162658384f
commit 8e2dc1d781
6 changed files with 83 additions and 7 deletions

View File

@@ -52,6 +52,8 @@ const retrievalDetailOpen = ref(false);
const previewKnowledgeId = ref<number | null>(null);
const chatDetail = ref<ChatDetail | null>(null);
const chatDetailOpen = ref(false);
const chatDetailLoading = ref(false);
const chatDetailSessionId = ref<number | null>(null);
const selectedAiLog = ref<AiLogRecord | null>(null);
const aiLogDetailOpen = ref(false);
const recordTab = ref("chats");
@@ -63,6 +65,7 @@ const pagers = reactive({
retrievals: { page: 1, pageSize: 20, total: 0 },
attention: { page: 1, pageSize: 20, total: 0 },
});
const chatDetailMessagePager = reactive({ page: 1, pageSize: 20, total: 0 });
const editingModelId = ref<number | null>(null);
const editingKnowledgeId = ref<number | null>(null);
const batchNodeToken = ref("");
@@ -739,13 +742,38 @@ async function resetChatFilters() {
}
async function openChatDetail(row: ChatRecord) {
chatDetail.value = await api.chatDetail(row.id);
chatDetailOpen.value = true;
await openChatSession(row.id);
}
async function openChatSession(sessionId: number) {
chatDetail.value = await api.chatDetail(sessionId);
chatDetailOpen.value = true;
chatDetail.value = null;
chatDetailSessionId.value = sessionId;
Object.assign(chatDetailMessagePager, { page: 1, pageSize: chatDetailMessagePager.pageSize, total: 0 });
await loadChatDetail(sessionId, 1, chatDetailMessagePager.pageSize);
}
async function loadChatDetail(sessionId = chatDetailSessionId.value, page = chatDetailMessagePager.page, pageSize = chatDetailMessagePager.pageSize) {
if (!sessionId) return;
chatDetailLoading.value = true;
try {
const detail = await api.chatDetail(sessionId, { messagePage: page, messagePageSize: pageSize });
chatDetail.value = detail;
const messagePage = detail.messagesPage;
Object.assign(chatDetailMessagePager, {
page: messagePage?.page ?? page,
pageSize: messagePage?.pageSize ?? pageSize,
total: messagePage?.total ?? detail.messages.length,
});
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : "聊天详情加载失败");
} finally {
chatDetailLoading.value = false;
}
}
async function changeChatDetailMessagePage(page: number, pageSize: number) {
await loadChatDetail(chatDetailSessionId.value, page, pageSize);
}
async function openAiLogDetail(row: AiLogRecord) {
@@ -1206,6 +1234,7 @@ function formatRecordDateTime(value: string, boundary: "start" | "end") {
</el-drawer>
<el-drawer v-model="chatDetailOpen" size="760px" title="聊天详情">
<div v-loading="chatDetailLoading" class="chat-detail-body">
<template v-if="chatDetail">
<section class="chat-summary">
<div><span>会话ID</span><strong>{{ chatDetail.session.id }}</strong></div>
@@ -1235,6 +1264,12 @@ function formatRecordDateTime(value: string, boundary: "start" | "end") {
</div>
</article>
</section>
<AdminPagination
:page="chatDetailMessagePager.page"
:page-size="chatDetailMessagePager.pageSize"
:total="chatDetailMessagePager.total"
@change="changeChatDetailMessagePage"
/>
<h3 class="detail-title">关联 AI 请求</h3>
<el-collapse>
@@ -1263,6 +1298,8 @@ function formatRecordDateTime(value: string, boundary: "start" | "end") {
</el-collapse-item>
</el-collapse>
</template>
<el-empty v-else-if="!chatDetailLoading" description="聊天详情加载失败或暂无数据" :image-size="80" />
</div>
</el-drawer>
<el-drawer v-model="aiLogDetailOpen" size="820px" title="AI 请求详情">

View File

@@ -201,7 +201,8 @@ export const api = {
saveConfig: (payload: Record<string, unknown>) =>
request<SystemConfigItem>("/admin/config", { method: "PUT", body: JSON.stringify(payload) }),
chats: (query: ChatRecordQuery = {}) => request<PageResult<ChatRecord>>(`/admin/chat/list${queryString(query)}`),
chatDetail: (sessionId: number) => request<ChatDetail>(`/admin/chat/${sessionId}`),
chatDetail: (sessionId: number, query: { messagePage?: number; messagePageSize?: number } = {}) =>
request<ChatDetail>(`/admin/chat/${sessionId}${queryString(query)}`),
exportChats: (query: ChatRecordQuery = {}) => download(`/admin/chat/export${queryString(query)}`, "chat_records.csv"),
aiLogs: (query: { sessionId?: number; userId?: number; status?: string; page?: number; pageSize?: number } = {}) =>
request<PageResult<AiLogRecord>>(`/admin/ai-log/list${queryString(query)}`),

View File

@@ -1738,6 +1738,10 @@ textarea {
align-items: center;
}
.chat-detail-body {
min-height: 320px;
}
.chat-summary {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));

View File

@@ -356,6 +356,7 @@ export interface RetrievedKnowledgeChunk {
export interface ChatDetail {
session: ChatRecord;
messages: ChatMessageRecord[];
messagesPage?: PageResult<ChatMessageRecord>;
aiLogs: AiLogRecord[];
}