@fe-free/core 3.0.18 → 3.0.19

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 3.0.19
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: pro form list
8
+ - @fe-free/tool@3.0.19
9
+
3
10
  ## 3.0.18
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "3.0.18",
3
+ "version": "3.0.19",
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.18"
44
+ "@fe-free/tool": "3.0.19"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -170,6 +170,7 @@ export const ProFormListTextComponent: Story = {
170
170
  render: () => (
171
171
  <ProFormBase>
172
172
  <ProFormListText name="listText" />
173
+ <ProFormListText name="listText_isValueLabel" fieldProps={{ isValueLabel: true }} />
173
174
  </ProFormBase>
174
175
  ),
175
176
  };
@@ -178,7 +179,12 @@ export const ProFormListNumberComponent: Story = {
178
179
  render: () => (
179
180
  <ProFormBase>
180
181
  <ProFormListNumber name="listNumber" label="listNumber" />
182
+ <ProFormListNumber name="listNumber_isValueLabel" fieldProps={{ isValueLabel: true }} />
181
183
  <ProFormListNumber name="listInteger" label="listInteger" fieldProps={{ precision: 0 }} />
184
+ <ProFormListNumber
185
+ name="listInteger_isValueLabel"
186
+ fieldProps={{ isValueLabel: true, precision: 0 }}
187
+ />
182
188
  </ProFormBase>
183
189
  ),
184
190
  };
@@ -14,8 +14,18 @@ interface ListTextProps {
14
14
 
15
15
  function ListText(props: ListTextProps) {
16
16
  const { isValueLabel, placeholder } = props;
17
+
17
18
  return (
18
- <ProFormListHelper value={props.value} onChange={props.onChange} getAdd={() => ''}>
19
+ <ProFormListHelper
20
+ value={props.value}
21
+ onChange={props.onChange}
22
+ getAdd={() => {
23
+ if (isValueLabel) {
24
+ return { value: '', label: '' };
25
+ }
26
+ return '';
27
+ }}
28
+ >
19
29
  {({ item, onItemChange }) => {
20
30
  // @ts-ignore
21
31
  const value = isValueLabel ? item.value : item;
@@ -48,7 +58,16 @@ interface ListNumberProps {
48
58
  function ListNumber(props: ListNumberProps) {
49
59
  const { isValueLabel, placeholder, precision } = props;
50
60
  return (
51
- <ProFormListHelper value={props.value} onChange={props.onChange} getAdd={() => 0}>
61
+ <ProFormListHelper
62
+ value={props.value}
63
+ onChange={props.onChange}
64
+ getAdd={() => {
65
+ if (isValueLabel) {
66
+ return { value: 0, label: '0' };
67
+ }
68
+ return 0;
69
+ }}
70
+ >
52
71
  {({ item, onItemChange }) => {
53
72
  // @ts-ignore
54
73
  const value = isValueLabel ? item.value : item;
@@ -87,11 +106,9 @@ function ListBoolean(props: ListBooleanProps) {
87
106
  );
88
107
  }
89
108
 
90
- function ProFormListBase(props) {
109
+ function ProFormListText(props: ProFormItemProps<ListTextProps>) {
91
110
  const { fieldProps, ...rest } = props;
92
111
 
93
- const isValueLabel = fieldProps?.isValueLabel;
94
-
95
112
  return (
96
113
  <ProForm.Item
97
114
  {...rest}
@@ -101,17 +118,17 @@ function ProFormListBase(props) {
101
118
  // { required: true },
102
119
  {
103
120
  validator: async (_, value) => {
104
- if (isValueLabel) {
105
- if (value?.some((item) => item.value === undefined)) {
106
- return Promise.reject('每个选项都不能为空');
121
+ if (fieldProps?.isValueLabel) {
122
+ if (value?.some((item) => item.value === undefined || item.value === '')) {
123
+ return Promise.reject('存在空选项');
107
124
  }
108
125
  // 不能有重复的 value
109
126
  if (uniqBy(value, 'value').length !== value.length) {
110
127
  return Promise.reject('不能有重复');
111
128
  }
112
129
  } else {
113
- if (value?.some((item) => item === undefined)) {
114
- return Promise.reject('每个选项都不能为空');
130
+ if (value?.some((item) => item === undefined || item === '')) {
131
+ return Promise.reject('存在空选项');
115
132
  }
116
133
  // 不能有重复的 value
117
134
  if (uniq(value).length !== value.length) {
@@ -123,18 +140,8 @@ function ProFormListBase(props) {
123
140
  },
124
141
  ]}
125
142
  >
126
- {props.children}
127
- </ProForm.Item>
128
- );
129
- }
130
-
131
- function ProFormListText(props: ProFormItemProps<ListTextProps>) {
132
- const { fieldProps, ...rest } = props;
133
-
134
- return (
135
- <ProFormListBase {...rest}>
136
143
  <ListText {...fieldProps} />
137
- </ProFormListBase>
144
+ </ProForm.Item>
138
145
  );
139
146
  }
140
147
 
@@ -142,18 +149,47 @@ function ProFormListNumber(props: ProFormItemProps<ListNumberProps>) {
142
149
  const { fieldProps, ...rest } = props;
143
150
 
144
151
  return (
145
- <ProFormListBase {...rest}>
152
+ <ProForm.Item
153
+ {...rest}
154
+ required={props.required ?? true}
155
+ rules={[
156
+ ...(props.rules || []),
157
+ // { required: true },
158
+ {
159
+ validator: async (_, value) => {
160
+ if (fieldProps?.isValueLabel) {
161
+ if (value?.some((item) => item.value === undefined || item.value === null)) {
162
+ return Promise.reject('存在空选项');
163
+ }
164
+ // 不能有重复的 value
165
+ if (uniqBy(value, 'value').length !== value.length) {
166
+ return Promise.reject('不能有重复');
167
+ }
168
+ } else {
169
+ if (value?.some((item) => item === undefined || item === null)) {
170
+ return Promise.reject('存在空选项');
171
+ }
172
+ // 不能有重复的 value
173
+ if (uniq(value).length !== value.length) {
174
+ return Promise.reject('不能有重复');
175
+ }
176
+ }
177
+ return Promise.resolve();
178
+ },
179
+ },
180
+ ]}
181
+ >
146
182
  <ListNumber {...fieldProps} />
147
- </ProFormListBase>
183
+ </ProForm.Item>
148
184
  );
149
185
  }
150
186
 
151
187
  function ProFormListBoolean(props: ProFormItemProps<ListBooleanProps>) {
152
188
  const { fieldProps, ...rest } = props;
153
189
  return (
154
- <ProFormListBase {...rest}>
190
+ <ProForm.Item {...rest} required={props.required ?? true}>
155
191
  <ListBoolean {...fieldProps} />
156
- </ProFormListBase>
192
+ </ProForm.Item>
157
193
  );
158
194
  }
159
195