会话删除修复
This commit is contained in:
@@ -54,7 +54,8 @@ export function deleteSessionV2(id: string, requestOptions?: RequestOptions) {
|
||||
}
|
||||
|
||||
// 删除会话内的对话记录(AI 回复 / 用户问题单条或多条),传 Ids 数组,每项为 { id, type }
|
||||
export function deleteSessionRecord(ids: { id: number; type: string }[], requestOptions?: RequestOptions) {
|
||||
// 注意:记录 id 为 19 位雪花大整数,超出 JS Number 安全范围,必须用 string 形式传递,否则精度丢失
|
||||
export function deleteSessionRecord(ids: { id: string; type: string }[], requestOptions?: RequestOptions) {
|
||||
return request({
|
||||
url: '/ai-agent/session/deleteRecord',
|
||||
method: 'post',
|
||||
|
||||
@@ -55,6 +55,12 @@
|
||||
<el-icon><Delete /></el-icon>
|
||||
</button>
|
||||
</div>
|
||||
<!-- 用户消息操作栏(hover 显示,仅删除) -->
|
||||
<div v-if="msg.isUser && msg.recordId" class="msg-actions">
|
||||
<button class="msg-action is-danger" title="删除对话" @click="emit('delete', msg)">
|
||||
<el-icon><Delete /></el-icon>
|
||||
</button>
|
||||
</div>
|
||||
<div class="time">{{ msg.time }}</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -343,6 +349,10 @@ onMounted(() => {
|
||||
.message-row:hover & {
|
||||
opacity: 1;
|
||||
}
|
||||
/* 用户消息在右侧,操作栏右对齐 */
|
||||
.message-row.is-user & {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
.msg-action {
|
||||
|
||||
@@ -344,8 +344,8 @@ const currentSessionResultsLoading = computed(() => {
|
||||
return !!id && !!sessionResultsLoading[id];
|
||||
});
|
||||
|
||||
// session/get 分页:打开会话详情默认只拿最近 3 条对话,更早的通过滚动加载更多(下一页更早的记录)
|
||||
const SESSION_PAGE_SIZE = 3;
|
||||
// session/get 分页:打开会话详情默认只拿最近 10 条对话(约一屏),更早的通过滚动加载更多(下一页更早的记录)
|
||||
const SESSION_PAGE_SIZE = 10;
|
||||
const sessionPage = reactive<Record<string, { page: number; total: number; loading: boolean; done: boolean }>>({});
|
||||
const sessionLoadingMore = reactive<Record<string, boolean>>({});
|
||||
const currentSessionHasMore = computed(() => {
|
||||
@@ -523,22 +523,19 @@ const handleDeleteMessage = async (msg: ChatMessage) => {
|
||||
const idx = list.findIndex((m) => m.id === msg.id);
|
||||
if (idx < 0) return;
|
||||
// 收集后端记录 id(type 传记录类型:chat/workflow)
|
||||
const ids: { id: number; type: string }[] = [];
|
||||
// 记录 id 为 19 位雪花大整数,超出 JS Number 安全范围(2^53-1),必须保留字符串形式,
|
||||
// Number() 转换会导致精度丢失,删除请求发出后与后端实际 id 对不上
|
||||
const ids: { id: string; type: string }[] = [];
|
||||
const pushId = (m: ChatMessage | undefined | null) => {
|
||||
if (!m?.recordId) return;
|
||||
const id = Number(m.recordId);
|
||||
if (!Number.isFinite(id)) return;
|
||||
const id = String(m.recordId).trim();
|
||||
if (!id) return;
|
||||
if (ids.some((d) => d.id === id)) return;
|
||||
ids.push({ id, type: m.recordType || 'chat' });
|
||||
};
|
||||
// 后端一条记录同时承载用户问题与 AI 回复(rq- / ra- 共享同一 recordId),
|
||||
// 删除该记录即删除整组对话,无需向相邻消息扩展查找,避免误删相邻记录
|
||||
pushId(msg);
|
||||
// 向上找最近一条用户消息,一并删除(同一后端记录时自动去重)
|
||||
for (let i = idx - 1; i >= 0; i--) {
|
||||
if (list[i].isUser) {
|
||||
pushId(list[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ids.length === 0) {
|
||||
ElMessage.warning('该对话记录尚未生成(执行中),可刷新后再删除');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user