From 45451fd40b19c2b5cb876e6724deb9a7f2a74075 Mon Sep 17 00:00:00 2001 From: yangzhe Date: Wed, 17 Dec 2025 09:44:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=AF=B9=E8=AF=9D=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/http.api.js | 13 +-- pages/home/history/index.vue | 184 ++++++++++++++--------------------- 2 files changed, 80 insertions(+), 117 deletions(-) diff --git a/common/http.api.js b/common/http.api.js index c51c910..1fefe68 100644 --- a/common/http.api.js +++ b/common/http.api.js @@ -244,7 +244,7 @@ const install = (Vue, vm) => { vm.$u.post("api/Dialogue/DeleteDialogue", params); // 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下 - vm.$u.api = { + vm.$u.api = { UploadSingleImage, getTeacherInfo, getData, @@ -306,11 +306,12 @@ const install = (Vue, vm) => { GetDialogueList_UserApi, AddDialogueApi, SendMessage_PrivateApi, - GetChatHistoryDataApi, - GetReceiverUserInfoApi, - OverheadOneDialogueApi, - }; -}; + GetChatHistoryDataApi, + GetReceiverUserInfoApi, + OverheadOneDialogueApi, + DeleteDialogueApi, + }; +}; export default { install, diff --git a/pages/home/history/index.vue b/pages/home/history/index.vue index 5872706..2ac5be3 100644 --- a/pages/home/history/index.vue +++ b/pages/home/history/index.vue @@ -127,64 +127,6 @@ export default { isMoreMenuVisible: false, // 右上角更多菜单是否可见 selectedItems: [], // 选中的项目 selectAll: false, // 是否全选 - historyList: [ - { - id: 1, - title: "学校哪些专业比较好?", - content: - "学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?", - time: new Date().getTime(), // 今天 - type: "ai", - }, - { - id: 2, - title: "学校哪些专业比较好?", - content: - "学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?", - time: new Date().getTime(), // 今天 - type: "ai", - }, - { - id: 3, - title: "学校哪些专业比较好?", - content: - "学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?", - time: new Date().getTime(), // 今天 - type: "ai", - }, - { - id: 4, - title: "学校哪些专业比较好?", - content: - "学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?", - time: new Date().getTime(), // 今天 - type: "ai", - }, - { - id: 5, - title: "学校哪些专业比较好?", - content: - "学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?", - time: new Date().getTime() - 24 * 60 * 60 * 1000 * 2, // 2天前 - type: "ai", - }, - { - id: 6, - title: "学校哪些专业比较好?", - content: - "学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?", - time: new Date().getTime() - 365 * 24 * 60 * 60 * 1000, // 去年 - type: "human", - }, - { - id: 7, - title: "学校哪些专业比较好?", - content: - "学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?学校哪些专业比较好?", - time: new Date().getTime() - 24 * 60 * 60 * 1000 * 5, // 5天前 - type: "human", - }, - ], chatHistoryAI: [], // ai咨询历史记录 chatHistoryTeacher: [], // 人工咨询历史记录 }; @@ -199,43 +141,20 @@ export default { } }, - // 根据当前tab过滤历史记录 - filteredHistoryList() { - return this.historyList.filter((item) => { - if (this.activeTab === "1") { - return item.type === "ai"; - } else { - return item.type === "human"; - } + currentHistoryItems() { + const groups = this.currentHistoryList || []; + const items = []; + + groups.forEach((group) => { + const conversation = (group && group.conversation) || []; + conversation.forEach((item) => items.push(item)); }); + + return items; }, - // 按日期分组后的历史记录(日期标题固定在上方) - groupedHistoryList() { - // 先按时间倒序 - const list = [...this.filteredHistoryList].sort( - (a, b) => b.time - a.time - ); - const groups = []; - let currentHeader = null; - let currentItems = []; - - list.forEach((item) => { - const header = this.formatTime(item.time); - if (header !== currentHeader) { - if (currentItems.length) { - groups.push({ header: currentHeader, items: currentItems }); - } - currentHeader = header; - currentItems = [item]; - } else { - currentItems.push(item); - } - }); - if (currentItems.length) { - groups.push({ header: currentHeader, items: currentItems }); - } - return groups; + currentHistoryItemIds() { + return this.currentHistoryItems.map((item) => item.id); }, }, @@ -245,6 +164,12 @@ export default { }, methods: { + resetBatchState() { + this.selectedItems = []; + this.selectAll = false; + this.isBatchDeleteMode = false; + }, + // 获取ai历史记录 async getChatHistoryList() { this.$u.api.GetConversationPage().then((res) => { @@ -345,6 +270,14 @@ export default { }, switchTab(tab) { + if (this.activeTab === tab) return; + + // 批量删除模式下,切换tab时,清空选中项 + if (this.isBatchDeleteMode) { + this.selectedItems = []; + this.selectAll = false; + } + this.activeTab = tab; // 切换tab时,刷新当前tab的历史记录 if (tab === "1") { @@ -356,6 +289,8 @@ export default { // 显示/隐藏右上角更多菜单 toggleMoreMenu() { + if (this.isBatchDeleteMode) return; + this.isMoreMenuVisible = !this.isMoreMenuVisible; }, // 点击蒙层隐藏更多菜单 @@ -364,7 +299,7 @@ export default { }, // 取消批量删除模式 cancelBatchDelete() { - this.isBatchDeleteMode = false; + this.resetBatchState(); }, // 点击“批量删除”菜单项,进入批量删除模式 @@ -395,47 +330,74 @@ export default { } // 更新全选状态 this.selectAll = - this.selectedItems.length === this.filteredHistoryList.length; + this.selectedItems.length > 0 && + this.selectedItems.length === this.currentHistoryItemIds.length; }, // 切换全选状态 toggleSelectAll() { + const allIds = this.currentHistoryItemIds || []; + if (!allIds.length) { + this.selectAll = false; + this.selectedItems = []; + return; + } + this.selectAll = !this.selectAll; if (this.selectAll) { - this.selectedItems = this.filteredHistoryList.map((item) => item.id); + this.selectedItems = [...allIds]; } else { this.selectedItems = []; } }, // 批量删除选中项 - batchDelete() { + async batchDelete() { if (this.selectedItems.length === 0) { this.$refs.uToast.show({ - title: "请选择要删除的项目", + title: "请选择要删除的记录", type: "warning", }); return; } - // 删除选中的项目 - this.historyList = this.historyList.filter( - (item) => !this.selectedItems.includes(item.id) - ); + const deleteIds = [...this.selectedItems]; + const isAiTab = this.activeTab === "1"; - console.log('删除后的历史记录:',this.historyList); + try { + let res = null; + if (isAiTab) { + res = await this.$u.api.DeleteDialogueManagement({ id: deleteIds }); + } else { + res = await this.$u.api.DeleteDialogueApi({ dialogueManagementIds: deleteIds }); + } - return + if (res && res.succeed === true) { + this.resetBatchState(); - // 重置状态 - this.selectedItems = []; - this.selectAll = false; - this.isBatchDeleteMode = false; + if (isAiTab) { + this.getChatHistoryList(); + } else { + this.GetDialogueList_User(); + } - this.$refs.uToast.show({ - title: "删除成功", - type: "success", - }); + this.$refs.uToast.show({ + title: "删除成功", + type: "success", + }); + return; + } + + this.$refs.uToast.show({ + title: (res && (res.msg || res.message)) || "删除失败", + type: "error", + }); + } catch (e) { + this.$refs.uToast.show({ + title: "删除失败", + type: "error", + }); + } }, }, };