@jswork/antd-components 1.0.151 → 1.0.153

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.153",
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:43:01
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,14 @@ 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, overrideParams?: Record<string, any>) => {
173
179
  const abortController = new AbortController();
174
180
  const { params } = this.props;
175
- const { current, pageSize } = this.state;
181
+ const lastParams = { ...params, ...overrideParams };
176
182
  this.setState({ isLoading: true });
177
- this.sync.schedule({ page: current, size: pageSize, ...params });
183
+ this.sync.schedule({ page, size, ...lastParams });
178
184
  try {
179
- const result = await this.defaultFetcher({ current: page, pageSize: size, params });
185
+ const result = await this.defaultFetcher({ current: page, pageSize: size, params: lastParams });
180
186
  if (!abortController.signal.aborted) {
181
187
  this.setState({
182
188
  dataSource: result.data || [],
@@ -198,24 +204,33 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
198
204
  };
199
205
 
200
206
  /* ----- public eventBus methods start ----- */
207
+ /**
208
+ * Refresh data use current state.
209
+ */
201
210
  public refetch = async () => {
202
211
  const { current, pageSize } = this.state;
203
212
  await this.fetchData(current, pageSize);
204
213
  };
205
214
 
215
+ /**
216
+ * Reset to default state, and fetch data.
217
+ */
206
218
  public reset = async () => {
207
- const { defaultCurrent, defaultPageSize } = this.props;
219
+ const { defaultCurrent, defaultPageSize, paramsReset } = this.props;
208
220
  this.setState(
209
221
  {
210
222
  current: defaultCurrent,
211
223
  pageSize: defaultPageSize,
212
224
  },
213
225
  () => {
214
- void this.fetchData(defaultCurrent!, defaultPageSize!);
226
+ void this.fetchData(defaultCurrent!, defaultPageSize!, paramsReset);
215
227
  },
216
228
  );
217
229
  };
218
230
 
231
+ /**
232
+ * CURD(local): optimisticUpdate data before data fetch.
233
+ */
219
234
  public draft = async (payload: Record<string, any>) => {
220
235
  const { rowKey } = this.props;
221
236
  const id = payload[rowKey as string];
@@ -230,6 +245,9 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
230
245
  }
231
246
  };
232
247
 
248
+ /**
249
+ * CURD(action): Delete data from backend.
250
+ */
233
251
  public destroy = (item) => {
234
252
  const { name, onDestroyComplete } = this.props;
235
253
  this.setState({ isLoading: true });
@@ -241,12 +259,18 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
241
259
  });
242
260
  };
243
261
 
262
+ /**
263
+ * CURD(page): Redirect to add page.
264
+ */
244
265
  public add = () => {
245
266
  const { module, paramsAdd } = this.props;
246
267
  const qs = this.toQueryString(paramsAdd);
247
268
  nx.$nav?.(`/${module}/${this.routerKey}/add${qs}`);
248
269
  };
249
270
 
271
+ /**
272
+ * CURD(page): Redirect to edit page.
273
+ */
250
274
  public edit = (item: any) => {
251
275
  const { module, rowKey, paramsEdit } = this.props;
252
276
  const qs = this.toQueryString(paramsEdit);
@@ -275,6 +299,7 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
275
299
  params,
276
300
  paramsAdd,
277
301
  paramsEdit,
302
+ paramsReset,
278
303
  fetcher,
279
304
  dataPath,
280
305
  totalPath,