From 6221487991cd28144aece0b559e05f689ac50e66 Mon Sep 17 00:00:00 2001 From: sunlei Date: Tue, 2 Jun 2026 10:04:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E8=A1=8C=E6=93=8D=E4=BD=9C=E7=9C=81=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/ktTable/KtTable.tsx | 22 +++++++++++++++---- .../components/ktTable/config/constants.ts | 2 -- .../components/ktTable/config/ktTableProps.ts | 7 ++++++ .../src/components/ktTable/types.ts | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/apps/web-antdv-next/src/components/ktTable/KtTable.tsx b/apps/web-antdv-next/src/components/ktTable/KtTable.tsx index 46a72fd..17b57c2 100644 --- a/apps/web-antdv-next/src/components/ktTable/KtTable.tsx +++ b/apps/web-antdv-next/src/components/ktTable/KtTable.tsx @@ -33,7 +33,6 @@ import { renderKtTableSummary } from './components/KtTableSummary'; import { KT_TABLE_ACTION_COLUMN_KEY, KT_TABLE_INDEX_COLUMN_KEY, - KT_TABLE_ROW_ACTION_OVERFLOW_LIMIT, KT_TABLE_ROW_ACTION_VISIBLE_COUNT, } from './config/constants'; import { DEFAULT_TABLE_SETTING, ktTableProps } from './config/ktTableProps'; @@ -729,7 +728,9 @@ export default defineComponent({ * @param actions 当前行可见操作按钮列表。 */ function splitRowActions(actions: KtTableRowAction[]) { - if (actions.length <= KT_TABLE_ROW_ACTION_OVERFLOW_LIMIT) { + const visibleCount = resolveRowActionVisibleCount(); + + if (actions.length <= visibleCount) { return { inlineActions: actions, overflowActions: [], @@ -737,11 +738,24 @@ export default defineComponent({ } return { - inlineActions: actions.slice(0, KT_TABLE_ROW_ACTION_VISIBLE_COUNT), - overflowActions: actions.slice(KT_TABLE_ROW_ACTION_VISIBLE_COUNT), + inlineActions: actions.slice(0, visibleCount), + overflowActions: actions.slice(visibleCount), }; } + /** + * 解析行操作内联按钮数量,异常配置回退到默认两个。 + */ + function resolveRowActionVisibleCount() { + const visibleCount = Number(props.rowActionVisibleCount); + + if (!Number.isFinite(visibleCount)) { + return KT_TABLE_ROW_ACTION_VISIBLE_COUNT; + } + + return Math.max(0, Math.floor(visibleCount)); + } + /** * 渲染表格头部左侧业务按钮和 toolbar 插槽。 */ diff --git a/apps/web-antdv-next/src/components/ktTable/config/constants.ts b/apps/web-antdv-next/src/components/ktTable/config/constants.ts index 09483da..623f4ea 100644 --- a/apps/web-antdv-next/src/components/ktTable/config/constants.ts +++ b/apps/web-antdv-next/src/components/ktTable/config/constants.ts @@ -12,8 +12,6 @@ export const KT_TABLE_DEFAULT_ROW_RESIZE_MAX_HEIGHT = 140; export const KT_TABLE_DEFAULT_ROW_RESIZE_MIN_HEIGHT = 40; -export const KT_TABLE_ROW_ACTION_OVERFLOW_LIMIT = 3; - export const KT_TABLE_ROW_ACTION_VISIBLE_COUNT = 2; export const KT_TABLE_DEFAULT_PAGE_SIZE = 10; diff --git a/apps/web-antdv-next/src/components/ktTable/config/ktTableProps.ts b/apps/web-antdv-next/src/components/ktTable/config/ktTableProps.ts index 8798181..7e354f9 100644 --- a/apps/web-antdv-next/src/components/ktTable/config/ktTableProps.ts +++ b/apps/web-antdv-next/src/components/ktTable/config/ktTableProps.ts @@ -21,6 +21,7 @@ import { KT_TABLE_DEFAULT_PAGE_SIZE_OPTIONS, KT_TABLE_DEFAULT_ROW_RESIZE_MAX_HEIGHT, KT_TABLE_DEFAULT_ROW_RESIZE_MIN_HEIGHT, + KT_TABLE_ROW_ACTION_VISIBLE_COUNT, } from './constants'; export const DEFAULT_TABLE_SETTING: Required = { @@ -45,6 +46,7 @@ export const KT_TABLE_PROP_KEYS = [ 'pageSize', 'pageSizeOptions', 'rowActions', + 'rowActionVisibleCount', 'rowResizeMaxHeight', 'rowResizeMinHeight', 'rowResizable', @@ -83,6 +85,7 @@ export function createDefaultTableProps(): KtTableResolvedProps< pageSize: KT_TABLE_DEFAULT_PAGE_SIZE, pageSizeOptions: KT_TABLE_DEFAULT_PAGE_SIZE_OPTIONS, rowActions: [], + rowActionVisibleCount: KT_TABLE_ROW_ACTION_VISIBLE_COUNT, rowResizeMaxHeight: KT_TABLE_DEFAULT_ROW_RESIZE_MAX_HEIGHT, rowResizeMinHeight: KT_TABLE_DEFAULT_ROW_RESIZE_MIN_HEIGHT, rowResizable: false, @@ -154,6 +157,10 @@ export const ktTableProps = { default: () => [], type: Array as PropType, }, + rowActionVisibleCount: { + default: KT_TABLE_ROW_ACTION_VISIBLE_COUNT, + type: Number, + }, rowResizeMaxHeight: { default: KT_TABLE_DEFAULT_ROW_RESIZE_MAX_HEIGHT, type: Number, diff --git a/apps/web-antdv-next/src/components/ktTable/types.ts b/apps/web-antdv-next/src/components/ktTable/types.ts index 7737b72..9ee0507 100644 --- a/apps/web-antdv-next/src/components/ktTable/types.ts +++ b/apps/web-antdv-next/src/components/ktTable/types.ts @@ -234,6 +234,7 @@ export interface KtTableProps< pageSize?: number; pageSizeOptions?: string[]; rowActions?: Array>; + rowActionVisibleCount?: number; rowResizeMaxHeight?: number; rowResizeMinHeight?: number; rowResizable?: boolean; @@ -263,6 +264,7 @@ export type KtTableResolvedProps< pageSize: number; pageSizeOptions: string[]; rowActions: Array>; + rowActionVisibleCount: number; rowKey: ((row: Row) => string) | keyof Row | string; rowResizable: boolean; rowResizeMaxHeight: number;