@jswork/antd-components 1.0.150 → 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.150",
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:06:05
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 }
@@ -70,10 +76,10 @@ export type AcTableProps = TableProps & {
70
76
  */
71
77
  onPageChange?: (page: number, size: number) => void;
72
78
  /**
73
- * When destroy success.
79
+ * When destroy complete.
74
80
  * @param model
75
81
  */
76
- onDestroySuccess?: (model: any) => void;
82
+ onDestroyComplete?: (model: any) => void;
77
83
  /**
78
84
  * Default page.
79
85
  */
@@ -153,6 +159,10 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
153
159
  this.defaultFetcher = fetcher || nx.createFetcher(resourceId, { dataPath, totalPath });
154
160
  }
155
161
 
162
+ private toQueryString(params?: Record<string, any>) {
163
+ return params ? `?${new URLSearchParams(params).toString()}` : '';
164
+ }
165
+
156
166
  async componentDidMount() {
157
167
  const { current, pageSize } = this.state;
158
168
  this.harmonyEvents = ReactHarmonyEvents.create(this);
@@ -165,14 +175,15 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
165
175
  this.sync.cancel();
166
176
  }
167
177
 
168
- fetchData = async (page: number, size: number) => {
178
+ fetchData = async (page: number, size: number, extraParams?: Record<string, any>) => {
169
179
  const abortController = new AbortController();
170
180
  const { params } = this.props;
171
181
  const { current, pageSize } = this.state;
182
+ const lastParams = { current, pageSize, ...params, ...extraParams };
172
183
  this.setState({ isLoading: true });
173
- this.sync.schedule({ page: current, size: pageSize, ...params });
184
+ this.sync.schedule({ page: current, size: pageSize, ...lastParams });
174
185
  try {
175
- const result = await this.defaultFetcher({ current: page, pageSize: size, params });
186
+ const result = await this.defaultFetcher({ current: page, pageSize: size, params: lastParams });
176
187
  if (!abortController.signal.aborted) {
177
188
  this.setState({
178
189
  dataSource: result.data || [],
@@ -194,24 +205,33 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
194
205
  };
195
206
 
196
207
  /* ----- public eventBus methods start ----- */
208
+ /**
209
+ * Refresh data use current state.
210
+ */
197
211
  public refetch = async () => {
198
212
  const { current, pageSize } = this.state;
199
213
  await this.fetchData(current, pageSize);
200
214
  };
201
215
 
216
+ /**
217
+ * Reset to default state, and fetch data.
218
+ */
202
219
  public reset = async () => {
203
- const { defaultCurrent, defaultPageSize } = this.props;
220
+ const { defaultCurrent, defaultPageSize, paramsReset } = this.props;
204
221
  this.setState(
205
222
  {
206
223
  current: defaultCurrent,
207
224
  pageSize: defaultPageSize,
208
225
  },
209
226
  () => {
210
- void this.fetchData(defaultCurrent!, defaultPageSize!);
227
+ void this.fetchData(defaultCurrent!, defaultPageSize!, paramsReset);
211
228
  },
212
229
  );
213
230
  };
214
231
 
232
+ /**
233
+ * CURD(local): optimisticUpdate data before data fetch.
234
+ */
215
235
  public draft = async (payload: Record<string, any>) => {
216
236
  const { rowKey } = this.props;
217
237
  const id = payload[rowKey as string];
@@ -226,26 +246,35 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
226
246
  }
227
247
  };
228
248
 
249
+ /**
250
+ * CURD(action): Delete data from backend.
251
+ */
229
252
  public destroy = (item) => {
230
- const { name, onDestroySuccess } = this.props;
253
+ const { name, onDestroyComplete } = this.props;
231
254
  this.setState({ isLoading: true });
232
255
  nx.$api[`${name}_destroy`](item)
233
256
  .then(this.refetch)
234
257
  .finally(() => {
235
- onDestroySuccess?.(item);
258
+ onDestroyComplete?.(item);
236
259
  this.setState({ isLoading: false });
237
260
  });
238
261
  };
239
262
 
263
+ /**
264
+ * CURD(page): Redirect to add page.
265
+ */
240
266
  public add = () => {
241
267
  const { module, paramsAdd } = this.props;
242
- const qs = paramsAdd ? `?${new URLSearchParams(paramsAdd).toString()}` : '';
268
+ const qs = this.toQueryString(paramsAdd);
243
269
  nx.$nav?.(`/${module}/${this.routerKey}/add${qs}`);
244
270
  };
245
271
 
272
+ /**
273
+ * CURD(page): Redirect to edit page.
274
+ */
246
275
  public edit = (item: any) => {
247
276
  const { module, rowKey, paramsEdit } = this.props;
248
- const qs = paramsEdit ? `?${new URLSearchParams(paramsEdit).toString()}` : '';
277
+ const qs = this.toQueryString(paramsEdit);
249
278
  nx.$nav?.(`/${module}/${this.routerKey}/${item[rowKey as string]}/edit${qs}`);
250
279
  };
251
280