@kne/super-select-plus 0.1.0 → 0.1.2
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/README.md +806 -37
- package/dist/{city-230db4c1.js → city-39702d3a.js} +1 -1
- package/dist/{city-230db4c1.js.map → city-39702d3a.js.map} +1 -1
- package/dist/{function-9db71e91.js → function-871311da.js} +1 -1
- package/dist/{function-9db71e91.js.map → function-871311da.js.map} +1 -1
- package/dist/index.css +32 -32
- package/dist/index.js +643 -237
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +427 -41
- package/dist/index.modern.js.map +1 -1
- package/dist/{industry-2e3bda15.js → industry-f570d549.js} +1 -1
- package/dist/{industry-2e3bda15.js.map → industry-f570d549.js.map} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ npm i --save @kne/super-select-plus
|
|
|
28
28
|
- **单选/多选**:所有组件均支持单选和多选模式
|
|
29
29
|
- **数据缓存**:枚举显示组件内置多层缓存机制,提升性能
|
|
30
30
|
- **自定义渲染**:枚举显示组件支持自定义渲染函数,灵活展示
|
|
31
|
+
- **批量显示**:枚举显示组件支持 `names` 数组,一次转换多个编码为 label
|
|
31
32
|
|
|
32
33
|
### 组件列表
|
|
33
34
|
|
|
@@ -57,14 +58,18 @@ npm i --save @kne/super-select-plus
|
|
|
57
58
|
#### 示例代码
|
|
58
59
|
|
|
59
60
|
- SelectFunction 职能选择器
|
|
60
|
-
-
|
|
61
|
+
- 基于级联选择器的职能选择组件,支持多级职能数据的选择、值回显、搜索、单选/多选等功能
|
|
61
62
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],antd(antd)
|
|
62
63
|
|
|
63
64
|
```jsx
|
|
64
|
-
const { SelectFunction } = _SuperSelectPlus;
|
|
65
|
+
const { SelectFunction, FunctionEnum, enumItemsToSelectValue, enumItemToSelectValue } = _SuperSelectPlus;
|
|
65
66
|
const { Flex, Divider, Tag, Switch } = antd;
|
|
66
67
|
const { useState } = React;
|
|
67
68
|
|
|
69
|
+
// 模拟后端接口返回的职能编码
|
|
70
|
+
const savedFunctionCodes = ['001001001', '001001002', '001001003'];
|
|
71
|
+
const savedFunctionCode = '001001001';
|
|
72
|
+
|
|
68
73
|
// 基础多选示例
|
|
69
74
|
const BasicMultiExample = ({ isPopup }) => {
|
|
70
75
|
const [value, setValue] = useState([]);
|
|
@@ -155,6 +160,137 @@ const PopupModeExample = () => {
|
|
|
155
160
|
);
|
|
156
161
|
};
|
|
157
162
|
|
|
163
|
+
// 值回显 - 仅传 id,组件自动从 options 解析名称
|
|
164
|
+
const ValueEchoByIdExample = ({ isPopup }) => {
|
|
165
|
+
const [value, setValue] = useState(savedFunctionCodes.map((id) => ({ id })));
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<Flex vertical gap={8}>
|
|
169
|
+
<span>值回显(仅编码 {`{ id }`}):</span>
|
|
170
|
+
<Tag color="default">后端编码:{savedFunctionCodes.join('、')}</Tag>
|
|
171
|
+
<SelectFunction
|
|
172
|
+
value={value}
|
|
173
|
+
onChange={setValue}
|
|
174
|
+
isPopup={isPopup}
|
|
175
|
+
placeholder="请选择职能"
|
|
176
|
+
style={{ width: 320 }}
|
|
177
|
+
/>
|
|
178
|
+
</Flex>
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// 值回显 - 仅传编码字符串数组
|
|
183
|
+
const ValueEchoByCodesExample = ({ isPopup }) => {
|
|
184
|
+
const [value, setValue] = useState(savedFunctionCodes);
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<Flex vertical gap={8}>
|
|
188
|
+
<span>值回显(编码字符串数组):</span>
|
|
189
|
+
<Tag color="default">后端编码:{savedFunctionCodes.join('、')}</Tag>
|
|
190
|
+
<SelectFunction
|
|
191
|
+
value={value}
|
|
192
|
+
onChange={setValue}
|
|
193
|
+
isPopup={isPopup}
|
|
194
|
+
placeholder="请选择职能"
|
|
195
|
+
style={{ width: 320 }}
|
|
196
|
+
/>
|
|
197
|
+
</Flex>
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// 值回显 - 单选(对象编码)
|
|
202
|
+
const SingleValueEchoExample = ({ isPopup }) => {
|
|
203
|
+
const [value, setValue] = useState({ id: '001001001' });
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<Flex vertical gap={8}>
|
|
207
|
+
<span>单选值回显({`{ id: '001001001' }`}):</span>
|
|
208
|
+
<SelectFunction
|
|
209
|
+
single
|
|
210
|
+
value={value}
|
|
211
|
+
onChange={setValue}
|
|
212
|
+
isPopup={isPopup}
|
|
213
|
+
placeholder="请选择职能"
|
|
214
|
+
style={{ width: 320 }}
|
|
215
|
+
/>
|
|
216
|
+
</Flex>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// 值回显 - 单选(字符串编码)
|
|
221
|
+
const SingleValueEchoByCodeExample = ({ isPopup }) => {
|
|
222
|
+
const [value, setValue] = useState(savedFunctionCode);
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<Flex vertical gap={8}>
|
|
226
|
+
<span>单选值回显(编码字符串):</span>
|
|
227
|
+
<SelectFunction
|
|
228
|
+
single
|
|
229
|
+
value={value}
|
|
230
|
+
onChange={setValue}
|
|
231
|
+
isPopup={isPopup}
|
|
232
|
+
placeholder="请选择职能"
|
|
233
|
+
style={{ width: 320 }}
|
|
234
|
+
/>
|
|
235
|
+
</Flex>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// 值回显 - 单选(FunctionEnum name)
|
|
240
|
+
const SingleValueEchoWithEnumExample = ({ isPopup }) => {
|
|
241
|
+
const [value, setValue] = useState();
|
|
242
|
+
|
|
243
|
+
return (
|
|
244
|
+
<Flex vertical gap={8}>
|
|
245
|
+
<span>单选值回显(FunctionEnum name):</span>
|
|
246
|
+
<Tag color="default">后端编码:{savedFunctionCode}</Tag>
|
|
247
|
+
<FunctionEnum name={savedFunctionCode}>
|
|
248
|
+
{(item) => {
|
|
249
|
+
const resolved = enumItemToSelectValue(item);
|
|
250
|
+
if (!resolved) return <span>加载中...</span>;
|
|
251
|
+
return (
|
|
252
|
+
<SelectFunction
|
|
253
|
+
single
|
|
254
|
+
value={value ?? resolved}
|
|
255
|
+
onChange={setValue}
|
|
256
|
+
isPopup={isPopup}
|
|
257
|
+
placeholder="请选择职能"
|
|
258
|
+
style={{ width: 320 }}
|
|
259
|
+
/>
|
|
260
|
+
);
|
|
261
|
+
}}
|
|
262
|
+
</FunctionEnum>
|
|
263
|
+
</Flex>
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// 值回显 - 结合 FunctionEnum,仅传编码数组 names={[code, code]}
|
|
268
|
+
const ValueEchoWithEnumExample = ({ isPopup }) => {
|
|
269
|
+
const [value, setValue] = useState();
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<Flex vertical gap={8}>
|
|
273
|
+
<span>值回显(FunctionEnum names):</span>
|
|
274
|
+
<Tag color="default">后端编码:{savedFunctionCodes.join('、')}</Tag>
|
|
275
|
+
<FunctionEnum names={savedFunctionCodes}>
|
|
276
|
+
{(items) => {
|
|
277
|
+
const resolved = enumItemsToSelectValue(items);
|
|
278
|
+
if (!resolved.length) return <span>加载中...</span>;
|
|
279
|
+
return (
|
|
280
|
+
<SelectFunction
|
|
281
|
+
value={value ?? resolved}
|
|
282
|
+
onChange={setValue}
|
|
283
|
+
isPopup={isPopup}
|
|
284
|
+
placeholder="请选择职能"
|
|
285
|
+
style={{ width: 320 }}
|
|
286
|
+
/>
|
|
287
|
+
);
|
|
288
|
+
}}
|
|
289
|
+
</FunctionEnum>
|
|
290
|
+
</Flex>
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
|
|
158
294
|
const BaseExample = () => {
|
|
159
295
|
const [isPopup, setIsPopup] = useState(true);
|
|
160
296
|
|
|
@@ -179,6 +315,20 @@ const BaseExample = () => {
|
|
|
179
315
|
<Divider />
|
|
180
316
|
<MaxLimitExample isPopup={isPopup} />
|
|
181
317
|
<Divider />
|
|
318
|
+
<span style={{ fontWeight: 500 }}>单选值回显</span>
|
|
319
|
+
<SingleValueEchoExample isPopup={isPopup} />
|
|
320
|
+
<Divider />
|
|
321
|
+
<SingleValueEchoByCodeExample isPopup={isPopup} />
|
|
322
|
+
<Divider />
|
|
323
|
+
<SingleValueEchoWithEnumExample isPopup={isPopup} />
|
|
324
|
+
<Divider />
|
|
325
|
+
<span style={{ fontWeight: 500 }}>多选值回显</span>
|
|
326
|
+
<ValueEchoByIdExample isPopup={isPopup} />
|
|
327
|
+
<Divider />
|
|
328
|
+
<ValueEchoByCodesExample isPopup={isPopup} />
|
|
329
|
+
<Divider />
|
|
330
|
+
<ValueEchoWithEnumExample isPopup={isPopup} />
|
|
331
|
+
<Divider />
|
|
182
332
|
<PopupModeExample />
|
|
183
333
|
</Flex>
|
|
184
334
|
);
|
|
@@ -189,14 +339,18 @@ render(<BaseExample />);
|
|
|
189
339
|
```
|
|
190
340
|
|
|
191
341
|
- SelectIndustry 行业选择器
|
|
192
|
-
-
|
|
342
|
+
- 基于级联选择器的行业选择组件,支持多级行业数据的选择、值回显、搜索、单选/多选等功能
|
|
193
343
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],antd(antd)
|
|
194
344
|
|
|
195
345
|
```jsx
|
|
196
|
-
const { SelectIndustry } = _SuperSelectPlus;
|
|
346
|
+
const { SelectIndustry, IndustryEnum, enumItemsToSelectValue, enumItemToSelectValue } = _SuperSelectPlus;
|
|
197
347
|
const { Flex, Divider, Tag, Switch } = antd;
|
|
198
348
|
const { useState } = React;
|
|
199
349
|
|
|
350
|
+
// 模拟后端接口返回的行业编码
|
|
351
|
+
const savedIndustryCodes = ['001', '003', '004'];
|
|
352
|
+
const savedIndustryCode = '001';
|
|
353
|
+
|
|
200
354
|
// 基础多选示例
|
|
201
355
|
const BasicMultiExample = ({ isPopup }) => {
|
|
202
356
|
const [value, setValue] = useState([]);
|
|
@@ -266,6 +420,137 @@ const MaxLimitExample = ({ isPopup }) => {
|
|
|
266
420
|
);
|
|
267
421
|
};
|
|
268
422
|
|
|
423
|
+
// 值回显 - 仅传 id,组件自动从 options 解析名称
|
|
424
|
+
const ValueEchoByIdExample = ({ isPopup }) => {
|
|
425
|
+
const [value, setValue] = useState(savedIndustryCodes.map((id) => ({ id })));
|
|
426
|
+
|
|
427
|
+
return (
|
|
428
|
+
<Flex vertical gap={8}>
|
|
429
|
+
<span>值回显(仅编码 {`{ id }`}):</span>
|
|
430
|
+
<Tag color="default">后端编码:{savedIndustryCodes.join('、')}</Tag>
|
|
431
|
+
<SelectIndustry
|
|
432
|
+
value={value}
|
|
433
|
+
onChange={setValue}
|
|
434
|
+
isPopup={isPopup}
|
|
435
|
+
placeholder="请选择行业"
|
|
436
|
+
style={{ width: 320 }}
|
|
437
|
+
/>
|
|
438
|
+
</Flex>
|
|
439
|
+
);
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// 值回显 - 仅传编码字符串数组
|
|
443
|
+
const ValueEchoByCodesExample = ({ isPopup }) => {
|
|
444
|
+
const [value, setValue] = useState(savedIndustryCodes);
|
|
445
|
+
|
|
446
|
+
return (
|
|
447
|
+
<Flex vertical gap={8}>
|
|
448
|
+
<span>值回显(编码字符串数组):</span>
|
|
449
|
+
<Tag color="default">后端编码:{savedIndustryCodes.join('、')}</Tag>
|
|
450
|
+
<SelectIndustry
|
|
451
|
+
value={value}
|
|
452
|
+
onChange={setValue}
|
|
453
|
+
isPopup={isPopup}
|
|
454
|
+
placeholder="请选择行业"
|
|
455
|
+
style={{ width: 320 }}
|
|
456
|
+
/>
|
|
457
|
+
</Flex>
|
|
458
|
+
);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
// 值回显 - 单选(对象编码)
|
|
462
|
+
const SingleValueEchoExample = ({ isPopup }) => {
|
|
463
|
+
const [value, setValue] = useState({ id: '001' });
|
|
464
|
+
|
|
465
|
+
return (
|
|
466
|
+
<Flex vertical gap={8}>
|
|
467
|
+
<span>单选值回显({`{ id: '001' }`}):</span>
|
|
468
|
+
<SelectIndustry
|
|
469
|
+
single
|
|
470
|
+
value={value}
|
|
471
|
+
onChange={setValue}
|
|
472
|
+
isPopup={isPopup}
|
|
473
|
+
placeholder="请选择行业"
|
|
474
|
+
style={{ width: 320 }}
|
|
475
|
+
/>
|
|
476
|
+
</Flex>
|
|
477
|
+
);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// 值回显 - 单选(字符串编码)
|
|
481
|
+
const SingleValueEchoByCodeExample = ({ isPopup }) => {
|
|
482
|
+
const [value, setValue] = useState(savedIndustryCode);
|
|
483
|
+
|
|
484
|
+
return (
|
|
485
|
+
<Flex vertical gap={8}>
|
|
486
|
+
<span>单选值回显(编码字符串):</span>
|
|
487
|
+
<SelectIndustry
|
|
488
|
+
single
|
|
489
|
+
value={value}
|
|
490
|
+
onChange={setValue}
|
|
491
|
+
isPopup={isPopup}
|
|
492
|
+
placeholder="请选择行业"
|
|
493
|
+
style={{ width: 320 }}
|
|
494
|
+
/>
|
|
495
|
+
</Flex>
|
|
496
|
+
);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// 值回显 - 单选(IndustryEnum name)
|
|
500
|
+
const SingleValueEchoWithEnumExample = ({ isPopup }) => {
|
|
501
|
+
const [value, setValue] = useState();
|
|
502
|
+
|
|
503
|
+
return (
|
|
504
|
+
<Flex vertical gap={8}>
|
|
505
|
+
<span>单选值回显(IndustryEnum name):</span>
|
|
506
|
+
<Tag color="default">后端编码:{savedIndustryCode}</Tag>
|
|
507
|
+
<IndustryEnum name={savedIndustryCode}>
|
|
508
|
+
{(item) => {
|
|
509
|
+
const resolved = enumItemToSelectValue(item);
|
|
510
|
+
if (!resolved) return <span>加载中...</span>;
|
|
511
|
+
return (
|
|
512
|
+
<SelectIndustry
|
|
513
|
+
single
|
|
514
|
+
value={value ?? resolved}
|
|
515
|
+
onChange={setValue}
|
|
516
|
+
isPopup={isPopup}
|
|
517
|
+
placeholder="请选择行业"
|
|
518
|
+
style={{ width: 320 }}
|
|
519
|
+
/>
|
|
520
|
+
);
|
|
521
|
+
}}
|
|
522
|
+
</IndustryEnum>
|
|
523
|
+
</Flex>
|
|
524
|
+
);
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
// 值回显 - 结合 IndustryEnum,仅传编码数组 names={[code, code]}
|
|
528
|
+
const ValueEchoWithEnumExample = ({ isPopup }) => {
|
|
529
|
+
const [value, setValue] = useState();
|
|
530
|
+
|
|
531
|
+
return (
|
|
532
|
+
<Flex vertical gap={8}>
|
|
533
|
+
<span>值回显(IndustryEnum names):</span>
|
|
534
|
+
<Tag color="default">后端编码:{savedIndustryCodes.join('、')}</Tag>
|
|
535
|
+
<IndustryEnum names={savedIndustryCodes}>
|
|
536
|
+
{(items) => {
|
|
537
|
+
const resolved = enumItemsToSelectValue(items);
|
|
538
|
+
if (!resolved.length) return <span>加载中...</span>;
|
|
539
|
+
return (
|
|
540
|
+
<SelectIndustry
|
|
541
|
+
value={value ?? resolved}
|
|
542
|
+
onChange={setValue}
|
|
543
|
+
isPopup={isPopup}
|
|
544
|
+
placeholder="请选择行业"
|
|
545
|
+
style={{ width: 320 }}
|
|
546
|
+
/>
|
|
547
|
+
);
|
|
548
|
+
}}
|
|
549
|
+
</IndustryEnum>
|
|
550
|
+
</Flex>
|
|
551
|
+
);
|
|
552
|
+
};
|
|
553
|
+
|
|
269
554
|
const BaseExample = () => {
|
|
270
555
|
const [isPopup, setIsPopup] = useState(true);
|
|
271
556
|
|
|
@@ -289,6 +574,20 @@ const BaseExample = () => {
|
|
|
289
574
|
<SingleSelectExample isPopup={isPopup} />
|
|
290
575
|
<Divider />
|
|
291
576
|
<MaxLimitExample isPopup={isPopup} />
|
|
577
|
+
<Divider />
|
|
578
|
+
<span style={{ fontWeight: 500 }}>单选值回显</span>
|
|
579
|
+
<SingleValueEchoExample isPopup={isPopup} />
|
|
580
|
+
<Divider />
|
|
581
|
+
<SingleValueEchoByCodeExample isPopup={isPopup} />
|
|
582
|
+
<Divider />
|
|
583
|
+
<SingleValueEchoWithEnumExample isPopup={isPopup} />
|
|
584
|
+
<Divider />
|
|
585
|
+
<span style={{ fontWeight: 500 }}>多选值回显</span>
|
|
586
|
+
<ValueEchoByIdExample isPopup={isPopup} />
|
|
587
|
+
<Divider />
|
|
588
|
+
<ValueEchoByCodesExample isPopup={isPopup} />
|
|
589
|
+
<Divider />
|
|
590
|
+
<ValueEchoWithEnumExample isPopup={isPopup} />
|
|
292
591
|
</Flex>
|
|
293
592
|
);
|
|
294
593
|
};
|
|
@@ -298,14 +597,18 @@ render(<BaseExample />);
|
|
|
298
597
|
```
|
|
299
598
|
|
|
300
599
|
- SelectAddress 城市选择器
|
|
301
|
-
-
|
|
600
|
+
- 城市地址选择组件,支持国内外城市搜索选择、值回显,具备拼音搜索、首字母搜索等功能
|
|
302
601
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],(@kne/current-lib_super-select-plus/dist/index.css),antd(antd)
|
|
303
602
|
|
|
304
603
|
```jsx
|
|
305
|
-
const { SelectAddress } = _SuperSelectPlus;
|
|
604
|
+
const { SelectAddress, AddressEnum, addressEnumToSelectValue, addressEnumToSelectValueSingle } = _SuperSelectPlus;
|
|
306
605
|
const { Flex, Divider, Tag, Switch } = antd;
|
|
307
606
|
const { useState } = React;
|
|
308
607
|
|
|
608
|
+
// 模拟后端接口返回的城市编码
|
|
609
|
+
const savedCityCodes = ['010', '020'];
|
|
610
|
+
const savedCityCode = '010';
|
|
611
|
+
|
|
309
612
|
// 基础多选示例
|
|
310
613
|
const BasicMultiExample = ({ isPopup }) => {
|
|
311
614
|
const [value, setValue] = useState([]);
|
|
@@ -375,6 +678,142 @@ const MaxLimitExample = ({ isPopup }) => {
|
|
|
375
678
|
);
|
|
376
679
|
};
|
|
377
680
|
|
|
681
|
+
// 值回显 - 仅传 value 编码,组件自动解析 label
|
|
682
|
+
const ValueEchoByCodeExample = ({ isPopup }) => {
|
|
683
|
+
const [value, setValue] = useState(savedCityCodes.map((code) => ({ value: code })));
|
|
684
|
+
|
|
685
|
+
return (
|
|
686
|
+
<Flex vertical gap={8}>
|
|
687
|
+
<span>值回显(仅编码 {`{ value }`}):</span>
|
|
688
|
+
<Tag color="default">后端编码:{savedCityCodes.join('、')}</Tag>
|
|
689
|
+
<SelectAddress
|
|
690
|
+
value={value}
|
|
691
|
+
onChange={setValue}
|
|
692
|
+
isPopup={isPopup}
|
|
693
|
+
placeholder="请选择城市"
|
|
694
|
+
style={{ width: 320 }}
|
|
695
|
+
/>
|
|
696
|
+
</Flex>
|
|
697
|
+
);
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
// 值回显 - 完整对象(表单已缓存 label)
|
|
701
|
+
const cachedCityValue = [
|
|
702
|
+
{ value: '010', label: '北京' },
|
|
703
|
+
{ value: '020', label: '上海' }
|
|
704
|
+
];
|
|
705
|
+
|
|
706
|
+
const ValueEchoWithLabelExample = ({ isPopup }) => {
|
|
707
|
+
const [value, setValue] = useState(cachedCityValue);
|
|
708
|
+
|
|
709
|
+
return (
|
|
710
|
+
<Flex vertical gap={8}>
|
|
711
|
+
<span>值回显(含 label):</span>
|
|
712
|
+
<Tag color="default">后端编码:{savedCityCodes.join('、')}</Tag>
|
|
713
|
+
<SelectAddress
|
|
714
|
+
value={value}
|
|
715
|
+
onChange={setValue}
|
|
716
|
+
isPopup={isPopup}
|
|
717
|
+
placeholder="请选择城市"
|
|
718
|
+
style={{ width: 320 }}
|
|
719
|
+
/>
|
|
720
|
+
</Flex>
|
|
721
|
+
);
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
// 值回显 - 结合 AddressEnum,仅传编码数组 names={[code, code]}
|
|
725
|
+
const ValueEchoWithEnumExample = ({ isPopup }) => {
|
|
726
|
+
const [value, setValue] = useState();
|
|
727
|
+
|
|
728
|
+
return (
|
|
729
|
+
<Flex vertical gap={8}>
|
|
730
|
+
<span>值回显(AddressEnum names):</span>
|
|
731
|
+
<Tag color="default">后端编码:{savedCityCodes.join('、')}</Tag>
|
|
732
|
+
<AddressEnum names={savedCityCodes}>
|
|
733
|
+
{(outputs) => {
|
|
734
|
+
const resolved = addressEnumToSelectValue(outputs);
|
|
735
|
+
if (!resolved.length) return <span>加载中...</span>;
|
|
736
|
+
return (
|
|
737
|
+
<SelectAddress
|
|
738
|
+
value={value ?? resolved}
|
|
739
|
+
onChange={setValue}
|
|
740
|
+
isPopup={isPopup}
|
|
741
|
+
placeholder="请选择城市"
|
|
742
|
+
style={{ width: 320 }}
|
|
743
|
+
/>
|
|
744
|
+
);
|
|
745
|
+
}}
|
|
746
|
+
</AddressEnum>
|
|
747
|
+
</Flex>
|
|
748
|
+
);
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// 值回显 - 单选(仅编码)
|
|
752
|
+
const SingleValueEchoExample = ({ isPopup }) => {
|
|
753
|
+
const [value, setValue] = useState({ value: '010' });
|
|
754
|
+
|
|
755
|
+
return (
|
|
756
|
+
<Flex vertical gap={8}>
|
|
757
|
+
<span>单选值回显({`{ value: '010' }`}):</span>
|
|
758
|
+
<SelectAddress
|
|
759
|
+
single
|
|
760
|
+
value={value}
|
|
761
|
+
onChange={setValue}
|
|
762
|
+
isPopup={isPopup}
|
|
763
|
+
placeholder="请选择城市"
|
|
764
|
+
style={{ width: 320 }}
|
|
765
|
+
/>
|
|
766
|
+
</Flex>
|
|
767
|
+
);
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
// 值回显 - 单选(字符串编码)
|
|
771
|
+
const SingleValueEchoByCodeExample = ({ isPopup }) => {
|
|
772
|
+
const [value, setValue] = useState(savedCityCode);
|
|
773
|
+
|
|
774
|
+
return (
|
|
775
|
+
<Flex vertical gap={8}>
|
|
776
|
+
<span>单选值回显(编码字符串):</span>
|
|
777
|
+
<SelectAddress
|
|
778
|
+
single
|
|
779
|
+
value={value}
|
|
780
|
+
onChange={setValue}
|
|
781
|
+
isPopup={isPopup}
|
|
782
|
+
placeholder="请选择城市"
|
|
783
|
+
style={{ width: 320 }}
|
|
784
|
+
/>
|
|
785
|
+
</Flex>
|
|
786
|
+
);
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// 值回显 - 单选(AddressEnum name)
|
|
790
|
+
const SingleValueEchoWithEnumExample = ({ isPopup }) => {
|
|
791
|
+
const [value, setValue] = useState();
|
|
792
|
+
|
|
793
|
+
return (
|
|
794
|
+
<Flex vertical gap={8}>
|
|
795
|
+
<span>单选值回显(AddressEnum name):</span>
|
|
796
|
+
<Tag color="default">后端编码:{savedCityCode}</Tag>
|
|
797
|
+
<AddressEnum name={savedCityCode}>
|
|
798
|
+
{(output) => {
|
|
799
|
+
const resolved = addressEnumToSelectValueSingle(output);
|
|
800
|
+
if (!resolved) return <span>加载中...</span>;
|
|
801
|
+
return (
|
|
802
|
+
<SelectAddress
|
|
803
|
+
single
|
|
804
|
+
value={value ?? resolved}
|
|
805
|
+
onChange={setValue}
|
|
806
|
+
isPopup={isPopup}
|
|
807
|
+
placeholder="请选择城市"
|
|
808
|
+
style={{ width: 320 }}
|
|
809
|
+
/>
|
|
810
|
+
);
|
|
811
|
+
}}
|
|
812
|
+
</AddressEnum>
|
|
813
|
+
</Flex>
|
|
814
|
+
);
|
|
815
|
+
};
|
|
816
|
+
|
|
378
817
|
const BaseExample = () => {
|
|
379
818
|
const [isPopup, setIsPopup] = useState(true);
|
|
380
819
|
|
|
@@ -398,6 +837,20 @@ const BaseExample = () => {
|
|
|
398
837
|
<SingleSelectExample isPopup={isPopup} />
|
|
399
838
|
<Divider />
|
|
400
839
|
<MaxLimitExample isPopup={isPopup} />
|
|
840
|
+
<Divider />
|
|
841
|
+
<span style={{ fontWeight: 500 }}>单选值回显</span>
|
|
842
|
+
<SingleValueEchoExample isPopup={isPopup} />
|
|
843
|
+
<Divider />
|
|
844
|
+
<SingleValueEchoByCodeExample isPopup={isPopup} />
|
|
845
|
+
<Divider />
|
|
846
|
+
<SingleValueEchoWithEnumExample isPopup={isPopup} />
|
|
847
|
+
<Divider />
|
|
848
|
+
<span style={{ fontWeight: 500 }}>多选值回显</span>
|
|
849
|
+
<ValueEchoByCodeExample isPopup={isPopup} />
|
|
850
|
+
<Divider />
|
|
851
|
+
<ValueEchoWithLabelExample isPopup={isPopup} />
|
|
852
|
+
<Divider />
|
|
853
|
+
<ValueEchoWithEnumExample isPopup={isPopup} />
|
|
401
854
|
</Flex>
|
|
402
855
|
);
|
|
403
856
|
};
|
|
@@ -470,8 +923,26 @@ const BaseExample = createWithRemoteLoader({
|
|
|
470
923
|
<div><strong>姓名:</strong>张三</div>
|
|
471
924
|
<div><strong>所在城市:</strong><AddressEnum name="010" /></div>
|
|
472
925
|
<div><strong>期望工作城市:</strong><AddressEnum name="020" /></div>
|
|
926
|
+
<div><strong>可接受城市:</strong><AddressEnum names={['010', '020', '050020']} /></div>
|
|
473
927
|
</div>
|
|
474
928
|
</InfoPage.Part>
|
|
929
|
+
|
|
930
|
+
<InfoPage.Part title="批量显示 names">
|
|
931
|
+
<Flex vertical gap={12}>
|
|
932
|
+
<p>默认渲染:<AddressEnum names={['010', '020', '050020']} /></p>
|
|
933
|
+
<AddressEnum names={['010', '020']}>
|
|
934
|
+
{(outputs, { labels }) => (
|
|
935
|
+
<Flex gap={8} wrap="wrap">
|
|
936
|
+
{labels.map(label => (
|
|
937
|
+
<span key={label} style={{ padding: '4px 8px', background: '#f6ffed', borderRadius: '4px' }}>
|
|
938
|
+
{label}
|
|
939
|
+
</span>
|
|
940
|
+
))}
|
|
941
|
+
</Flex>
|
|
942
|
+
)}
|
|
943
|
+
</AddressEnum>
|
|
944
|
+
</Flex>
|
|
945
|
+
</InfoPage.Part>
|
|
475
946
|
|
|
476
947
|
<InfoPage.Part title="错误处理">
|
|
477
948
|
<p>不存在的城市编码 999999:<AddressEnum name="999999" /></p>
|
|
@@ -486,7 +957,7 @@ render(<BaseExample />);
|
|
|
486
957
|
```
|
|
487
958
|
|
|
488
959
|
- FunctionEnum 职能枚举显示
|
|
489
|
-
-
|
|
960
|
+
- 用于显示职能名称的枚举组件,支持国际化、自定义渲染及 names 批量显示
|
|
490
961
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],antd(antd),remoteLoader(@kne/remote-loader)
|
|
491
962
|
|
|
492
963
|
```jsx
|
|
@@ -555,8 +1026,26 @@ const BaseExample = createWithRemoteLoader({
|
|
|
555
1026
|
<div><strong>姓名:</strong>李四</div>
|
|
556
1027
|
<div><strong>当前职能:</strong><FunctionEnum name="001001001" /></div>
|
|
557
1028
|
<div><strong>期望职能:</strong><FunctionEnum name="001001002" /></div>
|
|
1029
|
+
<div><strong>可胜任职能:</strong><FunctionEnum names={['001001001', '001001002', '001001003']} /></div>
|
|
558
1030
|
</div>
|
|
559
1031
|
</InfoPage.Part>
|
|
1032
|
+
|
|
1033
|
+
<InfoPage.Part title="批量显示 names">
|
|
1034
|
+
<Flex vertical gap={12}>
|
|
1035
|
+
<p>默认渲染:<FunctionEnum names={['001001001', '001001002', '001001003']} /></p>
|
|
1036
|
+
<FunctionEnum names={['001001001', '001001002']}>
|
|
1037
|
+
{(items, { labels }) => (
|
|
1038
|
+
<Flex gap={8} wrap="wrap">
|
|
1039
|
+
{labels.map(label => (
|
|
1040
|
+
<span key={label} style={{ padding: '4px 8px', background: '#e6f7ff', borderRadius: '4px' }}>
|
|
1041
|
+
{label}
|
|
1042
|
+
</span>
|
|
1043
|
+
))}
|
|
1044
|
+
</Flex>
|
|
1045
|
+
)}
|
|
1046
|
+
</FunctionEnum>
|
|
1047
|
+
</Flex>
|
|
1048
|
+
</InfoPage.Part>
|
|
560
1049
|
|
|
561
1050
|
<InfoPage.Part title="国际化支持">
|
|
562
1051
|
<FunctionEnum name="001001003">
|
|
@@ -580,7 +1069,7 @@ render(<BaseExample />);
|
|
|
580
1069
|
```
|
|
581
1070
|
|
|
582
1071
|
- IndustryEnum 行业枚举显示
|
|
583
|
-
-
|
|
1072
|
+
- 用于显示行业名称的枚举组件,支持国际化、自定义渲染及 names 批量显示
|
|
584
1073
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],antd(antd),remoteLoader(@kne/remote-loader)
|
|
585
1074
|
|
|
586
1075
|
```jsx
|
|
@@ -639,15 +1128,27 @@ const BaseExample = createWithRemoteLoader({
|
|
|
639
1128
|
</InfoPage.Part>
|
|
640
1129
|
|
|
641
1130
|
<InfoPage.Part title="行业标签展示">
|
|
642
|
-
<Flex gap={8}>
|
|
643
|
-
<IndustryEnum
|
|
644
|
-
{(
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
1131
|
+
<Flex gap={8} wrap="wrap">
|
|
1132
|
+
<IndustryEnum names={['001', '003', '004']}>
|
|
1133
|
+
{(items, { labels }) => labels.map(label => (
|
|
1134
|
+
<span key={label} style={{ padding: '4px 8px', background: '#e6f7ff', borderRadius: '4px' }}>
|
|
1135
|
+
{label}
|
|
1136
|
+
</span>
|
|
1137
|
+
))}
|
|
648
1138
|
</IndustryEnum>
|
|
649
|
-
|
|
650
|
-
|
|
1139
|
+
</Flex>
|
|
1140
|
+
</InfoPage.Part>
|
|
1141
|
+
|
|
1142
|
+
<InfoPage.Part title="批量显示 names">
|
|
1143
|
+
<Flex vertical gap={12}>
|
|
1144
|
+
<p>默认渲染(逗号分隔):<IndustryEnum names={['001', '003', '004']} /></p>
|
|
1145
|
+
<IndustryEnum names={['001', '004']}>
|
|
1146
|
+
{(items, { labels, locale }) => (
|
|
1147
|
+
<div>
|
|
1148
|
+
<div style={{ marginBottom: 8 }}>当前语言:{locale}</div>
|
|
1149
|
+
<div>{labels.join(' · ')}</div>
|
|
1150
|
+
</div>
|
|
1151
|
+
)}
|
|
651
1152
|
</IndustryEnum>
|
|
652
1153
|
</Flex>
|
|
653
1154
|
</InfoPage.Part>
|
|
@@ -661,7 +1162,7 @@ render(<BaseExample />);
|
|
|
661
1162
|
```
|
|
662
1163
|
|
|
663
1164
|
- EnumDisplay 通用枚举显示
|
|
664
|
-
-
|
|
1165
|
+
- 通用枚举显示组件,支持自定义数据源、国际化、缓存及 names 批量显示
|
|
665
1166
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],antd(antd),remoteLoader(@kne/remote-loader)
|
|
666
1167
|
|
|
667
1168
|
```jsx
|
|
@@ -734,13 +1235,63 @@ const BaseExample = createWithRemoteLoader({
|
|
|
734
1235
|
<div><strong>姓名:</strong>赵六</div>
|
|
735
1236
|
<div><strong>最高学历:</strong><EnumDisplay name="3" type="education" {...educationEnumApi} /></div>
|
|
736
1237
|
<div><strong>第二学历:</strong><EnumDisplay name="2" type="education" {...educationEnumApi} /></div>
|
|
1238
|
+
<div><strong>全部学历:</strong><EnumDisplay names={['3', '2', '1']} type="education" {...educationEnumApi} /></div>
|
|
737
1239
|
</div>
|
|
738
1240
|
</InfoPage.Part>
|
|
1241
|
+
|
|
1242
|
+
<InfoPage.Part title="批量显示 names">
|
|
1243
|
+
<Flex vertical gap={12}>
|
|
1244
|
+
<p>默认渲染(label 数组 toString,逗号分隔):</p>
|
|
1245
|
+
<p>学历编码 ['1', '2', '3']:<EnumDisplay names={['1', '2', '3']} type="education" {...educationEnumApi} /></p>
|
|
1246
|
+
<p>学历编码 ['1', '3']:<EnumDisplay names={['1', '3']} type="education" {...educationEnumApi} /></p>
|
|
1247
|
+
<p>空数组:<EnumDisplay names={[]} type="education" {...educationEnumApi} /></p>
|
|
1248
|
+
</Flex>
|
|
1249
|
+
</InfoPage.Part>
|
|
1250
|
+
|
|
1251
|
+
<InfoPage.Part title="names 自定义渲染">
|
|
1252
|
+
<EnumDisplay names={['1', '2', '3']} type="education" {...educationEnumApi}>
|
|
1253
|
+
{(items, { labels, mapping, locale }) => (
|
|
1254
|
+
<Flex vertical gap={8}>
|
|
1255
|
+
<div>当前语言:{locale}</div>
|
|
1256
|
+
<div>labels:{labels.join(' / ')}</div>
|
|
1257
|
+
<Flex gap={8} wrap="wrap">
|
|
1258
|
+
{items.map((item, index) => item && (
|
|
1259
|
+
<span
|
|
1260
|
+
key={item.code}
|
|
1261
|
+
style={{ padding: '4px 8px', background: '#f0f5ff', borderRadius: '4px' }}
|
|
1262
|
+
>
|
|
1263
|
+
{item.label}
|
|
1264
|
+
{mapping.get(item.code)?.enName && ` (${mapping.get(item.code).enName})`}
|
|
1265
|
+
</span>
|
|
1266
|
+
))}
|
|
1267
|
+
</Flex>
|
|
1268
|
+
</Flex>
|
|
1269
|
+
)}
|
|
1270
|
+
</EnumDisplay>
|
|
1271
|
+
</InfoPage.Part>
|
|
739
1272
|
|
|
740
1273
|
<InfoPage.Part title="错误处理">
|
|
741
|
-
<
|
|
742
|
-
|
|
743
|
-
|
|
1274
|
+
<Flex vertical gap={12}>
|
|
1275
|
+
<p>单个无效编码:</p>
|
|
1276
|
+
<EnumDisplay name="999" type="education" {...educationEnumApi}>
|
|
1277
|
+
{(item) => <span>{item ? item.label : '未知学历'}</span>}
|
|
1278
|
+
</EnumDisplay>
|
|
1279
|
+
<p>批量含无效编码(默认跳过无效项):</p>
|
|
1280
|
+
<EnumDisplay names={['1', '999', '3']} type="education" {...educationEnumApi} />
|
|
1281
|
+
<p>批量含无效编码(自定义处理):</p>
|
|
1282
|
+
<EnumDisplay names={['1', '999', '3']} type="education" {...educationEnumApi}>
|
|
1283
|
+
{(items, { labels }) => (
|
|
1284
|
+
<span>
|
|
1285
|
+
{items.map((item, index) => (
|
|
1286
|
+
<span key={index}>
|
|
1287
|
+
{index > 0 && '、'}
|
|
1288
|
+
{item ? item.label : '未知'}
|
|
1289
|
+
</span>
|
|
1290
|
+
))}
|
|
1291
|
+
</span>
|
|
1292
|
+
)}
|
|
1293
|
+
</EnumDisplay>
|
|
1294
|
+
</Flex>
|
|
744
1295
|
</InfoPage.Part>
|
|
745
1296
|
</InfoPage>
|
|
746
1297
|
</PureGlobal>
|
|
@@ -795,6 +1346,48 @@ render(<BaseExample />);
|
|
|
795
1346
|
}
|
|
796
1347
|
```
|
|
797
1348
|
|
|
1349
|
+
#### 值回显
|
|
1350
|
+
|
|
1351
|
+
`value` 每项需包含 `id`(职能编码)和 `name`(显示名称)。编辑场景下后端通常只返回编码,组件会在 options 加载后自动解析 name:
|
|
1352
|
+
|
|
1353
|
+
```javascript
|
|
1354
|
+
// 方式一:仅传编码,组件加载 options 后自动解析 name
|
|
1355
|
+
const value = ['001001001', '001001002'];
|
|
1356
|
+
// 或对象形式
|
|
1357
|
+
const value = [{ id: '001001001' }, { id: '001001002' }];
|
|
1358
|
+
|
|
1359
|
+
// 方式二:单选回显
|
|
1360
|
+
const singleValue = { id: '001001001' };
|
|
1361
|
+
// 或字符串编码
|
|
1362
|
+
const singleValue = '001001001';
|
|
1363
|
+
|
|
1364
|
+
// 方式三:结合 FunctionEnum name,单选编码回显
|
|
1365
|
+
<FunctionEnum name="001001001">
|
|
1366
|
+
{(item) => (
|
|
1367
|
+
<SelectFunction
|
|
1368
|
+
single
|
|
1369
|
+
value={enumItemToSelectValue(item)}
|
|
1370
|
+
onChange={setValue}
|
|
1371
|
+
/>
|
|
1372
|
+
)}
|
|
1373
|
+
</FunctionEnum>
|
|
1374
|
+
|
|
1375
|
+
// 方式四:结合 FunctionEnum names,多选编码数组回显(推荐)
|
|
1376
|
+
const savedCodes = ['001001001', '001001002'];
|
|
1377
|
+
|
|
1378
|
+
<FunctionEnum names={savedCodes}>
|
|
1379
|
+
{(items) => {
|
|
1380
|
+
const resolved = enumItemsToSelectValue(items);
|
|
1381
|
+
return (
|
|
1382
|
+
<SelectFunction
|
|
1383
|
+
value={value ?? resolved}
|
|
1384
|
+
onChange={setValue}
|
|
1385
|
+
/>
|
|
1386
|
+
);
|
|
1387
|
+
}}
|
|
1388
|
+
</FunctionEnum>
|
|
1389
|
+
```
|
|
1390
|
+
|
|
798
1391
|
---
|
|
799
1392
|
|
|
800
1393
|
### SelectIndustry 行业选择器
|
|
@@ -839,6 +1432,48 @@ render(<BaseExample />);
|
|
|
839
1432
|
}
|
|
840
1433
|
```
|
|
841
1434
|
|
|
1435
|
+
#### 值回显
|
|
1436
|
+
|
|
1437
|
+
`value` 每项需包含 `id`(行业编码)和 `name`(显示名称)。编辑场景下后端通常只返回编码,组件会在 options 加载后自动解析 name:
|
|
1438
|
+
|
|
1439
|
+
```javascript
|
|
1440
|
+
// 方式一:仅传编码,组件加载 options 后自动解析 name
|
|
1441
|
+
const value = ['001', '003'];
|
|
1442
|
+
// 或对象形式
|
|
1443
|
+
const value = [{ id: '001' }, { id: '003' }];
|
|
1444
|
+
|
|
1445
|
+
// 方式二:单选回显
|
|
1446
|
+
const singleValue = { id: '001' };
|
|
1447
|
+
// 或字符串编码
|
|
1448
|
+
const singleValue = '001';
|
|
1449
|
+
|
|
1450
|
+
// 方式三:结合 IndustryEnum name,单选编码回显
|
|
1451
|
+
<IndustryEnum name="001">
|
|
1452
|
+
{(item) => (
|
|
1453
|
+
<SelectIndustry
|
|
1454
|
+
single
|
|
1455
|
+
value={enumItemToSelectValue(item)}
|
|
1456
|
+
onChange={setValue}
|
|
1457
|
+
/>
|
|
1458
|
+
)}
|
|
1459
|
+
</IndustryEnum>
|
|
1460
|
+
|
|
1461
|
+
// 方式四:结合 IndustryEnum names,多选编码数组回显(推荐)
|
|
1462
|
+
const savedCodes = ['001', '003'];
|
|
1463
|
+
|
|
1464
|
+
<IndustryEnum names={savedCodes}>
|
|
1465
|
+
{(items) => {
|
|
1466
|
+
const resolved = enumItemsToSelectValue(items);
|
|
1467
|
+
return (
|
|
1468
|
+
<SelectIndustry
|
|
1469
|
+
value={value ?? resolved}
|
|
1470
|
+
onChange={setValue}
|
|
1471
|
+
/>
|
|
1472
|
+
);
|
|
1473
|
+
}}
|
|
1474
|
+
</IndustryEnum>
|
|
1475
|
+
```
|
|
1476
|
+
|
|
842
1477
|
---
|
|
843
1478
|
|
|
844
1479
|
### SelectAddress 城市选择器
|
|
@@ -894,6 +1529,46 @@ render(<BaseExample />);
|
|
|
894
1529
|
}
|
|
895
1530
|
```
|
|
896
1531
|
|
|
1532
|
+
#### 值回显
|
|
1533
|
+
|
|
1534
|
+
编辑场景下后端通常只返回编码,组件会在数据加载后自动解析 label:
|
|
1535
|
+
|
|
1536
|
+
```javascript
|
|
1537
|
+
// 方式一:仅传编码,组件加载数据后自动解析 label
|
|
1538
|
+
const value = [{ value: '010' }, { value: '020' }];
|
|
1539
|
+
|
|
1540
|
+
// 方式二:单选回显
|
|
1541
|
+
const singleValue = { value: '010' };
|
|
1542
|
+
// 或字符串编码
|
|
1543
|
+
const singleValue = '010';
|
|
1544
|
+
|
|
1545
|
+
// 方式三:结合 AddressEnum name,单选编码回显
|
|
1546
|
+
<AddressEnum name="010">
|
|
1547
|
+
{(output) => (
|
|
1548
|
+
<SelectAddress
|
|
1549
|
+
single
|
|
1550
|
+
value={addressEnumToSelectValueSingle(output)}
|
|
1551
|
+
onChange={setValue}
|
|
1552
|
+
/>
|
|
1553
|
+
)}
|
|
1554
|
+
</AddressEnum>
|
|
1555
|
+
|
|
1556
|
+
// 方式四:结合 AddressEnum names,多选编码数组回显(推荐)
|
|
1557
|
+
const savedCodes = ['010', '020'];
|
|
1558
|
+
|
|
1559
|
+
<AddressEnum names={savedCodes}>
|
|
1560
|
+
{(outputs) => {
|
|
1561
|
+
const resolved = addressEnumToSelectValue(outputs);
|
|
1562
|
+
return (
|
|
1563
|
+
<SelectAddress
|
|
1564
|
+
value={value ?? resolved}
|
|
1565
|
+
onChange={setValue}
|
|
1566
|
+
/>
|
|
1567
|
+
);
|
|
1568
|
+
}}
|
|
1569
|
+
</AddressEnum>
|
|
1570
|
+
```
|
|
1571
|
+
|
|
897
1572
|
---
|
|
898
1573
|
|
|
899
1574
|
### AddressEnum 地址枚举显示组件
|
|
@@ -904,7 +1579,8 @@ render(<BaseExample />);
|
|
|
904
1579
|
|
|
905
1580
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
906
1581
|
|------|------|-------|------|
|
|
907
|
-
| name | string | - |
|
|
1582
|
+
| name | string | - | 城市编码,与 names 二选一 |
|
|
1583
|
+
| names | string[] | - | 城市编码数组,与 name 二选一,默认 label 数组 toString 输出 |
|
|
908
1584
|
| displayParent | boolean | false | 是否显示父级城市名称 |
|
|
909
1585
|
| force | boolean | false | 是否强制刷新缓存 |
|
|
910
1586
|
| children | function | - | 自定义渲染函数 |
|
|
@@ -913,14 +1589,19 @@ render(<BaseExample />);
|
|
|
913
1589
|
#### 自定义渲染函数
|
|
914
1590
|
|
|
915
1591
|
```javascript
|
|
1592
|
+
// 单个编码 name
|
|
916
1593
|
children={({ city, parent }, { displayParent, locale, getLabelForLocal }) => {
|
|
917
1594
|
// city: 城市数据对象
|
|
918
1595
|
// parent: 父级城市数据对象
|
|
919
|
-
// displayParent: 是否显示父级
|
|
920
|
-
// locale: 当前语言环境
|
|
921
|
-
// getLabelForLocal: 获取本地化标签的函数
|
|
922
1596
|
return <span>{getLabelForLocal(city, locale)}</span>;
|
|
923
1597
|
}}
|
|
1598
|
+
|
|
1599
|
+
// 批量编码 names
|
|
1600
|
+
children={(outputs, { labels, locale, getLabelForLocal }) => {
|
|
1601
|
+
// outputs: [{ city, parent }, ...] 数组
|
|
1602
|
+
// labels: 有效项的 label 字符串数组
|
|
1603
|
+
return <span>{labels.join('、')}</span>;
|
|
1604
|
+
}}
|
|
924
1605
|
```
|
|
925
1606
|
|
|
926
1607
|
#### 静态方法
|
|
@@ -936,16 +1617,16 @@ children={({ city, parent }, { displayParent, locale, getLabelForLocal }) => {
|
|
|
936
1617
|
// 基本用法
|
|
937
1618
|
<AddressEnum name="010" />
|
|
938
1619
|
|
|
1620
|
+
// 批量显示
|
|
1621
|
+
<AddressEnum names={['010', '020']} />
|
|
1622
|
+
|
|
939
1623
|
// 显示父级
|
|
940
1624
|
<AddressEnum name="010" displayParent />
|
|
941
1625
|
|
|
942
|
-
//
|
|
943
|
-
<AddressEnum
|
|
944
|
-
{(
|
|
945
|
-
<
|
|
946
|
-
{parent && <span>{getLabelForLocal(parent, locale)} · </span>}
|
|
947
|
-
{getLabelForLocal(city, locale)}
|
|
948
|
-
</div>
|
|
1626
|
+
// 结合 SelectAddress 值回显
|
|
1627
|
+
<AddressEnum names={['010', '020']}>
|
|
1628
|
+
{(outputs) => (
|
|
1629
|
+
<SelectAddress value={addressEnumToSelectValue(outputs)} />
|
|
949
1630
|
)}
|
|
950
1631
|
</AddressEnum>
|
|
951
1632
|
```
|
|
@@ -960,7 +1641,8 @@ children={({ city, parent }, { displayParent, locale, getLabelForLocal }) => {
|
|
|
960
1641
|
|
|
961
1642
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
962
1643
|
|------|------|-------|------|
|
|
963
|
-
| name | string | - |
|
|
1644
|
+
| name | string | - | 职能编码,与 names 二选一 |
|
|
1645
|
+
| names | string[] | - | 职能编码数组,与 name 二选一,默认 label 数组 toString 输出 |
|
|
964
1646
|
| force | boolean | false | 是否强制刷新缓存 |
|
|
965
1647
|
| children | function | - | 自定义渲染函数 |
|
|
966
1648
|
| api | object | - | 自定义 API 配置 |
|
|
@@ -968,12 +1650,21 @@ children={({ city, parent }, { displayParent, locale, getLabelForLocal }) => {
|
|
|
968
1650
|
#### 自定义渲染函数
|
|
969
1651
|
|
|
970
1652
|
```javascript
|
|
971
|
-
|
|
1653
|
+
// 单个编码 name
|
|
1654
|
+
children={(item, { locale, mapping, labels, names }) => {
|
|
972
1655
|
// item: 职能数据对象,包含 label, chName, enName 等
|
|
973
1656
|
// locale: 当前语言环境
|
|
974
1657
|
// mapping: 所有职能数据的 Map 对象
|
|
1658
|
+
// labels: 当前项的 label 数组
|
|
975
1659
|
return <span>{item.label}</span>;
|
|
976
1660
|
}}
|
|
1661
|
+
|
|
1662
|
+
// 批量编码 names
|
|
1663
|
+
children={(items, { locale, mapping, labels, names }) => {
|
|
1664
|
+
// items: 职能数据对象数组,无效编码对应 undefined
|
|
1665
|
+
// labels: 有效项的 label 字符串数组
|
|
1666
|
+
return <span>{labels.join('、')}</span>;
|
|
1667
|
+
}}
|
|
977
1668
|
```
|
|
978
1669
|
|
|
979
1670
|
#### 静态方法
|
|
@@ -989,6 +1680,9 @@ children={(item, { locale, mapping }) => {
|
|
|
989
1680
|
// 基本用法
|
|
990
1681
|
<FunctionEnum name="001001001" />
|
|
991
1682
|
|
|
1683
|
+
// 批量显示
|
|
1684
|
+
<FunctionEnum names={['001001001', '001001002', '001001003']} />
|
|
1685
|
+
|
|
992
1686
|
// 自定义渲染
|
|
993
1687
|
<FunctionEnum name="001001001">
|
|
994
1688
|
{(item, { locale }) => (
|
|
@@ -998,6 +1692,11 @@ children={(item, { locale, mapping }) => {
|
|
|
998
1692
|
</div>
|
|
999
1693
|
)}
|
|
1000
1694
|
</FunctionEnum>
|
|
1695
|
+
|
|
1696
|
+
// 批量自定义渲染
|
|
1697
|
+
<FunctionEnum names={['001001001', '001001002']}>
|
|
1698
|
+
{(items, { labels }) => labels.join(' / ')}
|
|
1699
|
+
</FunctionEnum>
|
|
1001
1700
|
```
|
|
1002
1701
|
|
|
1003
1702
|
---
|
|
@@ -1010,7 +1709,8 @@ children={(item, { locale, mapping }) => {
|
|
|
1010
1709
|
|
|
1011
1710
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
1012
1711
|
|------|------|-------|------|
|
|
1013
|
-
| name | string | - |
|
|
1712
|
+
| name | string | - | 行业编码,与 names 二选一 |
|
|
1713
|
+
| names | string[] | - | 行业编码数组,与 name 二选一,默认 label 数组 toString 输出 |
|
|
1014
1714
|
| force | boolean | false | 是否强制刷新缓存 |
|
|
1015
1715
|
| children | function | - | 自定义渲染函数 |
|
|
1016
1716
|
| api | object | - | 自定义 API 配置 |
|
|
@@ -1018,12 +1718,21 @@ children={(item, { locale, mapping }) => {
|
|
|
1018
1718
|
#### 自定义渲染函数
|
|
1019
1719
|
|
|
1020
1720
|
```javascript
|
|
1021
|
-
|
|
1721
|
+
// 单个编码 name
|
|
1722
|
+
children={(item, { locale, mapping, labels, names }) => {
|
|
1022
1723
|
// item: 行业数据对象,包含 label, chName, enName 等
|
|
1023
1724
|
// locale: 当前语言环境
|
|
1024
1725
|
// mapping: 所有行业数据的 Map 对象
|
|
1726
|
+
// labels: 当前项的 label 数组
|
|
1025
1727
|
return <span>{item.label}</span>;
|
|
1026
1728
|
}}
|
|
1729
|
+
|
|
1730
|
+
// 批量编码 names
|
|
1731
|
+
children={(items, { locale, mapping, labels, names }) => {
|
|
1732
|
+
// items: 行业数据对象数组,无效编码对应 undefined
|
|
1733
|
+
// labels: 有效项的 label 字符串数组
|
|
1734
|
+
return <span>{labels.join('、')}</span>;
|
|
1735
|
+
}}
|
|
1027
1736
|
```
|
|
1028
1737
|
|
|
1029
1738
|
#### 静态方法
|
|
@@ -1039,6 +1748,9 @@ children={(item, { locale, mapping }) => {
|
|
|
1039
1748
|
// 基本用法
|
|
1040
1749
|
<IndustryEnum name="001" />
|
|
1041
1750
|
|
|
1751
|
+
// 批量显示
|
|
1752
|
+
<IndustryEnum names={['001', '003', '004']} />
|
|
1753
|
+
|
|
1042
1754
|
// 自定义渲染
|
|
1043
1755
|
<IndustryEnum name="001">
|
|
1044
1756
|
{(item, { locale }) => (
|
|
@@ -1048,6 +1760,11 @@ children={(item, { locale, mapping }) => {
|
|
|
1048
1760
|
</div>
|
|
1049
1761
|
)}
|
|
1050
1762
|
</IndustryEnum>
|
|
1763
|
+
|
|
1764
|
+
// 批量自定义渲染
|
|
1765
|
+
<IndustryEnum names={['001', '004']}>
|
|
1766
|
+
{(items, { labels }) => labels.join(' · ')}
|
|
1767
|
+
</IndustryEnum>
|
|
1051
1768
|
```
|
|
1052
1769
|
|
|
1053
1770
|
---
|
|
@@ -1060,7 +1777,8 @@ children={(item, { locale, mapping }) => {
|
|
|
1060
1777
|
|
|
1061
1778
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
1062
1779
|
|------|------|-------|------|
|
|
1063
|
-
| name | string | - |
|
|
1780
|
+
| name | string | - | 单个枚举值编码,与 names 二选一 |
|
|
1781
|
+
| names | string[] | - | 多个枚举值编码,与 name 二选一,默认 label 数组 toString 输出 |
|
|
1064
1782
|
| type | string | - | 枚举类型标识 |
|
|
1065
1783
|
| cache | string | 'ENUM_DATA' | 缓存键名 |
|
|
1066
1784
|
| force | boolean | false | 是否强制刷新缓存 |
|
|
@@ -1092,12 +1810,22 @@ api={{
|
|
|
1092
1810
|
#### 自定义渲染函数
|
|
1093
1811
|
|
|
1094
1812
|
```javascript
|
|
1095
|
-
|
|
1813
|
+
// 单个编码 name
|
|
1814
|
+
children={(item, { locale, mapping, labels, names }) => {
|
|
1096
1815
|
// item: 枚举数据对象
|
|
1097
1816
|
// locale: 当前语言环境
|
|
1098
1817
|
// mapping: 所有枚举数据的 Map 对象
|
|
1818
|
+
// labels: 当前项的 label 数组
|
|
1099
1819
|
return <span>{item.label}</span>;
|
|
1100
1820
|
}}
|
|
1821
|
+
|
|
1822
|
+
// 批量编码 names
|
|
1823
|
+
children={(items, { locale, mapping, labels, names }) => {
|
|
1824
|
+
// items: 枚举数据对象数组,无效编码对应 undefined
|
|
1825
|
+
// labels: 有效项的 label 字符串数组
|
|
1826
|
+
// names: 传入的编码数组
|
|
1827
|
+
return <span>{labels.join('、')}</span>;
|
|
1828
|
+
}}
|
|
1101
1829
|
```
|
|
1102
1830
|
|
|
1103
1831
|
#### 使用示例
|
|
@@ -1116,6 +1844,13 @@ children={(item, { locale, mapping }) => {
|
|
|
1116
1844
|
}}
|
|
1117
1845
|
/>
|
|
1118
1846
|
|
|
1847
|
+
// 批量显示
|
|
1848
|
+
<EnumDisplay
|
|
1849
|
+
names={['1', '2', '3']}
|
|
1850
|
+
type="education"
|
|
1851
|
+
api={educationEnumApi}
|
|
1852
|
+
/>
|
|
1853
|
+
|
|
1119
1854
|
// 自定义 getLabel
|
|
1120
1855
|
<EnumDisplay
|
|
1121
1856
|
name="1"
|
|
@@ -1125,6 +1860,40 @@ children={(item, { locale, mapping }) => {
|
|
|
1125
1860
|
return locale === 'en-US' ? item.enName : item.name;
|
|
1126
1861
|
}}
|
|
1127
1862
|
/>
|
|
1863
|
+
|
|
1864
|
+
// 批量自定义渲染
|
|
1865
|
+
<EnumDisplay names={['1', '2', '3']} type="education" api={api}>
|
|
1866
|
+
{(items, { labels }) => labels.join(' / ')}
|
|
1867
|
+
</EnumDisplay>
|
|
1868
|
+
```
|
|
1869
|
+
|
|
1870
|
+
#### 工具函数
|
|
1871
|
+
|
|
1872
|
+
用于将 `names={[code, code]}` 解析结果转为选择器 `value`:
|
|
1873
|
+
|
|
1874
|
+
| 函数 | 说明 |
|
|
1875
|
+
|------|------|
|
|
1876
|
+
| `enumItemsToSelectValue(items, options?)` | 将 FunctionEnum / IndustryEnum 的 items 转为 `{ id, name }[]`,可选 `valueKey` / `labelKey` |
|
|
1877
|
+
| `enumItemToSelectValue(item, options?)` | 单选:将 FunctionEnum / IndustryEnum 的 item 转为 `{ id, name }` |
|
|
1878
|
+
| `addressEnumToSelectValue(outputs)` | 将 AddressEnum 解析结果转为 SelectAddress 的 `{ value, label }[]`(支持 name 单值或 names 数组) |
|
|
1879
|
+
| `addressEnumToSelectValueSingle(output)` | 单选:将 AddressEnum name 解析结果转为 `{ value, label }` |
|
|
1880
|
+
|
|
1881
|
+
```javascript
|
|
1882
|
+
import { enumItemsToSelectValue, addressEnumToSelectValue } from '@kne/super-select-plus';
|
|
1883
|
+
|
|
1884
|
+
// 职能/行业选择器回显
|
|
1885
|
+
<FunctionEnum names={['001001001', '001001002']}>
|
|
1886
|
+
{(items) => (
|
|
1887
|
+
<SelectFunction value={enumItemsToSelectValue(items)} />
|
|
1888
|
+
)}
|
|
1889
|
+
</FunctionEnum>
|
|
1890
|
+
|
|
1891
|
+
// 城市选择器回显
|
|
1892
|
+
<AddressEnum names={['010', '020']}>
|
|
1893
|
+
{(outputs) => (
|
|
1894
|
+
<SelectAddress value={addressEnumToSelectValue(outputs)} />
|
|
1895
|
+
)}
|
|
1896
|
+
</AddressEnum>
|
|
1128
1897
|
```
|
|
1129
1898
|
|
|
1130
1899
|
---
|