@jswork/antd-components 1.0.185 → 1.0.186

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.185",
3
+ "version": "1.0.186",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.esm.js",
6
6
  "types": "dist/main.d.ts",
@@ -2,7 +2,7 @@
2
2
  * @Author: aric.zheng 1290657123@qq.com
3
3
  * @Date: 2025-10-29 14:09:01
4
4
  * @LastEditors: aric.zheng 1290657123@qq.com
5
- * @LastEditTime: 2025-10-29 14:54:35
5
+ * @LastEditTime: 2025-10-29 15:08:25
6
6
  */
7
7
  import ReactAntStatusSwitch from '@jswork/react-ant-status-switch';
8
8
  import React, { FC } from 'react';
@@ -20,16 +20,16 @@ export type AcTableStatusSwitcherProps = ReactAntStatusSwitchProps & {
20
20
  items: any[];
21
21
  model: any;
22
22
  params?: any;
23
- statusKey?: string;
24
23
  idKey?: string;
25
- statusUpdateApi?: string;
24
+ updateKey?: string;
25
+ updateApi?: string;
26
26
  onSuccess?: () => void;
27
27
  };
28
28
 
29
29
  const defaultProps = {
30
30
  items: [],
31
31
  idKey: 'id',
32
- statusKey: 'status',
32
+ updateKey: 'status',
33
33
  };
34
34
 
35
35
  export const AcTableStatusSwitcher: FC<AcTableStatusSwitcherProps> = (props) => {
@@ -37,20 +37,20 @@ export const AcTableStatusSwitcher: FC<AcTableStatusSwitcherProps> = (props) =>
37
37
  name,
38
38
  items,
39
39
  model,
40
- statusKey,
40
+ updateKey,
41
41
  idKey,
42
- statusUpdateApi,
42
+ updateApi,
43
43
  params,
44
44
  onSuccess,
45
45
  ...rest
46
46
  } = { ...defaultProps, ...props };
47
- const _apiPath = statusUpdateApi || `${name}_update`;
47
+ const _apiPath = updateApi || `${name}_update`;
48
48
  const _onSuccess = onSuccess || (() => nx.$event.emit(`${name}:refetch`));
49
- const _currentStatus = nx.get(model, statusKey!);
49
+ const _currentStatus = nx.get(model, updateKey!);
50
50
  const handleStatusChange = (e) => {
51
51
  const id = nx.get(model, idKey!);
52
- const status = e.target.value;
53
- const payload = { id, [statusKey!]: status, ...params };
52
+ const { value } = e.target;
53
+ const payload = { id, [updateKey!]: value, ...params };
54
54
  nx.$event.emit(`${name}:draft`, { ...model, ...payload });
55
55
  nx.$api[_apiPath](payload).then(_onSuccess);
56
56
  };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @Author: aric.zheng 1290657123@qq.com
3
+ * @Date: 2025-10-29 14:09:01
4
+ * @LastEditors: aric.zheng 1290657123@qq.com
5
+ * @LastEditTime: 2025-10-29 15:08:59
6
+ */
7
+ import React, { FC } from 'react';
8
+ import nx from '@jswork/next';
9
+ import { Switch, SwitchProps } from 'antd';
10
+
11
+ declare global {
12
+ interface NxStatic {
13
+ $api: Record<string, any>;
14
+ }
15
+ }
16
+
17
+ export type AcTableToggleSwitcherProps = SwitchProps & {
18
+ name: string;
19
+ model: any;
20
+ updateKey: string;
21
+ params?: any;
22
+ idKey?: string;
23
+ updateApi?: string;
24
+ onSuccess?: () => void;
25
+ };
26
+
27
+ const defaultProps = {
28
+ items: [],
29
+ idKey: 'id',
30
+ };
31
+
32
+ export const AcTableToggleSwitcher: FC<AcTableToggleSwitcherProps> = (props) => {
33
+ const {
34
+ name,
35
+ items,
36
+ model,
37
+ updateKey,
38
+ idKey,
39
+ updateApi,
40
+ params,
41
+ onSuccess,
42
+ ...rest
43
+ } = { ...defaultProps, ...props };
44
+ const _apiPath = updateApi || `${name}_update`;
45
+ const _onSuccess = onSuccess || (() => nx.$event.emit(`${name}:refetch`));
46
+ const _currentValue = nx.get(model, updateKey);
47
+ const handleStatusChange = (e) => {
48
+ const id = nx.get(model, idKey!);
49
+ const { value } = e.target;
50
+ const payload = { id, [updateKey]: value, ...params };
51
+ nx.$event.emit(`${name}:draft`, { ...model, ...payload });
52
+ nx.$api[_apiPath](payload).then(_onSuccess);
53
+ };
54
+
55
+ return (
56
+ <Switch
57
+ defaultChecked={_currentValue}
58
+ onChange={handleStatusChange}
59
+ {...rest}
60
+ />
61
+ );
62
+ };
package/src/main.ts CHANGED
@@ -84,6 +84,8 @@ import { AcTableExtraSearch } from './lib/table-extra-search';
84
84
  import type { AcTableExtraSearchProps } from './lib/table-extra-search';
85
85
  import { AcTableStatusSwitcher } from './lib/table-status-switcher';
86
86
  import type { AcTableStatusSwitcherProps } from './lib/table-status-switcher';
87
+ import { AcTableToggleSwitcher } from './lib/table-toggle-switcher';
88
+ import type { AcTableToggleSwitcherProps } from './lib/table-toggle-switcher';
87
89
 
88
90
  export * from './lib/button';
89
91
 
@@ -177,6 +179,7 @@ export {
177
179
  FormActions,
178
180
  AcTableExtraSearch,
179
181
  AcTableStatusSwitcher,
182
+ AcTableToggleSwitcher,
180
183
 
181
184
  // ---- commands ----
182
185
  useTableCommand,
@@ -217,6 +220,7 @@ export {
217
220
  FormActionsProps,
218
221
  AcTableExtraSearchProps,
219
222
  AcTableStatusSwitcherProps,
223
+ AcTableToggleSwitcherProps,
220
224
 
221
225
  // ---- widgets ----
222
226
  initWidgets,