Commit 5fd6b0e5 by chenwq

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

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