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" >