@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/dist/index.js
CHANGED
|
@@ -18,6 +18,25 @@ var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);
|
|
|
18
18
|
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
19
19
|
var SearchInput__default = /*#__PURE__*/_interopDefaultLegacy(SearchInput);
|
|
20
20
|
|
|
21
|
+
function _extends() {
|
|
22
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
23
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
24
|
+
var t = arguments[e];
|
|
25
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
26
|
+
}
|
|
27
|
+
return n;
|
|
28
|
+
}, _extends.apply(null, arguments);
|
|
29
|
+
}
|
|
30
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
31
|
+
if (null == r) return {};
|
|
32
|
+
var t = {};
|
|
33
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
34
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
35
|
+
t[n] = r[n];
|
|
36
|
+
}
|
|
37
|
+
return t;
|
|
38
|
+
}
|
|
39
|
+
|
|
21
40
|
const locale$1 = {
|
|
22
41
|
placeholder: '请选择',
|
|
23
42
|
searchPlaceholder: '搜索',
|
|
@@ -59,10 +78,113 @@ const withLocale = reactIntl.createWithIntlProvider({
|
|
|
59
78
|
namespace: 'super-select-plus'
|
|
60
79
|
});
|
|
61
80
|
|
|
81
|
+
const _excluded$4 = ["data", "name", "names", "type", "cache", "children", "getLabel", "dataFormat", "transformItem"];
|
|
62
82
|
const enumCache = new Map();
|
|
63
83
|
|
|
64
84
|
// 默认子组件渲染函数
|
|
65
|
-
const defaultChildren =
|
|
85
|
+
const defaultChildren = output => {
|
|
86
|
+
if (Array.isArray(output)) {
|
|
87
|
+
return output.map(item => get__default["default"](item, 'label', '')).filter(Boolean).toString();
|
|
88
|
+
}
|
|
89
|
+
return get__default["default"](output, 'label', '');
|
|
90
|
+
};
|
|
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
|
+
};
|
|
142
|
+
const resolveOutput = (mapping, name, names) => {
|
|
143
|
+
if (names) {
|
|
144
|
+
return names.map(code => mapping.get(code));
|
|
145
|
+
}
|
|
146
|
+
return mapping.get(name);
|
|
147
|
+
};
|
|
148
|
+
const cacheOutput = (output, _ref4) => {
|
|
149
|
+
let cacheKey = _ref4.cacheKey,
|
|
150
|
+
type = _ref4.type,
|
|
151
|
+
name = _ref4.name,
|
|
152
|
+
names = _ref4.names;
|
|
153
|
+
if (!cacheKey || !type) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (names) {
|
|
157
|
+
names.forEach((code, index) => {
|
|
158
|
+
const item = output[index];
|
|
159
|
+
if (item) {
|
|
160
|
+
enumCache.set(cacheKey + "_" + type + "_" + code, item);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (output) {
|
|
166
|
+
enumCache.set(cacheKey + "_" + type + "_" + name, output);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const getCachedOutput = _ref5 => {
|
|
170
|
+
var _enumCache$get;
|
|
171
|
+
let cacheKey = _ref5.cacheKey,
|
|
172
|
+
type = _ref5.type,
|
|
173
|
+
name = _ref5.name,
|
|
174
|
+
names = _ref5.names,
|
|
175
|
+
force = _ref5.force;
|
|
176
|
+
if (force) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
if (names != null && names.length) {
|
|
180
|
+
const items = names.map(code => enumCache.get(cacheKey + "_" + type + "_" + code));
|
|
181
|
+
return items.every(Boolean) ? items : null;
|
|
182
|
+
}
|
|
183
|
+
if (name == null) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return (_enumCache$get = enumCache.get(cacheKey + "_" + type + "_" + name)) != null ? _enumCache$get : null;
|
|
187
|
+
};
|
|
66
188
|
|
|
67
189
|
/**
|
|
68
190
|
* 默认获取标签函数
|
|
@@ -82,8 +204,7 @@ const defaultDataFormat = data => data.data || data;
|
|
|
82
204
|
/**
|
|
83
205
|
* 默认映射项转换函数
|
|
84
206
|
*/
|
|
85
|
-
const defaultTransformItem = (item, label) => ({
|
|
86
|
-
...item,
|
|
207
|
+
const defaultTransformItem = (item, label) => _extends({}, item, {
|
|
87
208
|
id: item.code,
|
|
88
209
|
label,
|
|
89
210
|
parentId: item.parentCode || null
|
|
@@ -92,21 +213,19 @@ const defaultTransformItem = (item, label) => ({
|
|
|
92
213
|
/**
|
|
93
214
|
* 内部枚举显示组件
|
|
94
215
|
*/
|
|
95
|
-
const EnumDisplayInner = reactFetch.withFetch(
|
|
96
|
-
let
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
type,
|
|
100
|
-
cache
|
|
101
|
-
children,
|
|
102
|
-
getLabel,
|
|
103
|
-
dataFormat,
|
|
104
|
-
transformItem,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
locale
|
|
109
|
-
} = reactIntl.useIntl();
|
|
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);
|
|
227
|
+
const _useIntl = reactIntl.useIntl(),
|
|
228
|
+
locale = _useIntl.locale;
|
|
110
229
|
|
|
111
230
|
// 格式化数据
|
|
112
231
|
const formattedData = react.useMemo(() => dataFormat(data), [data, dataFormat]);
|
|
@@ -119,54 +238,63 @@ const EnumDisplayInner = reactFetch.withFetch(_ref => {
|
|
|
119
238
|
return [item.code, transformedItem];
|
|
120
239
|
}));
|
|
121
240
|
}, [formattedData, getLabel, locale, transformItem]);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
enumCache.set(`${cacheKey}_${type}_${name}`, output);
|
|
129
|
-
}
|
|
130
|
-
return children(output, {
|
|
131
|
-
...props,
|
|
132
|
-
locale,
|
|
133
|
-
mapping
|
|
241
|
+
const output = react.useMemo(() => resolveOutput(mapping, name, names), [mapping, name, names]);
|
|
242
|
+
cacheOutput(output, {
|
|
243
|
+
cacheKey,
|
|
244
|
+
type,
|
|
245
|
+
name,
|
|
246
|
+
names
|
|
134
247
|
});
|
|
248
|
+
return children(output, _extends({}, props, {
|
|
249
|
+
locale,
|
|
250
|
+
mapping,
|
|
251
|
+
names,
|
|
252
|
+
labels: getLabels(output)
|
|
253
|
+
}));
|
|
135
254
|
});
|
|
136
255
|
|
|
137
256
|
/**
|
|
138
257
|
* 枚举显示组件
|
|
139
258
|
*/
|
|
140
259
|
const EnumDisplay = withLocale(props => {
|
|
141
|
-
|
|
142
|
-
|
|
260
|
+
const name = props.name,
|
|
261
|
+
names = props.names,
|
|
262
|
+
_props$type = props.type,
|
|
263
|
+
type = _props$type === void 0 ? 'default' : _props$type,
|
|
264
|
+
_props$cache = props.cache,
|
|
265
|
+
cacheKey = _props$cache === void 0 ? 'ENUM_DATA' : _props$cache,
|
|
266
|
+
_props$force = props.force,
|
|
267
|
+
force = _props$force === void 0 ? false : _props$force,
|
|
268
|
+
_props$getLabel = props.getLabel,
|
|
269
|
+
getLabel = _props$getLabel === void 0 ? defaultGetLabel : _props$getLabel,
|
|
270
|
+
_props$dataFormat = props.dataFormat,
|
|
271
|
+
dataFormat = _props$dataFormat === void 0 ? defaultDataFormat : _props$dataFormat,
|
|
272
|
+
_props$transformItem = props.transformItem,
|
|
273
|
+
transformItem = _props$transformItem === void 0 ? defaultTransformItem : _props$transformItem,
|
|
274
|
+
_props$children = props.children,
|
|
275
|
+
children = _props$children === void 0 ? defaultChildren : _props$children;
|
|
276
|
+
const cached = getCachedOutput({
|
|
277
|
+
cacheKey,
|
|
278
|
+
type,
|
|
143
279
|
name,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
dataFormat = defaultDataFormat,
|
|
149
|
-
transformItem = defaultTransformItem,
|
|
150
|
-
children = defaultChildren
|
|
151
|
-
} = props;
|
|
152
|
-
|
|
153
|
-
// 检查缓存
|
|
154
|
-
const key = `${cacheKey}_${type}_${name}`;
|
|
155
|
-
const cached = enumCache.get(key);
|
|
156
|
-
if (cached && !force) {
|
|
280
|
+
names,
|
|
281
|
+
force
|
|
282
|
+
});
|
|
283
|
+
if (cached) {
|
|
157
284
|
return children(cached, {
|
|
158
|
-
locale: props.locale
|
|
285
|
+
locale: props.locale,
|
|
286
|
+
names,
|
|
287
|
+
labels: getLabels(cached)
|
|
159
288
|
});
|
|
160
289
|
}
|
|
161
|
-
return /*#__PURE__*/jsxRuntime.jsx(EnumDisplayInner, {
|
|
162
|
-
...props,
|
|
290
|
+
return /*#__PURE__*/jsxRuntime.jsx(EnumDisplayInner, _extends({}, props, {
|
|
163
291
|
type: type,
|
|
164
292
|
cache: cacheKey,
|
|
165
293
|
getLabel: getLabel,
|
|
166
294
|
dataFormat: dataFormat,
|
|
167
295
|
transformItem: transformItem,
|
|
168
296
|
children: children
|
|
169
|
-
});
|
|
297
|
+
}));
|
|
170
298
|
});
|
|
171
299
|
|
|
172
300
|
/**
|
|
@@ -181,39 +309,44 @@ const EnumDisplay = withLocale(props => {
|
|
|
181
309
|
* @returns {React.Component} 枚举组件
|
|
182
310
|
*/
|
|
183
311
|
const createEnumComponent = options => {
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
getLabel = defaultGetLabel,
|
|
188
|
-
dataFormat =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
312
|
+
const type = options.type,
|
|
313
|
+
cache = options.cache,
|
|
314
|
+
_options$getLabel = options.getLabel,
|
|
315
|
+
getLabel = _options$getLabel === void 0 ? defaultGetLabel : _options$getLabel,
|
|
316
|
+
_options$dataFormat = options.dataFormat,
|
|
317
|
+
dataFormat = _options$dataFormat === void 0 ? defaultDataFormat : _options$dataFormat,
|
|
318
|
+
_options$transformIte = options.transformItem,
|
|
319
|
+
transformItem = _options$transformIte === void 0 ? defaultTransformItem : _options$transformIte,
|
|
320
|
+
defaultApi = options.defaultApi;
|
|
192
321
|
const EnumComponent = withLocale(props => {
|
|
193
|
-
const
|
|
322
|
+
const name = props.name,
|
|
323
|
+
names = props.names,
|
|
324
|
+
_props$force2 = props.force,
|
|
325
|
+
force = _props$force2 === void 0 ? false : _props$force2,
|
|
326
|
+
_props$children2 = props.children,
|
|
327
|
+
children = _props$children2 === void 0 ? defaultChildren : _props$children2;
|
|
328
|
+
const cached = getCachedOutput({
|
|
329
|
+
cacheKey: cache,
|
|
330
|
+
type,
|
|
194
331
|
name,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// 检查缓存
|
|
200
|
-
const key = `${cache}_${type}_${name}`;
|
|
201
|
-
const cached = enumCache.get(key);
|
|
202
|
-
if (cached && !force) {
|
|
332
|
+
names,
|
|
333
|
+
force
|
|
334
|
+
});
|
|
335
|
+
if (cached) {
|
|
203
336
|
return children(cached, {
|
|
204
|
-
locale: props.locale
|
|
337
|
+
locale: props.locale,
|
|
338
|
+
names,
|
|
339
|
+
labels: getLabels(cached)
|
|
205
340
|
});
|
|
206
341
|
}
|
|
207
|
-
return /*#__PURE__*/jsxRuntime.jsx(EnumDisplayInner, {
|
|
208
|
-
...props,
|
|
209
|
-
...defaultApi,
|
|
342
|
+
return /*#__PURE__*/jsxRuntime.jsx(EnumDisplayInner, _extends({}, props, defaultApi, {
|
|
210
343
|
type: type,
|
|
211
344
|
cache: cache,
|
|
212
345
|
getLabel: getLabel,
|
|
213
346
|
dataFormat: dataFormat,
|
|
214
347
|
transformItem: transformItem,
|
|
215
348
|
children: children
|
|
216
|
-
});
|
|
349
|
+
}));
|
|
217
350
|
});
|
|
218
351
|
|
|
219
352
|
// 附加静态属性
|
|
@@ -246,7 +379,7 @@ const defaultFunctionApi = {
|
|
|
246
379
|
ttl: 1000 * 60 * 60 * 24,
|
|
247
380
|
// 24小时
|
|
248
381
|
loader: () => {
|
|
249
|
-
return Promise.resolve().then(function () { return require('./function-
|
|
382
|
+
return Promise.resolve().then(function () { return require('./function-871311da.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
250
383
|
}
|
|
251
384
|
};
|
|
252
385
|
|
|
@@ -260,19 +393,178 @@ const FunctionEnum = createEnumComponent({
|
|
|
260
393
|
defaultApi: defaultFunctionApi
|
|
261
394
|
});
|
|
262
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
|
+
|
|
555
|
+
const _excluded$3 = ["value", "onChange", "single", "placeholder", "isPopup", "overlayWidth", "apis", "onSearch"];
|
|
263
556
|
const defaultFunctionData = () => {
|
|
264
|
-
return Promise.resolve().then(function () { return require('./function-
|
|
557
|
+
return Promise.resolve().then(function () { return require('./function-871311da.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
265
558
|
};
|
|
266
559
|
const transformToCascaderData$1 = (data, locale) => {
|
|
267
560
|
// 创建映射表
|
|
268
561
|
const mapping = new Map();
|
|
269
562
|
data.forEach(item => {
|
|
270
|
-
mapping.set(item.code, {
|
|
271
|
-
...item,
|
|
563
|
+
mapping.set(item.code, _extends({}, item, {
|
|
272
564
|
id: item.code,
|
|
273
565
|
name: getLabelForLocal$3(item, locale),
|
|
274
566
|
children: []
|
|
275
|
-
});
|
|
567
|
+
}));
|
|
276
568
|
});
|
|
277
569
|
|
|
278
570
|
// 构建嵌套结构
|
|
@@ -301,41 +593,71 @@ const transformToCascaderData$1 = (data, locale) => {
|
|
|
301
593
|
return roots;
|
|
302
594
|
};
|
|
303
595
|
const SelectFunctionInner = _ref => {
|
|
304
|
-
let
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
single = false,
|
|
308
|
-
placeholder,
|
|
309
|
-
isPopup =
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
locale,
|
|
317
|
-
formatMessage
|
|
318
|
-
|
|
319
|
-
|
|
596
|
+
let value = _ref.value,
|
|
597
|
+
onChange = _ref.onChange,
|
|
598
|
+
_ref$single = _ref.single,
|
|
599
|
+
single = _ref$single === void 0 ? false : _ref$single,
|
|
600
|
+
placeholder = _ref.placeholder,
|
|
601
|
+
_ref$isPopup = _ref.isPopup,
|
|
602
|
+
isPopup = _ref$isPopup === void 0 ? true : _ref$isPopup,
|
|
603
|
+
_ref$overlayWidth = _ref.overlayWidth,
|
|
604
|
+
overlayWidth = _ref$overlayWidth === void 0 ? 320 : _ref$overlayWidth,
|
|
605
|
+
onSearch = _ref.onSearch,
|
|
606
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
607
|
+
const _useIntl = reactIntl.useIntl(),
|
|
608
|
+
locale = _useIntl.locale,
|
|
609
|
+
formatMessage = _useIntl.formatMessage;
|
|
610
|
+
const _useState = react.useState([]),
|
|
611
|
+
data = _useState[0],
|
|
612
|
+
setData = _useState[1];
|
|
320
613
|
react.useEffect(() => {
|
|
321
614
|
defaultFunctionData().then(result => {
|
|
322
615
|
setData(result.data || result);
|
|
323
616
|
});
|
|
324
617
|
}, []);
|
|
325
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]);
|
|
326
651
|
const handleSearch = (searchText, _ref2) => {
|
|
327
|
-
let
|
|
328
|
-
mapping
|
|
329
|
-
} = _ref2;
|
|
652
|
+
let mapping = _ref2.mapping;
|
|
330
653
|
if (!searchText) return Array.from(mapping.values());
|
|
331
654
|
const keyword = searchText.toLowerCase();
|
|
332
655
|
return Array.from(mapping.values()).filter(item => {
|
|
333
656
|
return item.chName && item.chName.toLowerCase().includes(keyword) || item.enName && item.enName.toLowerCase().includes(keyword) || item.pinyin && item.pinyin.toLowerCase().includes(keyword) || item.spelling && item.spelling.toLowerCase().includes(keyword);
|
|
334
657
|
});
|
|
335
658
|
};
|
|
336
|
-
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, {
|
|
337
|
-
|
|
338
|
-
value: value,
|
|
659
|
+
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, _extends({}, props, {
|
|
660
|
+
value: normalizedValue,
|
|
339
661
|
onChange: onChange,
|
|
340
662
|
single: single,
|
|
341
663
|
placeholder: placeholder || formatMessage({
|
|
@@ -345,15 +667,14 @@ const SelectFunctionInner = _ref => {
|
|
|
345
667
|
}),
|
|
346
668
|
isPopup: isPopup,
|
|
347
669
|
menuItemWidth: 200,
|
|
348
|
-
style: {
|
|
349
|
-
width: overlayWidth
|
|
350
|
-
|
|
351
|
-
},
|
|
670
|
+
style: _extends({
|
|
671
|
+
width: overlayWidth
|
|
672
|
+
}, props.style),
|
|
352
673
|
options: options,
|
|
353
674
|
valueKey: "id",
|
|
354
675
|
labelKey: "name",
|
|
355
676
|
onSearch: onSearch || handleSearch
|
|
356
|
-
});
|
|
677
|
+
}));
|
|
357
678
|
};
|
|
358
679
|
const SelectFunction = withLocale(SelectFunctionInner);
|
|
359
680
|
SelectFunction.defaultData = defaultFunctionData;
|
|
@@ -378,7 +699,7 @@ const defaultIndustryApi = {
|
|
|
378
699
|
ttl: 1000 * 60 * 60 * 24,
|
|
379
700
|
// 24小时
|
|
380
701
|
loader: () => {
|
|
381
|
-
return Promise.resolve().then(function () { return require('./industry-
|
|
702
|
+
return Promise.resolve().then(function () { return require('./industry-f570d549.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
382
703
|
}
|
|
383
704
|
};
|
|
384
705
|
|
|
@@ -392,8 +713,9 @@ const IndustryEnum = createEnumComponent({
|
|
|
392
713
|
defaultApi: defaultIndustryApi
|
|
393
714
|
});
|
|
394
715
|
|
|
716
|
+
const _excluded$2 = ["value", "onChange", "single", "placeholder", "isPopup", "overlayWidth", "apis", "onSearch"];
|
|
395
717
|
const defaultIndustryData = () => {
|
|
396
|
-
return Promise.resolve().then(function () { return require('./industry-
|
|
718
|
+
return Promise.resolve().then(function () { return require('./industry-f570d549.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
397
719
|
};
|
|
398
720
|
const transformToCascaderData = (data, locale) => {
|
|
399
721
|
// 过滤掉"全部行业"
|
|
@@ -402,12 +724,11 @@ const transformToCascaderData = (data, locale) => {
|
|
|
402
724
|
// 创建映射表
|
|
403
725
|
const mapping = new Map();
|
|
404
726
|
filteredData.forEach(item => {
|
|
405
|
-
mapping.set(item.code, {
|
|
406
|
-
...item,
|
|
727
|
+
mapping.set(item.code, _extends({}, item, {
|
|
407
728
|
id: item.code,
|
|
408
729
|
name: getLabelForLocal$2(item, locale),
|
|
409
730
|
children: []
|
|
410
|
-
});
|
|
731
|
+
}));
|
|
411
732
|
});
|
|
412
733
|
|
|
413
734
|
// 构建嵌套结构
|
|
@@ -436,41 +757,71 @@ const transformToCascaderData = (data, locale) => {
|
|
|
436
757
|
return roots;
|
|
437
758
|
};
|
|
438
759
|
const SelectIndustryInner = _ref => {
|
|
439
|
-
let
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
single = false,
|
|
443
|
-
placeholder,
|
|
444
|
-
isPopup =
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
locale,
|
|
452
|
-
formatMessage
|
|
453
|
-
|
|
454
|
-
|
|
760
|
+
let value = _ref.value,
|
|
761
|
+
onChange = _ref.onChange,
|
|
762
|
+
_ref$single = _ref.single,
|
|
763
|
+
single = _ref$single === void 0 ? false : _ref$single,
|
|
764
|
+
placeholder = _ref.placeholder,
|
|
765
|
+
_ref$isPopup = _ref.isPopup,
|
|
766
|
+
isPopup = _ref$isPopup === void 0 ? true : _ref$isPopup,
|
|
767
|
+
_ref$overlayWidth = _ref.overlayWidth,
|
|
768
|
+
overlayWidth = _ref$overlayWidth === void 0 ? 320 : _ref$overlayWidth,
|
|
769
|
+
onSearch = _ref.onSearch,
|
|
770
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
771
|
+
const _useIntl = reactIntl.useIntl(),
|
|
772
|
+
locale = _useIntl.locale,
|
|
773
|
+
formatMessage = _useIntl.formatMessage;
|
|
774
|
+
const _useState = react.useState([]),
|
|
775
|
+
data = _useState[0],
|
|
776
|
+
setData = _useState[1];
|
|
455
777
|
react.useEffect(() => {
|
|
456
778
|
defaultIndustryData().then(result => {
|
|
457
779
|
setData(result.data || result);
|
|
458
780
|
});
|
|
459
781
|
}, []);
|
|
460
782
|
const options = react.useMemo(() => transformToCascaderData(data, locale), [data, locale]);
|
|
783
|
+
const flatMapping = react.useMemo(() => {
|
|
784
|
+
const mapping = new Map();
|
|
785
|
+
data.filter(item => item.code !== '000').forEach(item => {
|
|
786
|
+
mapping.set(item.code, _extends({}, item, {
|
|
787
|
+
id: item.code,
|
|
788
|
+
name: getLabelForLocal$2(item, locale)
|
|
789
|
+
}));
|
|
790
|
+
});
|
|
791
|
+
return mapping;
|
|
792
|
+
}, [data, locale]);
|
|
793
|
+
const normalizedValue = react.useMemo(() => resolveCascaderValueFromMap(value, flatMapping, {
|
|
794
|
+
valueKey: 'id',
|
|
795
|
+
labelKey: 'name',
|
|
796
|
+
single
|
|
797
|
+
}), [value, flatMapping, single]);
|
|
798
|
+
react.useEffect(() => {
|
|
799
|
+
if (!onChange || !flatMapping.size) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
const resolved = resolveCascaderValueFromMap(value, flatMapping, {
|
|
803
|
+
valueKey: 'id',
|
|
804
|
+
labelKey: 'name',
|
|
805
|
+
single
|
|
806
|
+
});
|
|
807
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
808
|
+
valueKey: 'id',
|
|
809
|
+
labelKey: 'name',
|
|
810
|
+
single
|
|
811
|
+
})) {
|
|
812
|
+
onChange(resolved);
|
|
813
|
+
}
|
|
814
|
+
}, [value, flatMapping, single, onChange]);
|
|
461
815
|
const handleSearch = (searchText, _ref2) => {
|
|
462
|
-
let
|
|
463
|
-
mapping
|
|
464
|
-
} = _ref2;
|
|
816
|
+
let mapping = _ref2.mapping;
|
|
465
817
|
if (!searchText) return Array.from(mapping.values());
|
|
466
818
|
const keyword = searchText.toLowerCase();
|
|
467
819
|
return Array.from(mapping.values()).filter(item => {
|
|
468
820
|
return item.chName && item.chName.toLowerCase().includes(keyword) || item.enName && item.enName.toLowerCase().includes(keyword) || item.pinyin && item.pinyin.toLowerCase().includes(keyword) || item.spelling && item.spelling.toLowerCase().includes(keyword);
|
|
469
821
|
});
|
|
470
822
|
};
|
|
471
|
-
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, {
|
|
472
|
-
|
|
473
|
-
value: value,
|
|
823
|
+
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, _extends({}, props, {
|
|
824
|
+
value: normalizedValue,
|
|
474
825
|
onChange: onChange,
|
|
475
826
|
single: single,
|
|
476
827
|
placeholder: placeholder || formatMessage({
|
|
@@ -480,20 +831,21 @@ const SelectIndustryInner = _ref => {
|
|
|
480
831
|
}),
|
|
481
832
|
isPopup: isPopup,
|
|
482
833
|
menuItemWidth: 200,
|
|
483
|
-
style: {
|
|
484
|
-
width: overlayWidth
|
|
485
|
-
|
|
486
|
-
},
|
|
834
|
+
style: _extends({
|
|
835
|
+
width: overlayWidth
|
|
836
|
+
}, props.style),
|
|
487
837
|
options: options,
|
|
488
838
|
valueKey: "id",
|
|
489
839
|
labelKey: "name",
|
|
490
840
|
onSearch: onSearch || handleSearch
|
|
491
|
-
});
|
|
841
|
+
}));
|
|
492
842
|
};
|
|
493
843
|
const SelectIndustry = withLocale(SelectIndustryInner);
|
|
494
844
|
SelectIndustry.defaultData = defaultIndustryData;
|
|
495
845
|
SelectIndustry.Enum = IndustryEnum;
|
|
496
846
|
|
|
847
|
+
const _excluded$1 = ["data", "name", "names", "children", "displayParent"],
|
|
848
|
+
_excluded2$1 = ["displayParent"];
|
|
497
849
|
const getLabelForLocal$1 = (item, locale) => {
|
|
498
850
|
if (locale === 'en-US') {
|
|
499
851
|
return get__default["default"](item, 'enName') || get__default["default"](item, 'name');
|
|
@@ -510,7 +862,7 @@ const addressDefaultApi = {
|
|
|
510
862
|
ttl: 1000 * 60 * 60 * 24,
|
|
511
863
|
// 24小时
|
|
512
864
|
loader: () => {
|
|
513
|
-
return Promise.resolve().then(function () { return require('./city-
|
|
865
|
+
return Promise.resolve().then(function () { return require('./city-39702d3a.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
514
866
|
}
|
|
515
867
|
};
|
|
516
868
|
|
|
@@ -518,33 +870,53 @@ const addressDefaultApi = {
|
|
|
518
870
|
* 地址枚举显示组件
|
|
519
871
|
*/
|
|
520
872
|
const AddressEnumInner = reactFetch.withFetch(_ref => {
|
|
521
|
-
let
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
children,
|
|
525
|
-
displayParent,
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
locale
|
|
530
|
-
} = reactIntl.useIntl();
|
|
873
|
+
let data = _ref.data,
|
|
874
|
+
name = _ref.name,
|
|
875
|
+
names = _ref.names,
|
|
876
|
+
children = _ref.children,
|
|
877
|
+
displayParent = _ref.displayParent,
|
|
878
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
879
|
+
const _useIntl = reactIntl.useIntl(),
|
|
880
|
+
locale = _useIntl.locale;
|
|
531
881
|
const addressApi = react.useMemo(() => createAddressApi(data), [data]);
|
|
882
|
+
const formatCityData = cityData => {
|
|
883
|
+
const city = cityData.city,
|
|
884
|
+
parent = cityData.parent;
|
|
885
|
+
if (!city) {
|
|
886
|
+
return '';
|
|
887
|
+
}
|
|
888
|
+
if (displayParent && parent) {
|
|
889
|
+
return getLabelForLocal$1(parent, locale) + "\xB7" + getLabelForLocal$1(city, locale);
|
|
890
|
+
}
|
|
891
|
+
return getLabelForLocal$1(city, locale);
|
|
892
|
+
};
|
|
893
|
+
if (names != null && names.length) {
|
|
894
|
+
const outputs = names.map(code => addressApi.getCity(code));
|
|
895
|
+
const labels = outputs.map(formatCityData).filter(Boolean);
|
|
896
|
+
if (children) {
|
|
897
|
+
return children(outputs, _extends({
|
|
898
|
+
displayParent,
|
|
899
|
+
locale,
|
|
900
|
+
getLabelForLocal: getLabelForLocal$1,
|
|
901
|
+
names,
|
|
902
|
+
labels
|
|
903
|
+
}, props));
|
|
904
|
+
}
|
|
905
|
+
return labels.toString();
|
|
906
|
+
}
|
|
532
907
|
|
|
533
908
|
// 获取城市数据
|
|
534
909
|
const cityData = addressApi.getCity(name);
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
parent
|
|
538
|
-
} = cityData;
|
|
910
|
+
const city = cityData.city,
|
|
911
|
+
parent = cityData.parent;
|
|
539
912
|
|
|
540
913
|
// 如果提供了自定义渲染函数
|
|
541
914
|
if (children) {
|
|
542
|
-
return children(cityData, {
|
|
915
|
+
return children(cityData, _extends({
|
|
543
916
|
displayParent,
|
|
544
917
|
locale,
|
|
545
|
-
getLabelForLocal: getLabelForLocal$1
|
|
546
|
-
|
|
547
|
-
});
|
|
918
|
+
getLabelForLocal: getLabelForLocal$1
|
|
919
|
+
}, props));
|
|
548
920
|
}
|
|
549
921
|
|
|
550
922
|
// 默认渲染逻辑
|
|
@@ -552,20 +924,17 @@ const AddressEnumInner = reactFetch.withFetch(_ref => {
|
|
|
552
924
|
return '';
|
|
553
925
|
}
|
|
554
926
|
if (displayParent && parent) {
|
|
555
|
-
return
|
|
927
|
+
return getLabelForLocal$1(parent, locale) + "\xB7" + getLabelForLocal$1(city, locale);
|
|
556
928
|
}
|
|
557
929
|
return getLabelForLocal$1(city, locale);
|
|
558
930
|
});
|
|
559
931
|
const AddressEnum = withLocale(props => {
|
|
560
|
-
const
|
|
561
|
-
displayParent = false,
|
|
562
|
-
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
displayParent: displayParent,
|
|
567
|
-
...restProps
|
|
568
|
-
});
|
|
932
|
+
const _props$displayParent = props.displayParent,
|
|
933
|
+
displayParent = _props$displayParent === void 0 ? false : _props$displayParent,
|
|
934
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded2$1);
|
|
935
|
+
return /*#__PURE__*/jsxRuntime.jsx(AddressEnumInner, _extends({}, addressDefaultApi, {
|
|
936
|
+
displayParent: displayParent
|
|
937
|
+
}, restProps));
|
|
569
938
|
});
|
|
570
939
|
AddressEnum.addressDefaultApi = addressDefaultApi;
|
|
571
940
|
|
|
@@ -649,8 +1018,10 @@ var classnames = createCommonjsModule(function (module) {
|
|
|
649
1018
|
}());
|
|
650
1019
|
});
|
|
651
1020
|
|
|
652
|
-
var style = {"address":"
|
|
1021
|
+
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"};
|
|
653
1022
|
|
|
1023
|
+
const _excluded = ["value", "single", "onChange"],
|
|
1024
|
+
_excluded2 = ["single", "isPopup", "showChinaQuan", "showForeignQuan"];
|
|
654
1025
|
const getLabelForLocal = (item, locale) => {
|
|
655
1026
|
if (locale === 'en-US') {
|
|
656
1027
|
return get__default["default"](item, 'enName') || get__default["default"](item, 'name');
|
|
@@ -658,14 +1029,12 @@ const getLabelForLocal = (item, locale) => {
|
|
|
658
1029
|
return get__default["default"](item, 'name');
|
|
659
1030
|
};
|
|
660
1031
|
const defaultCityData = () => {
|
|
661
|
-
return Promise.resolve().then(function () { return require('./city-
|
|
1032
|
+
return Promise.resolve().then(function () { return require('./city-39702d3a.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
662
1033
|
};
|
|
663
1034
|
const createAddressApi = _ref => {
|
|
664
|
-
let
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
country
|
|
668
|
-
} = _ref;
|
|
1035
|
+
let city = _ref.city,
|
|
1036
|
+
province = _ref.province,
|
|
1037
|
+
country = _ref.country;
|
|
669
1038
|
const getSearchList = memoize__default["default"](() => {
|
|
670
1039
|
const list = [];
|
|
671
1040
|
['gangaotai', 'municipality'].forEach(name => {
|
|
@@ -707,25 +1076,24 @@ const createAddressApi = _ref => {
|
|
|
707
1076
|
}, country.list[id])).filter(item => item.code);
|
|
708
1077
|
}),
|
|
709
1078
|
getList: memoize__default["default"]((pid, options) => {
|
|
710
|
-
const {
|
|
711
|
-
showChinaQuan,
|
|
712
|
-
showForeignQuan
|
|
713
|
-
} = Object.assign({}, options);
|
|
1079
|
+
const _Object$assign = Object.assign({}, options),
|
|
1080
|
+
showChinaQuan = _Object$assign.showChinaQuan,
|
|
1081
|
+
showForeignQuan = _Object$assign.showForeignQuan;
|
|
714
1082
|
if (pid === 'gangaotai') {
|
|
715
1083
|
return (province.relations['gangaotai'] || []).map(id => city.list[id]).filter(Boolean);
|
|
716
1084
|
}
|
|
717
1085
|
const current = Object.assign({}, city.list[pid]);
|
|
718
1086
|
if ((province.relations.municipality || []).indexOf(pid) > -1) {
|
|
719
|
-
current.name =
|
|
1087
|
+
current.name = "" + (showChinaQuan ? '全' : '') + current.name;
|
|
720
1088
|
return [current];
|
|
721
1089
|
}
|
|
722
1090
|
const list = (city.relations[pid] || []).map(id => city.list[id]).filter(Boolean);
|
|
723
1091
|
if ((province.relations.provinces || []).indexOf(pid) > -1 && showChinaQuan) {
|
|
724
|
-
current.name =
|
|
1092
|
+
current.name = "\u5168" + current.name;
|
|
725
1093
|
list.splice(0, 0, current);
|
|
726
1094
|
}
|
|
727
1095
|
if ((country.relations.continents || []).indexOf(pid) > -1 && showForeignQuan) {
|
|
728
|
-
current.name =
|
|
1096
|
+
current.name = "\u5168" + current.name;
|
|
729
1097
|
list.splice(0, 0, current);
|
|
730
1098
|
}
|
|
731
1099
|
return list;
|
|
@@ -765,16 +1133,14 @@ const createAddressApi = _ref => {
|
|
|
765
1133
|
});
|
|
766
1134
|
}).map(item => {
|
|
767
1135
|
const parent = item.parentCode ? city.list[item.parentCode] : null;
|
|
768
|
-
return {
|
|
769
|
-
label: parent ?
|
|
770
|
-
value: item.code
|
|
771
|
-
|
|
772
|
-
};
|
|
1136
|
+
return _extends({
|
|
1137
|
+
label: parent ? parent.name + "\xB7" + item.name : item.name,
|
|
1138
|
+
value: item.code
|
|
1139
|
+
}, item);
|
|
773
1140
|
});
|
|
774
1141
|
}),
|
|
775
1142
|
getCityList: memoize__default["default"](() => {
|
|
776
|
-
return Object.values(city.list).map(item => ({
|
|
777
|
-
...item,
|
|
1143
|
+
return Object.values(city.list).map(item => _extends({}, item, {
|
|
778
1144
|
value: item.code,
|
|
779
1145
|
label: item.name
|
|
780
1146
|
}));
|
|
@@ -783,18 +1149,21 @@ const createAddressApi = _ref => {
|
|
|
783
1149
|
return apis;
|
|
784
1150
|
};
|
|
785
1151
|
const AddressInner = _ref2 => {
|
|
786
|
-
let
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
|
|
1152
|
+
let value = _ref2.value,
|
|
1153
|
+
setValue = _ref2.setValue,
|
|
1154
|
+
props = _ref2.props;
|
|
1155
|
+
const _useIntl = reactIntl.useIntl(),
|
|
1156
|
+
locale = _useIntl.locale,
|
|
1157
|
+
formatMessage = _useIntl.formatMessage;
|
|
1158
|
+
const _useState = react.useState(''),
|
|
1159
|
+
searchText = _useState[0],
|
|
1160
|
+
setSearchText = _useState[1];
|
|
1161
|
+
const _useState2 = react.useState('2'),
|
|
1162
|
+
menuKey = _useState2[0],
|
|
1163
|
+
setMenuKey = _useState2[1];
|
|
1164
|
+
const _useState3 = react.useState(null),
|
|
1165
|
+
cityData = _useState3[0],
|
|
1166
|
+
setCityData = _useState3[1];
|
|
798
1167
|
react.useEffect(() => {
|
|
799
1168
|
defaultCityData().then(result => {
|
|
800
1169
|
setCityData(result);
|
|
@@ -804,21 +1173,20 @@ const AddressInner = _ref2 => {
|
|
|
804
1173
|
if (!cityData) return null;
|
|
805
1174
|
return createAddressApi(cityData);
|
|
806
1175
|
}, [cityData]);
|
|
807
|
-
const {
|
|
808
|
-
getCity,
|
|
809
|
-
getChinaCities,
|
|
810
|
-
getCountries,
|
|
811
|
-
getList,
|
|
812
|
-
searchCities
|
|
813
|
-
} = addressApi || {};
|
|
1176
|
+
const _ref3 = addressApi || {},
|
|
1177
|
+
getCity = _ref3.getCity,
|
|
1178
|
+
getChinaCities = _ref3.getChinaCities,
|
|
1179
|
+
getCountries = _ref3.getCountries,
|
|
1180
|
+
getList = _ref3.getList,
|
|
1181
|
+
searchCities = _ref3.searchCities;
|
|
814
1182
|
const onSelect = react.useCallback(code => {
|
|
815
|
-
|
|
1183
|
+
var _cityData$city;
|
|
1184
|
+
const cityInfo = cityData == null || (_cityData$city = cityData.city) == null || (_cityData$city = _cityData$city.list) == null ? void 0 : _cityData$city[code];
|
|
816
1185
|
if (!cityInfo) return;
|
|
817
|
-
const item = {
|
|
1186
|
+
const item = _extends({
|
|
818
1187
|
value: code,
|
|
819
|
-
label: cityInfo.name
|
|
820
|
-
|
|
821
|
-
};
|
|
1188
|
+
label: cityInfo.name
|
|
1189
|
+
}, cityInfo);
|
|
822
1190
|
if (props.single) {
|
|
823
1191
|
setValue([item]);
|
|
824
1192
|
return;
|
|
@@ -858,7 +1226,7 @@ const AddressInner = _ref2 => {
|
|
|
858
1226
|
})
|
|
859
1227
|
})
|
|
860
1228
|
});
|
|
861
|
-
const currentCity = getCity
|
|
1229
|
+
const currentCity = getCity == null ? void 0 : getCity(menuKey);
|
|
862
1230
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
863
1231
|
className: classnames(style['address'], {
|
|
864
1232
|
[style['is-popup']]: props.isPopup
|
|
@@ -943,7 +1311,7 @@ const AddressInner = _ref2 => {
|
|
|
943
1311
|
children: [/*#__PURE__*/jsxRuntime.jsx(antd.Divider, {
|
|
944
1312
|
className: style['title'],
|
|
945
1313
|
orientation: "left",
|
|
946
|
-
children: currentCity
|
|
1314
|
+
children: currentCity != null && currentCity.city ? getLabelForLocal(currentCity.city, locale) : ''
|
|
947
1315
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
948
1316
|
className: style['scroll-box'],
|
|
949
1317
|
children: /*#__PURE__*/jsxRuntime.jsx(antd.Space, {
|
|
@@ -966,45 +1334,75 @@ const AddressInner = _ref2 => {
|
|
|
966
1334
|
});
|
|
967
1335
|
};
|
|
968
1336
|
const SelectAddressInner = /*#__PURE__*/react.forwardRef((props, ref) => {
|
|
969
|
-
const
|
|
970
|
-
formatMessage
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1337
|
+
const _useIntl2 = reactIntl.useIntl(),
|
|
1338
|
+
formatMessage = _useIntl2.formatMessage;
|
|
1339
|
+
const value = props.value,
|
|
1340
|
+
single = props.single,
|
|
1341
|
+
onChange = props.onChange,
|
|
1342
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
1343
|
+
const _useState4 = react.useState(null),
|
|
1344
|
+
cityData = _useState4[0],
|
|
1345
|
+
setCityData = _useState4[1];
|
|
1346
|
+
react.useEffect(() => {
|
|
1347
|
+
defaultCityData().then(setCityData);
|
|
1348
|
+
}, []);
|
|
1349
|
+
const addressApi = react.useMemo(() => cityData ? createAddressApi(cityData) : null, [cityData]);
|
|
1350
|
+
const normalizedValue = react.useMemo(() => resolveAddressValue(value, addressApi, {
|
|
1351
|
+
single
|
|
1352
|
+
}), [value, addressApi, single]);
|
|
1353
|
+
react.useEffect(() => {
|
|
1354
|
+
if (!onChange || !addressApi) {
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
const resolved = resolveAddressValue(value, addressApi, {
|
|
1358
|
+
single
|
|
1359
|
+
});
|
|
1360
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
1361
|
+
valueKey: 'value',
|
|
1362
|
+
labelKey: 'label',
|
|
1363
|
+
single
|
|
1364
|
+
})) {
|
|
1365
|
+
onChange(resolved);
|
|
1366
|
+
}
|
|
1367
|
+
}, [value, addressApi, single, onChange]);
|
|
1368
|
+
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectInput, _extends({
|
|
1369
|
+
ref: ref
|
|
1370
|
+
}, restProps, {
|
|
1371
|
+
single: single,
|
|
1372
|
+
value: normalizedValue,
|
|
1373
|
+
onChange: onChange,
|
|
1374
|
+
placeholder: restProps.placeholder || formatMessage({
|
|
976
1375
|
id: 'addressPlaceholder'
|
|
977
1376
|
}, {
|
|
978
1377
|
defaultMessage: '请选择城市'
|
|
979
1378
|
}),
|
|
980
1379
|
children: contextProps => {
|
|
981
|
-
const
|
|
982
|
-
|
|
983
|
-
setValue
|
|
984
|
-
} = contextProps;
|
|
1380
|
+
const currentValue = contextProps.value,
|
|
1381
|
+
setValue = contextProps.setValue;
|
|
985
1382
|
return /*#__PURE__*/jsxRuntime.jsx(AddressInner, {
|
|
986
|
-
value:
|
|
1383
|
+
value: currentValue,
|
|
987
1384
|
setValue: setValue,
|
|
988
1385
|
props: props
|
|
989
1386
|
});
|
|
990
1387
|
}
|
|
991
|
-
});
|
|
1388
|
+
}));
|
|
992
1389
|
});
|
|
993
|
-
const SelectAddress = withLocale(
|
|
994
|
-
let
|
|
995
|
-
single = false,
|
|
996
|
-
isPopup =
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1390
|
+
const SelectAddress = withLocale(_ref4 => {
|
|
1391
|
+
let _ref4$single = _ref4.single,
|
|
1392
|
+
single = _ref4$single === void 0 ? false : _ref4$single,
|
|
1393
|
+
_ref4$isPopup = _ref4.isPopup,
|
|
1394
|
+
isPopup = _ref4$isPopup === void 0 ? true : _ref4$isPopup,
|
|
1395
|
+
_ref4$showChinaQuan = _ref4.showChinaQuan,
|
|
1396
|
+
showChinaQuan = _ref4$showChinaQuan === void 0 ? false : _ref4$showChinaQuan,
|
|
1397
|
+
_ref4$showForeignQuan = _ref4.showForeignQuan,
|
|
1398
|
+
showForeignQuan = _ref4$showForeignQuan === void 0 ? false : _ref4$showForeignQuan,
|
|
1399
|
+
props = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
1400
|
+
return /*#__PURE__*/jsxRuntime.jsx(SelectAddressInner, _extends({
|
|
1002
1401
|
single: single,
|
|
1003
1402
|
isPopup: isPopup,
|
|
1004
1403
|
showChinaQuan: showChinaQuan,
|
|
1005
|
-
showForeignQuan: showForeignQuan
|
|
1006
|
-
|
|
1007
|
-
});
|
|
1404
|
+
showForeignQuan: showForeignQuan
|
|
1405
|
+
}, props));
|
|
1008
1406
|
}, 'SelectAddress');
|
|
1009
1407
|
SelectAddress.defaultData = defaultCityData;
|
|
1010
1408
|
SelectAddress.createAddressApi = createAddressApi;
|
|
@@ -1018,7 +1416,11 @@ var index = {
|
|
|
1018
1416
|
AddressEnum,
|
|
1019
1417
|
FunctionEnum,
|
|
1020
1418
|
IndustryEnum,
|
|
1021
|
-
EnumDisplay
|
|
1419
|
+
EnumDisplay,
|
|
1420
|
+
enumItemsToSelectValue,
|
|
1421
|
+
enumItemToSelectValue,
|
|
1422
|
+
addressEnumToSelectValue,
|
|
1423
|
+
addressEnumToSelectValueSingle
|
|
1022
1424
|
};
|
|
1023
1425
|
|
|
1024
1426
|
exports.AddressEnum = AddressEnum;
|
|
@@ -1028,6 +1430,10 @@ exports.IndustryEnum = IndustryEnum;
|
|
|
1028
1430
|
exports.SelectAddress = SelectAddress;
|
|
1029
1431
|
exports.SelectFunction = SelectFunction;
|
|
1030
1432
|
exports.SelectIndustry = SelectIndustry;
|
|
1433
|
+
exports.addressEnumToSelectValue = addressEnumToSelectValue;
|
|
1434
|
+
exports.addressEnumToSelectValueSingle = addressEnumToSelectValueSingle;
|
|
1031
1435
|
exports.createAddressApi = createAddressApi;
|
|
1032
1436
|
exports["default"] = index;
|
|
1437
|
+
exports.enumItemToSelectValue = enumItemToSelectValue;
|
|
1438
|
+
exports.enumItemsToSelectValue = enumItemsToSelectValue;
|
|
1033
1439
|
//# sourceMappingURL=index.js.map
|