@kne/super-select-plus 0.1.1 → 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 +646 -17
- package/dist/index.js +374 -34
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +335 -16
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,14 +58,18 @@ npm i --save @kne/super-select-plus
|
|
|
58
58
|
#### 示例代码
|
|
59
59
|
|
|
60
60
|
- SelectFunction 职能选择器
|
|
61
|
-
-
|
|
61
|
+
- 基于级联选择器的职能选择组件,支持多级职能数据的选择、值回显、搜索、单选/多选等功能
|
|
62
62
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],antd(antd)
|
|
63
63
|
|
|
64
64
|
```jsx
|
|
65
|
-
const { SelectFunction } = _SuperSelectPlus;
|
|
65
|
+
const { SelectFunction, FunctionEnum, enumItemsToSelectValue, enumItemToSelectValue } = _SuperSelectPlus;
|
|
66
66
|
const { Flex, Divider, Tag, Switch } = antd;
|
|
67
67
|
const { useState } = React;
|
|
68
68
|
|
|
69
|
+
// 模拟后端接口返回的职能编码
|
|
70
|
+
const savedFunctionCodes = ['001001001', '001001002', '001001003'];
|
|
71
|
+
const savedFunctionCode = '001001001';
|
|
72
|
+
|
|
69
73
|
// 基础多选示例
|
|
70
74
|
const BasicMultiExample = ({ isPopup }) => {
|
|
71
75
|
const [value, setValue] = useState([]);
|
|
@@ -156,6 +160,137 @@ const PopupModeExample = () => {
|
|
|
156
160
|
);
|
|
157
161
|
};
|
|
158
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
|
+
|
|
159
294
|
const BaseExample = () => {
|
|
160
295
|
const [isPopup, setIsPopup] = useState(true);
|
|
161
296
|
|
|
@@ -180,6 +315,20 @@ const BaseExample = () => {
|
|
|
180
315
|
<Divider />
|
|
181
316
|
<MaxLimitExample isPopup={isPopup} />
|
|
182
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 />
|
|
183
332
|
<PopupModeExample />
|
|
184
333
|
</Flex>
|
|
185
334
|
);
|
|
@@ -190,14 +339,18 @@ render(<BaseExample />);
|
|
|
190
339
|
```
|
|
191
340
|
|
|
192
341
|
- SelectIndustry 行业选择器
|
|
193
|
-
-
|
|
342
|
+
- 基于级联选择器的行业选择组件,支持多级行业数据的选择、值回显、搜索、单选/多选等功能
|
|
194
343
|
- _SuperSelectPlus(@kne/current-lib_super-select-plus)[import * as _SuperSelectPlus from "@kne/super-select-plus"],antd(antd)
|
|
195
344
|
|
|
196
345
|
```jsx
|
|
197
|
-
const { SelectIndustry } = _SuperSelectPlus;
|
|
346
|
+
const { SelectIndustry, IndustryEnum, enumItemsToSelectValue, enumItemToSelectValue } = _SuperSelectPlus;
|
|
198
347
|
const { Flex, Divider, Tag, Switch } = antd;
|
|
199
348
|
const { useState } = React;
|
|
200
349
|
|
|
350
|
+
// 模拟后端接口返回的行业编码
|
|
351
|
+
const savedIndustryCodes = ['001', '003', '004'];
|
|
352
|
+
const savedIndustryCode = '001';
|
|
353
|
+
|
|
201
354
|
// 基础多选示例
|
|
202
355
|
const BasicMultiExample = ({ isPopup }) => {
|
|
203
356
|
const [value, setValue] = useState([]);
|
|
@@ -267,6 +420,137 @@ const MaxLimitExample = ({ isPopup }) => {
|
|
|
267
420
|
);
|
|
268
421
|
};
|
|
269
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
|
+
|
|
270
554
|
const BaseExample = () => {
|
|
271
555
|
const [isPopup, setIsPopup] = useState(true);
|
|
272
556
|
|
|
@@ -290,6 +574,20 @@ const BaseExample = () => {
|
|
|
290
574
|
<SingleSelectExample isPopup={isPopup} />
|
|
291
575
|
<Divider />
|
|
292
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} />
|
|
293
591
|
</Flex>
|
|
294
592
|
);
|
|
295
593
|
};
|
|
@@ -299,14 +597,18 @@ render(<BaseExample />);
|
|
|
299
597
|
```
|
|
300
598
|
|
|
301
599
|
- SelectAddress 城市选择器
|
|
302
|
-
-
|
|
600
|
+
- 城市地址选择组件,支持国内外城市搜索选择、值回显,具备拼音搜索、首字母搜索等功能
|
|
303
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)
|
|
304
602
|
|
|
305
603
|
```jsx
|
|
306
|
-
const { SelectAddress } = _SuperSelectPlus;
|
|
604
|
+
const { SelectAddress, AddressEnum, addressEnumToSelectValue, addressEnumToSelectValueSingle } = _SuperSelectPlus;
|
|
307
605
|
const { Flex, Divider, Tag, Switch } = antd;
|
|
308
606
|
const { useState } = React;
|
|
309
607
|
|
|
608
|
+
// 模拟后端接口返回的城市编码
|
|
609
|
+
const savedCityCodes = ['010', '020'];
|
|
610
|
+
const savedCityCode = '010';
|
|
611
|
+
|
|
310
612
|
// 基础多选示例
|
|
311
613
|
const BasicMultiExample = ({ isPopup }) => {
|
|
312
614
|
const [value, setValue] = useState([]);
|
|
@@ -376,6 +678,142 @@ const MaxLimitExample = ({ isPopup }) => {
|
|
|
376
678
|
);
|
|
377
679
|
};
|
|
378
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
|
+
|
|
379
817
|
const BaseExample = () => {
|
|
380
818
|
const [isPopup, setIsPopup] = useState(true);
|
|
381
819
|
|
|
@@ -399,6 +837,20 @@ const BaseExample = () => {
|
|
|
399
837
|
<SingleSelectExample isPopup={isPopup} />
|
|
400
838
|
<Divider />
|
|
401
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} />
|
|
402
854
|
</Flex>
|
|
403
855
|
);
|
|
404
856
|
};
|
|
@@ -471,8 +923,26 @@ const BaseExample = createWithRemoteLoader({
|
|
|
471
923
|
<div><strong>姓名:</strong>张三</div>
|
|
472
924
|
<div><strong>所在城市:</strong><AddressEnum name="010" /></div>
|
|
473
925
|
<div><strong>期望工作城市:</strong><AddressEnum name="020" /></div>
|
|
926
|
+
<div><strong>可接受城市:</strong><AddressEnum names={['010', '020', '050020']} /></div>
|
|
474
927
|
</div>
|
|
475
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>
|
|
476
946
|
|
|
477
947
|
<InfoPage.Part title="错误处理">
|
|
478
948
|
<p>不存在的城市编码 999999:<AddressEnum name="999999" /></p>
|
|
@@ -876,6 +1346,48 @@ render(<BaseExample />);
|
|
|
876
1346
|
}
|
|
877
1347
|
```
|
|
878
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
|
+
|
|
879
1391
|
---
|
|
880
1392
|
|
|
881
1393
|
### SelectIndustry 行业选择器
|
|
@@ -920,6 +1432,48 @@ render(<BaseExample />);
|
|
|
920
1432
|
}
|
|
921
1433
|
```
|
|
922
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
|
+
|
|
923
1477
|
---
|
|
924
1478
|
|
|
925
1479
|
### SelectAddress 城市选择器
|
|
@@ -975,6 +1529,46 @@ render(<BaseExample />);
|
|
|
975
1529
|
}
|
|
976
1530
|
```
|
|
977
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
|
+
|
|
978
1572
|
---
|
|
979
1573
|
|
|
980
1574
|
### AddressEnum 地址枚举显示组件
|
|
@@ -985,7 +1579,8 @@ render(<BaseExample />);
|
|
|
985
1579
|
|
|
986
1580
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
987
1581
|
|------|------|-------|------|
|
|
988
|
-
| name | string | - |
|
|
1582
|
+
| name | string | - | 城市编码,与 names 二选一 |
|
|
1583
|
+
| names | string[] | - | 城市编码数组,与 name 二选一,默认 label 数组 toString 输出 |
|
|
989
1584
|
| displayParent | boolean | false | 是否显示父级城市名称 |
|
|
990
1585
|
| force | boolean | false | 是否强制刷新缓存 |
|
|
991
1586
|
| children | function | - | 自定义渲染函数 |
|
|
@@ -994,14 +1589,19 @@ render(<BaseExample />);
|
|
|
994
1589
|
#### 自定义渲染函数
|
|
995
1590
|
|
|
996
1591
|
```javascript
|
|
1592
|
+
// 单个编码 name
|
|
997
1593
|
children={({ city, parent }, { displayParent, locale, getLabelForLocal }) => {
|
|
998
1594
|
// city: 城市数据对象
|
|
999
1595
|
// parent: 父级城市数据对象
|
|
1000
|
-
// displayParent: 是否显示父级
|
|
1001
|
-
// locale: 当前语言环境
|
|
1002
|
-
// getLabelForLocal: 获取本地化标签的函数
|
|
1003
1596
|
return <span>{getLabelForLocal(city, locale)}</span>;
|
|
1004
1597
|
}}
|
|
1598
|
+
|
|
1599
|
+
// 批量编码 names
|
|
1600
|
+
children={(outputs, { labels, locale, getLabelForLocal }) => {
|
|
1601
|
+
// outputs: [{ city, parent }, ...] 数组
|
|
1602
|
+
// labels: 有效项的 label 字符串数组
|
|
1603
|
+
return <span>{labels.join('、')}</span>;
|
|
1604
|
+
}}
|
|
1005
1605
|
```
|
|
1006
1606
|
|
|
1007
1607
|
#### 静态方法
|
|
@@ -1017,16 +1617,16 @@ children={({ city, parent }, { displayParent, locale, getLabelForLocal }) => {
|
|
|
1017
1617
|
// 基本用法
|
|
1018
1618
|
<AddressEnum name="010" />
|
|
1019
1619
|
|
|
1620
|
+
// 批量显示
|
|
1621
|
+
<AddressEnum names={['010', '020']} />
|
|
1622
|
+
|
|
1020
1623
|
// 显示父级
|
|
1021
1624
|
<AddressEnum name="010" displayParent />
|
|
1022
1625
|
|
|
1023
|
-
//
|
|
1024
|
-
<AddressEnum
|
|
1025
|
-
{(
|
|
1026
|
-
<
|
|
1027
|
-
{parent && <span>{getLabelForLocal(parent, locale)} · </span>}
|
|
1028
|
-
{getLabelForLocal(city, locale)}
|
|
1029
|
-
</div>
|
|
1626
|
+
// 结合 SelectAddress 值回显
|
|
1627
|
+
<AddressEnum names={['010', '020']}>
|
|
1628
|
+
{(outputs) => (
|
|
1629
|
+
<SelectAddress value={addressEnumToSelectValue(outputs)} />
|
|
1030
1630
|
)}
|
|
1031
1631
|
</AddressEnum>
|
|
1032
1632
|
```
|
|
@@ -1267,6 +1867,35 @@ children={(items, { locale, mapping, labels, names }) => {
|
|
|
1267
1867
|
</EnumDisplay>
|
|
1268
1868
|
```
|
|
1269
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>
|
|
1897
|
+
```
|
|
1898
|
+
|
|
1270
1899
|
---
|
|
1271
1900
|
|
|
1272
1901
|
### 国际化支持
|