From 88093515373e1b431c83c0da9c28a2688421d151 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Wed, 15 Oct 2025 14:32:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(table):=20action=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AEdisabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/table/src/ActionsColumn.vue | 14 ++++++++++++ packages/table/src/schema.ts | 3 ++- playground/src/pages/Table.vue | 33 +++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/packages/table/src/ActionsColumn.vue b/packages/table/src/ActionsColumn.vue index c7497011..421fd1d8 100644 --- a/packages/table/src/ActionsColumn.vue +++ b/packages/table/src/ActionsColumn.vue @@ -15,6 +15,7 @@ size="small" :type="action.buttonType || 'primary'" :icon="action.icon" + :disabled="disabled(action.disabled, scope.row)" @click="actionHandler(action, scope.row, scope.$index)" > @@ -71,9 +72,22 @@ const display = (fuc: boolean | Function | undefined, row: any) => { if (typeof fuc === 'function') { return fuc(row); } + if (typeof fuc === 'boolean') { + return fuc; + } return true; }; +const disabled = (fuc: boolean | Function | undefined, row: any) => { + if (typeof fuc === 'function') { + return fuc(row); + } + if (typeof fuc === 'boolean') { + return fuc; + } + return false; +}; + const formatter = (fuc: string | Function | undefined, row: any) => { if (typeof fuc === 'function') { return fuc(row); diff --git a/packages/table/src/schema.ts b/packages/table/src/schema.ts index ff010342..a3f5f3fc 100644 --- a/packages/table/src/schema.ts +++ b/packages/table/src/schema.ts @@ -21,7 +21,8 @@ import { FormConfig, FormValue } from '@tmagic/form'; export interface ColumnActionConfig { type?: 'delete' | 'copy' | 'edit' | string; buttonType?: string; - display?: (row: any) => boolean; + display?: boolean | ((row: any) => boolean); + disabled?: boolean | ((row: any) => boolean); text?: string | ((row: any) => string); name?: string; tooltip?: string; diff --git a/playground/src/pages/Table.vue b/playground/src/pages/Table.vue index f2c0f226..6b553480 100644 --- a/playground/src/pages/Table.vue +++ b/playground/src/pages/Table.vue @@ -2,7 +2,7 @@
- + @@ -41,6 +41,21 @@ const columns = ref([ prop: 'a', label: '1231', }, + { + label: '操作', + actions: [ + { + type: 'delete', + buttonType: 'danger', + disabled: (row) => row.a === 'a1', + display: (row) => row.a !== 'b1', + text: '删除', + handler: (row) => { + console.log(row); + }, + }, + ], + }, ]); const data = ref([ @@ -52,6 +67,22 @@ const data = ref([ }, ], }, + { + a: 'b1', + b: [ + { + a: 2, + }, + ], + }, + { + a: 'c2', + b: [ + { + a: 3, + }, + ], + }, ]); const menu: MenuButton[] = [