Skip to content

Commit 16b2b2a

Browse files
committed
feat: enhance tag selection logic to synchronize deselection across grouped rows
--bug=1065649@tapd-62980211 --user=刘瑞斌 【知识库】标签管理-批量删除标签全选后,取消勾选多个标签值的标签,只删除单标签值的标签,会将所有标签全部删除 https://www.tapd.cn/62980211/s/1830676
1 parent 4764246 commit 16b2b2a

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

ui/src/views/document/tag/TagDrawer.vue

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/>
3030
</div>
3131
<el-table
32+
ref="tableRef"
3233
:data="pagedTableData"
3334
:span-method="spanMethod"
3435
v-loading="loading"
@@ -130,7 +131,7 @@
130131
</template>
131132

132133
<script setup lang="ts">
133-
import { computed, ref } from 'vue'
134+
import { computed, ref, nextTick } from 'vue'
134135
import { useRoute } from 'vue-router'
135136
import { loadSharedApi } from '@/utils/dynamics-api/shared-api.ts'
136137
import CreateTagDialog from './CreateTagDialog.vue'
@@ -235,8 +236,42 @@ const spanMethod = ({ row, columnIndex }: any) => {
235236
}
236237
237238
const multipleSelection = ref<any[]>([])
238-
const handleSelectionChange = (val: any[]) => {
239-
multipleSelection.value = val
239+
const tableRef = ref<any>(null)
240+
const syncingSelection = ref(false)
241+
242+
const handleSelectionChange = async (val: any[]) => {
243+
if (syncingSelection.value) return
244+
245+
// 当前已选中的 id 集合(用于判断哪些行刚刚被取消)
246+
const selectedIds = new Set(val.map((r) => r.id))
247+
248+
// 找出“刚被取消选中的行”
249+
const deselectedRows = multipleSelection.value.filter((r) => !selectedIds.has(r.id))
250+
if (deselectedRows.length === 0) {
251+
multipleSelection.value = val
252+
return
253+
}
254+
255+
// 取消选中时:把同 key 分组里其它行也一并取消
256+
syncingSelection.value = true
257+
await nextTick()
258+
259+
for (const dr of deselectedRows) {
260+
const sameGroupRows = pagedTableData.value.filter((r) => r.key === dr.key)
261+
for (const r of sameGroupRows) {
262+
if (!selectedIds.has(r.id)) continue
263+
tableRef.value?.toggleRowSelection?.(r, false)
264+
}
265+
}
266+
267+
await nextTick()
268+
syncingSelection.value = false
269+
270+
// 以表格最终状态为准更新缓存(这里直接用传入 val 可能已过期)
271+
// 简化:重新从表格取 selection(Element Plus 有 store,没暴露就用 val\+补丁)
272+
multipleSelection.value = pagedTableData.value.filter((r) =>
273+
tableRef.value?.getSelectionRows ? tableRef.value.getSelectionRows().some((s: any) => s.id === r.id) : selectedIds.has(r.id)
274+
)
240275
}
241276
242277
const createTagDialogRef = ref()

0 commit comments

Comments
 (0)