From 67d01c678a8fda1ddc48239bb424029e806dd66d Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Fri, 25 Sep 2026 23:56:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=99=BA=E8=83=BD=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E4=BE=A7=E6=A0=8F=E6=94=AF=E6=8C=81=E6=94=B6=E8=B5=B7?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E8=BD=A8=E4=B8=8E=E5=B1=85=E4=B8=AD=E5=8F=AF?= =?UTF-8?q?=E6=8B=96=E6=8B=BD=E4=BC=9A=E8=AF=9D=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-antd/src/views/agent/chat/index.vue | 283 ++++++++++++++---- .../views/agent/chat/session-search-modal.vue | 107 +++++++ 2 files changed, 339 insertions(+), 51 deletions(-) create mode 100644 apps/web/apps/web-antd/src/views/agent/chat/session-search-modal.vue diff --git a/apps/web/apps/web-antd/src/views/agent/chat/index.vue b/apps/web/apps/web-antd/src/views/agent/chat/index.vue index 8f78979d..5433f962 100644 --- a/apps/web/apps/web-antd/src/views/agent/chat/index.vue +++ b/apps/web/apps/web-antd/src/views/agent/chat/index.vue @@ -2,6 +2,7 @@ import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'; import { EllipsisText, Page } from '@vben/common-ui'; +import { createIconifyIcon } from '@vben/icons'; import { BarChartOutlined, CalendarOutlined, @@ -11,7 +12,7 @@ import { } from '@ant-design/icons-vue'; import dayjs from 'dayjs'; -import { Empty, Select, Spin, Tooltip, message } from 'ant-design-vue'; +import { Empty, Popover, Select, Spin, Tooltip, message } from 'ant-design-vue'; import { ChatItem } from '@tdesign-vue-next/chat'; import 'tdesign-vue-next/es/style/index.css'; import '@tdesign-vue-next/chat/es/style/index.css'; @@ -27,6 +28,7 @@ import { } from '#/api/agent'; import CatalogCiteSender from './catalog-cite-sender.vue'; +import SessionSearchModal from './session-search-modal.vue'; import { composeMessageWithCites, stripTrailingMention, @@ -35,6 +37,15 @@ import { defineOptions({ name: 'AgentChat' }); +const AgentBrandIcon = createIconifyIcon('lucide:bot'); +const SearchIcon = createIconifyIcon('lucide:search'); +const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close'); +const PanelOpenIcon = createIconifyIcon('lucide:panel-left'); +const NewChatIcon = createIconifyIcon('lucide:square-pen'); +const RecentChatIcon = createIconifyIcon('lucide:message-square'); + +const SIDER_COLLAPSED_KEY = 'agent-chat-sider-collapsed'; + /** 空态快捷 chips:短标签展示,点击填入完整提问 */ const starterPrompts = [ { @@ -77,6 +88,14 @@ const sessions = ref([]); const activeThreadId = ref(null); /** 点了「新对话」但还没发出第一条消息,此时不请求后端 */ const composingNew = ref(false); +/** 侧栏收起状态(localStorage 持久化) */ +const siderCollapsed = ref( + typeof localStorage !== 'undefined' && + localStorage.getItem(SIDER_COLLAPSED_KEY) === '1', +); +/** 收起态:最近会话浮层 */ +const collapsedRecentOpen = ref(false); +const sessionSearchModalRef = ref<{ open: () => void } | null>(null); const messages = ref([]); /** 当前流式助手正文(与 messages 末条同步) */ const streamingText = ref(''); @@ -157,9 +176,42 @@ function sessionTime(s: AgentVO.Session) { return d?.isValid() ? d : null; } +function setSiderCollapsed(next: boolean) { + siderCollapsed.value = next; + try { + localStorage.setItem(SIDER_COLLAPSED_KEY, next ? '1' : '0'); + } catch { + /* ignore */ + } + if (!next) { + collapsedRecentOpen.value = false; + } +} + +/** 居中弹窗搜索会话(展开/收起侧栏共用入口) */ +function openSessionSearch() { + sessionSearchModalRef.value?.open(); +} + +function onCollapsedRecentOpenChange(open: boolean) { + collapsedRecentOpen.value = open; +} + +/** 收起态浮层 / 搜索弹窗点选会话 */ +function pickSessionFromOverlay(threadId: string) { + collapsedRecentOpen.value = false; + onSessionClick(threadId); +} + +/** 收起态「最近」列表(按接口顺序,最多 20 条) */ +const recentSessions = computed(() => sessions.value.slice(0, 20)); + /** 侧栏按「今天 / 昨天 / 近7天 / 更早」分组,对齐常见助手布局 */ const sessionGroups = computed(() => { - const buckets: Record = { + const buckets: Record< + 'today' | 'yesterday' | 'week' | 'earlier', + AgentVO.Session[] + > = { today: [], yesterday: [], week: [], @@ -180,14 +232,14 @@ const sessionGroups = computed(() => { buckets.earlier.push(s); } } - const labels: Array<[string, string]> = [ + const labels: Array<[keyof typeof buckets, string]> = [ ['today', '今天'], ['yesterday', '昨天'], ['week', '近 7 天'], ['earlier', '更早'], ]; return labels - .map(([key, label]) => ({ key, label, items: buckets[key]! })) + .map(([key, label]) => ({ key, label, items: buckets[key] })) .filter((g) => g.items.length > 0); }); @@ -542,67 +594,190 @@ void loadEnabledModels().then(() => refreshSessions()); + diff --git a/apps/web/apps/web-antd/src/views/agent/chat/session-search-modal.vue b/apps/web/apps/web-antd/src/views/agent/chat/session-search-modal.vue new file mode 100644 index 00000000..ab10369c --- /dev/null +++ b/apps/web/apps/web-antd/src/views/agent/chat/session-search-modal.vue @@ -0,0 +1,107 @@ + + +