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.post("api/Dialogue/DeleteDialogue", params);
|
||||||
|
|
||||||
// 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
|
// 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
|
||||||
vm.$u.api = {
|
vm.$u.api = {
|
||||||
UploadSingleImage,
|
UploadSingleImage,
|
||||||
getTeacherInfo,
|
getTeacherInfo,
|
||||||
getData,
|
getData,
|
||||||
|
|
@ -306,11 +306,12 @@ const install = (Vue, vm) => {
|
||||||
GetDialogueList_UserApi,
|
GetDialogueList_UserApi,
|
||||||
AddDialogueApi,
|
AddDialogueApi,
|
||||||
SendMessage_PrivateApi,
|
SendMessage_PrivateApi,
|
||||||
GetChatHistoryDataApi,
|
GetChatHistoryDataApi,
|
||||||
GetReceiverUserInfoApi,
|
GetReceiverUserInfoApi,
|
||||||
OverheadOneDialogueApi,
|
OverheadOneDialogueApi,
|
||||||
};
|
DeleteDialogueApi,
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
install,
|
install,
|
||||||
|
|
|
||||||
|
|
@ -127,64 +127,6 @@ export default {
|
||||||
isMoreMenuVisible: false, // 右上角更多菜单是否可见
|
isMoreMenuVisible: false, // 右上角更多菜单是否可见
|
||||||
selectedItems: [], // 选中的项目
|
selectedItems: [], // 选中的项目
|
||||||
selectAll: false, // 是否全选
|
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咨询历史记录
|
chatHistoryAI: [], // ai咨询历史记录
|
||||||
chatHistoryTeacher: [], // 人工咨询历史记录
|
chatHistoryTeacher: [], // 人工咨询历史记录
|
||||||
};
|
};
|
||||||
|
|
@ -199,43 +141,20 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 根据当前tab过滤历史记录
|
currentHistoryItems() {
|
||||||
filteredHistoryList() {
|
const groups = this.currentHistoryList || [];
|
||||||
return this.historyList.filter((item) => {
|
const items = [];
|
||||||
if (this.activeTab === "1") {
|
|
||||||
return item.type === "ai";
|
groups.forEach((group) => {
|
||||||
} else {
|
const conversation = (group && group.conversation) || [];
|
||||||
return item.type === "human";
|
conversation.forEach((item) => items.push(item));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return items;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 按日期分组后的历史记录(日期标题固定在上方)
|
currentHistoryItemIds() {
|
||||||
groupedHistoryList() {
|
return this.currentHistoryItems.map((item) => item.id);
|
||||||
// 先按时间倒序
|
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -245,6 +164,12 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
resetBatchState() {
|
||||||
|
this.selectedItems = [];
|
||||||
|
this.selectAll = false;
|
||||||
|
this.isBatchDeleteMode = false;
|
||||||
|
},
|
||||||
|
|
||||||
// 获取ai历史记录
|
// 获取ai历史记录
|
||||||
async getChatHistoryList() {
|
async getChatHistoryList() {
|
||||||
this.$u.api.GetConversationPage().then((res) => {
|
this.$u.api.GetConversationPage().then((res) => {
|
||||||
|
|
@ -345,6 +270,14 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
switchTab(tab) {
|
switchTab(tab) {
|
||||||
|
if (this.activeTab === tab) return;
|
||||||
|
|
||||||
|
// 批量删除模式下,切换tab时,清空选中项
|
||||||
|
if (this.isBatchDeleteMode) {
|
||||||
|
this.selectedItems = [];
|
||||||
|
this.selectAll = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.activeTab = tab;
|
this.activeTab = tab;
|
||||||
// 切换tab时,刷新当前tab的历史记录
|
// 切换tab时,刷新当前tab的历史记录
|
||||||
if (tab === "1") {
|
if (tab === "1") {
|
||||||
|
|
@ -356,6 +289,8 @@ export default {
|
||||||
|
|
||||||
// 显示/隐藏右上角更多菜单
|
// 显示/隐藏右上角更多菜单
|
||||||
toggleMoreMenu() {
|
toggleMoreMenu() {
|
||||||
|
if (this.isBatchDeleteMode) return;
|
||||||
|
|
||||||
this.isMoreMenuVisible = !this.isMoreMenuVisible;
|
this.isMoreMenuVisible = !this.isMoreMenuVisible;
|
||||||
},
|
},
|
||||||
// 点击蒙层隐藏更多菜单
|
// 点击蒙层隐藏更多菜单
|
||||||
|
|
@ -364,7 +299,7 @@ export default {
|
||||||
},
|
},
|
||||||
// 取消批量删除模式
|
// 取消批量删除模式
|
||||||
cancelBatchDelete() {
|
cancelBatchDelete() {
|
||||||
this.isBatchDeleteMode = false;
|
this.resetBatchState();
|
||||||
},
|
},
|
||||||
|
|
||||||
// 点击“批量删除”菜单项,进入批量删除模式
|
// 点击“批量删除”菜单项,进入批量删除模式
|
||||||
|
|
@ -395,47 +330,74 @@ export default {
|
||||||
}
|
}
|
||||||
// 更新全选状态
|
// 更新全选状态
|
||||||
this.selectAll =
|
this.selectAll =
|
||||||
this.selectedItems.length === this.filteredHistoryList.length;
|
this.selectedItems.length > 0 &&
|
||||||
|
this.selectedItems.length === this.currentHistoryItemIds.length;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 切换全选状态
|
// 切换全选状态
|
||||||
toggleSelectAll() {
|
toggleSelectAll() {
|
||||||
|
const allIds = this.currentHistoryItemIds || [];
|
||||||
|
if (!allIds.length) {
|
||||||
|
this.selectAll = false;
|
||||||
|
this.selectedItems = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selectAll = !this.selectAll;
|
this.selectAll = !this.selectAll;
|
||||||
if (this.selectAll) {
|
if (this.selectAll) {
|
||||||
this.selectedItems = this.filteredHistoryList.map((item) => item.id);
|
this.selectedItems = [...allIds];
|
||||||
} else {
|
} else {
|
||||||
this.selectedItems = [];
|
this.selectedItems = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 批量删除选中项
|
// 批量删除选中项
|
||||||
batchDelete() {
|
async batchDelete() {
|
||||||
if (this.selectedItems.length === 0) {
|
if (this.selectedItems.length === 0) {
|
||||||
this.$refs.uToast.show({
|
this.$refs.uToast.show({
|
||||||
title: "请选择要删除的项目",
|
title: "请选择要删除的记录",
|
||||||
type: "warning",
|
type: "warning",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除选中的项目
|
const deleteIds = [...this.selectedItems];
|
||||||
this.historyList = this.historyList.filter(
|
const isAiTab = this.activeTab === "1";
|
||||||
(item) => !this.selectedItems.includes(item.id)
|
|
||||||
);
|
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
// 重置状态
|
if (isAiTab) {
|
||||||
this.selectedItems = [];
|
this.getChatHistoryList();
|
||||||
this.selectAll = false;
|
} else {
|
||||||
this.isBatchDeleteMode = false;
|
this.GetDialogueList_User();
|
||||||
|
}
|
||||||
|
|
||||||
this.$refs.uToast.show({
|
this.$refs.uToast.show({
|
||||||
title: "删除成功",
|
title: "删除成功",
|
||||||
type: "success",
|
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