feat(对话管理): 实现批量删除对话记录功能并优化历史记录处理

This commit is contained in:
yangzhe 2025-12-17 09:44:19 +08:00
parent df1649e7c5
commit 45451fd40b
2 changed files with 80 additions and 117 deletions

View File

@ -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,

View File

@ -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;
// tabtab
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",
});
}
},
},
};