From ea216a0d24f3c3b1e93da041266a0754c5bd2f06 Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Tue, 25 Aug 2026 14:49:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(table):=20=E4=BC=98=E5=8C=96=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E7=BB=84=E4=BB=B6=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=92=8C=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入更严格的嵌套字段路径类型提示 - 定义支持嵌套字段路径的TableDataIndex类型 - 重构TableColumn类型,支持多级子列 - 调整TableProps类型,明确默认泛型参数 - 修改Table组件声明,适配泛型默认值 - 在FormItemsRenderer中将key类型改为React.Key,提高类型兼容性 --- .../FormBuilder/FormItemsRenderer.d.ts | 4 +-- src/components/Table/index.d.ts | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/FormBuilder/FormItemsRenderer.d.ts b/src/components/FormBuilder/FormItemsRenderer.d.ts index 54ffd38..47b260a 100644 --- a/src/components/FormBuilder/FormItemsRenderer.d.ts +++ b/src/components/FormBuilder/FormItemsRenderer.d.ts @@ -3,7 +3,7 @@ import type { ColProps } from "antd/es/col"; import type { FormItemProps, Rule } from "antd/es/form"; import type { FormListFieldData } from "antd/es/form/FormList"; import type { Gutter } from "antd/es/grid/row"; -import type { CSSProperties, ReactElement, ReactNode } from "react"; +import type { CSSProperties, Key, ReactElement, ReactNode } from "react"; import type { FORM_ITEM_RENDER_TYPE_MAP } from "../../enum/formItemRender"; import type { DeepPartial } from "./FormBuilder"; @@ -98,7 +98,7 @@ export interface FormOptionBase< Dependencies = NamePath, > { /** React 需要的 key,如果传递了唯一的 name,则不需要 */ - key?: string; + key?: Key; /** 表单项字段名 */ name?: Name; /** 表单项标签 */ diff --git a/src/components/Table/index.d.ts b/src/components/Table/index.d.ts index 967b6c1..aff7a41 100644 --- a/src/components/Table/index.d.ts +++ b/src/components/Table/index.d.ts @@ -1,11 +1,33 @@ -import type { ProTableProps } from "@ant-design/pro-table"; -import type { TableProps as AntdTableProps } from "antd"; +import type { ProColumns, ProTableProps } from "@ant-design/pro-components"; +import type { TableProps as AntdTableProps, TableColumnType } from "antd"; import type { FC } from "react"; +/** 保留 Ant Design 推导的嵌套元组路径,移除宽泛字符串和普通数组 */ +type StrictTableDataIndex = DataIndex extends string + ? never + : DataIndex extends readonly unknown[] + ? number extends DataIndex["length"] ? never : DataIndex + : DataIndex extends number ? DataIndex : never; + +/** 表格字段索引,支持一级字段和嵌套字段路径提示 */ +export type TableDataIndex + = | Extract + | StrictTableDataIndex["dataIndex"]>>; + +/** 表格列配置 */ +export type TableColumn = Omit, "children" | "dataIndex"> & { + /** 当前列对应的数据字段 */ + dataIndex?: TableDataIndex; + /** 多级表头子列 */ + children?: TableColumn[]; +}; + /** - * TablePro 组件属性 + * Table 组件属性 */ -export type TableProps = Omit & ProTableProps & { +export type TableProps, ValueType = "text"> = Omit, "columns"> & Omit, "columns"> & { + /** 表格列配置 */ + columns: TableColumn[]; /** 当一个路由下存在多个表格的情况下 需要给每一个表格设置一个唯一存储索引 若没有设置则使用默认索引,请注意缓存数据会被覆盖 */ storeIndex?: string; /** 是否禁用内容区滚动,默认 false */ @@ -25,5 +47,5 @@ export type TableProps = Omit(props: TableProps) => ReturnType; +declare const Table: , ValueType = "text">(props: TableProps) => ReturnType; export default Table;