feat(users): 支持恢复用户已删除会话

- 用户会话:展示删除时间并提供居中确认恢复
- 异步状态:避免切换用户后迟到结果覆盖详情
- README:说明历史会话恢复能力
This commit is contained in:
湛兮
2026-10-28 19:19:58 +08:00
parent 6d3f6a0a8e
commit 8dba72591a
2 changed files with 44 additions and 2 deletions
+42 -2
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
/** 独立 C 端用户管理:开户、内容偏好、停用、改密与区分对白/叙述的持久化聊天记录。 */
import { onMounted, ref } from "vue";
import { ElMessage } from "element-plus";
import { ElMessage, ElMessageBox } from "element-plus";
import DigitalMessageText from "@/components/DigitalMessageText.vue";
import {
digital,
@@ -171,6 +171,40 @@ async function loadConversations() {
if (version === chatVersion) conversationLoading.value = false;
}
}
const restoring = ref(false);
/** 恢复仅作用于选中的用户和会话,切换用户后的迟到结果不能覆盖当前详情。 */
async function restoreChat() {
if (!selected.value || !active.value?.deletedAt || restoring.value) return;
const user = selected.value.id,
conversation = active.value.id;
try {
await ElMessageBox.confirm(
"恢复后用户可在前台继续查看这段对话,原消息不会改变。",
"恢复会话",
{ type: "info" }
);
} catch {
return;
}
restoring.value = true;
try {
await digital(
`users/${user}/conversations/${conversation}/restore`,
"post",
{}
);
if (selected.value?.id === user) {
if (active.value?.id === conversation)
active.value = { ...active.value, deletedAt: null };
await loadConversations();
}
ElMessage.success("会话已恢复");
} catch (e) {
ElMessage.error(e instanceof Error ? e.message : "恢复失败");
} finally {
restoring.value = false;
}
}
async function chooseConversation(c: UserConversation) {
active.value = c;
messagePage.value = 1;
@@ -436,7 +470,7 @@ onMounted(load);
><span
>{{ c.title
}}<el-tag v-if="c.deletedAt" size="small" type="info"
>前台已删除</el-tag
>前台已删除 · {{ time(c.deletedAt) }}</el-tag
></span
><small
>{{ c.messages }} 条消息 · {{ time(c.updatedAt) }}</small
@@ -454,6 +488,12 @@ onMounted(load);
<template v-if="active"
><header>
<strong>{{ active.characterName }} · {{ active.title }}</strong
><el-button
v-if="active.deletedAt"
size="small"
:loading="restoring"
@click="restoreChat"
>恢复给用户</el-button
><el-button size="small" @click="loadMessages"
>刷新记录</el-button
>