Commit 5fd6b0e5 by chenwq

fix(群聊选择): 修复多选数据在搜索后丢失的问题

修复群聊选择对话框中,当用户进行搜索操作时,已选群聊列表数据丢失的问题。
- 在组件创建和搜索时,正确同步和计算多选数据
- 重构 `recoverySelection` 方法以恢复选中状态
- 新增 `getMutiDate` 方法用于合并新旧选择数据
1 parent 0282072f
......@@ -91,11 +91,13 @@ export default {
},
created() {
this.searchFormSearch = { ...this.searchForm };
this.selectedGroups = [...this.selectedData];
this.fetchGroupList();
},
methods: {
handleSearch() {
this.searchFormSearch = { ...this.searchForm };
this.selectedGroups = this.getMutiDate();
this.fetchGroupList();
},
fetchGroupList() {
......@@ -107,34 +109,60 @@ export default {
getGroupChatList(params)
.then((res) => {
this.groupChatList = res;
this.echoSelection();
this.recoverySelection(res);
})
.finally(() => {
this.loading = false;
});
},
echoSelection() {
if (!this.selectedData || !this.selectedData.length) return;
this.selectedGroups = [...this.selectedData];
recoverySelection(list) {
this.$nextTick(() => {
const exitIds = this.selectedData.map((item) => item.groupChatId);
this.groupChatList.forEach((item) => {
if (exitIds.includes(item.groupChatId)) {
this.$refs.groupTable &&
if (this.selectedGroups.length) {
this.selectedGroups.forEach((row) => {
const obj = this.groupChatList.find(
(item) => item.groupChatId == row.groupChatId
);
obj &&
this.$refs.groupTable.$refs[
this.tableParams.mutiSelectName + "MutiTable"
] &&
this.$refs.groupTable.$refs[
this.tableParams.mutiSelectName + "MutiTable"
].toggleRowSelection(item, true);
}
});
].toggleRowSelection(obj, true);
});
}
});
},
handleSelectionChange(val) {
this.selectedGroups = val;
getMutiDate() {
let selectedData =
this.$refs.groupTable.mutiSelectArr[this.tableParams.mutiSelectName] ||
[];
let deleteIds = [];
this.selectedGroups.forEach((item) => {
if (
!this.groupChatList
.map((k) => k.groupChatId)
.includes(item.groupChatId) &&
!selectedData.map((k) => k.groupChatId).includes(item.groupChatId)
) {
selectedData.push(item);
}
if (
selectedData?.map((k) => k.groupChatId).includes(item.groupChatId) &&
!selectedData?.map((k) => k.groupChatId).includes(item.groupChatId)
) {
deleteIds.push(item.groupChatId);
}
});
deleteIds.forEach((item) => {
const idx = selectedData.findIndex((k) => k.groupChatId == item.groupChatId);
if (idx !== -1) {
selectedData.splice(idx, 1);
}
});
return selectedData;
},
handleSelectionChange(val) {},
confirmGroupSelection() {
this.selectedGroups = this.getMutiDate();
this.$emit("confirm", this.selectedGroups);
this.$emit("close");
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!