@fe-free/core 3.0.2 → 3.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/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/form/form.stories.tsx +40 -0
- package/src/form/index.tsx +4 -1
- package/src/form/pro_form_switch.tsx +117 -0
- package/src/index.ts +3 -0
- package/src/tailwindcss.stories.tsx +30 -30
- package/src/theme.ts +26 -26
- package/src/value_type_map/index.tsx +12 -0
- package/src/value_type_map/switch.tsx +31 -0
- package/src/value_type_map/value_type_map.stories.tsx +16 -0
- package/src/form/pro_form_switch_number.tsx +0 -38
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"safe-stable-stringify": "^2.5.0",
|
|
42
42
|
"vanilla-jsoneditor": "^0.23.1",
|
|
43
43
|
"zustand": "^4.5.4",
|
|
44
|
-
"@fe-free/tool": "3.0.
|
|
44
|
+
"@fe-free/tool": "3.0.3"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@ant-design/pro-components": "2.8.9",
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
ProFormRecord,
|
|
12
12
|
ProFormRecordArray,
|
|
13
13
|
ProFormSwitchNumber,
|
|
14
|
+
ProFormSwitchOptions,
|
|
14
15
|
ProFormUpload,
|
|
15
16
|
ProFormUploadDragger,
|
|
16
17
|
} from '@fe-free/core';
|
|
@@ -127,6 +128,45 @@ export const ProFormSwitchNumberComponent: Story = {
|
|
|
127
128
|
),
|
|
128
129
|
};
|
|
129
130
|
|
|
131
|
+
export const ProFormSwitchOptionsComponent: Story = {
|
|
132
|
+
render: () => (
|
|
133
|
+
<ProFormBase>
|
|
134
|
+
<ProFormSwitchOptions
|
|
135
|
+
name="switchOptions"
|
|
136
|
+
fieldProps={{
|
|
137
|
+
options: [
|
|
138
|
+
{ value: 'NO', label: '否' },
|
|
139
|
+
{ value: 'YES', label: '是' },
|
|
140
|
+
],
|
|
141
|
+
}}
|
|
142
|
+
/>
|
|
143
|
+
<ProFormSwitchOptions
|
|
144
|
+
name="switchOptionsLabel"
|
|
145
|
+
fieldProps={{
|
|
146
|
+
enableLabel: true,
|
|
147
|
+
options: [
|
|
148
|
+
{ value: 'NO', label: '否' },
|
|
149
|
+
{ value: 'YES', label: '是' },
|
|
150
|
+
],
|
|
151
|
+
}}
|
|
152
|
+
/>
|
|
153
|
+
<ProFormSwitchOptions
|
|
154
|
+
name="switchOptions2"
|
|
155
|
+
fieldProps={{
|
|
156
|
+
options: ['OFF', 'ON'],
|
|
157
|
+
}}
|
|
158
|
+
/>
|
|
159
|
+
<ProFormSwitchOptions
|
|
160
|
+
name="switchOptions2Label"
|
|
161
|
+
fieldProps={{
|
|
162
|
+
enableLabel: true,
|
|
163
|
+
options: ['OFF', 'ON'],
|
|
164
|
+
}}
|
|
165
|
+
/>
|
|
166
|
+
</ProFormBase>
|
|
167
|
+
),
|
|
168
|
+
};
|
|
169
|
+
|
|
130
170
|
export const ProFormListTextComponent: Story = {
|
|
131
171
|
render: () => (
|
|
132
172
|
<ProFormBase>
|
package/src/form/index.tsx
CHANGED
|
@@ -7,9 +7,12 @@ export { ProFormJSON } from './pro_form_json';
|
|
|
7
7
|
export { ProFormRecord, ProFormRecordArray } from './pro_form_record';
|
|
8
8
|
export {
|
|
9
9
|
ProFormSwitchNumber,
|
|
10
|
+
ProFormSwitchOptions,
|
|
10
11
|
SwitchNumber,
|
|
12
|
+
SwitchOptions,
|
|
11
13
|
type SwitchNumberProps,
|
|
12
|
-
|
|
14
|
+
type SwitchOptionsProps,
|
|
15
|
+
} from './pro_form_switch';
|
|
13
16
|
export {
|
|
14
17
|
ProFormImageUpload,
|
|
15
18
|
ProFormImageUploadDragger,
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ProFormItemProps } from '@ant-design/pro-components';
|
|
2
|
+
import { ProForm } from '@ant-design/pro-components';
|
|
3
|
+
import type { SwitchProps } from 'antd';
|
|
4
|
+
import { Switch } from 'antd';
|
|
5
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
interface SwitchNumberProps extends Omit<SwitchProps, 'value' | 'onChange'> {
|
|
8
|
+
value: number;
|
|
9
|
+
onChange?: (
|
|
10
|
+
value: number,
|
|
11
|
+
event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>,
|
|
12
|
+
) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function SwitchNumber(props: SwitchNumberProps) {
|
|
16
|
+
return (
|
|
17
|
+
<Switch
|
|
18
|
+
{...props}
|
|
19
|
+
value={props.value ? true : false}
|
|
20
|
+
onChange={(checked, event) => {
|
|
21
|
+
return props.onChange?.(checked ? 1 : 0, event);
|
|
22
|
+
}}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function ProFormSwitchNumber(props: ProFormItemProps<SwitchNumberProps>) {
|
|
28
|
+
const { fieldProps, ...rest } = props;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ProForm.Item {...rest}>
|
|
32
|
+
<SwitchNumber {...(fieldProps as SwitchNumberProps)} />
|
|
33
|
+
</ProForm.Item>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface SwitchOptionsProps extends Omit<SwitchProps, 'value' | 'onChange'> {
|
|
38
|
+
value: string;
|
|
39
|
+
onChange?: (
|
|
40
|
+
value: string,
|
|
41
|
+
event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>,
|
|
42
|
+
) => void;
|
|
43
|
+
options?:
|
|
44
|
+
| string[]
|
|
45
|
+
| {
|
|
46
|
+
value: string;
|
|
47
|
+
label: string;
|
|
48
|
+
}[];
|
|
49
|
+
enableLabel?: boolean;
|
|
50
|
+
}
|
|
51
|
+
const emptyArray = [];
|
|
52
|
+
function SwitchOptions({
|
|
53
|
+
value,
|
|
54
|
+
onChange,
|
|
55
|
+
options = emptyArray,
|
|
56
|
+
enableLabel,
|
|
57
|
+
...rest
|
|
58
|
+
}: SwitchOptionsProps) {
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (options.length !== 2) {
|
|
61
|
+
console.error('SwitchOptions 必须有 2 个选项');
|
|
62
|
+
}
|
|
63
|
+
}, [options]);
|
|
64
|
+
|
|
65
|
+
const newOptions = useMemo(() => {
|
|
66
|
+
return options.map((item) => {
|
|
67
|
+
if (typeof item === 'string') {
|
|
68
|
+
return {
|
|
69
|
+
value: item,
|
|
70
|
+
label: item,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
value: item.value,
|
|
75
|
+
label: item.label,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}, [options]);
|
|
79
|
+
|
|
80
|
+
const newValue = useMemo(() => {
|
|
81
|
+
// 1 true 其他 false
|
|
82
|
+
return newOptions.findIndex((item) => item.value === value) === 1 ? true : false;
|
|
83
|
+
}, [newOptions, value]);
|
|
84
|
+
|
|
85
|
+
const handleChange = useCallback(
|
|
86
|
+
(
|
|
87
|
+
checked: boolean,
|
|
88
|
+
event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>,
|
|
89
|
+
) => {
|
|
90
|
+
onChange?.(checked ? newOptions[1].value : newOptions[0].value, event);
|
|
91
|
+
},
|
|
92
|
+
[newOptions, onChange],
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<Switch
|
|
97
|
+
checkedChildren={enableLabel ? newOptions[1].label : undefined}
|
|
98
|
+
unCheckedChildren={enableLabel ? newOptions[0].label : undefined}
|
|
99
|
+
{...rest}
|
|
100
|
+
value={newValue}
|
|
101
|
+
onChange={handleChange}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function ProFormSwitchOptions(props: ProFormItemProps<SwitchOptionsProps>) {
|
|
107
|
+
const { fieldProps, ...rest } = props;
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<ProForm.Item {...rest}>
|
|
111
|
+
<SwitchOptions {...(fieldProps as SwitchOptionsProps)} />
|
|
112
|
+
</ProForm.Item>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { ProFormSwitchNumber, ProFormSwitchOptions, SwitchNumber, SwitchOptions };
|
|
117
|
+
export type { SwitchNumberProps, SwitchOptionsProps };
|
package/src/index.ts
CHANGED
|
@@ -37,8 +37,11 @@ export {
|
|
|
37
37
|
ProFormRecord,
|
|
38
38
|
ProFormRecordArray,
|
|
39
39
|
ProFormSwitchNumber,
|
|
40
|
+
ProFormSwitchOptions,
|
|
40
41
|
ProFormUpload,
|
|
41
42
|
ProFormUploadDragger,
|
|
43
|
+
SwitchNumber,
|
|
44
|
+
SwitchOptions,
|
|
42
45
|
proFormSelectSearchProps,
|
|
43
46
|
} from './form';
|
|
44
47
|
export { RequestError, initErrorHandle } from './global/error';
|
|
@@ -10,56 +10,56 @@ export const Default = () => {
|
|
|
10
10
|
<h1>tailwindcss</h1>
|
|
11
11
|
<h2>textColor</h2>
|
|
12
12
|
<div>
|
|
13
|
-
<div className="text-01">text-01
|
|
14
|
-
<div className="text-02">text-02
|
|
15
|
-
<div className="text-03">text-03
|
|
16
|
-
<div className="text-04">text-04</div>
|
|
13
|
+
<div className="p-1 text-01">text-01 主要</div>
|
|
14
|
+
<div className="p-1 text-02">text-02 次要</div>
|
|
15
|
+
<div className="p-1 text-03">text-03 描述</div>
|
|
16
|
+
<div className="p-1 text-04">text-04 placeholder</div>
|
|
17
17
|
</div>
|
|
18
18
|
<h2>borderColor</h2>
|
|
19
|
-
<div className="space-y-2">
|
|
20
|
-
<div className="border border-solid border-01">border-01
|
|
21
|
-
<div className="border border-solid border-02">border-02
|
|
22
|
-
<div className="border border-solid border-03">border-03</div>
|
|
19
|
+
<div className="space-y-2 p-1">
|
|
20
|
+
<div className="border border-solid border-01 p-1">border-01 主要</div>
|
|
21
|
+
<div className="border border-solid border-02 p-1">border-02 表单</div>
|
|
22
|
+
<div className="border border-solid border-03 p-1">border-03</div>
|
|
23
23
|
</div>
|
|
24
24
|
<h2>backgroundColor</h2>
|
|
25
25
|
<div>
|
|
26
|
-
<div className="bg-01">bg-01
|
|
27
|
-
<div className="bg-02">bg-02</div>
|
|
28
|
-
<div className="bg-03">bg-03</div>
|
|
29
|
-
<div className="bg-04">bg-04</div>
|
|
26
|
+
<div className="bg-01 p-1">bg-01 主要(对应设计稿 bg005)</div>
|
|
27
|
+
<div className="bg-02 p-1">bg-02 hover(对应设计稿 bg01)</div>
|
|
28
|
+
<div className="bg-03 p-1">bg-03 (对应设计稿 bg02)</div>
|
|
29
|
+
<div className="bg-04 p-1">bg-04 disabled(对应设计稿 bg03)</div>
|
|
30
30
|
</div>
|
|
31
31
|
<h2>colors</h2>
|
|
32
32
|
<div>
|
|
33
|
-
<div className="bg-primary">bg-primary
|
|
33
|
+
<div className="bg-primary p-1">bg-primary 主题色</div>
|
|
34
34
|
</div>
|
|
35
35
|
<h2>colors - themeColor</h2>
|
|
36
36
|
<div>
|
|
37
|
-
<div className="bg-theme09">theme09</div>
|
|
38
|
-
<div className="bg-theme08">theme08
|
|
39
|
-
<div className="bg-theme05">theme05
|
|
40
|
-
<div className="bg-theme03">theme03
|
|
41
|
-
<div className="bg-theme02">theme02</div>
|
|
37
|
+
<div className="bg-theme09 p-1">theme09 加深 hover</div>
|
|
38
|
+
<div className="bg-theme08 p-1">theme08 主要</div>
|
|
39
|
+
<div className="bg-theme05 p-1">theme05 次要</div>
|
|
40
|
+
<div className="bg-theme03 p-1">theme03 背景</div>
|
|
41
|
+
<div className="bg-theme02 p-1">theme02 </div>
|
|
42
42
|
</div>
|
|
43
43
|
<h2>colors - redColor</h2>
|
|
44
44
|
<div>
|
|
45
|
-
<div className="bg-red09">red09</div>
|
|
46
|
-
<div className="bg-red08">red08
|
|
47
|
-
<div className="bg-red05">red05
|
|
48
|
-
<div className="bg-red03">red03
|
|
45
|
+
<div className="bg-red09 p-1">red09 加深 hover</div>
|
|
46
|
+
<div className="bg-red08 p-1">red08 主要</div>
|
|
47
|
+
<div className="bg-red05 p-1">red05 次要</div>
|
|
48
|
+
<div className="bg-red03 p-1">red03 背景</div>
|
|
49
49
|
</div>
|
|
50
50
|
<h2>colors - greenColor</h2>
|
|
51
51
|
<div>
|
|
52
|
-
<div className="bg-green09">green09</div>
|
|
53
|
-
<div className="bg-green08">green08
|
|
54
|
-
<div className="bg-green05">green05
|
|
55
|
-
<div className="bg-green03">green03
|
|
52
|
+
<div className="bg-green09 p-1">green09 加深 hover</div>
|
|
53
|
+
<div className="bg-green08 p-1">green08 主要</div>
|
|
54
|
+
<div className="bg-green05 p-1">green05 次要</div>
|
|
55
|
+
<div className="bg-green03 p-1">green03 背景</div>
|
|
56
56
|
</div>
|
|
57
57
|
<h2>colors - yellowColor</h2>
|
|
58
58
|
<div>
|
|
59
|
-
<div className="bg-yellow09">yellow09</div>
|
|
60
|
-
<div className="bg-yellow08">yellow08
|
|
61
|
-
<div className="bg-yellow05">yellow05
|
|
62
|
-
<div className="bg-yellow03">yellow03
|
|
59
|
+
<div className="bg-yellow09 p-1">yellow09 加深 hover</div>
|
|
60
|
+
<div className="bg-yellow08 p-1">yellow08 主要</div>
|
|
61
|
+
<div className="bg-yellow05 p-1">yellow05 次要</div>
|
|
62
|
+
<div className="bg-yellow03 p-1">yellow03 背景</div>
|
|
63
63
|
</div>
|
|
64
64
|
</div>
|
|
65
65
|
);
|
package/src/theme.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
const themeVariables = {
|
|
2
2
|
color: {
|
|
3
|
-
primary: '#0374e9',
|
|
3
|
+
primary: '#0374e9', // 主题色
|
|
4
4
|
|
|
5
5
|
// 目前是主题蓝
|
|
6
|
-
theme09: '#0368d2',
|
|
7
|
-
theme08: '#0374e9',
|
|
8
|
-
theme05: '#a2cbf7',
|
|
9
|
-
theme03: '#e6f1fd',
|
|
6
|
+
theme09: '#0368d2', // 加深 hover
|
|
7
|
+
theme08: '#0374e9', // 主要
|
|
8
|
+
theme05: '#a2cbf7', // 次要
|
|
9
|
+
theme03: '#e6f1fd', // 背景
|
|
10
10
|
theme02: '#f0f7fe',
|
|
11
11
|
|
|
12
|
-
red09: '#e64547',
|
|
13
|
-
red08: '#ff4d4f',
|
|
14
|
-
red05: '#ffb8b9',
|
|
15
|
-
red03: '#ffeded',
|
|
12
|
+
red09: '#e64547', // 加深 hover
|
|
13
|
+
red08: '#ff4d4f', // 主要
|
|
14
|
+
red05: '#ffb8b9', // 次要
|
|
15
|
+
red03: '#ffeded', // 背景
|
|
16
16
|
|
|
17
|
-
green09: '#01a468',
|
|
18
|
-
green08: '#01b673',
|
|
19
|
-
green05: '#9be5c8',
|
|
20
|
-
green03: '#ddf9ec',
|
|
17
|
+
green09: '#01a468', // 加深 hover
|
|
18
|
+
green08: '#01b673', // 主要
|
|
19
|
+
green05: '#9be5c8', // 次要
|
|
20
|
+
green03: '#ddf9ec', // 背景
|
|
21
21
|
|
|
22
|
-
yellow09: '#bf7a05',
|
|
23
|
-
yellow08: '#faad14',
|
|
24
|
-
yellow05: '#eecf9b',
|
|
25
|
-
yellow03: '#f6e7cd',
|
|
22
|
+
yellow09: '#bf7a05', // 加深 hover
|
|
23
|
+
yellow08: '#faad14', // 主要
|
|
24
|
+
yellow05: '#eecf9b', // 次要
|
|
25
|
+
yellow03: '#f6e7cd', // 背景
|
|
26
26
|
},
|
|
27
27
|
textColor: {
|
|
28
|
-
'01': '#15191e',
|
|
29
|
-
'02': '#444444',
|
|
30
|
-
'03': '#777777',
|
|
31
|
-
'04': '#94999f',
|
|
28
|
+
'01': '#15191e', // 主要
|
|
29
|
+
'02': '#444444', // 次要
|
|
30
|
+
'03': '#777777', // 描述
|
|
31
|
+
'04': '#94999f', // placeholder
|
|
32
32
|
},
|
|
33
33
|
borderColor: {
|
|
34
|
-
'01': '#e2e7f0',
|
|
35
|
-
'02': '#d5dde9',
|
|
34
|
+
'01': '#e2e7f0', // 主要
|
|
35
|
+
'02': '#d5dde9', // 表单
|
|
36
36
|
'03': '#c0c7d2',
|
|
37
37
|
},
|
|
38
38
|
backgroundColor: {
|
|
39
|
-
'01': '#f1f3f5',
|
|
40
|
-
'02': '#ececec',
|
|
41
|
-
'03': '#d9d9d9',
|
|
39
|
+
'01': '#f1f3f5', // 主要
|
|
40
|
+
'02': '#ececec', // 加深 hover
|
|
41
|
+
'03': '#d9d9d9', // disabled
|
|
42
42
|
'04': '#c0c0c0',
|
|
43
43
|
},
|
|
44
44
|
} as const;
|
|
@@ -2,6 +2,7 @@ import type { ProRenderFieldPropsType } from '@ant-design/pro-components';
|
|
|
2
2
|
import { dateRender } from './date';
|
|
3
3
|
import { jsonRender } from './json';
|
|
4
4
|
import { jsonModalRender } from './json_modal';
|
|
5
|
+
import { switchNumberRender, switchOptionsRender } from './switch';
|
|
5
6
|
|
|
6
7
|
enum CustomValueTypeEnum {
|
|
7
8
|
/** 渲染时间 + 搜索日期范围 */
|
|
@@ -12,6 +13,9 @@ enum CustomValueTypeEnum {
|
|
|
12
13
|
CustomJSON = 'CustomJSON',
|
|
13
14
|
/** JSON Modal */
|
|
14
15
|
CustomJSONModal = 'CustomJSONModal',
|
|
16
|
+
/** 渲染开关 */
|
|
17
|
+
CustomSwitchNumber = 'CustomSwitchNumber',
|
|
18
|
+
CustomSwitchOptions = 'CustomSwitchOptions',
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
const customValueTypeMap: Record<string, ProRenderFieldPropsType> = {
|
|
@@ -31,6 +35,14 @@ const customValueTypeMap: Record<string, ProRenderFieldPropsType> = {
|
|
|
31
35
|
render: jsonModalRender.render,
|
|
32
36
|
renderFormItem: jsonModalRender.renderFormItem,
|
|
33
37
|
},
|
|
38
|
+
[CustomValueTypeEnum.CustomSwitchNumber]: {
|
|
39
|
+
render: switchNumberRender.render,
|
|
40
|
+
renderFormItem: switchNumberRender.renderFormItem,
|
|
41
|
+
},
|
|
42
|
+
[CustomValueTypeEnum.CustomSwitchOptions]: {
|
|
43
|
+
render: switchOptionsRender.render,
|
|
44
|
+
renderFormItem: switchOptionsRender.renderFormItem,
|
|
45
|
+
},
|
|
34
46
|
};
|
|
35
47
|
|
|
36
48
|
export { CustomValueTypeEnum, customValueTypeMap };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProFormSwitchNumber,
|
|
3
|
+
ProFormSwitchOptions,
|
|
4
|
+
SwitchNumber,
|
|
5
|
+
SwitchOptions,
|
|
6
|
+
} from '../form/pro_form_switch';
|
|
7
|
+
|
|
8
|
+
const switchNumberRender = {
|
|
9
|
+
render: (text) => {
|
|
10
|
+
if (text === undefined || text === null) return <div>-</div>;
|
|
11
|
+
|
|
12
|
+
return <SwitchNumber value={text} />;
|
|
13
|
+
},
|
|
14
|
+
renderFormItem: (_, props) => {
|
|
15
|
+
return <ProFormSwitchNumber {...props} />;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const switchOptionsRender = {
|
|
20
|
+
render: (text, props) => {
|
|
21
|
+
console.log('text', text, props.fieldProps);
|
|
22
|
+
if (text === undefined || text === null) return <div>-</div>;
|
|
23
|
+
|
|
24
|
+
return <SwitchOptions value={text} {...props.fieldProps} />;
|
|
25
|
+
},
|
|
26
|
+
renderFormItem: (_, props) => {
|
|
27
|
+
return <ProFormSwitchOptions {...props} />;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { switchNumberRender, switchOptionsRender };
|
|
@@ -25,6 +25,8 @@ async function fakeRequest() {
|
|
|
25
25
|
dateNumber: +dayjs('2024-10-01'),
|
|
26
26
|
seconds: Math.abs(+dayjs('2024-10-01') / 1000),
|
|
27
27
|
jsonText: JSON.stringify({ name: 'hello world hello world hello world' }),
|
|
28
|
+
switchNumber: Math.random() > 0.5 ? 1 : 0,
|
|
29
|
+
switchOptions: Math.random() > 0.5 ? 'ON' : 'OFF',
|
|
28
30
|
}));
|
|
29
31
|
|
|
30
32
|
return Promise.resolve({
|
|
@@ -82,6 +84,20 @@ const Table = () => {
|
|
|
82
84
|
ellipsis: true,
|
|
83
85
|
valueType: CustomValueTypeEnum.CustomJSONModal,
|
|
84
86
|
},
|
|
87
|
+
{
|
|
88
|
+
title: '开关 number',
|
|
89
|
+
dataIndex: 'switchNumber',
|
|
90
|
+
valueType: CustomValueTypeEnum.CustomSwitchNumber,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
title: '开关 options',
|
|
94
|
+
dataIndex: 'switchOptions',
|
|
95
|
+
valueType: CustomValueTypeEnum.CustomSwitchOptions,
|
|
96
|
+
fieldProps: {
|
|
97
|
+
enableLabel: true,
|
|
98
|
+
options: ['OFF', 'ON'],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
85
101
|
];
|
|
86
102
|
|
|
87
103
|
return (
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ProFormItemProps } from '@ant-design/pro-components';
|
|
2
|
-
import { ProForm } from '@ant-design/pro-components';
|
|
3
|
-
import type { SwitchProps } from 'antd';
|
|
4
|
-
import { Switch } from 'antd';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
interface SwitchNumberProps extends Omit<SwitchProps, 'value' | 'onChange'> {
|
|
8
|
-
value: number;
|
|
9
|
-
onChange: (
|
|
10
|
-
value: number,
|
|
11
|
-
event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>,
|
|
12
|
-
) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function SwitchNumber(props: SwitchNumberProps) {
|
|
16
|
-
return (
|
|
17
|
-
<Switch
|
|
18
|
-
{...props}
|
|
19
|
-
value={props.value ? true : false}
|
|
20
|
-
onChange={(checked, event) => {
|
|
21
|
-
return props.onChange(checked ? 1 : 0, event);
|
|
22
|
-
}}
|
|
23
|
-
/>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function ProFormSwitchNumber(props: ProFormItemProps<SwitchNumberProps>) {
|
|
28
|
-
const { fieldProps, ...rest } = props;
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<ProForm.Item {...rest}>
|
|
32
|
-
<SwitchNumber {...(fieldProps as SwitchNumberProps)} />
|
|
33
|
-
</ProForm.Item>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { ProFormSwitchNumber, SwitchNumber };
|
|
38
|
-
export type { SwitchNumberProps };
|