From 15e7b7bcefaa82faf36d558a4a079d7f41c23dd2 Mon Sep 17 00:00:00 2001 From: liutao <790864623@qq.com> Date: Wed, 29 Apr 2026 11:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=B9=E5=87=BA=E6=A1=86?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=8F=8A=E6=A8=A1=E5=85=B7=E5=BC=B9=E5=87=BA?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TableSelectDialog/TableSelectDialog.vue | 33 ++++- .../mes/organization/OrganizationForm.vue | 13 +- .../inspectionPlan/InspectionPlanForm.vue | 127 +++++++++++++++++- 3 files changed, 168 insertions(+), 5 deletions(-) diff --git a/src/components/TableSelectDialog/TableSelectDialog.vue b/src/components/TableSelectDialog/TableSelectDialog.vue index bed9363b..edc0cfab 100644 --- a/src/components/TableSelectDialog/TableSelectDialog.vue +++ b/src/components/TableSelectDialog/TableSelectDialog.vue @@ -64,13 +64,16 @@ const props = withDefaults( pageSize?: number initialRows?: any[] queryParams?: Record // 新增 + /** ✅ 新增 */ + defaultSelectedKeys?: (string | number)[] }>(), { selectionType: 'multiple', rowKey: 'id', pageSize: 10, initialRows: () => [], - queryParams: () => ({}) // 默认值 + queryParams: () => ({}), // 默认值 + defaultSelectedKeys: () => [] } ) @@ -111,6 +114,16 @@ const refreshSelectionOnTable = async () => { syncingSelection.value = false } } +/** + * ✅ 新增:根据 defaultSelectedKeys 初始化选中状态 + */ +const initDefaultSelection = () => { + if (!props.defaultSelectedKeys.length) return + + props.defaultSelectedKeys.forEach((key) => { + selectedMap.value.set(key, { [props.rowKey]: key }) + }) +} const getList = async () => { loading.value = true @@ -161,12 +174,30 @@ const handleRowClick = (row: any) => { } const open = async (rows?: any[]) => { + /* selectedMap.value.clear() + const initialRows = rows || props.initialRows + const nextRows = isSingleSelect.value ? initialRows.slice(0, 1) : initialRows + nextRows.forEach((row) => { + selectedMap.value.set(resolveRowKey(row), row) + }) + queryParams.pageNo = 1 + queryParams.pageSize = props.pageSize + dialogVisible.value = true + await getList()*/ selectedMap.value.clear() + + // ✅ 优先使用 defaultSelectedKeys + if (props.defaultSelectedKeys.length) { + initDefaultSelection() + } + + // ✅ 兼容原来的 initialRows / rows const initialRows = rows || props.initialRows const nextRows = isSingleSelect.value ? initialRows.slice(0, 1) : initialRows nextRows.forEach((row) => { selectedMap.value.set(resolveRowKey(row), row) }) + queryParams.pageNo = 1 queryParams.pageSize = props.pageSize dialogVisible.value = true diff --git a/src/views/mes/organization/OrganizationForm.vue b/src/views/mes/organization/OrganizationForm.vue index ebcb42a0..9c11c945 100644 --- a/src/views/mes/organization/OrganizationForm.vue +++ b/src/views/mes/organization/OrganizationForm.vue @@ -141,6 +141,7 @@ @confirm="handleDeviceSelectConfirm" :query-params="mergedQueryParams" :selection-type="'single'" + :default-selected-keys="ids" >