From ed3c2513c35efa714f2a377aef55501dd15d1fec Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期一, 12 十月 2026 09:27:36 +0800
Subject: [PATCH] fix: 修改对话模块
---
src/api/chatApi.js | 51 ++
src/components/ChatView.vue | 18
src/stores/chatStore.js | 302 +++++++++++--
src/api/axios.js | 7
src/components/Sidebar.vue | 893 +++++++++++++++++++++++++++++----------
src/views/Chat.vue | 16
6 files changed, 975 insertions(+), 312 deletions(-)
diff --git a/src/api/axios.js b/src/api/axios.js
index 894d8de..ffcf015 100644
--- a/src/api/axios.js
+++ b/src/api/axios.js
@@ -40,6 +40,13 @@
(response) => {
const body = response.data
+ // 璋冪敤鏂规樉寮忚姹傘�屽畬鏁村搷搴斻�嶆椂鐩存帴杩斿洖銆�
+ // 鍏稿瀷鍦烘櫙鏄枃浠朵笅杞斤細寤鸿鏂囦欢鍚嶅湪 Content-Disposition 鍝嶅簲澶撮噷锛�
+ // 鑰屼笅闈㈢殑瑙e寘閫昏緫鍙繑鍥� body锛屼細鎶婂搷搴斿ご涓�璧蜂涪鎺夈��
+ if (response.config && response.config.__returnFullResponse) {
+ return response
+ }
+
// 浜岃繘鍒跺搷搴旓紙鍥剧墖銆佹枃浠朵笅杞斤級鐩存帴杩斿洖 Blob/ArrayBuffer銆�
// 涓嶈兘璧颁笅闈㈢殑 Result 瑙e寘锛氬畠涓嶆槸 {code,msg,data} 缁撴瀯锛�
// 涓旇В鍖呴�昏緫浼氭妸瀹冨綋鎴愭櫘閫氬璞″鐞嗐��
diff --git a/src/api/chatApi.js b/src/api/chatApi.js
index a970691..77f4950 100644
--- a/src/api/chatApi.js
+++ b/src/api/chatApi.js
@@ -1,8 +1,15 @@
import http from './axios'
-/** 浼氳瘽鍒楄〃 */
-export function listChats() {
- return http.get('/chats')
+/**
+ * 浼氳瘽鍒楄〃銆�
+ *
+ * @param {boolean} archived false=涓诲垪琛紙鏈綊妗o級锛宼rue=褰掓。鍒楄〃
+ *
+ * 鎺掑簭鐢�**鍚庣**鍐冲畾锛堢疆椤朵紭鍏堬紝鍏舵鏈�杩戞椿璺冿級锛屽墠绔彧鎸夋椂闂村垎缁勩��
+ * 涓嶉噸鏂版帓搴� 鈥斺�� 涓よ竟鍚勬帓涓�娆″繀鐒朵細鍑虹幇椤哄簭涓嶄竴鑷淬��
+ */
+export function listChats(archived = false) {
+ return http.get('/chats', { params: { archived } })
}
/**
@@ -11,9 +18,12 @@
* 鍚庣鍚屾椂鍖归厤鏍囬涓庢秷鎭唴瀹癸紝杩斿洖鐨勬瘡涓�椤瑰甫锛�
* - matchSnippet锛氬懡涓鐨勪笂涓嬫枃鐗囨
* - matchType锛歵itle / message / both
+ *
+ * @param {boolean} archived 鎼滅储鑼冨洿锛岄渶涓庡綋鍓嶈鍥句竴鑷达細
+ * 鍦ㄤ富鍒楄〃鎼滀笉璇ョ炕鍑哄凡褰掓。鐨勫璇�
*/
-export function searchChats(keyword, limit = 30) {
- return http.get('/chats/search', { params: { q: keyword, limit } })
+export function searchChats(keyword, limit = 30, archived = false) {
+ return http.get('/chats/search', { params: { q: keyword, limit, archived } })
}
/** 鏂板缓浼氳瘽 */
@@ -22,8 +32,9 @@
}
/**
- * 淇敼浼氳瘽鏍囬鎴栨ā鍨嬪弬鏁般��
- * meta 鏄暣浣撹鐩栬涔夛紝璇锋彁浜ゅ畬鏁寸殑鍙傛暟瀵硅薄銆�
+ * 淇敼浼氳瘽锛氭爣棰� / 妯″瀷鍙傛暟 / 缃《 / 褰掓。銆�
+ * meta 鏄暣浣撹鐩栬涔夛紝璇锋彁浜ゅ畬鏁寸殑鍙傛暟瀵硅薄锛�
+ * 鍏朵綑瀛楁鏄�屼紶浜嗘墠鏀广�嶇殑灞�閮ㄦ洿鏂拌涔夈��
*/
export function updateChat(chatId, payload) {
return http.put(`/chats/${chatId}`, payload)
@@ -34,6 +45,32 @@
return http.delete(`/chats/${chatId}`)
}
+/**
+ * 鎶婁細璇濈Щ鍏� / 绉诲嚭鍒嗙粍銆�
+ *
+ * 鍗曠嫭涓�涓鐐癸紙鑰屼笉鏄鐢� updateChat锛夛細閭h竟绾﹀畾銆屽瓧娈典负 null 琛ㄧず涓嶄慨鏀广�嶏紝
+ * 鑰屻�岀Щ鍑哄垎缁勩�嶆鏄鎶� groupId 缃负 null锛屽悓涓�涓瓧娈典笂璇箟浼氭墦鏋躲��
+ *
+ * @param {number|null} groupId 鐩爣鍒嗙粍 id锛沶ull = 绉诲嚭鍒嗙粍
+ */
+export function moveChatToGroup(chatId, groupId) {
+ return http.put(`/chats/${chatId}/group`, { groupId })
+}
+
+/**
+ * 瀵煎嚭浼氳瘽涓� json / txt / pdf銆�
+ *
+ * 鐢� __returnFullResponse 鎷�**瀹屾暣鍝嶅簲**锛氫笅杞芥枃浠跺悕鍦�
+ * Content-Disposition 鍝嶅簲澶撮噷锛岃�岄粯璁ょ殑鍝嶅簲鎷︽埅鍣ㄥ彧杩斿洖 body銆�
+ */
+export function exportChat(chatId, format) {
+ return http.get(`/chats/${chatId}/export`, {
+ params: { format },
+ responseType: 'blob',
+ __returnFullResponse: true
+ })
+}
+
/** 鑾峰彇浼氳瘽鐨勬秷鎭爲锛堟牴鑺傜偣鏁扮粍锛岃妭鐐瑰唴宓� children锛� */
export function listMessages(chatId) {
return http.get(`/chats/${chatId}/messages`)
diff --git a/src/components/ChatView.vue b/src/components/ChatView.vue
index 313ab03..0c157fe 100644
--- a/src/components/ChatView.vue
+++ b/src/components/ChatView.vue
@@ -120,15 +120,15 @@
</label>
<div class="composer-buttons">
- <n-button
- size="small"
- :disabled="!chatId || chatStore.streaming"
- :loading="pendingImages.some((i) => i.status === 'ocr')"
- title="涓婁紶鍥剧墖锛岃瘑鍒叾涓枃瀛楀悗涓�骞跺璇�"
- @click="pickImage"
- >
- 鍥剧墖
- </n-button>
+<!-- <n-button-->
+<!-- size="small"-->
+<!-- :disabled="!chatId || chatStore.streaming"-->
+<!-- :loading="pendingImages.some((i) => i.status === 'ocr')"-->
+<!-- title="涓婁紶鍥剧墖锛岃瘑鍒叾涓枃瀛楀悗涓�骞跺璇�"-->
+<!-- @click="pickImage"-->
+<!-- >-->
+<!-- 鍥剧墖-->
+<!-- </n-button>-->
<n-button
v-if="chatStore.streaming"
size="small"
diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue
index 3c549fc..b6ab2d9 100644
--- a/src/components/Sidebar.vue
+++ b/src/components/Sidebar.vue
@@ -25,84 +25,138 @@
</div>
<div class="sidebar-list">
- <!-- 鎼滅储鎬侊細鏄剧ず缁撴灉锛屽懡涓唴瀹规椂缁欏嚭涓婁笅鏂囩墖娈� -->
+ <!-- 鎼滅储鎬侊細璺ㄥ叏閮ㄤ細璇濇悳锛堝惈鍒嗙粍閲岀殑锛夛紝鍛戒腑鍐呭鏃剁粰鍑轰笂涓嬫枃鐗囨 -->
<template v-if="isSearching">
<n-spin v-if="chatStore.searching" size="small" class="sidebar-loading" />
- <div v-else-if="visibleChats.length === 0" class="empty-hint sidebar-empty">
+ <div v-else-if="chatStore.searchResults.length === 0" class="empty-hint sidebar-empty">
娌℃湁鎵惧埌鍖归厤銆寋{ chatStore.searchKeyword }}銆嶇殑瀵硅瘽<br />
璇曡瘯鍏朵粬鍏抽敭璇�
</div>
- <div
- v-for="chat in visibleChats"
+ <ChatListItem
+ v-for="chat in chatStore.searchResults"
v-else
:key="chat.id"
- class="chat-item"
- :class="{ active: chat.id === activeChatId }"
- @click="$emit('select', chat.id)"
- >
- <div class="chat-item-main">
- <div class="chat-title">{{ chat.title || '鏂板璇�' }}</div>
- <!-- 鍛戒腑娑堟伅鍐呭鏃跺睍绀虹墖娈碉紝鏂逛究纭鏄笉鏄繖娆″璇� -->
- <div v-if="chat.matchSnippet" class="chat-snippet">
- {{ chat.matchSnippet }}
- </div>
- <div class="chat-meta">
- <span>{{ chat.messageCount || 0 }} 鏉℃秷鎭�</span>
- <span class="match-badge">{{ matchLabel(chat.matchType) }}</span>
- </div>
- </div>
- </div>
+ :chat="chat"
+ :active="chat.id === activeChatId"
+ :options="menuFor(chat)"
+ @select="(id) => $emit('select', id)"
+ @menu="handleMenu"
+ />
</template>
<!-- 鏅�氭�� -->
<template v-else>
<n-spin v-if="loading" size="small" class="sidebar-loading" />
+ <!-- ============ 鍒嗙粍鍖哄潡 ============ -->
+ <div class="section">
+ <div class="section-head" @click="toggleGroupSection()">
+ <span class="chevron" :class="{ collapsed: groupSectionCollapsed }">鈻�</span>
+ <span class="section-title">鍒嗙粍</span>
+ <span class="section-count">{{ sections.groups.length || '' }}</span>
+ <n-button
+ text
+ class="section-add"
+ title="鏂板缓鍒嗙粍"
+ @click.stop="openCreateGroup"
+ >
+ +
+ </n-button>
+ </div>
+
+ <template v-if="!groupSectionCollapsed">
+ <div v-if="sections.groups.length === 0" class="section-empty">
+ 杩樻病鏈夊垎缁勶紝鐐瑰彸涓婅銆�+銆嶆柊寤�
+ </div>
+
+ <div v-for="group in sections.groups" :key="group.id" class="group-block">
+ <div class="group-head" @click="toggleGroup(group.id)">
+ <span class="chevron small" :class="{ collapsed: isGroupCollapsed(group.id) }">鈻�</span>
+ <span class="group-name" :title="group.name">{{ group.name }}</span>
+ <span class="group-count">{{ group.chats.length }}</span>
+
+ <n-dropdown
+ trigger="click"
+ :options="groupMenuOptions"
+ placement="bottom-end"
+ @select="(key) => handleGroupMenu(key, group)"
+ >
+ <n-button text class="group-more" @click.stop>鈰�</n-button>
+ </n-dropdown>
+ </div>
+
+ <template v-if="!isGroupCollapsed(group.id)">
+ <div v-if="group.chats.length === 0" class="group-empty">
+ 绌哄垎缁� 鈥斺�� 鐢ㄥ璇濆彸涓婅鐨勩�屸嫰 鈫� 绉诲姩鍒板垎缁勩�嶆斁杩涙潵
+ </div>
+ <ChatListItem
+ v-for="chat in group.chats"
+ v-else
+ :key="chat.id"
+ :chat="chat"
+ :active="chat.id === activeChatId"
+ indented
+ :options="menuFor(chat)"
+ @select="(id) => $emit('select', id)"
+ @menu="handleMenu"
+ />
+ </template>
+ </div>
+ </template>
+ </div>
+
+ <!-- ============ 缃《锛堟湭鍒嗙粍鐨勭疆椤朵細璇濓級============ -->
+ <div v-if="sections.pinned.length" class="section">
+ <div class="section-head static">
+ <span class="chevron">鈻�</span>
+ <span class="section-title">缃《</span>
+ </div>
+ <ChatListItem
+ v-for="chat in sections.pinned"
+ :key="chat.id"
+ :chat="chat"
+ :active="chat.id === activeChatId"
+ :options="menuFor(chat)"
+ @select="(id) => $emit('select', id)"
+ @menu="handleMenu"
+ />
+ </div>
+
+ <!-- ============ 鏈垎缁勭殑浼氳瘽锛屾寜鏃堕棿褰掔被 ============ -->
<div v-if="!loading && chats.length === 0" class="empty-hint sidebar-empty">
杩樻病鏈夊璇�<br />鐐瑰嚮涓婃柟銆屾柊瀵硅瘽銆嶅紑濮�
</div>
- <div
- v-for="chat in chats"
- :key="chat.id"
- class="chat-item"
- :class="{ active: chat.id === activeChatId }"
- @click="$emit('select', chat.id)"
- >
- <div class="chat-item-main">
- <!-- 鍙屽嚮杩涘叆閲嶅懡鍚嶏紝绗﹀悎妗岄潰绔枃浠剁鐞嗙殑鐩磋 -->
- <n-input
- v-if="editingId === chat.id"
- ref="renameInputRef"
- v-model:value="editingTitle"
- size="tiny"
- @blur="commitRename(chat)"
- @keyup.enter="commitRename(chat)"
- @keyup.esc="cancelRename"
- @click.stop
+ <div v-for="group in sections.timeGroups" :key="group.key" class="chat-group">
+ <div class="chat-group-title">{{ group.label }}</div>
+ <ChatListItem
+ v-for="chat in group.chats"
+ :key="chat.id"
+ :chat="chat"
+ :active="chat.id === activeChatId"
+ :options="menuFor(chat)"
+ @select="(id) => $emit('select', id)"
+ @menu="handleMenu"
/>
- <div v-else class="chat-title" @dblclick.stop="startRename(chat)">
- {{ chat.title || '鏂板璇�' }}
- </div>
- <div class="chat-meta">
- <span>{{ chat.messageCount || 0 }} 鏉℃秷鎭�</span>
- <span v-if="chat.collectionNames?.length" class="chat-rag-tag">
- 路 {{ chat.collectionNames.length }} 涓煡璇嗗簱
- </span>
- </div>
- </div>
-
- <n-dropdown
- trigger="click"
- :options="menuOptions"
- @select="(key) => handleMenu(key, chat)"
- >
- <n-button text class="chat-more" @click.stop>鈰�</n-button>
- </n-dropdown>
</div>
</template>
+ </div>
+
+ <!-- 褰掓。鍏ュ彛 -->
+ <div class="sidebar-archive">
+ <div class="archive-entry" @click="archiveVisible = true">
+ <span class="archive-icon">馃梽</span>
+ <span class="archive-text">褰掓。瀵硅瘽</span>
+ <n-badge
+ v-if="archivedCount > 0"
+ :value="archivedCount"
+ :max="99"
+ type="info"
+ class="archive-badge"
+ />
+ </div>
</div>
<div class="sidebar-footer">
@@ -117,14 +171,80 @@
</div>
</n-dropdown>
</div>
+
+ <!-- 鏂板缓 / 閲嶅懡鍚嶅垎缁勫叡鐢ㄥ悓涓�涓脊绐� -->
+ <n-modal
+ v-model:show="groupModal.show"
+ preset="card"
+ :title="groupModal.id ? '閲嶅懡鍚嶅垎缁�' : '鏂板缓鍒嗙粍'"
+ class="small-modal"
+ :bordered="false"
+ >
+ <n-input
+ v-model:value="groupModal.name"
+ placeholder="鍒嗙粍鍚嶇О锛屼緥濡傘�屽伐浣溿�嶃�屽涔犺祫鏂欍��"
+ maxlength="64"
+ show-count
+ @keyup.enter="confirmGroupModal"
+ />
+ <template #footer>
+ <div class="modal-footer">
+ <n-button size="small" @click="groupModal.show = false">鍙栨秷</n-button>
+ <n-button
+ size="small"
+ type="primary"
+ :loading="groupModal.saving"
+ @click="confirmGroupModal"
+ >
+ 淇濆瓨
+ </n-button>
+ </div>
+ </template>
+ </n-modal>
+
+ <!-- 閲嶅懡鍚嶅璇� -->
+ <n-modal
+ v-model:show="renameModal.show"
+ preset="card"
+ title="閲嶅懡鍚嶅璇�"
+ class="small-modal"
+ :bordered="false"
+ >
+ <n-input
+ v-model:value="renameModal.title"
+ placeholder="杈撳叆鏂扮殑瀵硅瘽鍚嶇О"
+ maxlength="255"
+ show-count
+ @keyup.enter="confirmRenameModal"
+ />
+ <template #footer>
+ <div class="modal-footer">
+ <n-button size="small" @click="renameModal.show = false">鍙栨秷</n-button>
+ <n-button
+ size="small"
+ type="primary"
+ :loading="renameModal.saving"
+ @click="confirmRenameModal"
+ >
+ 淇濆瓨
+ </n-button>
+ </div>
+ </template>
+ </n-modal>
+
+ <ArchivedChatDrawer v-model:show="archiveVisible" @select="handleArchivedSelect" />
</div>
</template>
<script setup>
-import { computed, nextTick, ref } from 'vue'
-import { NButton, NDropdown, NInput, NSpin, useDialog, useMessage } from 'naive-ui'
+import { computed, ref } from 'vue'
+import { NBadge, NButton, NDropdown, NInput, NModal, NSpin, useDialog, useMessage } from 'naive-ui'
+import ArchivedChatDrawer from '@/components/ArchivedChatDrawer.vue'
+import ChatListItem from '@/components/ChatListItem.vue'
import { useAuthStore } from '@/stores/authStore'
import { useChatStore } from '@/stores/chatStore'
+import { buildSidebarSections } from '@/utils/sidebarGroups'
+import { usePersistentFlag, usePersistentMap } from '@/utils/uiPrefs'
const emit = defineEmits(['select', 'created', 'deleted', 'open-files', 'open-admin-knowledge'])
@@ -134,31 +254,311 @@
const dialog = useDialog()
const loading = ref(false)
-const editingId = ref(null)
-const editingTitle = ref('')
-const renameInputRef = ref(null)
+const archiveVisible = ref(false)
/** 鎼滅储妗嗙殑鏈湴杈撳叆鍊硷紙涓� store 閲岀殑宸叉彁浜ゅ叧閿瘝鍖哄垎寮�锛� */
const keyword = ref('')
+/**
+ * 鎶樺彔鐘舵�侊細绾鍥惧亸濂斤紝瀛� localStorage锛屼笉鎵撴壈鍚庣銆�
+ *
+ * 銆屾暣涓垎缁勫尯鍧椼�嶇殑寮�鍏宠В鏋勬垚椤跺眰 ref 鈥斺�� Vue 鍙細鑷姩瑙e寘
+ * setup 椤跺眰杩斿洖鐨� ref锛屽鏋滄妸瀹冪暀鍦ㄥ璞¢噷锛坒lag.value锛夛紝
+ * 妯℃澘閲屽氨寰楀啓 flag.value.value锛屾瀬鏄撳啓閿欍��
+ */
+const {
+ collapsed: groupSectionCollapsed,
+ toggle: toggleGroupSection
+} = usePersistentFlag('group_section_collapsed', false)
+const groupCollapse = usePersistentMap('group_collapsed')
+
const chats = computed(() => chatStore.chats)
const activeChatId = computed(() => chatStore.activeChatId)
-
-/** 鏄惁澶勪簬鎼滅储鎬侊細鍙鍏抽敭璇嶉潪绌哄氨鏄剧ず鎼滅储缁撴灉鑰岄潪瀹屾暣鍒楄〃 */
+const archivedCount = computed(() => chatStore.archivedChats.length)
const isSearching = computed(() => chatStore.searchKeyword.length > 0)
-/** 鎼滅储鎬佹樉绀虹粨鏋滃垪琛紝鏅�氭�佹樉绀哄叏閮ㄤ細璇� */
-const visibleChats = computed(() =>
- isSearching.value ? chatStore.searchResults : chatStore.chats
+/**
+ * 渚ц竟鏍忕粨鏋勶細鍒嗙粍 / 缃《 / 浠婂ぉ / 鏄ㄥぉ / 鏇存棭銆�
+ *
+ * 绾绠楀睘鎬� 鈥斺�� 缂栨帓瑙勫垯閮藉湪 buildSidebarSections 閲岋紝
+ * 缁勪欢鍙礋璐f覆鏌擄紝瑙勫垯涔熻兘鍗曠嫭娴嬨��
+ */
+const sections = computed(() =>
+ buildSidebarSections(chats.value, chatStore.chatGroups)
)
+function isGroupCollapsed(id) {
+ return groupCollapse.isCollapsed(id)
+}
+
+function toggleGroup(id) {
+ groupCollapse.toggle(id)
+}
+
+const avatarText = computed(() => (auth.displayName || '?').charAt(0).toUpperCase())
+
+// ---------------- 寮圭獥鐘舵�� ----------------
+
+const groupModal = ref({ show: false, id: null, name: '', saving: false })
+const renameModal = ref({ show: false, id: null, title: '', saving: false })
+
+function openCreateGroup() {
+ groupModal.value = { show: true, id: null, name: '', saving: false }
+}
+
+function openRenameGroup(group) {
+ groupModal.value = { show: true, id: group.id, name: group.name, saving: false }
+}
+
+async function confirmGroupModal() {
+ const name = groupModal.value.name.trim()
+ if (!name) {
+ message.warning('鍒嗙粍鍚嶄笉鑳戒负绌�')
+ return
+ }
+ groupModal.value.saving = true
+ try {
+ if (groupModal.value.id) {
+ await chatStore.renameChatGroup(groupModal.value.id, name)
+ message.success('鍒嗙粍宸查噸鍛藉悕')
+ } else {
+ await chatStore.createChatGroup(name)
+ message.success('鍒嗙粍宸插垱寤�')
+ }
+ groupModal.value.show = false
+ } catch (error) {
+ // 閲嶅悕绛変笟鍔¢敊璇敱鍚庣缁欏嚭浜鸿瘽鎻愮ず锛岃繖閲岀洿鎺ュ睍绀�
+ message.error(error.message || '鎿嶄綔澶辫触')
+ } finally {
+ groupModal.value.saving = false
+ }
+}
+
+// ---------------- 鑿滃崟 ----------------
+
/**
- * 杈撳叆闃叉姈銆�
+ * 姣忔潯浼氳瘽鐨勮彍鍗曘��
*
- * 銆岃緭鍏ュ嵆鏌ャ�嶈嫢涓嶉槻鎶栵紝姣忔暡涓�涓瓧閮戒細鎵撲竴娆℃帴鍙o紝
- * 鑰屼笖涓枃杈撳叆娉曞湪鎷奸煶闃舵涔熶細棰戠箒瑙﹀彂 input 浜嬩欢銆�
- * 250ms 鏄墦瀛楀仠椤夸笌鍝嶅簲閫熷害涔嬮棿鐨勫父瑙佹姌涓��
+ * 銆岀Щ鍔ㄥ埌鍒嗙粍銆嶇殑瀛愯彍鍗曞垪鍑恒�屾湭鍒嗙粍 + 鎵�鏈夊垎缁勩�嶏紝褰撳墠鎵�鍦ㄧ殑閭d竴椤规墦鍕� 鈥斺��
+ * 鐢ㄦ埛涓嶅繀鍏堣浣忓畠鍦ㄥ摢涓垎缁勯噷銆�
*/
+function menuFor(chat) {
+ const moveChildren = [
+ {
+ label: chat.groupId == null ? '鉁� 鏈垎缁�' : '鏈垎缁�',
+ key: 'move-none'
+ },
+ ...chatStore.chatGroups.map((group) => ({
+ label: (chat.groupId === group.id ? '鉁� ' : '') + group.name,
+ key: 'move-' + group.id
+ }))
+ ]
+
+ return [
+ { label: chat.pinned ? '鍙栨秷缃《' : '缃《', key: 'pin' },
+ { label: '閲嶅懡鍚�', key: 'rename' },
+ { label: '绉诲姩鍒板垎缁�', key: 'move', children: moveChildren },
+ {
+ label: '涓嬭浇',
+ key: 'download',
+ children: [
+ { label: 'JSON锛堝惈鍏ㄩ儴鍒嗘敮锛�', key: 'download-json' },
+ { label: 'TXT锛堢函鏂囨湰锛�', key: 'download-txt' },
+ { label: 'PDF锛堝甫椤电爜鎺掔増锛�', key: 'download-pdf' }
+ ]
+ },
+ { label: '褰掓。', key: 'archive' },
+ { type: 'divider', key: 'd1' },
+ { label: '鐭ヨ瘑搴撹缃�', key: 'rag' },
+ { label: '鍒犻櫎瀵硅瘽', key: 'delete', props: { style: 'color: #d03050;' } }
+ ]
+}
+
+const groupMenuOptions = [
+ { label: '閲嶅懡鍚嶅垎缁�', key: 'rename' },
+ { label: '鍒犻櫎鍒嗙粍', key: 'delete', props: { style: 'color: #d03050;' } }
+]
+
+const userMenuOptions = computed(() => {
+ const options = [{ label: '鎴戠殑鐭ヨ瘑搴�', key: 'files' }]
+ // 绠$悊鍛橀澶栨彁渚涘叏灞�鐭ヨ瘑搴撶淮鎶ゅ叆鍙c��
+ // 鍚庣瀵� /api/files/global/upload 绛夌鐐瑰彟鏈� 403 鏍¢獙锛�
+ // 杩欓噷鐨勯殣钘忓彧鏄伩鍏嶆櫘閫氱敤鎴风湅鍒版棤鏉冮檺鐨勮彍鍗曢」銆�
+ if (auth.isAdmin) {
+ options.push({ label: '鍏ㄥ眬鐭ヨ瘑搴擄紙绠$悊鍛橈級', key: 'admin-knowledge' })
+ }
+ options.push({ type: 'divider', key: 'd1' })
+ options.push({ label: '閫�鍑虹櫥褰�', key: 'logout' })
+ return options
+})
+
+async function handleMenu(key, chat) {
+ if (key.startsWith('move-')) {
+ const raw = key.slice('move-'.length)
+ const groupId = raw === 'none' ? null : Number(raw)
+ await moveChat(chat, groupId)
+ return
+ }
+
+ switch (key) {
+ case 'pin':
+ await togglePin(chat)
+ break
+ case 'rename':
+ renameModal.value = { show: true, id: chat.id, title: chat.title || '', saving: false }
+ break
+ case 'download-json':
+ await download(chat, 'json')
+ break
+ case 'download-txt':
+ await download(chat, 'txt')
+ break
+ case 'download-pdf':
+ await download(chat, 'pdf')
+ break
+ case 'archive':
+ archive(chat)
+ break
+ case 'rag':
+ emit('select', chat.id)
+ emit('open-files')
+ break
+ case 'delete':
+ confirmDelete(chat)
+ break
+ default:
+ break
+ }
+}
+
+async function handleGroupMenu(key, group) {
+ if (key === 'rename') {
+ openRenameGroup(group)
+ return
+ }
+ if (key === 'delete') {
+ dialog.warning({
+ title: '鍒犻櫎鍒嗙粍',
+ content: `纭畾鍒犻櫎鍒嗙粍銆�${group.name}銆嶅悧锛熺粍鍐呯殑 ${group.chats.length} 鏉″璇漙
+ + '**涓嶄細琚垹闄�**锛屽畠浠細鍥炲埌銆屾湭鍒嗙粍銆嶏紝缁х画鎸夋椂闂村綊绫汇��',
+ positiveText: '鍒犻櫎鍒嗙粍',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ const moved = await chatStore.deleteChatGroup(group.id)
+ message.success(moved > 0
+ ? `鍒嗙粍宸插垹闄わ紝${moved} 鏉″璇濆凡鍥炲埌鏈垎缁刞
+ : '鍒嗙粍宸插垹闄�')
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎鍒嗙粍澶辫触')
+ return false
+ }
+ return true
+ }
+ })
+ }
+}
+
+async function moveChat(chat, groupId) {
+ if ((chat.groupId ?? null) === groupId) {
+ return
+ }
+ try {
+ await chatStore.moveChatToGroup(chat.id, groupId)
+ const name = groupId == null
+ ? '鏈垎缁�'
+ : chatStore.chatGroups.find((g) => g.id === groupId)?.name || '鍒嗙粍'
+ message.success(`宸茬Щ鍔ㄥ埌銆�${name}銆峘)
+ } catch (error) {
+ message.error(error.message || '绉诲姩澶辫触')
+ }
+}
+
+async function togglePin(chat) {
+ try {
+ await chatStore.setPinned(chat.id, !chat.pinned)
+ message.success(chat.pinned ? '宸插彇娑堢疆椤�' : '宸茬疆椤�')
+ } catch (error) {
+ message.error(error.message || '鎿嶄綔澶辫触')
+ }
+}
+
+const downloading = ref(false)
+
+async function download(chat, format) {
+ if (downloading.value) return
+ downloading.value = true
+ message.loading(`姝e湪瀵煎嚭 ${format.toUpperCase()}鈥, { duration: 1200 })
+ try {
+ const filename = await chatStore.exportChat(chat.id, format)
+ message.success(`宸插鍑� ${filename}`)
+ } catch (error) {
+ message.error(error.message || '瀵煎嚭澶辫触')
+ } finally {
+ downloading.value = false
+ }
+}
+
+function archive(chat) {
+ dialog.create({
+ title: '褰掓。瀵硅瘽',
+ content: `銆�${chat.title || '鏂板璇�'}銆嶅皢浠庡垪琛ㄦ敹璧枫�傛秷鎭笌鐭ヨ瘑搴撶粦瀹氶兘浼氫繚鐣欙紝`
+ + '涔嬪悗鍙互鍦ㄣ�屽綊妗e璇濄�嶉噷鎵惧埌骞舵仮澶嶃��',
+ positiveText: '褰掓。',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await chatStore.setArchived(chat.id, true)
+ message.success('宸插綊妗o紝鍙湪銆屽綊妗e璇濄�嶄腑鏌ョ湅')
+ } catch (error) {
+ message.error(error.message || '褰掓。澶辫触')
+ return false
+ }
+ return true
+ }
+ })
+}
+
+function confirmDelete(chat) {
+ dialog.warning({
+ title: '鍒犻櫎瀵硅瘽',
+ content: `纭畾鍒犻櫎銆�${chat.title}銆嶅悧锛熻浼氳瘽鐨勬墍鏈夋秷鎭兘浼氳涓�骞跺垹闄わ紝涓旀棤娉曟仮澶嶃�俙,
+ positiveText: '鍒犻櫎',
+ negativeText: '鍙栨秷',
+ onPositiveClick: async () => {
+ try {
+ await chatStore.removeChat(chat.id)
+ message.success('宸插垹闄�')
+ emit('deleted', chat.id)
+ } catch (error) {
+ message.error(error.message || '鍒犻櫎澶辫触')
+ return false
+ }
+ return true
+ }
+ })
+}
+
+async function confirmRenameModal() {
+ const title = renameModal.value.title.trim()
+ if (!title) {
+ message.warning('鍚嶇О涓嶈兘涓虹┖')
+ return
+ }
+ renameModal.value.saving = true
+ try {
+ await chatStore.renameChat(renameModal.value.id, title)
+ message.success('宸查噸鍛藉悕')
+ renameModal.value.show = false
+ } catch (error) {
+ message.error(error.message || '閲嶅懡鍚嶅け璐�')
+ } finally {
+ renameModal.value.saving = false
+ }
+}
+
+// ---------------- 鎼滅储 ----------------
+
let searchTimer = null
const SEARCH_DEBOUNCE_MS = 250
@@ -169,7 +569,6 @@
const value = keyword.value
if (!value || !value.trim()) {
- // 娓呯┖鏃剁珛鍗虫仮澶嶅畬鏁村垪琛紝涓嶅繀绛夐槻鎶�
if (searchTimer) clearTimeout(searchTimer)
chatStore.clearSearch()
return
@@ -190,47 +589,9 @@
chatStore.clearSearch()
}
-/** 鍛戒腑绫诲瀷鏂囨 */
-function matchLabel(type) {
- if (type === 'title') return '鏍囬鍛戒腑'
- if (type === 'both') return '鏍囬+鍐呭'
- return '鍐呭鍛戒腑'
-}
-
-const avatarText = computed(() => (auth.displayName || '?').charAt(0).toUpperCase())
-
-const menuOptions = [
- { label: '閲嶅懡鍚�', key: 'rename' },
- { label: '鐭ヨ瘑搴撹缃�', key: 'rag' },
- { type: 'divider', key: 'd1' },
- { label: '鍒犻櫎瀵硅瘽', key: 'delete' }
-]
-
-const userMenuOptions = computed(() => {
- const options = [{ label: '鎴戠殑鐭ヨ瘑搴�', key: 'files' }]
- // 绠$悊鍛橀澶栨彁渚涘叏灞�鐭ヨ瘑搴撶淮鎶ゅ叆鍙c��
- // 鍚庣瀵� /api/files/global/upload 绛夌鐐瑰彟鏈� 403 鏍¢獙锛�
- // 杩欓噷鐨勯殣钘忓彧鏄伩鍏嶆櫘閫氱敤鎴风湅鍒版棤鏉冮檺鐨勮彍鍗曢」銆�
- if (auth.isAdmin) {
- options.push({ label: '鍏ㄥ眬鐭ヨ瘑搴擄紙绠$悊鍛橈級', key: 'admin-knowledge' })
- }
- options.push({ type: 'divider', key: 'd1' })
- options.push({ label: '閫�鍑虹櫥褰�', key: 'logout' })
- return options
-})
-
-/** 鐢辩埗缁勪欢鍦ㄦ寕杞芥椂璋冪敤锛岄伩鍏嶇粍浠惰嚜宸辫Е鍙戣姹傞�犳垚鏃跺簭涓嶇‘瀹� */
-async function refresh() {
- loading.value = true
- try {
- // 鍒锋柊浼氳瘽鍒楄〃鏃堕��鍑烘悳绱㈡�侊紝閬垮厤鍋滅暀鍦ㄦ棫缁撴灉涓�
- handleClearSearch()
- await chatStore.loadChats()
- } catch (error) {
- message.error(error.message || '鍔犺浇浼氳瘽鍒楄〃澶辫触')
- } finally {
- loading.value = false
- }
+function handleArchivedSelect(id) {
+ archiveVisible.value = false
+ emit('select', id)
}
async function handleNewChat() {
@@ -242,65 +603,6 @@
}
}
-function startRename(chat) {
- editingId.value = chat.id
- editingTitle.value = chat.title
- nextTick(() => {
- // ref 鍦� v-for 涓細鏄暟缁�
- const input = Array.isArray(renameInputRef.value)
- ? renameInputRef.value[0]
- : renameInputRef.value
- input?.focus?.()
- })
-}
-
-function cancelRename() {
- editingId.value = null
- editingTitle.value = ''
-}
-
-async function commitRename(chat) {
- const title = editingTitle.value.trim()
- // 娌℃敼鍔ㄦ垨涓虹┖鍒欐斁寮冿紝閬垮厤浜х敓绌烘爣棰�
- if (!title || title === chat.title) {
- cancelRename()
- return
- }
- try {
- await chatStore.renameChat(chat.id, title)
- message.success('宸查噸鍛藉悕')
- } catch (error) {
- message.error(error.message || '閲嶅懡鍚嶅け璐�')
- } finally {
- cancelRename()
- }
-}
-
-function handleMenu(key, chat) {
- if (key === 'rename') {
- startRename(chat)
- } else if (key === 'rag') {
- emit('select', chat.id)
- emit('open-files')
- } else if (key === 'delete') {
- dialog.warning({
- title: '鍒犻櫎瀵硅瘽',
- content: `纭畾鍒犻櫎銆�${chat.title}銆嶅悧锛熻浼氳瘽鐨勬墍鏈夋秷鎭兘浼氳涓�骞跺垹闄わ紝涓旀棤娉曟仮澶嶃�俙,
- positiveText: '鍒犻櫎',
- negativeText: '鍙栨秷',
- onPositiveClick: async () => {
- try {
- await chatStore.removeChat(chat.id)
- message.success('宸插垹闄�')
- emit('deleted', chat.id)
- } catch (error) {
- message.error(error.message || '鍒犻櫎澶辫触')
- }
- }
- })
- }
-}
-
function handleUserMenu(key) {
if (key === 'files') {
emit('open-files')
@@ -309,6 +611,23 @@
} else if (key === 'logout') {
auth.logout()
emit('deleted', null)
+ }
+}
+
+/** 鐢辩埗缁勪欢鍦ㄦ寕杞芥椂璋冪敤锛岄伩鍏嶇粍浠惰嚜宸辫Е鍙戣姹傞�犳垚鏃跺簭涓嶇‘瀹� */
+async function refresh() {
+ loading.value = true
+ try {
+ handleClearSearch()
+ await Promise.all([
+ chatStore.loadChats(),
+ chatStore.loadArchivedChats(),
+ chatStore.loadChatGroups()
+ ])
+ } catch (error) {
+ message.error(error.message || '鍔犺浇浼氳瘽鍒楄〃澶辫触')
+ } finally {
+ loading.value = false
}
}
@@ -349,27 +668,147 @@
color: var(--text-muted);
}
-.chat-snippet {
- font-size: 11.5px;
- color: var(--text-secondary);
- margin-top: 3px;
- /* 鐗囨鏈�澶氫袱琛岋紝瓒呭嚭鐢ㄧ渷鐣ュ彿鎴柇 */
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- overflow: hidden;
- line-height: 1.5;
-}
-
-.match-badge {
- color: #0f766e;
- margin-left: 6px;
-}
-
.sidebar-list {
flex: 1;
overflow-y: auto;
padding: 0 8px 8px;
+}
+
+/* ---------- 鍒嗙粍鍖哄潡 ---------- */
+
+.section {
+ margin-bottom: 6px;
+}
+
+.section-head {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ padding: 6px 10px;
+ border-radius: 6px;
+ cursor: pointer;
+ user-select: none;
+}
+
+.section-head:hover {
+ background: var(--bg-hover);
+}
+
+.section-head.static {
+ cursor: default;
+}
+
+.section-head.static:hover {
+ background: transparent;
+}
+
+.section-title {
+ font-size: 11.5px;
+ font-weight: 600;
+ letter-spacing: 0.3px;
+ color: var(--text-muted);
+}
+
+.section-count {
+ font-size: 11px;
+ color: var(--text-muted);
+}
+
+.section-add {
+ margin-left: auto;
+ font-size: 15px;
+ line-height: 1;
+ padding: 0 4px;
+ color: var(--text-secondary);
+}
+
+.section-add:hover {
+ color: #2080f0;
+}
+
+.section-empty,
+.group-empty {
+ padding: 6px 10px 8px 26px;
+ font-size: 11.5px;
+ color: var(--text-muted);
+ line-height: 1.7;
+}
+
+/* 鎶樺彔绠ご锛氶粯璁ゆ湞涓嬶紝鎶樺彔鏃惰浆 -90 搴� */
+.chevron {
+ display: inline-block;
+ width: 12px;
+ font-size: 10px;
+ color: var(--text-muted);
+ transition: transform 0.15s ease;
+}
+
+.chevron.collapsed {
+ transform: rotate(-90deg);
+}
+
+.chevron.small {
+ font-size: 9px;
+}
+
+.group-block {
+ margin-bottom: 2px;
+}
+
+.group-head {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ padding: 6px 10px 6px 14px;
+ border-radius: 6px;
+ cursor: pointer;
+ user-select: none;
+}
+
+.group-head:hover {
+ background: var(--bg-hover);
+}
+
+.group-name {
+ font-size: 12.5px;
+ font-weight: 500;
+ color: var(--text-primary);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.group-count {
+ font-size: 11px;
+ color: var(--text-muted);
+}
+
+.group-more {
+ margin-left: auto;
+ font-size: 14px;
+ line-height: 1;
+ padding: 0 4px;
+ color: var(--text-secondary);
+ opacity: 0;
+ transition: opacity 0.12s ease;
+}
+
+.group-head:hover .group-more {
+ opacity: 1;
+}
+
+/* ---------- 鏃堕棿鍒嗙粍 ---------- */
+
+.chat-group-title {
+ position: sticky;
+ top: 0;
+ z-index: 1;
+ padding: 8px 10px 4px;
+ font-size: 11px;
+ font-weight: 600;
+ letter-spacing: 0.3px;
+ color: var(--text-muted);
+ background: var(--bg-sidebar);
}
.sidebar-loading {
@@ -383,64 +822,36 @@
line-height: 1.9;
}
-.chat-item {
- display: flex;
- align-items: center;
- gap: 4px;
- padding: 9px 10px;
- border-radius: 8px;
- cursor: pointer;
- margin-bottom: 2px;
- transition: background 0.12s ease;
+/* ---------- 褰掓。鍏ュ彛 ---------- */
+
+.sidebar-archive {
+ padding: 4px 8px 0;
}
-.chat-item:hover {
+.archive-entry {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 8px 10px;
+ border-radius: 8px;
+ cursor: pointer;
+ font-size: 12.5px;
+ color: var(--text-secondary);
+}
+
+.archive-entry:hover {
background: var(--bg-hover);
}
-.chat-item.active {
- background: #e3e5e8;
+.archive-icon {
+ font-size: 13px;
}
-.chat-item-main {
+.archive-text {
flex: 1;
- min-width: 0;
}
-.chat-title {
- font-size: 13.5px;
- font-weight: 500;
- /* 鍗曡鎴柇锛岄伩鍏嶉暱鏍囬鎶婁晶杈规爮鎾戝紑 */
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.chat-meta {
- font-size: 11.5px;
- color: var(--text-muted);
- margin-top: 3px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.chat-rag-tag {
- color: #6b7280;
-}
-
-.chat-more {
- opacity: 0;
- font-size: 16px;
- line-height: 1;
- padding: 0 4px;
- color: var(--text-secondary);
- transition: opacity 0.12s ease;
-}
-
-.chat-item:hover .chat-more {
- opacity: 1;
-}
+/* ---------- 搴曢儴鐢ㄦ埛鍖� ---------- */
.sidebar-footer {
border-top: 1px solid var(--border-color);
@@ -495,4 +906,14 @@
.user-more {
color: var(--text-muted);
}
+
+.small-modal {
+ width: 420px;
+}
+
+.modal-footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: 8px;
+}
</style>
diff --git a/src/stores/chatStore.js b/src/stores/chatStore.js
index d2cb46b..681a144 100644
--- a/src/stores/chatStore.js
+++ b/src/stores/chatStore.js
@@ -1,6 +1,8 @@
import { defineStore } from 'pinia'
import { computed, reactive, ref } from 'vue'
import * as chatApi from '@/api/chatApi'
+import * as chatGroupApi from '@/api/chatGroupApi'
+import { filenameFromDisposition, saveBlob } from '@/utils/download'
import { useAuthStore } from './authStore'
import { streamChat as openSseStream } from '@/utils/sse'
import {
@@ -31,6 +33,27 @@
*/
export const useChatStore = defineStore('chat', () => {
const chats = ref([])
+
+ /**
+ * 宸插綊妗g殑浼氳瘽銆�
+ *
+ * 鍗曠嫭涓�浠借�屼笉鏄拰 chats 娣峰湪涓�璧烽潬瀛楁杩囨护锛�
+ * 涓诲垪琛ㄤ笌褰掓。鍒楄〃鏄�**涓や釜瑙嗗浘**锛屽悇鑷湁鐙珛鐨勫姞杞芥椂鏈轰笌鎼滅储鍏抽敭璇嶏紝
+ * 娣峰湪涓�璧峰悗姣忔娓叉煋閮借杩囨护锛屽緢瀹规槗鍑虹幇銆屽綊妗d簡浣嗕富鍒楄〃杩樻樉绀恒�嶈繖绫�
+ * 鐘舵�佷笉涓�鑷淬�傚垎寮�瀛樻斁锛屽綊妗e姩浣滃氨鏄妸鍏冪礌浠庝竴涓暟缁勬惉鍒板彟涓�涓��
+ */
+ const archivedChats = ref([])
+ /** 褰掓。鍒楄〃鏄惁宸插姞杞借繃 鈥斺�� 鐢ㄤ簬鍖哄垎銆岀‘瀹炴病鏈夊綊妗c�嶅拰銆岃繕娌℃煡銆� */
+ const archiveLoaded = ref(false)
+
+ /**
+ * 鐢ㄦ埛鑷缓鐨勫垎缁勶紙鏂囦欢澶癸級銆�
+ *
+ * 鍙瓨鍒嗙粍鏈韩锛涖�屽摢浜涗細璇濆湪鍝釜鍒嗙粍閲屻�嶇敱姣忔潯浼氳瘽鐨� groupId 鍐冲畾锛�
+ * 鍓嶇鎸夊畠鍒嗘《銆傝繖鏍风Щ鍔ㄤ細璇濆彧闇�瑕佸埛鏂颁細璇濆垪琛紝涓嶅繀鍐嶆媺涓�娆″垎缁勩��
+ */
+ const chatGroups = ref([])
+
const activeChatId = ref(null)
const tree = ref([])
@@ -49,7 +72,12 @@
const path = computed(() => buildPath(tree.value, selections))
const activeChat = computed(
- () => chats.value.find((chat) => chat.id === activeChatId.value) || null
+ () =>
+ chats.value.find((chat) => chat.id === activeChatId.value) ||
+ // 褰掓。鐨勪細璇濅笉鍦ㄤ富鍒楄〃閲岋紝浣嗙敤鎴峰彲鑳藉垰浠庛�屽綊妗e璇濄�嶉噷鐐瑰紑瀹� 鈥斺��
+ // 鎵句笉鍒板氨杩斿洖 null 浼氳鏍囬鏍忋�佹ā鍨嬪弬鏁版娊灞変竴璧峰彉绌�
+ archivedChats.value.find((chat) => chat.id === activeChatId.value) ||
+ null
)
// ============================================================
@@ -57,65 +85,145 @@
// ============================================================
async function loadChats() {
- chats.value = await chatApi.listChats()
+ chats.value = await chatApi.listChats(false)
return chats.value
+ }
+
+ /** 鍔犺浇褰掓。鍒楄〃 */
+ async function loadArchivedChats() {
+ archivedChats.value = await chatApi.listChats(true)
+ archiveLoaded.value = true
+ return archivedChats.value
+ }
+
+ // ---------------- 鑷缓鍒嗙粍 ----------------
+
+ async function loadChatGroups() {
+ chatGroups.value = await chatGroupApi.listChatGroups()
+ return chatGroups.value
+ }
+
+ async function createChatGroup(name) {
+ const group = await chatGroupApi.createChatGroup(name)
+ chatGroups.value.push(group)
+ return group
+ }
+
+ async function renameChatGroup(groupId, name) {
+ const updated = await chatGroupApi.renameChatGroup(groupId, name)
+ const index = chatGroups.value.findIndex((g) => g.id === groupId)
+ if (index !== -1) {
+ chatGroups.value[index] = updated
+ }
+ return updated
+ }
+
+ /**
+ * 鍒犻櫎鍒嗙粍锛氱粍鍐呬細璇濆洖鍒般�屾湭鍒嗙粍銆嶃��
+ *
+ * 蹇呴』閲嶆柊鎷変細璇濆垪琛� 鈥斺�� 浼氳瘽鏈韩娌″彉锛堣繕鍦ㄥ師澶勩�佽繕鏄師鏉ョ殑鏃堕棿锛夛紝
+ * 浣嗗畠浠殑 groupId 宸茬粡琚悗绔竻绌猴紝涓嶅埛鏂扮殑璇濆畠浠細鎸傚湪涓�涓�
+ * 宸茬粡涓嶅瓨鍦ㄥ垎缁勪笅鑰屾暣涓秷澶便��
+ */
+ async function deleteChatGroup(groupId) {
+ const result = await chatGroupApi.deleteChatGroup(groupId)
+ chatGroups.value = chatGroups.value.filter((g) => g.id !== groupId)
+ await loadChats()
+ return result?.movedChats ?? 0
+ }
+
+ /** 鎶婁細璇濈Щ鍏� / 绉诲嚭鍒嗙粍锛坓roupId 浼� null 琛ㄧず绉诲嚭锛� */
+ async function moveChatToGroup(chatId, groupId) {
+ const updated = await chatApi.moveChatToGroup(chatId, groupId)
+ replaceInLists(updated)
+ // 鍒嗙粍鏁板瓧瑕佽窡鐫�鍙橈紝鍚屾椂鍒锋柊椤哄簭锛堝悗绔粛鎸夌疆椤�/娲昏穬鎺掑簭锛�
+ await Promise.all([loadChats(), loadChatGroups()])
+ return updated
}
// ---------------- 鎼滅储鍘嗗彶瀵硅瘽 ----------------
- /** 鎼滅储鍏抽敭璇嶏紱涓虹┖琛ㄧず鏈浜庢悳绱㈡�� */
- const searchKeyword = ref('')
- /** 鎼滅储缁撴灉锛圕hatDTO 鏁扮粍锛屽甫 matchSnippet / matchType锛� */
- const searchResults = ref([])
- const searching = ref(false)
/**
- * 璇锋眰搴忓彿銆�
+ * 寤轰竴涓嫭绔嬬殑鎼滅储鍣ㄣ��
*
- * 鎼滅储鏄�岃緭鍏ュ嵆鏌ャ�嶏紝鎱㈢殑鏃ц姹傚彲鑳藉悗浜庢柊璇锋眰杩斿洖锛�
- * 鐩存帴鎶婃棫缁撴灉鍐欒繘鍘诲氨浼氬嚭鐜般�岃緭鍏ヤ簡鏂拌瘝鍗存樉绀烘棫缁撴灉銆嶃��
- * 姣忔鍙戣捣閫掑骞惰浣忓簭鍙凤紝鍥炴潵鏃跺涓嶄笂灏变涪寮冦��
+ * 涓诲垪琛ㄤ笌褰掓。鍒楄〃瑕佸悇鏈変竴浠藉叧閿瘝涓庣粨鏋滐紝鎵�浠ュ仛鎴愬伐鍘傝�屼笉鏄袱缁勫彉閲忥細
+ * 涓ょ粍鍙橀噺鎰忓懗鐫�銆岃姹傚簭鍙枫�佺珵鎬佷涪寮冦�乴oading 鐘舵�併�嶈繖濂楅�昏緫瑕佸啓涓ら亶锛�
+ * 鑰屽畠鎭版伆鏄渶瀹规槗鍐欐紡銆佸啓閿欑殑閮ㄥ垎銆�
*/
- let searchSeq = 0
+ function createSearcher(archived) {
+ /** 鎼滅储鍏抽敭璇嶏紱涓虹┖琛ㄧず鏈浜庢悳绱㈡�� */
+ const keyword = ref('')
+ /** 鎼滅储缁撴灉锛圕hatDTO 鏁扮粍锛屽甫 matchSnippet / matchType锛� */
+ const results = ref([])
+ const loading = ref(false)
+ /**
+ * 璇锋眰搴忓彿銆傛悳绱㈡槸銆岃緭鍏ュ嵆鏌ャ�嶏紝鎱㈢殑鏃ц姹傚彲鑳藉悗浜庢柊璇锋眰杩斿洖锛�
+ * 鐩存帴鎶婃棫缁撴灉鍐欒繘鍘诲氨浼氬嚭鐜般�岃緭鍏ヤ簡鏂拌瘝鍗存樉绀烘棫缁撴灉銆嶃��
+ */
+ let seq = 0
- async function searchChats(keyword) {
- const kw = (keyword || '').trim()
- searchKeyword.value = kw
+ async function run(raw) {
+ const kw = (raw || '').trim()
+ keyword.value = kw
- if (!kw) {
- searchResults.value = []
- searching.value = false
- return []
- }
-
- const seq = ++searchSeq
- searching.value = true
- try {
- const results = await chatApi.searchChats(kw)
- if (seq !== searchSeq) {
- // 宸叉湁鏇存柊鐨勮姹傚彂鍑猴紝涓㈠純杩欐鐨勭粨鏋�
- return searchResults.value
+ if (!kw) {
+ results.value = []
+ loading.value = false
+ return []
}
- searchResults.value = Array.isArray(results) ? results : []
- return searchResults.value
- } catch (error) {
- if (seq === searchSeq) {
- searchResults.value = []
- }
- throw error
- } finally {
- if (seq === searchSeq) {
- searching.value = false
+
+ const mine = ++seq
+ loading.value = true
+ try {
+ const found = await chatApi.searchChats(kw, 30, archived)
+ if (mine !== seq) {
+ // 宸叉湁鏇存柊鐨勮姹傚彂鍑猴紝涓㈠純杩欐鐨勭粨鏋�
+ return results.value
+ }
+ results.value = Array.isArray(found) ? found : []
+ return results.value
+ } catch (error) {
+ if (mine === seq) {
+ results.value = []
+ }
+ throw error
+ } finally {
+ if (mine === seq) {
+ loading.value = false
+ }
}
}
+
+ function clear() {
+ seq++ // 璁╁湪閫旇姹傚け鏁�
+ keyword.value = ''
+ results.value = []
+ loading.value = false
+ }
+
+ return { keyword, results, loading, run, clear }
}
- /** 閫�鍑烘悳绱㈡�侊紝鎭㈠鏄剧ず瀹屾暣浼氳瘽鍒楄〃 */
- function clearSearch() {
- searchSeq++ // 璁╁湪閫旇姹傚け鏁�
- searchKeyword.value = ''
- searchResults.value = []
- searching.value = false
- }
+ const mainSearch = createSearcher(false)
+ const archiveSearch = createSearcher(true)
+
+ // 涓诲垪琛ㄦ悳绱細淇濈暀鎵佸钩鍛藉悕锛屼晶杈规爮鐩存帴鐢ㄨ繖浜涖��
+ //
+ // 娉ㄦ剰 Pinia 鍙 **椤跺眰** 杩斿洖鐨� ref 鍋氳嚜鍔ㄨВ鍖咃細杩欓噷浠ラ《灞傛垚鍛樻毚闇诧紝
+ // 缁勪欢閲屽氨鑳界洿鎺� `chatStore.searchKeyword`锛涘鏋滄妸鏁翠釜 searcher 瀵硅薄
+ // 鏆撮湶鍑哄幓锛岄噷闈㈡瘡涓� ref 閮藉緱鍐� `.value`锛屾瀬鏄撳啓閿欍��
+ const searchKeyword = mainSearch.keyword
+ const searchResults = mainSearch.results
+ const searching = mainSearch.loading
+ const searchChats = mainSearch.run
+ const clearSearch = mainSearch.clear
+
+ // 褰掓。鍒楄〃鐨勬悳绱細鍚屾牱浠ラ《灞傛垚鍛樻毚闇�
+ const archiveKeyword = archiveSearch.keyword
+ const archiveResults = archiveSearch.results
+ const archiveSearching = archiveSearch.loading
+ const searchArchive = archiveSearch.run
+ const clearArchiveSearch = archiveSearch.clear
async function createChat(payload = {}) {
const chat = await chatApi.createChat(payload)
@@ -124,34 +232,93 @@
return chat
}
- async function renameChat(chatId, title) {
- const updated = await chatApi.updateChat(chatId, { title })
- const index = chats.value.findIndex((chat) => chat.id === chatId)
- if (index !== -1) {
- // 鐢ㄦ浛鎹㈣�屼笉鏄� Object.assign锛氫繚璇佹墍鏈夊瓧娈甸兘涓庡悗绔竴鑷�
- chats.value[index] = updated
+ /**
+ * 鐢ㄦ湇鍔$杩斿洖鐨勬渶鏂板璞℃浛鎹㈡湰鍦扮紦瀛橀噷鐨勫悓涓�鏉°��
+ *
+ * 鍚屾椂鏌ヤ袱浠藉垪琛細涓�鏉′細璇濆彲鑳芥棦涓嶅湪涓诲垪琛紙宸插綊妗o級涔熶笉鍦ㄥ綊妗e垪琛�
+ * 锛堝垰鎭㈠锛夛紝鍙煡 chats 浼氳褰掓。瀵硅瘽鐨勯噸鍛藉悕銆岀湅璧锋潵娌$敓鏁堛�嶃��
+ */
+ function replaceInLists(updated) {
+ for (const list of [chats.value, archivedChats.value]) {
+ const index = list.findIndex((chat) => chat.id === updated.id)
+ if (index !== -1) {
+ // 鐢ㄦ浛鎹㈣�屼笉鏄� Object.assign锛氫繚璇佹墍鏈夊瓧娈甸兘涓庡悗绔竴鑷�
+ list[index] = updated
+ }
}
return updated
}
+ async function renameChat(chatId, title) {
+ return replaceInLists(await chatApi.updateChat(chatId, { title }))
+ }
+
async function updateChatMeta(chatId, meta) {
- const updated = await chatApi.updateChat(chatId, { meta })
- const index = chats.value.findIndex((chat) => chat.id === chatId)
- if (index !== -1) {
- chats.value[index] = updated
- }
+ return replaceInLists(await chatApi.updateChat(chatId, { meta }))
+ }
+
+ /**
+ * 缃《 / 鍙栨秷缃《銆�
+ *
+ * 鎿嶄綔瀹岄噸鏂版媺鍙栦富鍒楄〃锛岃�屼笉鏄湰鍦版敼涓�涓瓧娈典簡浜嬶細
+ * 缃《浼氭敼鍙樿繖鏉′細璇濆湪鍒楄〃涓殑**浣嶇疆**锛堣繘鍏ョ疆椤跺尯锛夛紝
+ * 鑰屾帓搴忚鍒欏湪鍚庣锛坧inned DESC, pinned_at DESC, updated_at DESC锛夈��
+ * 鏈湴鑷繁鎺掍竴閬嶅氨浼氬嚭鐜般�屽墠绔『搴忓拰鍚庣椤哄簭涓嶄竴鑷淬�嶏紝
+ * 鍒锋柊涓�娆″張璺冲洖鍘� 鈥斺�� 璁╁敮涓�鐨勬帓搴忔潈濞佺暀鍦ㄥ悗绔紝鍓嶇鍙礋璐e垎缁勩��
+ */
+ async function setPinned(chatId, pinned) {
+ const updated = await chatApi.updateChat(chatId, { pinned })
+ replaceInLists(updated)
+ await loadChats()
+ return updated
+ }
+
+ /**
+ * 褰掓。 / 鍙栨秷褰掓。銆�
+ *
+ * 褰掓。鏄竴娆°�岃法鍒楄〃鎼Щ銆嶏細涓诲垪琛ㄥ皯涓�鏉°�佸綊妗e垪琛ㄥ涓�鏉°��
+ * 涓や唤鍒楄〃閮介噸鏂版媺锛屼繚璇佷袱杈归兘涓�鑷达紙褰掓。鍒楄〃杩樿鎸夊綊妗f椂闂村�掑簭锛夈��
+ */
+ async function setArchived(chatId, archived) {
+ const updated = await chatApi.updateChat(chatId, { archived })
+ await Promise.all([loadChats(), loadArchivedChats()])
return updated
}
async function removeChat(chatId) {
await chatApi.deleteChat(chatId)
chats.value = chats.value.filter((chat) => chat.id !== chatId)
+ archivedChats.value = archivedChats.value.filter((chat) => chat.id !== chatId)
+ // 鎼滅储缁撴灉閲屼篃鍙兘娈嬬暀杩欎竴鏉★紝涓�骞舵竻鎺夛紝閬垮厤鐐硅繘鍘绘姤 404
+ mainSearch.results.value = mainSearch.results.value.filter((chat) => chat.id !== chatId)
+ archiveSearch.results.value = archiveSearch.results.value.filter((chat) => chat.id !== chatId)
if (activeChatId.value === chatId) {
activeChatId.value = null
tree.value = []
clearSelections()
}
+ }
+
+ /**
+ * 涓嬭浇浼氳瘽涓� json / txt / pdf銆�
+ *
+ * 鏂囦欢鍚嶄紭鍏堢敤鏈嶅姟绔� Content-Disposition 閲岀殑寤鸿鍚嶏紙瀹冨甫浜嗘爣棰樹笌鏃堕棿鎴筹級锛�
+ * 鎷夸笉鍒版椂鎵嶇敤鏈湴鎷肩殑鍏滃簳鍚嶃��
+ *
+ * @returns {Promise<string>} 瀹為檯淇濆瓨鐨勬枃浠跺悕
+ */
+ async function exportChat(chatId, format) {
+ const response = await chatApi.exportChat(chatId, format)
+ const blob = response.data
+ const disposition = response.headers?.['content-disposition']
+ const chat = chats.value.find((c) => c.id === chatId)
+ || archivedChats.value.find((c) => c.id === chatId)
+ const fallback = `${chat?.title || '瀵硅瘽'}_${chatId}.${format}`
+
+ const filename = filenameFromDisposition(disposition) || fallback
+ saveBlob(blob, filename)
+ return filename
}
// ============================================================
@@ -483,6 +650,11 @@
await loadMessages(chatId, true)
}
await loadChats()
+ // 浼氳瘽琚綊妗f椂涓嶅湪涓诲垪琛ㄩ噷锛屾爣棰樼瓑鍙樺寲鍙綋鐜板湪褰掓。鍒楄〃锛�
+ // 涓嶅埛鏂板氨浼氬嚭鐜般�屽湪褰掓。瀵硅瘽閲岃亰瀹岋紝鏍囬杩樻槸鏃х殑銆�
+ if (archivedChats.value.some((chat) => chat.id === chatId)) {
+ await loadArchivedChats()
+ }
} catch {
// 鍒锋柊澶辫触涓嶅奖鍝嶅凡娓叉煋鐨勫唴瀹癸紝闈欓粯澶勭悊
}
@@ -570,6 +742,9 @@
return {
// state
chats,
+ archivedChats,
+ archiveLoaded,
+ chatGroups,
activeChatId,
tree,
streaming,
@@ -582,14 +757,29 @@
activeChat,
// actions
loadChats,
+ loadArchivedChats,
+ loadChatGroups,
+ createChatGroup,
+ renameChatGroup,
+ deleteChatGroup,
+ moveChatToGroup,
searchKeyword,
searchResults,
searching,
searchChats,
clearSearch,
+ // 褰掓。鍒楄〃鐨勬悳绱紙鐙珛鐨勫彟涓�濂楃姸鎬侊級
+ archiveKeyword,
+ archiveResults,
+ archiveSearching,
+ searchArchive,
+ clearArchiveSearch,
createChat,
renameChat,
updateChatMeta,
+ setPinned,
+ setArchived,
+ exportChat,
removeChat,
loadMessages,
switchBranch,
diff --git a/src/views/Chat.vue b/src/views/Chat.vue
index 56c2738..72cedde 100644
--- a/src/views/Chat.vue
+++ b/src/views/Chat.vue
@@ -84,11 +84,19 @@
// 鍏滃簳锛氳矾鐢辨寚鍚戜笉瀛樺湪鐨勪細璇濇椂鎻愮ず骞舵竻鐞�
watch(chatId, async (id) => {
if (!id) return
- const exists = chatStore.chats.some((chat) => chat.id === id)
- if (!exists && chatStore.chats.length > 0) {
- message.warning('璇ュ璇濅笉瀛樺湪鎴栧凡琚垹闄�')
- router.replace('/c')
+
+ const inMain = chatStore.chats.some((chat) => chat.id === id)
+ // 褰掓。鐨勪細璇濅笉鍦ㄤ富鍒楄〃閲岋紝浣嗕粛鐒舵槸鏈夋晥浼氳瘽 鈥斺��
+ // 鍙湅涓诲垪琛ㄤ細鎶娿�屾墦寮�涓�涓綊妗e璇濄�嶈鍒ゆ垚銆屽璇濆凡琚垹闄ゃ��
+ const inArchive = chatStore.archivedChats.some((chat) => chat.id === id)
+
+ // 褰掓。鍒楄〃杩樻病鍔犺浇瀹屾椂涓嶅仛鍒ゅ畾锛氬畞鍙櫄涓�鐐规彁绀猴紝涔熶笉瑕佽鎶�
+ if (inMain || inArchive || !chatStore.archiveLoaded || chatStore.chats.length === 0) {
+ return
}
+
+ message.warning('璇ュ璇濅笉瀛樺湪鎴栧凡琚垹闄�')
+ router.replace('/c')
})
</script>
--
Gitblit v1.9.1