@kne/super-select-plus 0.1.1 → 0.1.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/README.md +646 -17
- package/dist/index.js +379 -34
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +339 -16
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -89,17 +89,67 @@ const defaultChildren = output => {
|
|
|
89
89
|
return get__default["default"](output, 'label', '');
|
|
90
90
|
};
|
|
91
91
|
const getLabels = output => Array.isArray(output) ? output.map(item => get__default["default"](item, 'label', '')).filter(Boolean) : output ? [get__default["default"](output, 'label', '')].filter(Boolean) : [];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 将 EnumDisplay / FunctionEnum / IndustryEnum 解析结果转为选择器 value
|
|
95
|
+
* @param {Array|Object} items createEnumComponent children 第一个参数
|
|
96
|
+
* @param {Object} options valueKey / labelKey 字段映射
|
|
97
|
+
*/
|
|
98
|
+
const enumItemsToSelectValue = function (items, _temp) {
|
|
99
|
+
let _ref = _temp === void 0 ? {} : _temp,
|
|
100
|
+
_ref$valueKey = _ref.valueKey,
|
|
101
|
+
valueKey = _ref$valueKey === void 0 ? 'id' : _ref$valueKey,
|
|
102
|
+
_ref$labelKey = _ref.labelKey,
|
|
103
|
+
labelKey = _ref$labelKey === void 0 ? 'name' : _ref$labelKey;
|
|
104
|
+
return (Array.isArray(items) ? items : [items]).filter(Boolean).map(item => {
|
|
105
|
+
var _item$id, _ref2, _item$label;
|
|
106
|
+
return {
|
|
107
|
+
[valueKey]: (_item$id = item.id) != null ? _item$id : item.code,
|
|
108
|
+
[labelKey]: (_ref2 = (_item$label = item.label) != null ? _item$label : item.name) != null ? _ref2 : item.chName
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 将单个 Enum 解析结果转为选择器 value(单选)
|
|
115
|
+
*/
|
|
116
|
+
const enumItemToSelectValue = (item, options) => {
|
|
117
|
+
var _enumItemsToSelectVal;
|
|
118
|
+
return (_enumItemsToSelectVal = enumItemsToSelectValue(item, options)[0]) != null ? _enumItemsToSelectVal : null;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 将 AddressEnum 解析结果转为 SelectAddress value(支持 name 单值或 names 数组)
|
|
123
|
+
*/
|
|
124
|
+
const addressEnumToSelectValue = outputs => {
|
|
125
|
+
const list = Array.isArray(outputs) ? outputs : outputs ? [outputs] : [];
|
|
126
|
+
return list.filter(item => item == null ? void 0 : item.city).map(_ref3 => {
|
|
127
|
+
let city = _ref3.city;
|
|
128
|
+
return _extends({
|
|
129
|
+
value: city.code,
|
|
130
|
+
label: city.name
|
|
131
|
+
}, city);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 将单个 AddressEnum 解析结果转为 SelectAddress value(单选)
|
|
137
|
+
*/
|
|
138
|
+
const addressEnumToSelectValueSingle = output => {
|
|
139
|
+
var _addressEnumToSelectV;
|
|
140
|
+
return (_addressEnumToSelectV = addressEnumToSelectValue(output)[0]) != null ? _addressEnumToSelectV : null;
|
|
141
|
+
};
|
|
92
142
|
const resolveOutput = (mapping, name, names) => {
|
|
93
143
|
if (names) {
|
|
94
144
|
return names.map(code => mapping.get(code));
|
|
95
145
|
}
|
|
96
146
|
return mapping.get(name);
|
|
97
147
|
};
|
|
98
|
-
const cacheOutput = (output,
|
|
99
|
-
let cacheKey =
|
|
100
|
-
type =
|
|
101
|
-
name =
|
|
102
|
-
names =
|
|
148
|
+
const cacheOutput = (output, _ref4) => {
|
|
149
|
+
let cacheKey = _ref4.cacheKey,
|
|
150
|
+
type = _ref4.type,
|
|
151
|
+
name = _ref4.name,
|
|
152
|
+
names = _ref4.names;
|
|
103
153
|
if (!cacheKey || !type) {
|
|
104
154
|
return;
|
|
105
155
|
}
|
|
@@ -116,13 +166,13 @@ const cacheOutput = (output, _ref) => {
|
|
|
116
166
|
enumCache.set(cacheKey + "_" + type + "_" + name, output);
|
|
117
167
|
}
|
|
118
168
|
};
|
|
119
|
-
const getCachedOutput =
|
|
169
|
+
const getCachedOutput = _ref5 => {
|
|
120
170
|
var _enumCache$get;
|
|
121
|
-
let cacheKey =
|
|
122
|
-
type =
|
|
123
|
-
name =
|
|
124
|
-
names =
|
|
125
|
-
force =
|
|
171
|
+
let cacheKey = _ref5.cacheKey,
|
|
172
|
+
type = _ref5.type,
|
|
173
|
+
name = _ref5.name,
|
|
174
|
+
names = _ref5.names,
|
|
175
|
+
force = _ref5.force;
|
|
126
176
|
if (force) {
|
|
127
177
|
return null;
|
|
128
178
|
}
|
|
@@ -163,17 +213,17 @@ const defaultTransformItem = (item, label) => _extends({}, item, {
|
|
|
163
213
|
/**
|
|
164
214
|
* 内部枚举显示组件
|
|
165
215
|
*/
|
|
166
|
-
const EnumDisplayInner = reactFetch.withFetch(
|
|
167
|
-
let data =
|
|
168
|
-
name =
|
|
169
|
-
names =
|
|
170
|
-
type =
|
|
171
|
-
cacheKey =
|
|
172
|
-
children =
|
|
173
|
-
getLabel =
|
|
174
|
-
dataFormat =
|
|
175
|
-
transformItem =
|
|
176
|
-
props = _objectWithoutPropertiesLoose(
|
|
216
|
+
const EnumDisplayInner = reactFetch.withFetch(_ref6 => {
|
|
217
|
+
let data = _ref6.data,
|
|
218
|
+
name = _ref6.name,
|
|
219
|
+
names = _ref6.names,
|
|
220
|
+
type = _ref6.type,
|
|
221
|
+
cacheKey = _ref6.cache,
|
|
222
|
+
children = _ref6.children,
|
|
223
|
+
getLabel = _ref6.getLabel,
|
|
224
|
+
dataFormat = _ref6.dataFormat,
|
|
225
|
+
transformItem = _ref6.transformItem,
|
|
226
|
+
props = _objectWithoutPropertiesLoose(_ref6, _excluded$4);
|
|
177
227
|
const _useIntl = reactIntl.useIntl(),
|
|
178
228
|
locale = _useIntl.locale;
|
|
179
229
|
|
|
@@ -343,6 +393,165 @@ const FunctionEnum = createEnumComponent({
|
|
|
343
393
|
defaultApi: defaultFunctionApi
|
|
344
394
|
});
|
|
345
395
|
|
|
396
|
+
const getItemId = function (item, valueKey) {
|
|
397
|
+
var _ref, _ref2, _item$valueKey;
|
|
398
|
+
if (valueKey === void 0) {
|
|
399
|
+
valueKey = 'id';
|
|
400
|
+
}
|
|
401
|
+
if (item == null) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
if (typeof item !== 'object') {
|
|
405
|
+
return item;
|
|
406
|
+
}
|
|
407
|
+
return (_ref = (_ref2 = (_item$valueKey = item[valueKey]) != null ? _item$valueKey : item.id) != null ? _ref2 : item.code) != null ? _ref : null;
|
|
408
|
+
};
|
|
409
|
+
const getItemLabel = function (item, labelKey) {
|
|
410
|
+
var _ref3, _ref4, _item$labelKey;
|
|
411
|
+
if (labelKey === void 0) {
|
|
412
|
+
labelKey = 'name';
|
|
413
|
+
}
|
|
414
|
+
if (item == null || typeof item !== 'object') {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
return (_ref3 = (_ref4 = (_item$labelKey = item[labelKey]) != null ? _item$labelKey : item.label) != null ? _ref4 : item.name) != null ? _ref3 : null;
|
|
418
|
+
};
|
|
419
|
+
const resolveItemFromNode = function (item, node, _temp) {
|
|
420
|
+
let _ref5 = _temp === void 0 ? {} : _temp,
|
|
421
|
+
_ref5$valueKey = _ref5.valueKey,
|
|
422
|
+
valueKey = _ref5$valueKey === void 0 ? 'id' : _ref5$valueKey,
|
|
423
|
+
_ref5$labelKey = _ref5.labelKey,
|
|
424
|
+
labelKey = _ref5$labelKey === void 0 ? 'name' : _ref5$labelKey;
|
|
425
|
+
const id = getItemId(item, valueKey);
|
|
426
|
+
if (id == null) {
|
|
427
|
+
return item;
|
|
428
|
+
}
|
|
429
|
+
if (!node) {
|
|
430
|
+
const label = getItemLabel(item, labelKey);
|
|
431
|
+
if (typeof item === 'object') {
|
|
432
|
+
return label != null && label !== String(id) ? item : _extends({}, typeof item === 'object' ? item : {}, {
|
|
433
|
+
[valueKey]: id,
|
|
434
|
+
[labelKey]: label || String(id)
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
[valueKey]: id,
|
|
439
|
+
[labelKey]: String(id)
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
const label = getItemLabel(item, labelKey) || node[labelKey] || node.name;
|
|
443
|
+
return _extends({}, node, typeof item === 'object' ? item : {}, {
|
|
444
|
+
[valueKey]: id,
|
|
445
|
+
[labelKey]: label
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* 通过扁平 Map 解析 value(推荐,不依赖级联树结构)
|
|
451
|
+
*/
|
|
452
|
+
const resolveCascaderValueFromMap = function (value, mapping, _temp2) {
|
|
453
|
+
let _ref6 = _temp2 === void 0 ? {} : _temp2,
|
|
454
|
+
_ref6$valueKey = _ref6.valueKey,
|
|
455
|
+
valueKey = _ref6$valueKey === void 0 ? 'id' : _ref6$valueKey,
|
|
456
|
+
_ref6$labelKey = _ref6.labelKey,
|
|
457
|
+
labelKey = _ref6$labelKey === void 0 ? 'name' : _ref6$labelKey,
|
|
458
|
+
_ref6$single = _ref6.single,
|
|
459
|
+
single = _ref6$single === void 0 ? false : _ref6$single;
|
|
460
|
+
if (value == null || !(mapping != null && mapping.size)) {
|
|
461
|
+
return value;
|
|
462
|
+
}
|
|
463
|
+
const resolveItem = item => resolveItemFromNode(item, mapping.get(getItemId(item, valueKey)), {
|
|
464
|
+
valueKey,
|
|
465
|
+
labelKey
|
|
466
|
+
});
|
|
467
|
+
if (single) {
|
|
468
|
+
const current = Array.isArray(value) ? value[0] : value;
|
|
469
|
+
return current != null ? resolveItem(current) : value;
|
|
470
|
+
}
|
|
471
|
+
return Array.isArray(value) ? value.map(resolveItem) : value;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 将仅含编码的 value 解析为含 label 的完整对象(城市选择器)
|
|
476
|
+
*/
|
|
477
|
+
const resolveAddressValue = function (value, addressApi, _temp3) {
|
|
478
|
+
let _ref8 = _temp3 === void 0 ? {} : _temp3,
|
|
479
|
+
_ref8$single = _ref8.single,
|
|
480
|
+
single = _ref8$single === void 0 ? false : _ref8$single;
|
|
481
|
+
if (value == null || !addressApi) {
|
|
482
|
+
return value;
|
|
483
|
+
}
|
|
484
|
+
const resolveItem = item => {
|
|
485
|
+
var _item$value, _item$label;
|
|
486
|
+
if (item == null) {
|
|
487
|
+
return item;
|
|
488
|
+
}
|
|
489
|
+
const code = typeof item === 'object' ? (_item$value = item.value) != null ? _item$value : item.code : item;
|
|
490
|
+
if (!code) {
|
|
491
|
+
return typeof item === 'object' ? item : null;
|
|
492
|
+
}
|
|
493
|
+
const label = typeof item === 'object' ? (_item$label = item.label) != null ? _item$label : item.name : null;
|
|
494
|
+
if (label && label !== String(code)) {
|
|
495
|
+
return typeof item === 'object' ? item : {
|
|
496
|
+
value: code,
|
|
497
|
+
label
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
const _addressApi$getCity = addressApi.getCity(code),
|
|
501
|
+
city = _addressApi$getCity.city;
|
|
502
|
+
return city ? _extends({
|
|
503
|
+
value: code,
|
|
504
|
+
label: city.name
|
|
505
|
+
}, city) : {
|
|
506
|
+
value: code,
|
|
507
|
+
label: String(code)
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
if (single) {
|
|
511
|
+
const current = Array.isArray(value) ? value[0] : value;
|
|
512
|
+
return current != null ? resolveItem(current) : value;
|
|
513
|
+
}
|
|
514
|
+
return Array.isArray(value) ? value.map(resolveItem) : value;
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* 判断是否需要将解析后的 value 同步回 onChange(仅编码 -> 含 label)
|
|
519
|
+
*/
|
|
520
|
+
const shouldSyncSelectValue = function (value, resolved, _temp4) {
|
|
521
|
+
let _ref9 = _temp4 === void 0 ? {} : _temp4,
|
|
522
|
+
_ref9$valueKey = _ref9.valueKey,
|
|
523
|
+
valueKey = _ref9$valueKey === void 0 ? 'id' : _ref9$valueKey,
|
|
524
|
+
_ref9$labelKey = _ref9.labelKey,
|
|
525
|
+
labelKey = _ref9$labelKey === void 0 ? 'name' : _ref9$labelKey,
|
|
526
|
+
_ref9$single = _ref9.single,
|
|
527
|
+
single = _ref9$single === void 0 ? false : _ref9$single;
|
|
528
|
+
if (resolved == null || value == null) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
const needSyncItem = (original, resolvedItem) => {
|
|
532
|
+
const id = getItemId(original, valueKey);
|
|
533
|
+
const resolvedId = getItemId(resolvedItem, valueKey);
|
|
534
|
+
if (id == null || id !== resolvedId) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
const resolvedLabel = getItemLabel(resolvedItem, labelKey);
|
|
538
|
+
if (!resolvedLabel || resolvedLabel === String(id)) {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
const valueLabel = getItemLabel(original, labelKey);
|
|
542
|
+
return !valueLabel || valueLabel === String(id);
|
|
543
|
+
};
|
|
544
|
+
if (single) {
|
|
545
|
+
const original = Array.isArray(value) ? value[0] : value;
|
|
546
|
+
const resolvedItem = Array.isArray(resolved) ? resolved[0] : resolved;
|
|
547
|
+
return needSyncItem(original, resolvedItem);
|
|
548
|
+
}
|
|
549
|
+
if (!Array.isArray(value) || !Array.isArray(resolved)) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
return resolved.some((item, index) => needSyncItem(value[index], item));
|
|
553
|
+
};
|
|
554
|
+
|
|
346
555
|
const _excluded$3 = ["value", "onChange", "single", "placeholder", "isPopup", "overlayWidth", "apis", "onSearch"];
|
|
347
556
|
const defaultFunctionData = () => {
|
|
348
557
|
return Promise.resolve().then(function () { return require('./function-871311da.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
@@ -407,6 +616,38 @@ const SelectFunctionInner = _ref => {
|
|
|
407
616
|
});
|
|
408
617
|
}, []);
|
|
409
618
|
const options = react.useMemo(() => transformToCascaderData$1(data, locale), [data, locale]);
|
|
619
|
+
const flatMapping = react.useMemo(() => {
|
|
620
|
+
const mapping = new Map();
|
|
621
|
+
data.forEach(item => {
|
|
622
|
+
mapping.set(item.code, _extends({}, item, {
|
|
623
|
+
id: item.code,
|
|
624
|
+
name: getLabelForLocal$3(item, locale)
|
|
625
|
+
}));
|
|
626
|
+
});
|
|
627
|
+
return mapping;
|
|
628
|
+
}, [data, locale]);
|
|
629
|
+
const normalizedValue = react.useMemo(() => resolveCascaderValueFromMap(value, flatMapping, {
|
|
630
|
+
valueKey: 'id',
|
|
631
|
+
labelKey: 'name',
|
|
632
|
+
single
|
|
633
|
+
}), [value, flatMapping, single]);
|
|
634
|
+
react.useEffect(() => {
|
|
635
|
+
if (!onChange || !flatMapping.size) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
const resolved = resolveCascaderValueFromMap(value, flatMapping, {
|
|
639
|
+
valueKey: 'id',
|
|
640
|
+
labelKey: 'name',
|
|
641
|
+
single
|
|
642
|
+
});
|
|
643
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
644
|
+
valueKey: 'id',
|
|
645
|
+
labelKey: 'name',
|
|
646
|
+
single
|
|
647
|
+
})) {
|
|
648
|
+
onChange(resolved);
|
|
649
|
+
}
|
|
650
|
+
}, [value, flatMapping, single, onChange]);
|
|
410
651
|
const handleSearch = (searchText, _ref2) => {
|
|
411
652
|
let mapping = _ref2.mapping;
|
|
412
653
|
if (!searchText) return Array.from(mapping.values());
|
|
@@ -416,7 +657,7 @@ const SelectFunctionInner = _ref => {
|
|
|
416
657
|
});
|
|
417
658
|
};
|
|
418
659
|
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, _extends({}, props, {
|
|
419
|
-
value:
|
|
660
|
+
value: normalizedValue,
|
|
420
661
|
onChange: onChange,
|
|
421
662
|
single: single,
|
|
422
663
|
placeholder: placeholder || formatMessage({
|
|
@@ -425,6 +666,7 @@ const SelectFunctionInner = _ref => {
|
|
|
425
666
|
defaultMessage: '请选择职能'
|
|
426
667
|
}),
|
|
427
668
|
isPopup: isPopup,
|
|
669
|
+
overlayWidth: overlayWidth,
|
|
428
670
|
menuItemWidth: 200,
|
|
429
671
|
style: _extends({
|
|
430
672
|
width: overlayWidth
|
|
@@ -539,6 +781,38 @@ const SelectIndustryInner = _ref => {
|
|
|
539
781
|
});
|
|
540
782
|
}, []);
|
|
541
783
|
const options = react.useMemo(() => transformToCascaderData(data, locale), [data, locale]);
|
|
784
|
+
const flatMapping = react.useMemo(() => {
|
|
785
|
+
const mapping = new Map();
|
|
786
|
+
data.filter(item => item.code !== '000').forEach(item => {
|
|
787
|
+
mapping.set(item.code, _extends({}, item, {
|
|
788
|
+
id: item.code,
|
|
789
|
+
name: getLabelForLocal$2(item, locale)
|
|
790
|
+
}));
|
|
791
|
+
});
|
|
792
|
+
return mapping;
|
|
793
|
+
}, [data, locale]);
|
|
794
|
+
const normalizedValue = react.useMemo(() => resolveCascaderValueFromMap(value, flatMapping, {
|
|
795
|
+
valueKey: 'id',
|
|
796
|
+
labelKey: 'name',
|
|
797
|
+
single
|
|
798
|
+
}), [value, flatMapping, single]);
|
|
799
|
+
react.useEffect(() => {
|
|
800
|
+
if (!onChange || !flatMapping.size) {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
const resolved = resolveCascaderValueFromMap(value, flatMapping, {
|
|
804
|
+
valueKey: 'id',
|
|
805
|
+
labelKey: 'name',
|
|
806
|
+
single
|
|
807
|
+
});
|
|
808
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
809
|
+
valueKey: 'id',
|
|
810
|
+
labelKey: 'name',
|
|
811
|
+
single
|
|
812
|
+
})) {
|
|
813
|
+
onChange(resolved);
|
|
814
|
+
}
|
|
815
|
+
}, [value, flatMapping, single, onChange]);
|
|
542
816
|
const handleSearch = (searchText, _ref2) => {
|
|
543
817
|
let mapping = _ref2.mapping;
|
|
544
818
|
if (!searchText) return Array.from(mapping.values());
|
|
@@ -548,7 +822,7 @@ const SelectIndustryInner = _ref => {
|
|
|
548
822
|
});
|
|
549
823
|
};
|
|
550
824
|
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, _extends({}, props, {
|
|
551
|
-
value:
|
|
825
|
+
value: normalizedValue,
|
|
552
826
|
onChange: onChange,
|
|
553
827
|
single: single,
|
|
554
828
|
placeholder: placeholder || formatMessage({
|
|
@@ -557,6 +831,7 @@ const SelectIndustryInner = _ref => {
|
|
|
557
831
|
defaultMessage: '请选择行业'
|
|
558
832
|
}),
|
|
559
833
|
isPopup: isPopup,
|
|
834
|
+
overlayWidth: overlayWidth,
|
|
560
835
|
menuItemWidth: 200,
|
|
561
836
|
style: _extends({
|
|
562
837
|
width: overlayWidth
|
|
@@ -571,8 +846,8 @@ const SelectIndustry = withLocale(SelectIndustryInner);
|
|
|
571
846
|
SelectIndustry.defaultData = defaultIndustryData;
|
|
572
847
|
SelectIndustry.Enum = IndustryEnum;
|
|
573
848
|
|
|
574
|
-
const _excluded$1 = ["data", "name", "children", "displayParent"],
|
|
575
|
-
_excluded2 = ["displayParent"];
|
|
849
|
+
const _excluded$1 = ["data", "name", "names", "children", "displayParent"],
|
|
850
|
+
_excluded2$1 = ["displayParent"];
|
|
576
851
|
const getLabelForLocal$1 = (item, locale) => {
|
|
577
852
|
if (locale === 'en-US') {
|
|
578
853
|
return get__default["default"](item, 'enName') || get__default["default"](item, 'name');
|
|
@@ -599,12 +874,38 @@ const addressDefaultApi = {
|
|
|
599
874
|
const AddressEnumInner = reactFetch.withFetch(_ref => {
|
|
600
875
|
let data = _ref.data,
|
|
601
876
|
name = _ref.name,
|
|
877
|
+
names = _ref.names,
|
|
602
878
|
children = _ref.children,
|
|
603
879
|
displayParent = _ref.displayParent,
|
|
604
880
|
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
605
881
|
const _useIntl = reactIntl.useIntl(),
|
|
606
882
|
locale = _useIntl.locale;
|
|
607
883
|
const addressApi = react.useMemo(() => createAddressApi(data), [data]);
|
|
884
|
+
const formatCityData = cityData => {
|
|
885
|
+
const city = cityData.city,
|
|
886
|
+
parent = cityData.parent;
|
|
887
|
+
if (!city) {
|
|
888
|
+
return '';
|
|
889
|
+
}
|
|
890
|
+
if (displayParent && parent) {
|
|
891
|
+
return getLabelForLocal$1(parent, locale) + "\xB7" + getLabelForLocal$1(city, locale);
|
|
892
|
+
}
|
|
893
|
+
return getLabelForLocal$1(city, locale);
|
|
894
|
+
};
|
|
895
|
+
if (names != null && names.length) {
|
|
896
|
+
const outputs = names.map(code => addressApi.getCity(code));
|
|
897
|
+
const labels = outputs.map(formatCityData).filter(Boolean);
|
|
898
|
+
if (children) {
|
|
899
|
+
return children(outputs, _extends({
|
|
900
|
+
displayParent,
|
|
901
|
+
locale,
|
|
902
|
+
getLabelForLocal: getLabelForLocal$1,
|
|
903
|
+
names,
|
|
904
|
+
labels
|
|
905
|
+
}, props));
|
|
906
|
+
}
|
|
907
|
+
return labels.toString();
|
|
908
|
+
}
|
|
608
909
|
|
|
609
910
|
// 获取城市数据
|
|
610
911
|
const cityData = addressApi.getCity(name);
|
|
@@ -632,7 +933,7 @@ const AddressEnumInner = reactFetch.withFetch(_ref => {
|
|
|
632
933
|
const AddressEnum = withLocale(props => {
|
|
633
934
|
const _props$displayParent = props.displayParent,
|
|
634
935
|
displayParent = _props$displayParent === void 0 ? false : _props$displayParent,
|
|
635
|
-
restProps = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
936
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded2$1);
|
|
636
937
|
return /*#__PURE__*/jsxRuntime.jsx(AddressEnumInner, _extends({}, addressDefaultApi, {
|
|
637
938
|
displayParent: displayParent
|
|
638
939
|
}, restProps));
|
|
@@ -721,7 +1022,8 @@ var classnames = createCommonjsModule(function (module) {
|
|
|
721
1022
|
|
|
722
1023
|
var style = {"address":"kne-super-select-plus_MMoPf","is-popup":"kne-super-select-plus_bYKMf","title":"kne-super-select-plus_pKOHI","scroll-box":"kne-super-select-plus_MObpF","scroll-plus-box":"kne-super-select-plus_iKm8i","content":"kne-super-select-plus_BfCap","col-left":"kne-super-select-plus_BEChX","menu-list":"kne-super-select-plus_gXzFG","menu-item":"kne-super-select-plus_LasXn","col-right":"kne-super-select-plus_1jQmu","search-input":"kne-super-select-plus_YB45l","list":"kne-super-select-plus_Y-MIq","list-item":"kne-super-select-plus_6JEMZ","item-label":"kne-super-select-plus_nlduJ"};
|
|
723
1024
|
|
|
724
|
-
const _excluded = ["
|
|
1025
|
+
const _excluded = ["value", "single", "onChange", "overlayWidth"],
|
|
1026
|
+
_excluded2 = ["single", "isPopup", "showChinaQuan", "showForeignQuan"];
|
|
725
1027
|
const getLabelForLocal = (item, locale) => {
|
|
726
1028
|
if (locale === 'en-US') {
|
|
727
1029
|
return get__default["default"](item, 'enName') || get__default["default"](item, 'name');
|
|
@@ -1036,19 +1338,54 @@ const AddressInner = _ref2 => {
|
|
|
1036
1338
|
const SelectAddressInner = /*#__PURE__*/react.forwardRef((props, ref) => {
|
|
1037
1339
|
const _useIntl2 = reactIntl.useIntl(),
|
|
1038
1340
|
formatMessage = _useIntl2.formatMessage;
|
|
1341
|
+
const value = props.value,
|
|
1342
|
+
single = props.single,
|
|
1343
|
+
onChange = props.onChange,
|
|
1344
|
+
_props$overlayWidth = props.overlayWidth,
|
|
1345
|
+
overlayWidth = _props$overlayWidth === void 0 ? 500 : _props$overlayWidth,
|
|
1346
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
1347
|
+
const _useState4 = react.useState(null),
|
|
1348
|
+
cityData = _useState4[0],
|
|
1349
|
+
setCityData = _useState4[1];
|
|
1350
|
+
react.useEffect(() => {
|
|
1351
|
+
defaultCityData().then(setCityData);
|
|
1352
|
+
}, []);
|
|
1353
|
+
const addressApi = react.useMemo(() => cityData ? createAddressApi(cityData) : null, [cityData]);
|
|
1354
|
+
const normalizedValue = react.useMemo(() => resolveAddressValue(value, addressApi, {
|
|
1355
|
+
single
|
|
1356
|
+
}), [value, addressApi, single]);
|
|
1357
|
+
react.useEffect(() => {
|
|
1358
|
+
if (!onChange || !addressApi) {
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
const resolved = resolveAddressValue(value, addressApi, {
|
|
1362
|
+
single
|
|
1363
|
+
});
|
|
1364
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
1365
|
+
valueKey: 'value',
|
|
1366
|
+
labelKey: 'label',
|
|
1367
|
+
single
|
|
1368
|
+
})) {
|
|
1369
|
+
onChange(resolved);
|
|
1370
|
+
}
|
|
1371
|
+
}, [value, addressApi, single, onChange]);
|
|
1039
1372
|
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectInput, _extends({
|
|
1040
1373
|
ref: ref
|
|
1041
|
-
},
|
|
1042
|
-
|
|
1374
|
+
}, restProps, {
|
|
1375
|
+
single: single,
|
|
1376
|
+
value: normalizedValue,
|
|
1377
|
+
onChange: onChange,
|
|
1378
|
+
overlayWidth: overlayWidth,
|
|
1379
|
+
placeholder: restProps.placeholder || formatMessage({
|
|
1043
1380
|
id: 'addressPlaceholder'
|
|
1044
1381
|
}, {
|
|
1045
1382
|
defaultMessage: '请选择城市'
|
|
1046
1383
|
}),
|
|
1047
1384
|
children: contextProps => {
|
|
1048
|
-
const
|
|
1385
|
+
const currentValue = contextProps.value,
|
|
1049
1386
|
setValue = contextProps.setValue;
|
|
1050
1387
|
return /*#__PURE__*/jsxRuntime.jsx(AddressInner, {
|
|
1051
|
-
value:
|
|
1388
|
+
value: currentValue,
|
|
1052
1389
|
setValue: setValue,
|
|
1053
1390
|
props: props
|
|
1054
1391
|
});
|
|
@@ -1064,7 +1401,7 @@ const SelectAddress = withLocale(_ref4 => {
|
|
|
1064
1401
|
showChinaQuan = _ref4$showChinaQuan === void 0 ? false : _ref4$showChinaQuan,
|
|
1065
1402
|
_ref4$showForeignQuan = _ref4.showForeignQuan,
|
|
1066
1403
|
showForeignQuan = _ref4$showForeignQuan === void 0 ? false : _ref4$showForeignQuan,
|
|
1067
|
-
props = _objectWithoutPropertiesLoose(_ref4,
|
|
1404
|
+
props = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
1068
1405
|
return /*#__PURE__*/jsxRuntime.jsx(SelectAddressInner, _extends({
|
|
1069
1406
|
single: single,
|
|
1070
1407
|
isPopup: isPopup,
|
|
@@ -1084,7 +1421,11 @@ var index = {
|
|
|
1084
1421
|
AddressEnum,
|
|
1085
1422
|
FunctionEnum,
|
|
1086
1423
|
IndustryEnum,
|
|
1087
|
-
EnumDisplay
|
|
1424
|
+
EnumDisplay,
|
|
1425
|
+
enumItemsToSelectValue,
|
|
1426
|
+
enumItemToSelectValue,
|
|
1427
|
+
addressEnumToSelectValue,
|
|
1428
|
+
addressEnumToSelectValueSingle
|
|
1088
1429
|
};
|
|
1089
1430
|
|
|
1090
1431
|
exports.AddressEnum = AddressEnum;
|
|
@@ -1094,6 +1435,10 @@ exports.IndustryEnum = IndustryEnum;
|
|
|
1094
1435
|
exports.SelectAddress = SelectAddress;
|
|
1095
1436
|
exports.SelectFunction = SelectFunction;
|
|
1096
1437
|
exports.SelectIndustry = SelectIndustry;
|
|
1438
|
+
exports.addressEnumToSelectValue = addressEnumToSelectValue;
|
|
1439
|
+
exports.addressEnumToSelectValueSingle = addressEnumToSelectValueSingle;
|
|
1097
1440
|
exports.createAddressApi = createAddressApi;
|
|
1098
1441
|
exports["default"] = index;
|
|
1442
|
+
exports.enumItemToSelectValue = enumItemToSelectValue;
|
|
1443
|
+
exports.enumItemsToSelectValue = enumItemsToSelectValue;
|
|
1099
1444
|
//# sourceMappingURL=index.js.map
|