feat(对话管理): 实现批量删除对话记录功能并优化历史记录处理
This commit is contained in:
parent
df1649e7c5
commit
45451fd40b
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue