@antdv-vue/pro-table 0.0.0-stage → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +255 -0
  2. package/README.md +106 -2
  3. package/dist/InternalTable.d.ts +360 -0
  4. package/dist/InternalTable.js +444 -0
  5. package/dist/RenderTypings.d.ts +33 -0
  6. package/dist/RenderTypings.js +1 -0
  7. package/dist/ResizableTableTitle.d.ts +24 -0
  8. package/dist/ResizableTableTitle.js +89 -0
  9. package/dist/Store/Provide.d.ts +68 -0
  10. package/dist/Store/Provide.js +132 -0
  11. package/dist/Table.d.ts +363 -0
  12. package/dist/Table.js +151 -0
  13. package/dist/TableRender.d.ts +54 -0
  14. package/dist/TableRender.js +295 -0
  15. package/dist/components/Alert/index.d.ts +45 -0
  16. package/dist/components/Alert/index.js +94 -0
  17. package/dist/components/Alert/style/index.d.ts +8 -0
  18. package/dist/components/Alert/style/index.js +11 -0
  19. package/dist/components/ColumnSetting/CheckboxList.d.ts +24 -0
  20. package/dist/components/ColumnSetting/CheckboxList.js +138 -0
  21. package/dist/components/ColumnSetting/CheckboxListItem.d.ts +17 -0
  22. package/dist/components/ColumnSetting/CheckboxListItem.js +84 -0
  23. package/dist/components/ColumnSetting/GroupCheckboxList.d.ts +22 -0
  24. package/dist/components/ColumnSetting/GroupCheckboxList.js +82 -0
  25. package/dist/components/ColumnSetting/ToolTipIcon.d.ts +12 -0
  26. package/dist/components/ColumnSetting/ToolTipIcon.js +47 -0
  27. package/dist/components/ColumnSetting/index.d.ts +26 -0
  28. package/dist/components/ColumnSetting/index.js +117 -0
  29. package/dist/components/ColumnSetting/style/index.d.ts +8 -0
  30. package/dist/components/ColumnSetting/style/index.js +73 -0
  31. package/dist/components/DragSortTable/index.d.ts +375 -0
  32. package/dist/components/DragSortTable/index.js +166 -0
  33. package/dist/components/DragSortTable/style/index.d.ts +8 -0
  34. package/dist/components/DragSortTable/style/index.js +25 -0
  35. package/dist/components/Dropdown/Button.d.ts +20 -0
  36. package/dist/components/Dropdown/Button.js +155 -0
  37. package/dist/components/Dropdown/index.d.ts +27 -0
  38. package/dist/components/Dropdown/index.js +149 -0
  39. package/dist/components/EditableTable/CellEditorTable.d.ts +63 -0
  40. package/dist/components/EditableTable/CellEditorTable.js +167 -0
  41. package/dist/components/EditableTable/EditableTable.d.ts +67 -0
  42. package/dist/components/EditableTable/EditableTable.js +141 -0
  43. package/dist/components/EditableTable/InternalEditableTable.d.ts +189 -0
  44. package/dist/components/EditableTable/InternalEditableTable.js +508 -0
  45. package/dist/components/EditableTable/RowEditorTable.d.ts +63 -0
  46. package/dist/components/EditableTable/RowEditorTable.js +147 -0
  47. package/dist/components/EditableTable/context.d.ts +9 -0
  48. package/dist/components/EditableTable/context.js +11 -0
  49. package/dist/components/EditableTable/index.d.ts +5 -0
  50. package/dist/components/EditableTable/index.js +5 -0
  51. package/dist/components/Form/FormRender.d.ts +77 -0
  52. package/dist/components/Form/FormRender.js +198 -0
  53. package/dist/components/Form/index.d.ts +33 -0
  54. package/dist/components/Form/index.js +91 -0
  55. package/dist/components/ToolBar/DensityIcon.d.ts +22 -0
  56. package/dist/components/ToolBar/DensityIcon.js +71 -0
  57. package/dist/components/ToolBar/FullScreenIcon.d.ts +6 -0
  58. package/dist/components/ToolBar/FullScreenIcon.js +30 -0
  59. package/dist/components/ToolBar/HeaderMenu.d.ts +22 -0
  60. package/dist/components/ToolBar/HeaderMenu.js +84 -0
  61. package/dist/components/ToolBar/index.d.ts +102 -0
  62. package/dist/components/ToolBar/index.js +322 -0
  63. package/dist/components/ToolBar/style/index.d.ts +8 -0
  64. package/dist/components/ToolBar/style/index.js +116 -0
  65. package/dist/index.d.ts +11 -0
  66. package/dist/index.js +10 -0
  67. package/dist/pro-table.esm.js +3274 -0
  68. package/dist/style/index.d.ts +11 -0
  69. package/dist/style/index.js +162 -0
  70. package/dist/typing.d.ts +409 -0
  71. package/dist/typing.js +1 -0
  72. package/dist/useFetchData.d.ts +10 -0
  73. package/dist/useFetchData.js +243 -0
  74. package/dist/utils/cellRenderToFromItem.d.ts +52 -0
  75. package/dist/utils/cellRenderToFromItem.js +163 -0
  76. package/dist/utils/columnRender.d.ts +54 -0
  77. package/dist/utils/columnRender.js +148 -0
  78. package/dist/utils/columnSort.d.ts +7 -0
  79. package/dist/utils/columnSort.js +17 -0
  80. package/dist/utils/genProColumnsToColumns.d.ts +69 -0
  81. package/dist/utils/genProColumnsToColumns.js +197 -0
  82. package/dist/utils/index.d.ts +122 -0
  83. package/dist/utils/index.js +227 -0
  84. package/dist/utils/useDragSort.d.ts +182 -0
  85. package/dist/utils/useDragSort.js +162 -0
  86. package/package.json +67 -3
@@ -0,0 +1,11 @@
1
+ import * as _$vue from "vue";
2
+ import { GenerateStyle, ProAliasCssVarToken } from "@antdv-vue/pro-provider";
3
+ import { Keyframes } from "@antdv-next/cssinjs";
4
+
5
+ //#region src/style/index.d.ts
6
+ interface ProTableToken extends ProAliasCssVarToken {}
7
+ declare const turn: Keyframes;
8
+ declare const genProTableStyle: GenerateStyle<ProTableToken>;
9
+ declare const _default: (prefixCls: _$vue.Ref<string>, rootCls?: _$vue.Ref<string | undefined>) => readonly [_$vue.Ref<string, string>, _$vue.ComputedRef<string | undefined>];
10
+ //#endregion
11
+ export { ProTableToken, _default as default, genProTableStyle, turn };
@@ -0,0 +1,162 @@
1
+ import { useStyle } from "@antdv-vue/pro-provider";
2
+ import { Keyframes, mergeToken } from "@antdv-next/cssinjs";
3
+ //#region src/style/index.ts
4
+ const turn = new Keyframes("turn", {
5
+ "0%": { transform: "rotate(0deg)" },
6
+ "25%": { transform: "rotate(90deg)" },
7
+ "50%": { transform: "rotate(180deg)" },
8
+ "75%": { transform: "rotate(270deg)" },
9
+ "100%": { transform: "rotate(360deg)" }
10
+ });
11
+ const genProTableStyle = (token) => {
12
+ return {
13
+ [token.componentCls]: {
14
+ zIndex: 1,
15
+ [`${token.antCls}-table-wrapper ${token.antCls}-table-pagination${token.antCls}-pagination`]: { marginBlockEnd: 0 },
16
+ "&:not(:root):fullscreen": {
17
+ minHeight: "100vh",
18
+ overflow: "auto",
19
+ background: token.colorBgContainer
20
+ },
21
+ "&-extra": { marginBlockEnd: token.margin },
22
+ "&-polling": { [`${token.componentCls}-list-toolbar-setting-item`]: { ".anticon.anticon-reload": {
23
+ transform: "rotate(0deg)",
24
+ animationName: turn,
25
+ animationDuration: "1s",
26
+ animationTimingFunction: "linear",
27
+ animationIterationCount: "infinite"
28
+ } } },
29
+ [`td${token.antCls}-table-cell`]: { ">a": { fontSize: token.fontSize } },
30
+ [`${token.antCls}-table${token.antCls}-table-tbody${token.antCls}-table-wrapper:only-child${token.antCls}-table`]: {
31
+ marginBlock: 0,
32
+ marginInline: 0
33
+ },
34
+ [`${token.antCls}-table${token.antCls}-table-middle ${token.componentCls}`]: {
35
+ marginBlock: 0,
36
+ marginInline: -8,
37
+ [`${token.proComponentsCls}-card`]: { backgroundColor: "initial" }
38
+ },
39
+ "& &-search": {
40
+ marginBlockEnd: token.margin,
41
+ background: token.colorBgContainer,
42
+ "&-ghost": { background: "transparent" },
43
+ [`&${token.componentCls}-form`]: {
44
+ marginBlock: 0,
45
+ marginInline: 0,
46
+ paddingBlock: 0,
47
+ paddingInline: 16,
48
+ overflow: "unset"
49
+ },
50
+ "&-light-filter": {
51
+ marginBlockEnd: 0,
52
+ paddingBlock: 0,
53
+ paddingInline: 0
54
+ },
55
+ "&-form-option": {
56
+ [`${token.antCls}-form-item`]: {},
57
+ [`${token.antCls}-form-item-label`]: {},
58
+ [`${token.antCls}-form-item-control-input`]: {}
59
+ },
60
+ "@media (max-width: 575px)": { [token.componentCls]: {
61
+ height: "auto !important",
62
+ paddingBlockEnd: token.paddingLG,
63
+ [`${token.antCls}-form-item-label`]: {
64
+ minWidth: 80,
65
+ textAlign: "start"
66
+ }
67
+ } }
68
+ },
69
+ "&-toolbar": {
70
+ display: "flex",
71
+ alignItems: "center",
72
+ justifyContent: "space-between",
73
+ height: 64,
74
+ paddingInline: token.paddingLG,
75
+ paddingBlock: 0,
76
+ "&-option": {
77
+ display: "flex",
78
+ alignItems: "center",
79
+ justifyContent: "flex-end"
80
+ },
81
+ "&-title": {
82
+ flex: "1",
83
+ color: token.colorTextLabel,
84
+ fontWeight: "500",
85
+ fontSize: 16,
86
+ lineHeight: "24px",
87
+ opacity: "0.85"
88
+ }
89
+ },
90
+ [`${token.antCls}-table-cell`]: { [`${token.antCls}-form-item`]: {
91
+ marginBlockStart: -5,
92
+ marginBlockEnd: -5,
93
+ marginInlineStart: 0,
94
+ marginInlineEnd: 0
95
+ } },
96
+ [`${token.antCls}-table-cell-resizable`]: {
97
+ position: "relative",
98
+ [`${token.antCls}-table-cell-resizable-handle`]: {
99
+ position: "absolute",
100
+ top: 0,
101
+ insetInlineEnd: -4,
102
+ zIndex: 10,
103
+ width: 12,
104
+ height: "100%",
105
+ cursor: "col-resize",
106
+ userSelect: "none",
107
+ touchAction: "none",
108
+ "&::before": {
109
+ position: "absolute",
110
+ top: "50%",
111
+ height: "1.6em",
112
+ insetInlineEnd: 4,
113
+ transform: "translateY(-50%)",
114
+ width: 1,
115
+ background: token.colorPrimary,
116
+ opacity: 0,
117
+ transition: `opacity ${token.motionDurationMid}`,
118
+ content: "\"\""
119
+ },
120
+ "&:hover::before": { opacity: 1 }
121
+ }
122
+ }
123
+ },
124
+ [`@media (max-width: ${token.screenXS})`]: { [token.componentCls]: { [`${token.antCls}-table`]: {
125
+ width: "100%",
126
+ overflowX: "auto",
127
+ "&-thead > tr,&-tbody > tr": { "> th,> td": {
128
+ whiteSpace: "pre",
129
+ ">span": { display: "block" }
130
+ } }
131
+ } } },
132
+ "@media (max-width: 575px)": { [`${token.componentCls}-toolbar`]: {
133
+ flexDirection: "column",
134
+ alignItems: "flex-start",
135
+ justifyContent: "flex-start",
136
+ height: "auto",
137
+ marginBlockEnd: 16,
138
+ marginInlineStart: 16,
139
+ paddingBlock: 8,
140
+ paddingInline: 8,
141
+ paddingBlockStart: 16,
142
+ lineHeight: "normal",
143
+ "&-title": { marginBlockEnd: 16 },
144
+ "&-option": {
145
+ display: "flex",
146
+ justifyContent: "space-between",
147
+ width: "100%"
148
+ },
149
+ "&-default-option": {
150
+ display: "flex",
151
+ flex: "1",
152
+ alignItems: "center",
153
+ justifyContent: "flex-end"
154
+ }
155
+ } }
156
+ };
157
+ };
158
+ var style_default = useStyle("ProTable", (token) => {
159
+ return [genProTableStyle(mergeToken(token, {}))];
160
+ });
161
+ //#endregion
162
+ export { style_default as default, genProTableStyle, turn };
@@ -0,0 +1,409 @@
1
+ import { DensitySize } from "./components/ToolBar/DensityIcon.js";
2
+ import { SearchConfig } from "./components/Form/FormRender.js";
3
+ import { ErrorBoundaryRender, TableAlertRender } from "./RenderTypings.js";
4
+ import { BaseToolbarProps, OptionConfig, ToolBarProps } from "./components/ToolBar/index.js";
5
+ import { ColumnsState } from "./Store/Provide.js";
6
+ import { CSSProperties, ComputedRef, Ref, UnwrapRef, VNode } from "vue";
7
+ import { LightWrapperProps, ProFormInstance, ProFormProps, ProQueryFilterProps } from "@antdv-vue/pro-form";
8
+ import { Key, PageInfo, ProCoreActionType, ProSchema, ProSchemaComponentTypes, ProTableEditableFnType, RowEditableConfig, SearchTransformKeyFn, VueNode, WithFalse } from "@antdv-vue/pro-utils";
9
+ import { InputProps, SpinProps, TableProps } from "antdv-next";
10
+ import { ProFieldEmptyText } from "@antdv-vue/pro-field";
11
+ import { ProCardProps } from "@antdv-vue/pro-card";
12
+ import { VueNode as VueNode$1 } from "antdv-next/dist/_util/type";
13
+ import { FormItemTooltipType } from "antdv-next/dist/form/FormItemLabel";
14
+ import { NamePath } from "antdv-next/dist/form/types";
15
+ import { ColumnType, SortOrder, SorterResult, TablePaginationConfig as TablePaginationConfig$1 } from "antdv-next/dist/table/index";
16
+ import { ColumnFilterItem, CompareFn, TableCurrentDataSource } from "antdv-next/dist/table/interface";
17
+ import { Dayjs } from "dayjs";
18
+
19
+ //#region src/typing.d.ts
20
+ /**
21
+ * Request filter 參數
22
+ * @description 与 antd 不同,Pro 有自己定义的 request FilterValue 类型,主要做了值内容的转换
23
+ */
24
+ type FilterValue = (string | number)[] | null;
25
+ type SearchProps = InputProps & {
26
+ inputPrefixCls?: string;
27
+ enterButton?: VueNode$1;
28
+ };
29
+ type ProSorter<T> = string | boolean | CompareFn<T> | {
30
+ compare?: CompareFn<T>; /** Config multiple sorter order priority */
31
+ multiple?: number;
32
+ };
33
+ type ProSorterResult<T> = Omit<SorterResult<T>, 'column'> & {
34
+ column?: ColumnType<T> & {
35
+ sorter?: ProSorter<T>;
36
+ };
37
+ };
38
+ type RequestData<T> = {
39
+ data: T[] | undefined;
40
+ success?: boolean;
41
+ total?: number;
42
+ } & Record<string, any>;
43
+ interface UseFetchDataAction<T = any> {
44
+ dataSource: Ref<T[] | undefined>;
45
+ setDataSource: (dataSource: T[] | undefined) => void;
46
+ loading: Ref<boolean | SpinProps | undefined>;
47
+ pageInfo: Ref<PageInfo>;
48
+ reload: () => Promise<void>;
49
+ fullScreen?: () => void;
50
+ reset: () => Promise<void>;
51
+ pollingLoading: Ref<boolean>;
52
+ setPageInfo: (pageInfo: Partial<PageInfo>) => Promise<void>;
53
+ }
54
+ type FixedType = 'start' | 'end';
55
+ type ExtraProColumnType<T> = Omit<ColumnType<T>, 'render' | 'children' | 'title' | 'filters' | 'onFilter' | 'sorter' | 'fixed'> & {
56
+ sorter?: ProSorter<T>;
57
+ };
58
+ type ProColumnType<T = unknown, ValueType = 'text'> = ProSchema<T, ExtraProColumnType<T> & {
59
+ children?: ProColumns<T>[];
60
+ index?: number;
61
+ /**
62
+ * 每个表单占据的格子大小
63
+ *
64
+ * @param 总宽度 = span* colSize
65
+ * @param 默认为 1
66
+ */
67
+ colSize?: number; /** 搜索表单的默认值 */
68
+ initialValue?: any; /** @name ellipsis 是否缩略 */
69
+ ellipsis?: ColumnType<T>['ellipsis']; /** @name copyable 是否拷贝 */
70
+ copyable?: boolean;
71
+ /**
72
+ * @name resizable 列宽调整
73
+ */
74
+ resizable?: boolean; /** 在查询表单中隐藏 */
75
+ search?: WithFalse<{
76
+ /**
77
+ * Transform: (value: any) => ({ startTime: value[0], endTime: value[1] }),
78
+ *
79
+ * @name transform 转化值的key, 一般用于事件区间的转化
80
+ */
81
+ transform: SearchTransformKeyFn;
82
+ }>; /** @name hideInTable 在 table 中隐藏 */
83
+ hideInTable?: boolean; /** @name hideInForm 在新建表单中删除 */
84
+ hideInForm?: boolean; /** @name hideInSetting 不在配置工具中显示 */
85
+ hideInSetting?: boolean; /** @name filters 表头的筛选菜单项 */
86
+ filters?: boolean | Partial<ColumnFilterItem>[]; /** @name onFilter 筛选的函数,设置为 false 会关闭自带的本地筛选 */
87
+ onFilter?: boolean | Partial<ColumnType<T>['onFilter']>; /** @name Form 的排序 */
88
+ order?: number;
89
+ fixed?: boolean | FixedType; /** @name editable 可编辑表格是否可编辑 */
90
+ editable?: boolean | ProTableEditableFnType<T>;
91
+ /**
92
+ * 用于 ProListy,指定该列映射到列表项的哪个插槽位置
93
+ *
94
+ * @name 列表项插槽
95
+ * @example listSlot: 'title'
96
+ * @example listSlot: 'avatar'
97
+ */
98
+ listSlot?: 'title' | 'subTitle' | 'avatar' | 'description' | 'content' | 'actions' | 'aside' | 'type' | (string & {}); /** @name readonly 只读 */
99
+ readonly?: boolean; /** @name disable 列设置的 disabled */
100
+ disable?: boolean | {
101
+ checkbox: boolean;
102
+ };
103
+ }, ProSchemaComponentTypes, ValueType, {
104
+ lightProps?: LightWrapperProps;
105
+ }>;
106
+ type ProColumns<T = any, ValueType = 'text'> = ProColumnType<T, ValueType>;
107
+ type BorderedType = 'search' | 'table';
108
+ type Bordered = boolean | {
109
+ search?: boolean;
110
+ table?: boolean;
111
+ };
112
+ interface ColumnStateType {
113
+ /**
114
+ * 持久化的类型,支持 localStorage 和 sessionStorage
115
+ *
116
+ * @param localStorage 设置在关闭浏览器后也是存在的
117
+ * @param sessionStorage 关闭浏览器后会丢失
118
+ */
119
+ persistenceType?: 'localStorage' | 'sessionStorage';
120
+ /** 持久化的key,用于存储到 storage 中 */
121
+ persistenceKey?: string;
122
+ /** ColumnsState 的值 */
123
+ defaultValue?: Record<string, ColumnsState>;
124
+ /** ColumnsState 的值 */
125
+ value?: Record<string, ColumnsState>;
126
+ onChange?: (map: Record<string, ColumnsState>) => void;
127
+ }
128
+ /** ProTable 的类型定义 继承自 antd 的 Table */
129
+ type ProTableProps<DataSource, U, ValueType = 'text'> = {
130
+ dataSource?: DataSource[];
131
+ size?: DensitySize;
132
+ /**
133
+ * @name columns 列配置能力,支持一个数组
134
+ */
135
+ columns?: ProColumns<DataSource, ValueType>[];
136
+ /**
137
+ * @name toolbar ToolBar 的属性
138
+ */
139
+ toolbar?: BaseToolbarProps;
140
+ /**
141
+ * @name ghost 幽灵模式,即是否取消卡片内容区域的 padding 和 卡片的背景颜色。
142
+ */
143
+ ghost?: boolean;
144
+ /**
145
+ * request 的参数,修改之后会触发更新
146
+ *
147
+ * @example pathname 修改重新触发 request
148
+ * params={{ pathName }}
149
+ */
150
+ params?: U; /** @name columnsState 列状态的配置,可以用来操作列功能 */
151
+ columnsState?: ColumnStateType;
152
+ onSizeChange?: (size: DensitySize) => void;
153
+ /**
154
+ * @name cardProps table 外面卡片的设置
155
+ */
156
+ cardProps?: ProCardProps | false;
157
+ /**
158
+ * @name tableRender 渲染 table
159
+ */
160
+ tableRender?: (props: ProTableProps<DataSource, U, ValueType>, defaultDom: VueNode, /** 各个区域的 dom */
161
+
162
+ domList: {
163
+ toolbar: VueNode;
164
+ alert: VueNode;
165
+ table: VueNode;
166
+ }) => VueNode;
167
+ /**
168
+ * @name tableViewRender 渲染 table 视图,用于定制 ProList,不推荐直接使用
169
+ */
170
+ tableViewRender?: (props: TableProps<DataSource> & {
171
+ class?: string;
172
+ style?: CSSProperties;
173
+ onChange?: (changePagination: TablePaginationConfig$1, filters: Record<string, FilterValue | null>, sorter: SorterResult<DataSource> | SorterResult<DataSource>[], extra: TableCurrentDataSource<DataSource>) => void;
174
+ }, defaultDom: VueNode) => VueNode;
175
+ /**
176
+ * @name tableExtraRender table 和搜索表单之间的 dom 渲染
177
+ *
178
+ * @example 在table 上方增加一个统计表单
179
+ *
180
+ * tableExtraRender={()=> <Statistic title="统计" value={10} />}
181
+ */
182
+ tableExtraRender?: (props: ProTableProps<DataSource, U, ValueType>, dataSource: DataSource[]) => VueNode;
183
+ onChange?: (pagination: TablePaginationConfig$1, filters: Record<string, FilterValue | null>, sorter: SorterResult<DataSource> | SorterResult<DataSource>[], extra: TableCurrentDataSource<DataSource>) => void;
184
+ /**
185
+ * @name searchFormRender 渲染搜索表单
186
+ */
187
+ searchFormRender?: (props: ProTableProps<DataSource, U, ValueType>, defaultDom: VueNode) => VNode; /** @name request 一个获得 dataSource 的方法 */
188
+ request?: (params: U & {
189
+ pageSize?: number;
190
+ current?: number;
191
+ keyword?: string;
192
+ }, sort: Record<string, SortOrder>, filter: Record<string, FilterValue>) => Promise<Partial<RequestData<DataSource>>>; /** @name postData 对数据进行一些处理 */
193
+ postData?: (dataSource: DataSource[]) => DataSource[]; /** @name defaultData 默认的数据 */
194
+ defaultData?: DataSource[];
195
+ /**
196
+ * @name actionRef 初始化的参数,可以操作 table
197
+ *
198
+ * @example 重新刷新表格
199
+ * actionRef.current?.reload();
200
+ *
201
+ * @example 重置表格
202
+ * actionRef.current?.reset();
203
+ */
204
+ /**
205
+ * @name formRef 操作自带的 form
206
+ */
207
+ /**
208
+ * @name toolBarRender 渲染操作栏
209
+ */
210
+ toolBarRender?: WithFalse<ToolBarProps<DataSource, ValueType>['toolBarRender']>;
211
+ optionsRender?: ToolBarProps<DataSource, ValueType>['optionsRender'];
212
+ /**
213
+ * @name onLoad 数据加载完成后触发
214
+ */
215
+ onLoad?: (dataSource: DataSource[]) => void;
216
+ /**
217
+ * @name onLoadingChange loading 被修改时触发,一般是网络请求导致的
218
+ */
219
+ onLoadingChange?: (loading: boolean | SpinProps | undefined) => void;
220
+ /**
221
+ * @name onRequestError 数据加载失败时触发
222
+ */
223
+ onRequestError?: (e: Error) => void;
224
+ /**
225
+ * 是否轮询 ProTable 它不会自动提交表单,如果你想自动提交表单的功能,需要在 onValueChange 中调用 formRef.current?.submit()
226
+ * @property {number} polling 表示轮询的时间间隔,0 表示关闭轮询,大于 0 表示开启轮询,最小的轮询时间为 2000ms
227
+ * @param dataSource 返回当前的表单数据,你可以用它判断要不要打开轮询
228
+ */
229
+ polling?: number | ((dataSource: DataSource[]) => number); /** @name tableClass 给封装的 table 的 className */
230
+ tableClass?: string; /** @name tableStyle 给封装的 table 的 style */
231
+ tableStyle?: CSSProperties; /** @name headerTitle 左上角的 title */
232
+ headerTitle?: VueNode; /** @name tooltip 标题旁边的 tooltip */
233
+ tooltip?: string | FormItemTooltipType; /** @name options 操作栏配置 */
234
+ options?: WithFalse<OptionConfig<DataSource, ValueType>>;
235
+ /**
236
+ * @type SearchConfig
237
+ * @name search 是否显示搜索表单
238
+ */
239
+ search?: WithFalse<SearchConfig>;
240
+ /**
241
+ * 基本配置与 antd Form 相同, 但是劫持了 form onFinish 的配置
242
+ *
243
+ * @name form type="form" 和 搜索表单 的 Form 配置
244
+ */
245
+ form?: Omit<ProFormProps<DataSource, U> & ProQueryFilterProps<DataSource, U>, 'form'>;
246
+ /**
247
+ * 暂时只支持 dayjs - string 会格式化为 YYYY-DD-MM - number 代表时间戳
248
+ *
249
+ * @name dateFormatter 如何格式化日期
250
+ */
251
+ dateFormatter?: (string & {}) | 'string' | 'number' | ((value: Dayjs, valueType: string) => string | number) | false; /** @name beforeSearchSubmit 格式化搜索表单提交数据 */
252
+ beforeSearchSubmit?: (params: Partial<U>) => any;
253
+ /**
254
+ * 设置或者返回false 即可关闭
255
+ *
256
+ * @name tableAlertRender 自定义 table 的 alert
257
+ */
258
+ tableAlertRender?: TableAlertRender<DataSource>;
259
+ /**
260
+ * 设置或者返回false 即可关闭
261
+ *
262
+ * @name tableAlertOptionRender 自定义 table 的 alert 的操作
263
+ */
264
+ tableAlertOptionRender?: TableAlertRender<DataSource>; /** @name rowSelection 选择项配置 */
265
+ rowSelection?: (TableProps<DataSource>['rowSelection'] & {
266
+ alwaysShowAlert?: boolean;
267
+ }) | false; /** 支持 ProTable 的类型 */
268
+ type?: ProSchemaComponentTypes; /** @name onSubmit 提交表单时触发 */
269
+ onSubmit?: (params?: U) => void; /** @name onReset 重置表单时触发 */
270
+ onReset?: (params?: U) => void; /** @name columnEmptyText 空值时显示 */
271
+ columnEmptyText?: ProFieldEmptyText; /** @name manualRequest 是否手动触发请求 */
272
+ manualRequest?: boolean;
273
+ /**
274
+ * @name editable 编辑行相关的配置
275
+ *
276
+ * @example 支持多行编辑
277
+ * editable={{type:"multiple"}}
278
+ *
279
+ * @example 保存的时候请求后端
280
+ * editable={{ onSave:async (rows)=>{ await save(rows) } }}
281
+ */
282
+ editable?: RowEditableConfig<DataSource>;
283
+ /**
284
+ * @name onDataSourceChange 可编辑表格修改数据的改变
285
+ */
286
+ onDataSourceChange?: (dataSource: DataSource[]) => void; /** @name cardBordered 查询表单和 Table 的卡片 border 配置 */
287
+ cardBordered?: Bordered; /** @name debounceTime 去抖时间 */
288
+ debounceTime?: number;
289
+ /**
290
+ * 只在request 存在的时候生效,可编辑表格也不会生效
291
+ *
292
+ * @default false
293
+ * @name revalidateOnFocus 窗口聚焦时自动重新请求
294
+ */
295
+ revalidateOnFocus?: boolean; /** 默认的表格大小 */
296
+ defaultSize?: DensitySize;
297
+ /**
298
+ * @name name 可编辑表格的name,通过这个name 可以直接与 form通信,无需嵌套
299
+ */
300
+ name?: NamePath<string | number | boolean>;
301
+ /**
302
+ * 错误边界自定义
303
+ */
304
+ errorBoundaryRender?: ErrorBoundaryRender;
305
+ } & Omit<TableProps<DataSource>, 'columns' | 'rowSelection' | 'size' | 'dataSource'>;
306
+ type ActionType<T extends Record<string, any>, U> = ProCoreActionType<T, U> & {
307
+ /** 原生 DOM 元素引用 */nativeElement?: HTMLDivElement | null; /** 聚焦方法 */
308
+ focus?: () => void;
309
+ fullScreen: () => Promise<void>;
310
+ setPageInfo: (page: Partial<PageInfo>) => Promise<void>;
311
+ /**
312
+ * 对齐 antd Table ScrollConfig
313
+ * - number: 作为 top 处理
314
+ * - { index?, key?, top? }
315
+ */
316
+ scrollTo?: (arg: number | {
317
+ index?: number;
318
+ key?: Key;
319
+ top?: number;
320
+ }) => void;
321
+ };
322
+ type ProTableInstance<T extends Record<string, any>> = {
323
+ formRef: ProFormInstance<T>;
324
+ } & ActionType<Record<string, any>, T>;
325
+ /**
326
+ * 用于定义 useFetch 的参数类型
327
+ * @typedef {object} UseFetchProps
328
+ * @property {any} [dataSource] - 数据源,可选参数
329
+ * @property {UseFetchDataAction['loading']} loading - 数据加载状态,必须参数
330
+ * @property {(loading: UseFetchDataAction['loading']) => void} [onLoadingChange] - 加载状态改变时的回调函数,可选参数
331
+ * @property {(dataSource: any[], extra: any) => void} [onLoad] - 数据加载完成时的回调函数,可选参数
332
+ * @property {(dataSource?: any) => void} [onDataSourceChange] - 数据源改变时的回调函数,可选参数
333
+ * @property {any} postData - 发送到后端的数据,必须参数
334
+ * @property {{current?: number; pageSize?: number; defaultCurrent?: number; defaultPageSize?: number;} | false} pageInfo - 分页信息,可选参数,false 表示不启用分页
335
+ * @property {(pageInfo: PageInfo) => void} [onPageInfoChange] - 分页信息改变时的回调函数,可选参数
336
+ * @property {any[]} [effects] - 依赖的其它 Hook 或其它变量,可选参数
337
+ * @property {(e: Error) => void} [onRequestError] - 请求出错时的回调函数,可选参数
338
+ * @property {boolean} manual - 是否手动触发请求,必须参数
339
+ * @property {number} [debounceTime] - 延迟时间,可选参数,单位为毫秒
340
+ * @property {number | ((dataSource: any[]) => number)} [polling] - 轮询时间,可选参数,单位为毫秒或一个返回时间的函数
341
+ * @property {boolean} [revalidateOnFocus] - 是否在焦点回到页面时重新验证数据,可选参数
342
+ */
343
+ interface UseFetchProps<T = any> {
344
+ /**
345
+ * 数据源
346
+ */
347
+ dataSource?: UseFetchDataAction<T>['dataSource'];
348
+ /**
349
+ * 是否处于加载状态
350
+ */
351
+ loading: UseFetchDataAction<T>['loading'];
352
+ /**
353
+ * 加载状态改变时的回调函数
354
+ */
355
+ onLoadingChange?: (loading: UnwrapRef<UseFetchDataAction['loading']>) => void;
356
+ /**
357
+ * 数据加载完成后的回调函数
358
+ */
359
+ onLoad?: (dataSource: any[], extra: any) => void;
360
+ /**
361
+ * 数据源变化时的回调函数
362
+ */
363
+ onDataSourceChange?: (dataSource?: any) => void;
364
+ /**
365
+ * 请求时附带的数据
366
+ */
367
+ postData?: (dataSource: any[]) => any[];
368
+ /**
369
+ * 分页信息
370
+ */
371
+ pageInfo: ComputedRef<WithFalse<{
372
+ current?: number;
373
+ pageSize?: number;
374
+ defaultPageSize?: number;
375
+ }>>;
376
+ /**
377
+ * 分页信息变化时的回调函数
378
+ */
379
+ onPageInfoChange?: (pageInfo: PageInfo) => void;
380
+ /**
381
+ * 请求相关的副作用
382
+ */
383
+ effects?: any[];
384
+ /**
385
+ * 请求出错时的回调函数
386
+ */
387
+ onRequestError?: (e: Error) => void;
388
+ /**
389
+ * 是否手动触发请求
390
+ */
391
+ manual: ComputedRef<boolean>;
392
+ /**
393
+ * 请求防抖时间
394
+ */
395
+ debounceTime: Ref<number | undefined>;
396
+ /**
397
+ * 数据源轮询间隔时间或轮询触发条件
398
+ */
399
+ polling: Ref<number | ((dataSource: any[]) => number) | undefined>;
400
+ /**
401
+ * 是否在页面获得焦点时重新验证数据
402
+ */
403
+ revalidateOnFocus?: Ref<boolean>;
404
+ }
405
+ type OptionSearchProps = Omit<SearchProps, 'onSearch'> & {
406
+ /** 如果 onSearch 返回一个false,直接拦截请求 */onSearch?: (keyword: string) => Promise<boolean | undefined> | boolean | undefined;
407
+ };
408
+ //#endregion
409
+ export { ActionType, Bordered, BorderedType, ColumnStateType, ExtraProColumnType, FilterValue, FixedType, OptionSearchProps, ProColumnType, ProColumns, ProSorter, ProSorterResult, ProTableInstance, ProTableProps, RequestData, SearchProps, UseFetchDataAction, UseFetchProps };
package/dist/typing.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { RequestData, UseFetchDataAction, UseFetchProps } from "./typing.js";
2
+ import { ComputedRef } from "vue";
3
+
4
+ //#region src/useFetchData.d.ts
5
+ declare function useFetchData<DataSource extends Record<string, any>>(getData: ComputedRef<((params?: {
6
+ pageSize: number;
7
+ current: number;
8
+ }) => Promise<Partial<RequestData<DataSource> | undefined>>) | undefined>, defaultData: DataSource[] | undefined, options: UseFetchProps<DataSource>): UseFetchDataAction<DataSource>;
9
+ //#endregion
10
+ export { useFetchData as default };