From dac4d7a20b48bc18d10995b1819d2800e91555d3 Mon Sep 17 00:00:00 2001 From: lq <121091329@qq.com> Date: Tue, 23 Sep 2025 18:16:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useTableSelectionWithPagination.ts | 42 +++++++++++--- .../components/draw-popup.vue | 44 ++++++++++++-- .../components/finished-product-drawer.vue | 58 +++++++++---------- .../assignment-management/index.vue | 6 +- 4 files changed, 105 insertions(+), 45 deletions(-) diff --git a/src/hooks/useTableSelectionWithPagination.ts b/src/hooks/useTableSelectionWithPagination.ts index 0c30800..563f9b7 100644 --- a/src/hooks/useTableSelectionWithPagination.ts +++ b/src/hooks/useTableSelectionWithPagination.ts @@ -4,6 +4,7 @@ import { cloneDeep } from 'lodash-es'; interface UseTableSelectionWithPaginationOptions { rowKey?: string; // 主键字段名,默认 'id' + type?: 'checkbox' | 'radio'; // 选择类型,默认 'checkbox' pageInfo?: { page?: number; page_size?: number; @@ -22,6 +23,7 @@ const DEFAULT_PAGE_INFO = { export function useTableSelectionWithPagination(options: UseTableSelectionWithPaginationOptions = {}) { const rowKey = options.rowKey || 'id'; + const type = options.type || 'checkbox'; // 默认为复选框 const selectedRowKeys = ref>([]); const selectedRows = ref>([]); @@ -33,12 +35,24 @@ export function useTableSelectionWithPagination(options: UseTableSelectionWithPa // 单行选择 const handleSelect = (record: any, select: boolean) => { const _targetKey = record[rowKey]; - if (select) { - selectedRows.value.push(record); - selectedRowKeys.value.push(_targetKey); + if (type === 'radio') { + // 单选模式 + if (select) { + selectedRows.value = [record]; + selectedRowKeys.value = [_targetKey]; + } else { + selectedRows.value = []; + selectedRowKeys.value = []; + } } else { - selectedRows.value = selectedRows.value.filter((v) => v[rowKey] !== _targetKey); - selectedRowKeys.value = selectedRowKeys.value.filter((key) => key !== _targetKey); + // 多选模式(默认) + if (select) { + selectedRows.value.push(record); + selectedRowKeys.value.push(_targetKey); + } else { + selectedRows.value = selectedRows.value.filter((v) => v[rowKey] !== _targetKey); + selectedRowKeys.value = selectedRowKeys.value.filter((key) => key !== _targetKey); + } } options.onSelectChange?.(); @@ -46,6 +60,9 @@ export function useTableSelectionWithPagination(options: UseTableSelectionWithPa // 全选/取消全选 const handleSelectAll = (checked: boolean) => { + // 单选模式下不支持全选 + if (type === 'radio') return; + const currentPageRows = dataSource.value; const currentPageKeys = currentPageRows.map((v) => v[rowKey]); @@ -64,8 +81,15 @@ export function useTableSelectionWithPagination(options: UseTableSelectionWithPa // 选择变更处理 const handleSelectChange = (keys: Array, rows: Array) => { - selectedRowKeys.value = keys; - selectedRows.value = rows; + if (type === 'radio') { + // 单选模式下只保留最后一个选择 + selectedRowKeys.value = keys.length > 0 ? [keys[keys.length - 1]] : []; + selectedRows.value = rows.length > 0 ? [rows[rows.length - 1]] : []; + } else { + // 多选模式 + selectedRowKeys.value = keys; + selectedRows.value = rows; + } options.onSelectChange?.(); }; @@ -88,8 +112,8 @@ export function useTableSelectionWithPagination(options: UseTableSelectionWithPa }; const rowSelection = computed(() => ({ - type: 'checkbox', - showCheckedAll: true, + type: type, + showCheckedAll: type === 'checkbox', // 只有复选框模式才显示全选 width: 48, selectedRowKeys: selectedRowKeys.value, onChange: handleSelectChange diff --git a/src/views/property-marketing/assignment-management/components/draw-popup.vue b/src/views/property-marketing/assignment-management/components/draw-popup.vue index 6d173e7..48a66d3 100644 --- a/src/views/property-marketing/assignment-management/components/draw-popup.vue +++ b/src/views/property-marketing/assignment-management/components/draw-popup.vue @@ -100,7 +100,7 @@
发布内容
(必填)
-
+