yuand 1.0.1 → 1.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.
package/README.md CHANGED
@@ -1,22 +1,6 @@
1
- # yu-component
1
+ # yuand
2
2
 
3
- [![NPM version](https://img.shields.io/npm/v/yu-component.svg?style=flat)](https://npmjs.org/package/yu-component)
4
- [![NPM downloads](http://img.shields.io/npm/dm/yu-component.svg?style=flat)](https://npmjs.org/package/yu-component)
5
3
 
6
- ## Install
7
-
8
- ```bash
9
- $ npm install
10
- ```
11
-
12
- ```bash
13
- $ npm run dev
14
- $ npm run build
15
- ```
16
-
17
- ## Options
18
-
19
- TODO
20
4
 
21
5
  ## LICENSE
22
6
 
package/README.test.md ADDED
@@ -0,0 +1,112 @@
1
+ # Table 组件测试说明
2
+
3
+ ## 安装测试依赖
4
+
5
+ ```bash
6
+ npm install -D vitest @vitest/ui @vitejs/plugin-react jsdom
7
+ npm install -D @testing-library/react @testing-library/user-event @testing-library/jest-dom
8
+ npm install -D @types/testing-library__jest-dom
9
+ ```
10
+
11
+ ## 运行测试
12
+
13
+ ```bash
14
+ # 运行所有测试
15
+ npm test
16
+
17
+ # 监听模式
18
+ npm test -- --watch
19
+
20
+ # 生成覆盖率报告
21
+ npm test -- --coverage
22
+
23
+ # 运行 UI 界面
24
+ npm test -- --ui
25
+
26
+ # 运行特定测试文件
27
+ npm test src/components/Table/__tests__/index.test.tsx
28
+ ```
29
+
30
+ ## 测试覆盖范围
31
+
32
+ ### 1. 组件基础功能测试 (`index.test.tsx`)
33
+ - ✅ 基础渲染
34
+ - ✅ 加载状态
35
+ - ✅ 自定义 classNames 和 styles
36
+ - ✅ 自定义 dataKey 和 totalKey
37
+ - ✅ 表单搜索功能
38
+ - ✅ 表单提交和重置
39
+ - ✅ handleValues 表单值处理
40
+ - ✅ 分页器显示和切换
41
+ - ✅ 每页大小变化
42
+ - ✅ 列排序功能
43
+ - ✅ Table 实例方法(run, reset, refresh, sortOrder)
44
+ - ✅ 动态列配置(函数形式 columns)
45
+ - ✅ Alert 和 Toolbar 渲染
46
+ - ✅ 国际化支持
47
+ - ✅ 静态方法(config, formatDate, removeEmpty)
48
+
49
+ ### 2. useTable Hook 测试 (`useTable.test.ts`)
50
+ - ✅ 返回正确的实例结构
51
+ - ✅ 默认和自定义初始状态
52
+ - ✅ 状态更新
53
+ - ✅ sortOrder 方法
54
+ - ✅ resetStore 方法
55
+ - ✅ 实例稳定性(多次渲染)
56
+ - ✅ subscribe 回调
57
+ - ✅ sorter 变化触发更新
58
+ - ✅ Form 实例
59
+ - ✅ 多实例独立性
60
+
61
+ ### 3. 集成测试 (`integration.test.tsx`)
62
+ - ✅ 完整的搜索-分页-排序流程
63
+ - ✅ 表单验证与条件搜索
64
+ - ✅ 自定义 handleValues 转换
65
+ - ✅ 动态列与数据联动
66
+ - ✅ Alert 统计信息显示
67
+ - ✅ 外部控制刷新与清空
68
+
69
+ ## 测试配置文件
70
+
71
+ ### vitest.config.ts
72
+ 配置了测试环境、覆盖率报告、路径别名等。
73
+
74
+ ### src/test/setup.ts
75
+ 测试环境初始化,包括:
76
+ - jest-dom 断言扩展
77
+ - 自动清理
78
+ - window.matchMedia mock
79
+ - IntersectionObserver mock
80
+ - ResizeObserver mock
81
+
82
+ ## 覆盖率目标
83
+
84
+ - **语句覆盖率**: > 80%
85
+ - **分支覆盖率**: > 75%
86
+ - **函数覆盖率**: > 80%
87
+ - **行覆盖率**: > 80%
88
+
89
+ ## 常见问题
90
+
91
+ ### Q: 如何调试测试?
92
+ A: 使用 `--ui` 参数打开 Vitest UI 界面进行可视化调试。
93
+
94
+ ### Q: 测试运行很慢怎么办?
95
+ A: 可以使用 `--run` 参数禁用监听模式,或使用 `--isolate=false` 提升性能。
96
+
97
+ ### Q: 如何 mock API 请求?
98
+ A: 在测试文件中使用 `vi.mock()` mock fetch 模块,参考测试文件中的示例。
99
+
100
+ ## package.json 脚本配置
101
+
102
+ 在 package.json 中添加以下脚本:
103
+
104
+ ```json
105
+ {
106
+ "scripts": {
107
+ "test": "vitest",
108
+ "test:ui": "vitest --ui",
109
+ "test:coverage": "vitest --coverage"
110
+ }
111
+ }
112
+ ```
@@ -1,12 +1,18 @@
1
1
  import type { ProTableProps, ProTableConfigOptions } from "./types";
2
2
  import "./style.css";
3
3
  declare const ProTable: {
4
- <T extends Record<string, any>>(props: ProTableProps<T>): import("react/jsx-runtime").JSX.Element;
4
+ <T extends Record<string, any>>(props: ProTableProps<T>): import("../../../node_modules/@types/react").JSX.Element;
5
5
  useTable: (options?: import("./types").UseTableProps) => import("./types").TableInstance<any>[];
6
6
  getQuery: ({ page, size, sorter, search, params, }: import("../../utils/table").GetQueryProps) => Record<string, unknown>;
7
7
  formatDate: (key: string, data: Record<string, any>, format?: string) => Record<string, any>;
8
8
  removeEmpty: (data: Record<string, any>) => Record<string, any>;
9
9
  pageSizeOptions: number[];
10
+ /**
11
+ * 自定义配置参数组合方式.
12
+ * getQuery函数配置默认提供 page,size,orderField,isAsc,...params,...search
13
+ * @param options
14
+ * @returns
15
+ */
10
16
  config(options: ProTableConfigOptions): void;
11
17
  };
12
18
  export default ProTable;
@@ -3,8 +3,8 @@ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
5
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
- var _excluded = ["request", "classNames", "styles", "table", "locale", "dataKey", "totalKey", "manual", "nostyle", "columns", "form", "alert", "toolbar", "pageSizeOptions", "pagination", "scroll", "useData"],
7
- _excluded2 = ["title", "extra", "right", "formItem", "layout", "items", "reset", "dataForm", "handleValues", "onResetBefore"];
6
+ var _excluded = ["request", "classNames", "styles", "table", "locale", "dataKey", "totalKey", "nostyle", "columns", "form", "alert", "toolbar", "pagination", "scroll", "useData"],
7
+ _excluded2 = ["title", "extra", "right", "layout", "items", "reset", "dataForm", "handleValues", "onResetBefore"];
8
8
  import { rq } from "../../fetch";
9
9
  import { I18nContext, t } from "../TableConfig";
10
10
  import { useShallow } from "zustand/react/shallow";
@@ -16,41 +16,48 @@ import { getDataSource, getQuery, getTotal, formatDate, removeEmpty } from "../.
16
16
  import useX from "../../hooks/useX";
17
17
  import useTable from "./useTable";
18
18
  import "./style.css";
19
+
20
+ // 统一默认配置管理
19
21
  import { jsx as _jsx } from "react/jsx-runtime";
20
22
  import { jsxs as _jsxs } from "react/jsx-runtime";
21
- var defaultClassNames = {
22
- root: "main-container",
23
- form: "search-form",
24
- table: "main-table"
25
- };
26
- var defaultStyles = {
27
- root: {},
28
- form: {
29
- display: "flex",
30
- justifyContent: "space-between"
23
+ var DEFAULT_PAGE_SIZE_OPTIONS = [10, 20, 50, 100];
24
+ var DEFAULT_CONFIG = {
25
+ classNames: {
26
+ root: "main-container",
27
+ form: "search-form",
28
+ table: "main-table"
29
+ },
30
+ styles: {
31
+ root: {},
32
+ form: {
33
+ display: "flex",
34
+ justifyContent: "space-between"
35
+ },
36
+ table: {},
37
+ toolbar: {
38
+ marginBottom: 15
39
+ }
31
40
  },
32
- table: {},
33
- toolbar: {
34
- marginBottom: 15
41
+ pagination: {
42
+ showQuickJumper: true,
43
+ showSizeChanger: true,
44
+ hideOnSinglePage: false
35
45
  }
36
46
  };
37
- var DEFAULT_PAGE_SIZE_OPTIONS = [10, 20, 50, 100];
38
47
  var ProTable = function ProTable(props) {
39
- var _scroll$x, _classNames$root, _classNames$form, _classNames$table;
48
+ var _pagination$showTotal, _pagination$pageSizeO, _scroll$x, _classNames$root, _classNames$form, _classNames$table;
40
49
  var _props$request = props.request,
41
50
  request = _props$request === void 0 ? {} : _props$request,
42
51
  _props$classNames = props.classNames,
43
- classNames = _props$classNames === void 0 ? defaultClassNames : _props$classNames,
52
+ classNames = _props$classNames === void 0 ? DEFAULT_CONFIG.classNames : _props$classNames,
44
53
  _props$styles = props.styles,
45
- styles = _props$styles === void 0 ? defaultStyles : _props$styles,
54
+ styles = _props$styles === void 0 ? DEFAULT_CONFIG.styles : _props$styles,
46
55
  table = props.table,
47
56
  locale = props.locale,
48
57
  _props$dataKey = props.dataKey,
49
58
  dataKey = _props$dataKey === void 0 ? "data" : _props$dataKey,
50
59
  _props$totalKey = props.totalKey,
51
60
  totalKey = _props$totalKey === void 0 ? "total" : _props$totalKey,
52
- _props$manual = props.manual,
53
- manual = _props$manual === void 0 ? false : _props$manual,
54
61
  nostyle = props.nostyle,
55
62
  columns = props.columns,
56
63
  _props$form = props.form,
@@ -58,27 +65,29 @@ var ProTable = function ProTable(props) {
58
65
  alert = props.alert,
59
66
  _props$toolbar = props.toolbar,
60
67
  toolbar = _props$toolbar === void 0 ? null : _props$toolbar,
61
- pageSizeOptions = props.pageSizeOptions,
62
- pagination = props.pagination,
68
+ _props$pagination = props.pagination,
69
+ pagination = _props$pagination === void 0 ? DEFAULT_CONFIG.pagination : _props$pagination,
63
70
  scroll = props.scroll,
64
71
  useData = props.useData,
65
72
  prop = _objectWithoutProperties(props, _excluded);
66
73
  var _useContext = useContext(I18nContext),
67
74
  lang = _useContext.lang;
75
+ (_pagination$showTotal = pagination.showTotal) !== null && _pagination$showTotal !== void 0 ? _pagination$showTotal : pagination.showTotal = function (total) {
76
+ return "".concat(t("共", lang), " ").concat(total, " ").concat(t("条记录", lang));
77
+ };
78
+ (_pagination$pageSizeO = pagination.pageSizeOptions) !== null && _pagination$pageSizeO !== void 0 ? _pagination$pageSizeO : pagination.pageSizeOptions = ProTable.pageSizeOptions;
68
79
  var formTitle = form.title,
69
80
  formExtra = form.extra,
70
81
  formRight = form.right,
71
- formItem = form.formItem,
72
82
  _form$layout = form.layout,
73
83
  layout = _form$layout === void 0 ? "inline" : _form$layout,
74
- items = form.items,
84
+ formItems = form.items,
75
85
  formReset = form.reset,
76
86
  dataForm = form.dataForm,
77
87
  formHandleValues = form.handleValues,
78
88
  formOnResetBefore = form.onResetBefore,
79
89
  otherFormProps = _objectWithoutProperties(form, _excluded2);
80
90
  var forceKey = useRef(0);
81
- var formItems = formItem || items;
82
91
  var queryClient = useQueryClient();
83
92
  var _table$useStore = table.useStore(useShallow(function (state) {
84
93
  return {
@@ -152,7 +161,7 @@ var ProTable = function ProTable(props) {
152
161
  data: data
153
162
  });
154
163
  }
155
- }, [data]);
164
+ }, [data, useData]);
156
165
  var _useMemo = useMemo(function () {
157
166
  return {
158
167
  column: typeof columns === "function" ? columns(data) : columns,
@@ -175,8 +184,9 @@ var ProTable = function ProTable(props) {
175
184
  }
176
185
  };
177
186
  var onReset = function onReset() {
187
+ var _ref4, _pagination$pageSizeO2;
178
188
  setState({
179
- size: (pageSizeOptions === null || pageSizeOptions === void 0 ? void 0 : pageSizeOptions[0]) || ProTable.pageSizeOptions[0],
189
+ size: (_ref4 = pagination === null || pagination === void 0 || (_pagination$pageSizeO2 = pagination.pageSizeOptions) === null || _pagination$pageSizeO2 === void 0 ? void 0 : _pagination$pageSizeO2[0]) !== null && _ref4 !== void 0 ? _ref4 : ProTable.pageSizeOptions[0],
180
190
  sorter: {}
181
191
  });
182
192
  if (formItems) {
@@ -187,23 +197,21 @@ var ProTable = function ProTable(props) {
187
197
  }
188
198
  }
189
199
  };
200
+ if (table) {
201
+ table.queryKey = queryKey;
202
+ table.clear = function () {
203
+ return queryClient.setQueryData(queryKey, {});
204
+ };
205
+ table.run = onSearch;
206
+ table.refresh = refetch;
207
+ table.reset = function () {
208
+ if (formItems) {
209
+ onReset();
210
+ }
211
+ };
212
+ }
190
213
  useEffect(function () {
191
- if (table) {
192
- table.run = onSearch;
193
- table.queryKey = queryKey;
194
- table.clear = function () {
195
- return queryClient.setQueryData(queryKey, {});
196
- };
197
- table.refresh = refetch;
198
- table.reset = function () {
199
- if (formItems) {
200
- onReset();
201
- }
202
- };
203
- }
204
- }, [table, queryKey]);
205
- useEffect(function () {
206
- if (manual) return;
214
+ if (request.manual) return;
207
215
  if (formItems) {
208
216
  table.form.submit();
209
217
  } else {
@@ -252,26 +260,19 @@ var ProTable = function ProTable(props) {
252
260
  onChange: function onChange(p, _, sorter) {
253
261
  return tableChange(p, sorter);
254
262
  },
255
- pagination: {
263
+ pagination: _objectSpread({
256
264
  current: page,
257
265
  pageSize: size,
258
- showQuickJumper: pagination ? pagination.showQuickJumper : true,
259
- showSizeChanger: pagination ? pagination.showSizeChanger : true,
260
- hideOnSinglePage: pagination ? pagination.hideOnSinglePage : false,
261
- pageSizeOptions: pageSizeOptions || ProTable.pageSizeOptions,
262
- total: total,
263
- showTotal: function showTotal(total) {
264
- return "".concat(t("共", lang), " ").concat(total, " ").concat(t("条记录", lang));
265
- }
266
- },
266
+ total: total
267
+ }, pagination),
267
268
  dataSource: dataSource
268
269
  }, prop));
269
270
  };
270
271
  return /*#__PURE__*/_jsxs("div", {
271
- className: (_classNames$root = classNames === null || classNames === void 0 ? void 0 : classNames.root) !== null && _classNames$root !== void 0 ? _classNames$root : defaultClassNames.root,
272
+ className: (_classNames$root = classNames === null || classNames === void 0 ? void 0 : classNames.root) !== null && _classNames$root !== void 0 ? _classNames$root : DEFAULT_CONFIG.classNames.root,
272
273
  style: styles.root,
273
274
  children: [!!formItems && /*#__PURE__*/_jsxs("div", {
274
- className: (_classNames$form = classNames === null || classNames === void 0 ? void 0 : classNames.form) !== null && _classNames$form !== void 0 ? _classNames$form : defaultClassNames.form,
275
+ className: (_classNames$form = classNames === null || classNames === void 0 ? void 0 : classNames.form) !== null && _classNames$form !== void 0 ? _classNames$form : DEFAULT_CONFIG.classNames.form,
275
276
  style: styles.form,
276
277
  children: [/*#__PURE__*/_jsxs(Form, _objectSpread(_objectSpread({
277
278
  form: table.form,
@@ -296,7 +297,7 @@ var ProTable = function ProTable(props) {
296
297
  })]
297
298
  })), formRight]
298
299
  }), /*#__PURE__*/_jsxs("div", {
299
- className: (_classNames$table = classNames === null || classNames === void 0 ? void 0 : classNames.table) !== null && _classNames$table !== void 0 ? _classNames$table : defaultClassNames.table,
300
+ className: (_classNames$table = classNames === null || classNames === void 0 ? void 0 : classNames.table) !== null && _classNames$table !== void 0 ? _classNames$table : DEFAULT_CONFIG.classNames.table,
300
301
  style: styles.table,
301
302
  children: [toolbar && /*#__PURE__*/_jsx("div", {
302
303
  style: styles.toolbar,
@@ -313,7 +314,12 @@ ProTable.formatDate = formatDate;
313
314
  ProTable.removeEmpty = removeEmpty;
314
315
  ProTable.pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS;
315
316
 
316
- //自定义配置参数组合方式. 默认提供 page,size,orderField,isAsc,...params,...search
317
+ /**
318
+ * 自定义配置参数组合方式.
319
+ * getQuery函数配置默认提供 page,size,orderField,isAsc,...params,...search
320
+ * @param options
321
+ * @returns
322
+ */
317
323
  ProTable.config = function (options) {
318
324
  if (!options || !isObject(options)) return;
319
325
  if (options.getQuery) {
@@ -1,3 +1,3 @@
1
1
  .search-form .ant-form-item {
2
- margin-bottom: 20px!important;
2
+ margin-bottom: 20px !important;
3
3
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import type { FormInstance, TableColumnType, TableProps, FormProps } from "antd";
2
+ import type { FormInstance, TableColumnType, TableProps, FormProps, PaginationProps } from "../../../node_modules/antd";
3
3
  import type { HttpMethod } from "../../fetch";
4
- import type { UseBoundStore, StoreApi } from "zustand";
4
+ import type { UseBoundStore, StoreApi } from "../../../node_modules/zustand";
5
5
  import type { GetQueryProps } from "../../utils/table";
6
6
  type RecordType = Record<string, any>;
7
7
  interface SorterType {
@@ -33,13 +33,11 @@ export interface TableInstance<TData = any> {
33
33
  }
34
34
  interface FormOptions extends Omit<FormProps, "form" | "title" | "children"> {
35
35
  title?: React.ReactNode;
36
- /** @deprecated 此属性已废弃,请使用新的formItem属性代替 */
37
36
  items?: React.ReactNode | React.ReactNode[];
38
- formItem?: React.ReactNode | React.ReactNode[];
39
37
  extra?: React.ReactNode;
40
38
  right?: React.ReactNode;
41
- handleValues?: (values: Record<string, any>) => any;
42
39
  reset?: boolean;
40
+ handleValues?: (values: Record<string, any>) => any;
43
41
  onResetBefore?: () => void | boolean;
44
42
  dataForm?: FormProps;
45
43
  }
@@ -59,34 +57,24 @@ export interface ProTableProps<Tdata = any> extends Omit<TableProps<Tdata>, "col
59
57
  request: {
60
58
  /** 请求地址方法 */
61
59
  url?: string;
60
+ /** 手动调用发送 table.run */
61
+ manual?: boolean;
62
62
  method?: HttpMethod;
63
- /** 请求参数 */
63
+ /** 请求额外参数 */
64
64
  params?: Record<string, any>;
65
65
  onBefore?: () => any;
66
66
  onSuccess?: (data: any) => any;
67
67
  };
68
- url: string;
69
68
  table: TableInstance<Tdata> | null;
70
69
  locale?: Record<string, any>;
71
70
  dataKey?: string;
72
71
  totalKey?: string;
73
- manual?: boolean;
74
72
  nostyle?: boolean;
75
- params?: RecordType;
76
73
  columns: ((data: Tdata) => TableColumnType<unknown>[]) | TableColumnType<unknown>[];
77
74
  form?: FormOptions;
78
75
  alert?: React.ReactNode | ((data: Tdata) => React.ReactNode);
79
76
  toolbar?: React.ReactNode;
80
- pageSizeOptions?: number[];
81
- onBefore?: () => void;
82
- onSuccess?: (data: Tdata) => any;
83
- pagination?: {
84
- showQuickJumper?: boolean;
85
- showSizeChanger?: boolean;
86
- hideOnSinglePage?: boolean;
87
- };
88
- loadingDelay?: number;
89
- method?: HttpMethod;
77
+ pagination?: PaginationProps;
90
78
  useData?: boolean;
91
79
  }
92
80
  export interface UseTableProps {
@@ -1,12 +1,18 @@
1
1
  import type { ProTableProps, ProTableConfigOptions } from "./types";
2
2
  import "./style.css";
3
3
  declare const ProTable: {
4
- <T extends Record<string, any>>(props: ProTableProps<T>): import("react/jsx-runtime").JSX.Element;
4
+ <T extends Record<string, any>>(props: ProTableProps<T>): import("../../../node_modules/@types/react").JSX.Element;
5
5
  useTable: (options?: import("./types").UseTableProps) => import("./types").TableRef[];
6
6
  getQuery(options: any): Record<string, unknown>;
7
7
  formatDate: (key: string, data: Record<string, any>, format?: string) => Record<string, any>;
8
8
  removeEmpty: (data: Record<string, any>) => Record<string, any>;
9
9
  pageSizeOptions: number[];
10
+ /**
11
+ * 自定义配置参数组合方式.
12
+ * getQuery函数配置默认提供 page,size,orderField,isAsc,...params,...search
13
+ * @param options
14
+ * @returns
15
+ */
10
16
  config(options: ProTableConfigOptions): void;
11
17
  };
12
18
  export default ProTable;
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["classNames", "styles", "table", "locale", "dataKey", "totalKey", "manual", "nostyle", "request", "columns", "form", "alert", "toolbar", "pageSizeOptions", "pagination", "loadingDelay", "scroll"],
4
- _excluded2 = ["title", "extra", "right", "formItem", "items", "reset", "dataForm", "handleValues", "onResetBefore"];
3
+ var _excluded = ["classNames", "styles", "table", "locale", "dataKey", "totalKey", "nostyle", "request", "columns", "form", "alert", "toolbar", "pagination", "scroll"],
4
+ _excluded2 = ["title", "extra", "right", "items", "reset", "dataForm", "handleValues", "onResetBefore"];
5
5
  import { useShallow } from "zustand/react/shallow";
6
6
  import { useEffect, useMemo } from "react";
7
7
  import { Table, Form, Button, Space } from "antd";
@@ -29,8 +29,9 @@ var defaultStyles = {
29
29
  marginBottom: 15
30
30
  }
31
31
  };
32
+ var DEFAULT_PAGE_SIZE_OPTIONS = [10, 20, 50, 100];
32
33
  var ProTable = function ProTable(props) {
33
- var _classNames$root, _classNames$form, _classNames$table;
34
+ var _pagination$showQuick, _pagination$showSizeC, _pagination$hideOnSin, _pagination$pageSizeO, _pagination$showTotal, _classNames$root, _classNames$form, _classNames$table;
34
35
  var _props$classNames = props.classNames,
35
36
  classNames = _props$classNames === void 0 ? defaultClassNames : _props$classNames,
36
37
  _props$styles = props.styles,
@@ -41,8 +42,6 @@ var ProTable = function ProTable(props) {
41
42
  dataKey = _props$dataKey === void 0 ? "data" : _props$dataKey,
42
43
  _props$totalKey = props.totalKey,
43
44
  totalKey = _props$totalKey === void 0 ? "total" : _props$totalKey,
44
- _props$manual = props.manual,
45
- manual = _props$manual === void 0 ? false : _props$manual,
46
45
  nostyle = props.nostyle,
47
46
  _props$request = props.request,
48
47
  request = _props$request === void 0 ? {} : _props$request,
@@ -52,24 +51,25 @@ var ProTable = function ProTable(props) {
52
51
  alert = props.alert,
53
52
  _props$toolbar = props.toolbar,
54
53
  toolbar = _props$toolbar === void 0 ? null : _props$toolbar,
55
- _props$pageSizeOption = props.pageSizeOptions,
56
- pageSizeOptions = _props$pageSizeOption === void 0 ? [10, 20, 50, 100] : _props$pageSizeOption,
57
54
  pagination = props.pagination,
58
- _props$loadingDelay = props.loadingDelay,
59
- loadingDelay = _props$loadingDelay === void 0 ? 300 : _props$loadingDelay,
60
55
  scroll = props.scroll,
61
56
  prop = _objectWithoutProperties(props, _excluded);
57
+ (_pagination$showQuick = pagination.showQuickJumper) !== null && _pagination$showQuick !== void 0 ? _pagination$showQuick : pagination.showQuickJumper = true;
58
+ (_pagination$showSizeC = pagination.showSizeChanger) !== null && _pagination$showSizeC !== void 0 ? _pagination$showSizeC : pagination.showSizeChanger = true;
59
+ (_pagination$hideOnSin = pagination.hideOnSinglePage) !== null && _pagination$hideOnSin !== void 0 ? _pagination$hideOnSin : pagination.hideOnSinglePage = false;
60
+ (_pagination$pageSizeO = pagination.pageSizeOptions) !== null && _pagination$pageSizeO !== void 0 ? _pagination$pageSizeO : pagination.pageSizeOptions = ProTable.pageSizeOptions;
61
+ (_pagination$showTotal = pagination.showTotal) !== null && _pagination$showTotal !== void 0 ? _pagination$showTotal : pagination.showTotal = function (total) {
62
+ return "\u5171 ".concat(total, " \u6761\u8BB0\u5F55");
63
+ };
62
64
  var formTitle = form.title,
63
65
  formExtra = form.extra,
64
66
  formRight = form.right,
65
- formItem = form.formItem,
66
- items = form.items,
67
+ formItems = form.items,
67
68
  formReset = form.reset,
68
69
  dataForm = form.dataForm,
69
70
  formHandleValues = form.handleValues,
70
71
  formOnResetBefore = form.onResetBefore,
71
72
  otherFormProps = _objectWithoutProperties(form, _excluded2);
72
- var formItems = formItem || items;
73
73
  var _table$useStore = table.useStore(useShallow(function (state) {
74
74
  return {
75
75
  data: state.data,
@@ -108,8 +108,7 @@ var ProTable = function ProTable(props) {
108
108
  setState({
109
109
  data: data
110
110
  });
111
- },
112
- loadingDelay: loadingDelay
111
+ }
113
112
  }),
114
113
  loading = _useFetch.loading;
115
114
  var _useMemo = useMemo(function () {
@@ -134,8 +133,9 @@ var ProTable = function ProTable(props) {
134
133
  }
135
134
  };
136
135
  var onReset = function onReset() {
136
+ var _ref, _pagination$pageSizeO2;
137
137
  setState({
138
- size: 10,
138
+ size: (_ref = pagination === null || pagination === void 0 || (_pagination$pageSizeO2 = pagination.pageSizeOptions) === null || _pagination$pageSizeO2 === void 0 ? void 0 : _pagination$pageSizeO2[0]) !== null && _ref !== void 0 ? _ref : ProTable.pageSizeOptions[0],
139
139
  sorter: {}
140
140
  });
141
141
  if (formItems) {
@@ -155,7 +155,7 @@ var ProTable = function ProTable(props) {
155
155
  };
156
156
  }
157
157
  useEffect(function () {
158
- if (manual) return;
158
+ if (request.manual) return;
159
159
  if (formItems) {
160
160
  table.form.submit();
161
161
  } else {
@@ -197,18 +197,11 @@ var ProTable = function ProTable(props) {
197
197
  onChange: function onChange(p, _, sorter) {
198
198
  return tableChange(p, sorter);
199
199
  },
200
- pagination: {
200
+ pagination: _objectSpread({
201
201
  current: page,
202
202
  pageSize: size,
203
- showQuickJumper: pagination ? pagination.showQuickJumper : true,
204
- showSizeChanger: pagination ? pagination.showSizeChanger : true,
205
- hideOnSinglePage: pagination ? pagination.hideOnSinglePage : false,
206
- pageSizeOptions: pageSizeOptions,
207
- total: total,
208
- showTotal: function showTotal(total) {
209
- return "\u5171 ".concat(total, " \u6761\u8BB0\u5F55");
210
- }
211
- },
203
+ total: total
204
+ }, pagination),
212
205
  dataSource: dataSource
213
206
  }, prop));
214
207
  };
@@ -269,8 +262,14 @@ ProTable.getQuery = function (options) {
269
262
  };
270
263
  ProTable.formatDate = formatDate;
271
264
  ProTable.removeEmpty = removeEmpty;
272
- ProTable.pageSizeOptions = [10, 20, 50, 100];
273
- //自定义配置参数组合方式. 默认提供 page,size,orderField,isAsc,...urlParams,...search
265
+ ProTable.pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS;
266
+
267
+ /**
268
+ * 自定义配置参数组合方式.
269
+ * getQuery函数配置默认提供 page,size,orderField,isAsc,...params,...search
270
+ * @param options
271
+ * @returns
272
+ */
274
273
  ProTable.config = function (options) {
275
274
  if (!options || !isObject(options)) return;
276
275
  if (options.getQuery) {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import type { FormInstance, TableColumnType, TableProps, FormProps } from "antd";
2
+ import type { FormInstance, TableColumnType, TableProps, FormProps, PaginationProps } from "../../../node_modules/antd";
3
3
  import type { HttpMethod } from "../../fetch";
4
- import type { UseBoundStore, StoreApi } from "zustand";
4
+ import type { UseBoundStore, StoreApi } from "../../../node_modules/zustand";
5
5
  import type { GetQueryProps } from "../../utils/table";
6
6
  type RecordType = Record<string, any>;
7
7
  interface SorterType {
@@ -27,17 +27,16 @@ export interface TableInstance<TData = any> {
27
27
  reset: () => void;
28
28
  sortOrder: (key: string) => any;
29
29
  update: () => void;
30
+ resetStore: () => void;
30
31
  form?: FormInstance;
31
32
  }
32
33
  interface FormOptions extends Omit<FormProps, "form" | "title"> {
33
34
  title?: React.ReactNode;
34
- /** @deprecated 此属性已废弃,请使用新的formItem属性代替 */
35
35
  items?: React.ReactNode | React.ReactNode[];
36
- formItem?: React.ReactNode | React.ReactNode[];
37
36
  extra?: React.ReactNode;
37
+ reset?: boolean;
38
38
  right?: React.ReactNode;
39
39
  handleValues?: (values: Record<string, any>) => any;
40
- reset?: boolean;
41
40
  onResetBefore?: () => void | boolean;
42
41
  dataForm?: FormProps;
43
42
  }
@@ -55,7 +54,10 @@ export interface ProTableProps<Tdata = any> extends Omit<TableProps<Tdata>, "col
55
54
  };
56
55
  request?: {
57
56
  url?: string;
57
+ /** 手动调用发送 table.run */
58
+ manual?: boolean;
58
59
  method?: HttpMethod;
60
+ /** 请求额外参数 */
59
61
  params?: RecordType;
60
62
  onBefore?: () => any;
61
63
  onSuccess?: (data: Tdata) => any;
@@ -64,18 +66,12 @@ export interface ProTableProps<Tdata = any> extends Omit<TableProps<Tdata>, "col
64
66
  locale?: Record<string, any>;
65
67
  dataKey?: string;
66
68
  totalKey?: string;
67
- manual?: boolean;
68
69
  nostyle?: boolean;
69
70
  columns: ((data: Tdata) => TableColumnType<unknown>[]) | TableColumnType<unknown>[];
70
71
  form?: FormOptions;
71
72
  alert?: React.ReactNode | ((data: Tdata) => React.ReactNode);
72
73
  toolbar?: React.ReactNode;
73
- pageSizeOptions?: number[];
74
- pagination?: {
75
- showQuickJumper?: boolean;
76
- showSizeChanger?: boolean;
77
- hideOnSinglePage?: boolean;
78
- };
74
+ pagination?: PaginationProps;
79
75
  loadingDelay?: number;
80
76
  }
81
77
  export interface UseTableProps {
@@ -91,6 +87,7 @@ export interface TableRef {
91
87
  refresh: () => void;
92
88
  reset: () => void;
93
89
  sortOrder: (key: string) => "ascend" | "descend" | null;
90
+ resetStore: () => void;
94
91
  update: () => void;
95
92
  }
96
93
  export interface ProTableConfigOptions {