@jswork/antd-components 1.0.151 → 1.0.152

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jswork/antd-components",
3
- "version": "1.0.151",
3
+ "version": "1.0.152",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.esm.js",
6
6
  "types": "dist/main.d.ts",
package/src/lib/table.tsx CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: aric 1290657123@qq.com
3
3
  * @Date: 2025-10-03 07:11:26
4
4
  * @LastEditors: aric 1290657123@qq.com
5
- * @LastEditTime: 2025-10-26 19:11:01
5
+ * @LastEditTime: 2025-10-26 19:35:27
6
6
  *
7
7
  *
8
8
  * 路由风格: /{module}/{name} eg: /admin/staff-roles
@@ -54,6 +54,12 @@ export type AcTableProps = TableProps & {
54
54
  * `paramsEdit` will merge with `paramsAdd` when redirect to edit page.
55
55
  */
56
56
  paramsEdit?: Record<string, any>;
57
+
58
+ /**
59
+ * The extra params when reset.
60
+ * `paramsReset` will merge with `params` when reset.
61
+ */
62
+ paramsReset?: Record<string, any>;
57
63
  /**
58
64
  * Custom get standard data.
59
65
  * @param params { current: number; pageSize: number }
@@ -169,14 +175,15 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
169
175
  this.sync.cancel();
170
176
  }
171
177
 
172
- fetchData = async (page: number, size: number) => {
178
+ fetchData = async (page: number, size: number, extraParams?: Record<string, any>) => {
173
179
  const abortController = new AbortController();
174
180
  const { params } = this.props;
175
181
  const { current, pageSize } = this.state;
182
+ const lastParams = { current, pageSize, ...params, ...extraParams };
176
183
  this.setState({ isLoading: true });
177
- this.sync.schedule({ page: current, size: pageSize, ...params });
184
+ this.sync.schedule({ page: current, size: pageSize, ...lastParams });
178
185
  try {
179
- const result = await this.defaultFetcher({ current: page, pageSize: size, params });
186
+ const result = await this.defaultFetcher({ current: page, pageSize: size, params: lastParams });
180
187
  if (!abortController.signal.aborted) {
181
188
  this.setState({
182
189
  dataSource: result.data || [],
@@ -198,24 +205,33 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
198
205
  };
199
206
 
200
207
  /* ----- public eventBus methods start ----- */
208
+ /**
209
+ * Refresh data use current state.
210
+ */
201
211
  public refetch = async () => {
202
212
  const { current, pageSize } = this.state;
203
213
  await this.fetchData(current, pageSize);
204
214
  };
205
215
 
216
+ /**
217
+ * Reset to default state, and fetch data.
218
+ */
206
219
  public reset = async () => {
207
- const { defaultCurrent, defaultPageSize } = this.props;
220
+ const { defaultCurrent, defaultPageSize, paramsReset } = this.props;
208
221
  this.setState(
209
222
  {
210
223
  current: defaultCurrent,
211
224
  pageSize: defaultPageSize,
212
225
  },
213
226
  () => {
214
- void this.fetchData(defaultCurrent!, defaultPageSize!);
227
+ void this.fetchData(defaultCurrent!, defaultPageSize!, paramsReset);
215
228
  },
216
229
  );
217
230
  };
218
231
 
232
+ /**
233
+ * CURD(local): optimisticUpdate data before data fetch.
234
+ */
219
235
  public draft = async (payload: Record<string, any>) => {
220
236
  const { rowKey } = this.props;
221
237
  const id = payload[rowKey as string];
@@ -230,6 +246,9 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
230
246
  }
231
247
  };
232
248
 
249
+ /**
250
+ * CURD(action): Delete data from backend.
251
+ */
233
252
  public destroy = (item) => {
234
253
  const { name, onDestroyComplete } = this.props;
235
254
  this.setState({ isLoading: true });
@@ -241,12 +260,18 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
241
260
  });
242
261
  };
243
262
 
263
+ /**
264
+ * CURD(page): Redirect to add page.
265
+ */
244
266
  public add = () => {
245
267
  const { module, paramsAdd } = this.props;
246
268
  const qs = this.toQueryString(paramsAdd);
247
269
  nx.$nav?.(`/${module}/${this.routerKey}/add${qs}`);
248
270
  };
249
271
 
272
+ /**
273
+ * CURD(page): Redirect to edit page.
274
+ */
250
275
  public edit = (item: any) => {
251
276
  const { module, rowKey, paramsEdit } = this.props;
252
277
  const qs = this.toQueryString(paramsEdit);