From 7c60847f46c26f8e64620e3e6d7558752a26825a Mon Sep 17 00:00:00 2001 From: BianLzhaoMin <11485688+bianliangzhaomin123@user.noreply.gitee.com> Date: Wed, 4 Feb 2026 15:55:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/planMange/dailyPlan/edit.vue | 40 +++++++++++++++++++-- src/views/planMange/monthlyPlan/edit.vue | 44 +++++++++++++++++++++--- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/views/planMange/dailyPlan/edit.vue b/src/views/planMange/dailyPlan/edit.vue index 1a0eaf1..305b9ec 100644 --- a/src/views/planMange/dailyPlan/edit.vue +++ b/src/views/planMange/dailyPlan/edit.vue @@ -535,6 +535,9 @@ const managerDialog = reactive({ type: 'plan', // 'plan', 'actual', 'highAltitude', 'ground', 'actual_highAltitude', 'actual_ground' }) +// 标志:是否正在同步表格选中状态(防止同步时触发 selection-change 事件导致选中状态丢失) +const isSyncingSelection = ref(false) + // 将公共人员列表转换为表格展示需要的字段结构 const personList = computed(() => { return (personnelCommonOptions.value || []).map((item) => ({ @@ -593,6 +596,7 @@ const selectedManagerNames = computed(() => { // 同步表格选中状态:根据 managerDialog.selected 设置表格的选中状态 const syncTableSelection = () => { if (!personTableRef.value || !managerDialogConfig.outerVisible) return + isSyncingSelection.value = true nextTick(() => { // 清空当前表格选中状态 personTableRef.value.clearSelection() @@ -603,6 +607,10 @@ const syncTableSelection = () => { personTableRef.value.toggleRowSelection(row, true) } }) + // 同步完成后,延迟清除标志,确保所有 selection-change 事件都已处理 + nextTick(() => { + isSyncingSelection.value = false + }) }) } @@ -649,6 +657,9 @@ const onOpenPersonPicker = async (type = 'plan', subType = null) => { } const onManagerSelectionChange = (rows) => { + // 如果正在同步选中状态,直接返回,避免错误地更新选中状态 + if (isSyncingSelection.value) return + // 获取当前过滤结果中所有行的 ID const currentFilteredIds = new Set(filteredPersons.value.map((row) => row.id)) @@ -667,14 +678,29 @@ const onManagerSelectionChange = (rows) => { const onRemoveManager = (item) => { managerDialog.selected = managerDialog.selected.filter((row) => row.id !== item.id) if (personTableRef.value) { - const target = personList.value.find((row) => row.id === item.id) - if (target) personTableRef.value.toggleRowSelection(target, false) + // 优先在过滤后的列表中查找,如果找不到再在全量列表中查找 + const target = + filteredPersons.value.find((row) => row.id === item.id) || + personList.value.find((row) => row.id === item.id) + if (target) { + isSyncingSelection.value = true + personTableRef.value.toggleRowSelection(target, false) + nextTick(() => { + isSyncingSelection.value = false + }) + } } } const onClearManagers = () => { managerDialog.selected = [] - if (personTableRef.value) personTableRef.value.clearSelection() + if (personTableRef.value) { + isSyncingSelection.value = true + personTableRef.value.clearSelection() + nextTick(() => { + isSyncingSelection.value = false + }) + } } const onConfirmManager = () => { @@ -944,6 +970,14 @@ watch( { immediate: true }, ) +watch( + () => managerDialogConfig.outerVisible, + (newVisible) => { + if (!newVisible) { + managerDialog.keyword = '' + } + }, +) // onMounted(() => { // if (route.query.id) { // getDetail() diff --git a/src/views/planMange/monthlyPlan/edit.vue b/src/views/planMange/monthlyPlan/edit.vue index 80efc82..c27f33e 100644 --- a/src/views/planMange/monthlyPlan/edit.vue +++ b/src/views/planMange/monthlyPlan/edit.vue @@ -567,7 +567,7 @@ - + 取消 确定 @@ -849,6 +849,9 @@ const managerDialog = reactive({ selected: [], }) +// 标志:是否正在同步表格选中状态(防止同步时触发 selection-change 事件导致选中状态丢失) +const isSyncingSelection = ref(false) + // 将公共人员列表转换为表格展示需要的字段结构 const personList = computed(() => { return (personnelCommonOptions.value || []).map((item) => ({ @@ -880,6 +883,7 @@ const selectedManagerNames = computed(() => // 同步表格选中状态:根据 managerDialog.selected 设置表格的选中状态 const syncTableSelection = () => { if (!personTableRef.value || !managerDialog.visible) return + isSyncingSelection.value = true nextTick(() => { // 清空当前表格选中状态 personTableRef.value.clearSelection() @@ -890,6 +894,10 @@ const syncTableSelection = () => { personTableRef.value.toggleRowSelection(row, true) } }) + // 同步完成后,延迟清除标志,确保所有 selection-change 事件都已处理 + nextTick(() => { + isSyncingSelection.value = false + }) }) } @@ -912,6 +920,9 @@ const onOpenPersonPicker = async () => { } const onManagerSelectionChange = (rows) => { + // 如果正在同步选中状态,直接返回,避免错误地更新选中状态 + if (isSyncingSelection.value) return + // 获取当前过滤结果中所有行的 ID const currentFilteredIds = new Set(filteredPersons.value.map((row) => row.id)) @@ -930,14 +941,29 @@ const onManagerSelectionChange = (rows) => { const onRemoveManager = (item) => { managerDialog.selected = managerDialog.selected.filter((row) => row.id !== item.id) if (personTableRef.value) { - const target = personList.value.find((row) => row.id === item.id) - if (target) personTableRef.value.toggleRowSelection(target, false) + // 优先在过滤后的列表中查找,如果找不到再在全量列表中查找 + const target = + filteredPersons.value.find((row) => row.id === item.id) || + personList.value.find((row) => row.id === item.id) + if (target) { + isSyncingSelection.value = true + personTableRef.value.toggleRowSelection(target, false) + nextTick(() => { + isSyncingSelection.value = false + }) + } } } const onClearManagers = () => { managerDialog.selected = [] - if (personTableRef.value) personTableRef.value.clearSelection() + if (personTableRef.value) { + isSyncingSelection.value = true + personTableRef.value.clearSelection() + nextTick(() => { + isSyncingSelection.value = false + }) + } } const onConfirmManager = () => { @@ -1130,6 +1156,16 @@ watch( { immediate: true }, ) +watch( + () => managerDialogConfig.outerVisible, + (newVisible) => { + if (!newVisible) { + managerDialog.keyword = '' + } + }, + { immediate: true }, +) + // onMounted(() => { // getDetail() // })