refactor(table): 优化表格组件类型定义和导出
- 引入更严格的嵌套字段路径类型提示 - 定义支持嵌套字段路径的TableDataIndex类型 - 重构TableColumn类型,支持多级子列 - 调整TableProps类型,明确默认泛型参数 - 修改Table组件声明,适配泛型默认值 - 在FormItemsRenderer中将key类型改为React.Key,提高类型兼容性1.0
parent
9719a46751
commit
ac6db2113f
|
|
@ -3,7 +3,7 @@ import type { FormItemProps, Rule } from "antd/es/form";
|
||||||
import type { FormListFieldData } from "antd/es/form/FormList";
|
import type { FormListFieldData } from "antd/es/form/FormList";
|
||||||
import type { Gutter } from "antd/es/grid/row";
|
import type { Gutter } from "antd/es/grid/row";
|
||||||
import type { NamePath } from "rc-field-form/lib/interface";
|
import type { NamePath } from "rc-field-form/lib/interface";
|
||||||
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 { FORM_ITEM_RENDER_TYPE_MAP } from "../../enum/formItemRender";
|
||||||
import type { DeepPartial } from "./FormBuilder";
|
import type { DeepPartial } from "./FormBuilder";
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ export interface FormOptionBase<
|
||||||
Dependencies = NamePath<Values>,
|
Dependencies = NamePath<Values>,
|
||||||
> {
|
> {
|
||||||
/** React 需要的 key,如果传递了唯一的 name,则不需要 */
|
/** React 需要的 key,如果传递了唯一的 name,则不需要 */
|
||||||
key?: string;
|
key?: Key;
|
||||||
/** 表单项字段名 */
|
/** 表单项字段名 */
|
||||||
name?: Name;
|
name?: Name;
|
||||||
/** 表单项标签 */
|
/** 表单项标签 */
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,33 @@
|
||||||
import type { ProTableProps } from "@ant-design/pro-table";
|
import type { ProColumns, ProTableProps } from "@ant-design/pro-components";
|
||||||
import type { TableProps as AntdTableProps } from "antd";
|
import type { TableProps as AntdTableProps, TableColumnType } from "antd";
|
||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
|
|
||||||
|
/** 保留 Ant Design 推导的嵌套元组路径,移除宽泛字符串和普通数组 */
|
||||||
|
type StrictTableDataIndex<DataIndex> = DataIndex extends string
|
||||||
|
? never
|
||||||
|
: DataIndex extends readonly unknown[]
|
||||||
|
? number extends DataIndex["length"] ? never : DataIndex
|
||||||
|
: DataIndex extends number ? DataIndex : never;
|
||||||
|
|
||||||
|
/** 表格字段索引,支持一级字段和嵌套字段路径提示 */
|
||||||
|
export type TableDataIndex<DataSource>
|
||||||
|
= | Extract<keyof DataSource, string | number>
|
||||||
|
| StrictTableDataIndex<NonNullable<TableColumnType<DataSource>["dataIndex"]>>;
|
||||||
|
|
||||||
|
/** 表格列配置 */
|
||||||
|
export type TableColumn<DataSource, ValueType = "text"> = Omit<ProColumns<DataSource, ValueType>, "children" | "dataIndex"> & {
|
||||||
|
/** 当前列对应的数据字段 */
|
||||||
|
dataIndex?: TableDataIndex<DataSource>;
|
||||||
|
/** 多级表头子列 */
|
||||||
|
children?: TableColumn<DataSource, ValueType>[];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TablePro 组件属性
|
* Table 组件属性
|
||||||
*/
|
*/
|
||||||
export type TableProps<DataSource, U, ValueType> = Omit<AntdTableProps, "columns"> & ProTableProps<DataSource, U, ValueType> & {
|
export type TableProps<DataSource, U = Record<string, unknown>, ValueType = "text"> = Omit<AntdTableProps<DataSource>, "columns"> & Omit<ProTableProps<DataSource, U, ValueType>, "columns"> & {
|
||||||
|
/** 表格列配置 */
|
||||||
|
columns: TableColumn<DataSource, ValueType>[];
|
||||||
/** 当一个路由下存在多个表格的情况下 需要给每一个表格设置一个唯一存储索引 若没有设置则使用默认索引,请注意缓存数据会被覆盖 */
|
/** 当一个路由下存在多个表格的情况下 需要给每一个表格设置一个唯一存储索引 若没有设置则使用默认索引,请注意缓存数据会被覆盖 */
|
||||||
storeIndex?: string;
|
storeIndex?: string;
|
||||||
/** 是否禁用内容区滚动,默认 false */
|
/** 是否禁用内容区滚动,默认 false */
|
||||||
|
|
@ -25,5 +47,5 @@ export type TableProps<DataSource, U, ValueType> = Omit<AntdTableProps, "columns
|
||||||
/**
|
/**
|
||||||
* 表格组件
|
* 表格组件
|
||||||
*/
|
*/
|
||||||
declare const Table: <DataSource, U, ValueType = "text">(props: TableProps<DataSource, U, ValueType>) => ReturnType<FC>;
|
declare const Table: <DataSource, U = Record<string, unknown>, ValueType = "text">(props: TableProps<DataSource, U, ValueType>) => ReturnType<FC>;
|
||||||
export default Table;
|
export default Table;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue