refactor: 助手记忆页改用 VXE 表格与 Alert 对齐系统列表风格

This commit is contained in:
2026-09-25 00:35:36 +08:00
parent 41f022bd63
commit 0b460e22b0
3 changed files with 188 additions and 68 deletions
+3 -3
View File
@@ -114,7 +114,7 @@ const MemoryIcon = createIconifyIcon('lucide:brain');
// 意见反馈图标 // 意见反馈图标
const FeedbackIcon = createIconifyIcon('lucide:message-square-plus'); const FeedbackIcon = createIconifyIcon('lucide:message-square-plus');
/** 是否具备智能助手聊天权限(用于「我的记忆」入口;含超管) */ /** 是否具备智能助手聊天权限(用于「助手记忆」入口;含超管) */
const canUseAgentChat = computed(() => hasPermission('agent:chat')); const canUseAgentChat = computed(() => hasPermission('agent:chat'));
/** 当前用户可切换的可用公司数 */ /** 当前用户可切换的可用公司数 */
@@ -134,14 +134,14 @@ const menus = computed(() => {
icon: UserIcon, icon: UserIcon,
text: '个人中心', text: '个人中心',
}); });
// 我的记忆(有助手聊天权才显示) // 助手记忆(有助手聊天权才显示)
if (canUseAgentChat.value) { if (canUseAgentChat.value) {
menuItems.push({ menuItems.push({
handler: () => { handler: () => {
router.push('/agent/memories'); router.push('/agent/memories');
}, },
icon: MemoryIcon, icon: MemoryIcon,
text: '我的记忆', text: '助手记忆',
}); });
} }
// 意见反馈 // 意见反馈
@@ -1,7 +1,7 @@
import type { RouteRecordRaw } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router';
/** /**
* 用户记忆管理(头像下拉入口;不进侧栏菜单) * 助手长期记忆管理(头像下拉「助手记忆」入口;不进侧栏菜单)
*/ */
const staticRoutes: RouteRecordRaw[] = [ const staticRoutes: RouteRecordRaw[] = [
{ {
@@ -10,7 +10,7 @@ const staticRoutes: RouteRecordRaw[] = [
component: () => import('#/views/agent/memories/index.vue'), component: () => import('#/views/agent/memories/index.vue'),
meta: { meta: {
icon: 'lucide:brain', icon: 'lucide:brain',
title: '我的记忆', title: '助手记忆',
hideInMenu: true, hideInMenu: true,
ignoreAccess: true, ignoreAccess: true,
}, },
@@ -1,10 +1,16 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, ref } from 'vue'; /**
* 助手长期记忆:Page + VXE 表格(与反馈/API Key 等列表页一致)。
*/
import type { VxeGridProps } from '#/adapter/vxe-table';
import { Page } from '@vben/common-ui'; import { ref } from 'vue';
import { Button, Card, Empty, Spin, message } from 'ant-design-vue'; import { EllipsisText, Page } from '@vben/common-ui';
import { Alert, Button, Modal, Popconfirm, Space, Tag, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
deleteAgentMemoryApi, deleteAgentMemoryApi,
listAgentMemoriesApi, listAgentMemoriesApi,
@@ -13,79 +19,193 @@ import {
defineOptions({ name: 'AgentMemories' }); defineOptions({ name: 'AgentMemories' });
const loading = ref(true); const loading = ref(false);
const memories = ref<AgentVO.Memory[]>([]);
async function loadMemories() { const KIND_META: Record<string, { color: string; label: string }> = {
loading.value = true; note: { color: 'blue', label: '笔记' },
try { preference: { color: 'purple', label: '偏好' },
const res = await listAgentMemoriesApi(); fact: { color: 'green', label: '事实' },
memories.value = res.items || []; };
} catch (e: any) {
message.error(e?.message || '加载记忆失败'); function kindMeta(kind?: string) {
} finally { const k = (kind || 'note').trim() || 'note';
loading.value = false; return KIND_META[k] || { color: 'default', label: k };
}
} }
async function removeMemory(id: string) { function formatTime(raw?: string) {
if (!raw) return '—';
// 后端多为 ISO;展示时去掉过长毫秒/Z
return raw.replace('T', ' ').replace(/\.\d+Z?$/, '').replace(/Z$/, '');
}
const gridOptions: VxeGridProps<AgentVO.Memory> = {
columns: [
{ type: 'seq', width: 56, title: '序号' },
{
field: 'kind',
title: '类型',
width: 96,
slots: { default: 'kind' },
},
{
field: 'summary',
title: '摘要',
minWidth: 200,
slots: { default: 'summary' },
},
{
field: 'text',
title: '原文',
minWidth: 240,
slots: { default: 'text' },
},
{
field: 'key',
title: '键',
width: 120,
showOverflow: 'tooltip',
formatter: ({ cellValue }) => cellValue || '—',
},
{
field: 'updatedAt',
title: '更新时间',
width: 176,
formatter: ({ cellValue }) => formatTime(cellValue),
},
{
title: '操作',
width: 96,
fixed: 'right',
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
rowConfig: { isHover: true },
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50],
layouts: ['Total', 'Sizes', 'PrevPage', 'Number', 'NextPage'],
},
proxyConfig: {
ajax: {
query: async ({ page }) => {
loading.value = true;
try {
const res = await listAgentMemoriesApi();
const all = res.items || [];
const pageSize = page.pageSize || 20;
const current = page.currentPage || 1;
const start = (current - 1) * pageSize;
return {
items: all.slice(start, start + pageSize),
total: all.length,
};
} catch (e: any) {
message.error(e?.message || '加载记忆失败');
return { items: [], total: 0 };
} finally {
loading.value = false;
}
},
},
},
};
const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
async function removeMemory(row: AgentVO.Memory) {
try { try {
await deleteAgentMemoryApi(id); await deleteAgentMemoryApi(row.id);
memories.value = memories.value.filter((m) => m.id !== id); message.success('已删除');
message.success('已删除记忆'); await gridApi.reload();
} catch (e: any) { } catch (e: any) {
message.error(e?.message || '删除失败'); message.error(e?.message || '删除失败');
} }
} }
onMounted(() => { function clearAll() {
void loadMemories(); Modal.confirm({
}); title: '清空全部助手记忆?',
content: '将逐条删除当前列表中的记忆,且不可恢复。',
okText: '清空',
okType: 'danger',
cancelText: '取消',
async onOk() {
const res = await listAgentMemoriesApi();
const items = res.items || [];
for (const m of items) {
await deleteAgentMemoryApi(m.id);
}
message.success(items.length ? `已清空 ${items.length} 条` : '暂无记忆');
await gridApi.reload();
},
});
}
</script> </script>
<template> <template>
<Page auto-content-height> <Page
<div class="relative mx-auto max-w-3xl pb-8"> auto-content-height
<div title="助手记忆"
v-if="loading" description="智能助手跨会话保存的称呼、偏好与事实,按需检索,不会默认整包注入对话。"
class="absolute inset-0 z-10 flex items-center justify-center bg-background/50" >
> <Alert
<Spin /> type="info"
</div> show-icon
class="mb-4"
message="在智能助手里发送「记住:……」即可写入;不需要的条目可随时删除。"
/>
<Card title="我的记忆" :bordered="false"> <Grid :loading="loading">
<p class="text-muted-foreground mb-4 text-sm"> <template #toolbar-tools>
在智能助手对话中发送「记住:…」可写入;助手按需检索,不会默认注入全部记忆。 <Space>
</p> <Button danger @click="clearAll">清空全部</Button>
<Empty </Space>
v-if="!loading && memories.length === 0" </template>
description="暂无记忆"
/> <template #kind="{ row }">
<div <Tag :color="kindMeta(row.kind).color">
v-for="m in memories" {{ kindMeta(row.kind).label }}
:key="m.id" </Tag>
class="mb-2 flex items-start gap-2 rounded-md bg-muted/50 px-3 py-2 text-sm" </template>
<template #summary="{ row }">
<EllipsisText :max-width="360" tooltip-when-ellipsis>
{{ row.summary || row.text || '—' }}
</EllipsisText>
</template>
<template #text="{ row }">
<EllipsisText
v-if="row.summary && row.text && row.summary !== row.text"
:max-width="420"
tooltip-when-ellipsis
> >
<div class="min-w-0 flex-1"> {{ row.text }}
<div class="break-words">{{ m.summary || m.text }}</div> </EllipsisText>
<div <span v-else class="text-muted-foreground">—</span>
v-if="m.summary && m.text && m.summary !== m.text" </template>
class="text-muted-foreground mt-1 break-words text-xs"
> <template #action="{ row }">
{{ m.text }} <Popconfirm
</div> title="确定删除这条记忆?"
<div ok-text="删除"
v-if="m.updatedAt" cancel-text="取消"
class="text-muted-foreground mt-1 text-xs" ok-type="danger"
> @confirm="removeMemory(row)"
{{ m.updatedAt }} >
</div> <Button type="link" size="small" danger>删除</Button>
</div> </Popconfirm>
<Button type="link" size="small" danger @click="removeMemory(m.id)"> </template>
删除 </Grid>
</Button>
</div>
</Card>
</div>
</Page> </Page>
</template> </template>