@kne/super-select-plus 0.1.0

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.
@@ -0,0 +1,1020 @@
1
+ import { SelectCascader, SelectInput } from '@kne/super-select';
2
+ import { createWithIntlProvider, useIntl } from '@kne/react-intl';
3
+ import { useMemo, useState, useEffect, forwardRef, useCallback } from 'react';
4
+ import get from 'lodash/get';
5
+ import { withFetch } from '@kne/react-fetch';
6
+ import { jsx, jsxs } from 'react/jsx-runtime';
7
+ import memoize from 'lodash/memoize';
8
+ import cloneDeep from 'lodash/cloneDeep';
9
+ import { List, Row, Col, Tabs, Divider, Space, Tag } from 'antd';
10
+ import SearchInput from '@kne/search-input';
11
+ import '@kne/search-input/dist/index.css';
12
+ import '@kne/super-select/dist/index.css';
13
+
14
+ function _extends() {
15
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
16
+ for (var e = 1; e < arguments.length; e++) {
17
+ var t = arguments[e];
18
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
19
+ }
20
+ return n;
21
+ }, _extends.apply(null, arguments);
22
+ }
23
+ function _objectWithoutPropertiesLoose(r, e) {
24
+ if (null == r) return {};
25
+ var t = {};
26
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
27
+ if (-1 !== e.indexOf(n)) continue;
28
+ t[n] = r[n];
29
+ }
30
+ return t;
31
+ }
32
+
33
+ const locale$1 = {
34
+ placeholder: '请选择',
35
+ searchPlaceholder: '搜索',
36
+ // FunctionSelectField
37
+ functionPlaceholder: '请选择职能',
38
+ functionSearchPlaceholder: '搜索职能',
39
+ // IndustrySelectField
40
+ industryPlaceholder: '请选择行业',
41
+ industrySearchPlaceholder: '搜索行业',
42
+ // AddressSelectField
43
+ addressPlaceholder: '请选择城市',
44
+ addressSearchPlaceholder: '搜索城市',
45
+ domestic: '国内',
46
+ abroad: '国外'
47
+ };
48
+
49
+ const locale = {
50
+ placeholder: 'Please select',
51
+ searchPlaceholder: 'Search',
52
+ // FunctionSelectField
53
+ functionPlaceholder: 'Please select function',
54
+ functionSearchPlaceholder: 'Search function',
55
+ // IndustrySelectField
56
+ industryPlaceholder: 'Please select industry',
57
+ industrySearchPlaceholder: 'Search industry',
58
+ // AddressSelectField
59
+ addressPlaceholder: 'Please select city',
60
+ addressSearchPlaceholder: 'Search city',
61
+ domestic: 'Domestic',
62
+ abroad: 'Abroad'
63
+ };
64
+
65
+ const withLocale = createWithIntlProvider({
66
+ defaultLocale: 'zh-CN',
67
+ messages: {
68
+ 'zh-CN': locale$1,
69
+ 'en-US': locale
70
+ },
71
+ namespace: 'super-select-plus'
72
+ });
73
+
74
+ const _excluded$4 = ["data", "name", "type", "cache", "children", "getLabel", "dataFormat", "transformItem"];
75
+ const enumCache = new Map();
76
+
77
+ // 默认子组件渲染函数
78
+ const defaultChildren = item => get(item, 'label', '');
79
+
80
+ /**
81
+ * 默认获取标签函数
82
+ */
83
+ const defaultGetLabel = (item, locale) => {
84
+ if (locale === 'en-US') {
85
+ return get(item, 'enName') || get(item, 'name') || get(item, 'chName');
86
+ }
87
+ return get(item, 'name') || get(item, 'chName');
88
+ };
89
+
90
+ /**
91
+ * 默认数据格式化函数
92
+ */
93
+ const defaultDataFormat = data => data.data || data;
94
+
95
+ /**
96
+ * 默认映射项转换函数
97
+ */
98
+ const defaultTransformItem = (item, label) => _extends({}, item, {
99
+ id: item.code,
100
+ label,
101
+ parentId: item.parentCode || null
102
+ });
103
+
104
+ /**
105
+ * 内部枚举显示组件
106
+ */
107
+ const EnumDisplayInner = withFetch(_ref => {
108
+ let {
109
+ data,
110
+ name,
111
+ type,
112
+ cache: cacheKey,
113
+ children,
114
+ getLabel,
115
+ dataFormat,
116
+ transformItem
117
+ } = _ref,
118
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
119
+ const {
120
+ locale
121
+ } = useIntl();
122
+
123
+ // 格式化数据
124
+ const formattedData = useMemo(() => dataFormat(data), [data, dataFormat]);
125
+
126
+ // 创建映射表
127
+ const mapping = useMemo(() => {
128
+ return new Map(formattedData.map(item => {
129
+ const label = getLabel(item, locale);
130
+ const transformedItem = transformItem(item, label);
131
+ return [item.code, transformedItem];
132
+ }));
133
+ }, [formattedData, getLabel, locale, transformItem]);
134
+
135
+ // 获取枚举值
136
+ const output = mapping.get(name);
137
+
138
+ // 缓存结果
139
+ if (output && cacheKey && type) {
140
+ enumCache.set(`${cacheKey}_${type}_${name}`, output);
141
+ }
142
+ return children(output, _extends({}, props, {
143
+ locale,
144
+ mapping
145
+ }));
146
+ });
147
+
148
+ /**
149
+ * 枚举显示组件
150
+ */
151
+ const EnumDisplay = withLocale(props => {
152
+ useIntl();
153
+ const {
154
+ name,
155
+ type = 'default',
156
+ cache: cacheKey = 'ENUM_DATA',
157
+ force = false,
158
+ getLabel = defaultGetLabel,
159
+ dataFormat = defaultDataFormat,
160
+ transformItem = defaultTransformItem,
161
+ children = defaultChildren
162
+ } = props;
163
+
164
+ // 检查缓存
165
+ const key = `${cacheKey}_${type}_${name}`;
166
+ const cached = enumCache.get(key);
167
+ if (cached && !force) {
168
+ return children(cached, {
169
+ locale: props.locale
170
+ });
171
+ }
172
+ return /*#__PURE__*/jsx(EnumDisplayInner, _extends({}, props, {
173
+ type: type,
174
+ cache: cacheKey,
175
+ getLabel: getLabel,
176
+ dataFormat: dataFormat,
177
+ transformItem: transformItem,
178
+ children: children
179
+ }));
180
+ });
181
+
182
+ /**
183
+ * 创建特定枚举组件的工厂函数
184
+ * @param {Object} options 配置选项
185
+ * @param {string} options.type 枚举类型标识
186
+ * @param {string} options.cache 缓存键
187
+ * @param {Function} options.getLabel 获取标签函数
188
+ * @param {Function} options.dataFormat 数据格式化函数
189
+ * @param {Function} options.transformItem 映射项转换函数
190
+ * @param {Object} options.defaultApi 默认API配置
191
+ * @returns {React.Component} 枚举组件
192
+ */
193
+ const createEnumComponent = options => {
194
+ const {
195
+ type,
196
+ cache,
197
+ getLabel = defaultGetLabel,
198
+ dataFormat = defaultDataFormat,
199
+ transformItem = defaultTransformItem,
200
+ defaultApi
201
+ } = options;
202
+ const EnumComponent = withLocale(props => {
203
+ const {
204
+ name,
205
+ force = false,
206
+ children = defaultChildren
207
+ } = props;
208
+
209
+ // 检查缓存
210
+ const key = `${cache}_${type}_${name}`;
211
+ const cached = enumCache.get(key);
212
+ if (cached && !force) {
213
+ return children(cached, {
214
+ locale: props.locale
215
+ });
216
+ }
217
+ return /*#__PURE__*/jsx(EnumDisplayInner, _extends({}, props, defaultApi, {
218
+ type: type,
219
+ cache: cache,
220
+ getLabel: getLabel,
221
+ dataFormat: dataFormat,
222
+ transformItem: transformItem,
223
+ children: children
224
+ }));
225
+ });
226
+
227
+ // 附加静态属性
228
+ EnumComponent.getLabel = getLabel;
229
+ EnumComponent.defaultApi = defaultApi;
230
+ EnumComponent.type = type;
231
+ EnumComponent.cache = cache;
232
+ return EnumComponent;
233
+ };
234
+
235
+ // 导出缓存实例供外部使用
236
+ EnumDisplay.cache = enumCache;
237
+
238
+ /**
239
+ * 获取本地化标签
240
+ */
241
+ const getLabelForLocal$3 = (item, locale) => {
242
+ if (locale === 'en-US') {
243
+ return get(item, 'enName') || get(item, 'chName');
244
+ }
245
+ return get(item, 'chName');
246
+ };
247
+
248
+ /**
249
+ * 默认职能数据加载器
250
+ */
251
+ const defaultFunctionApi = {
252
+ cache: 'FUNCTION_DATA',
253
+ isLocal: true,
254
+ ttl: 1000 * 60 * 60 * 24,
255
+ // 24小时
256
+ loader: () => {
257
+ return import('./function-99219f66.js').then(module => module['__esModule'] ? module.default : module);
258
+ }
259
+ };
260
+
261
+ /**
262
+ * 职能枚举显示组件
263
+ */
264
+ const FunctionEnum = createEnumComponent({
265
+ type: 'function',
266
+ cache: 'FUNCTION_DATA',
267
+ getLabel: getLabelForLocal$3,
268
+ defaultApi: defaultFunctionApi
269
+ });
270
+
271
+ const _excluded$3 = ["value", "onChange", "single", "placeholder", "isPopup", "overlayWidth", "apis", "onSearch"];
272
+ const defaultFunctionData = () => {
273
+ return import('./function-99219f66.js').then(module => module['__esModule'] ? module.default : module);
274
+ };
275
+ const transformToCascaderData$1 = (data, locale) => {
276
+ // 创建映射表
277
+ const mapping = new Map();
278
+ data.forEach(item => {
279
+ mapping.set(item.code, _extends({}, item, {
280
+ id: item.code,
281
+ name: getLabelForLocal$3(item, locale),
282
+ children: []
283
+ }));
284
+ });
285
+
286
+ // 构建嵌套结构
287
+ const roots = [];
288
+ data.forEach(item => {
289
+ const node = mapping.get(item.code);
290
+ if (!item.parentCode || !mapping.has(item.parentCode)) {
291
+ roots.push(node);
292
+ } else {
293
+ const parent = mapping.get(item.parentCode);
294
+ parent.children.push(node);
295
+ }
296
+ });
297
+
298
+ // 清理空的 children 数组
299
+ const cleanEmptyChildren = nodes => {
300
+ nodes.forEach(node => {
301
+ if (node.children && node.children.length === 0) {
302
+ delete node.children;
303
+ } else if (node.children && node.children.length > 0) {
304
+ cleanEmptyChildren(node.children);
305
+ }
306
+ });
307
+ };
308
+ cleanEmptyChildren(roots);
309
+ return roots;
310
+ };
311
+ const SelectFunctionInner = _ref => {
312
+ let {
313
+ value,
314
+ onChange,
315
+ single = false,
316
+ placeholder,
317
+ isPopup = true,
318
+ overlayWidth = 320,
319
+ onSearch
320
+ } = _ref,
321
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
322
+ const {
323
+ locale,
324
+ formatMessage
325
+ } = useIntl();
326
+ const [data, setData] = useState([]);
327
+ useEffect(() => {
328
+ defaultFunctionData().then(result => {
329
+ setData(result.data || result);
330
+ });
331
+ }, []);
332
+ const options = useMemo(() => transformToCascaderData$1(data, locale), [data, locale]);
333
+ const handleSearch = (searchText, {
334
+ mapping
335
+ }) => {
336
+ if (!searchText) return Array.from(mapping.values());
337
+ const keyword = searchText.toLowerCase();
338
+ return Array.from(mapping.values()).filter(item => {
339
+ 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);
340
+ });
341
+ };
342
+ return /*#__PURE__*/jsx(SelectCascader, _extends({}, props, {
343
+ value: value,
344
+ onChange: onChange,
345
+ single: single,
346
+ placeholder: placeholder || formatMessage({
347
+ id: 'placeholder'
348
+ }, {
349
+ defaultMessage: '请选择职能'
350
+ }),
351
+ isPopup: isPopup,
352
+ menuItemWidth: 200,
353
+ style: _extends({
354
+ width: overlayWidth
355
+ }, props.style),
356
+ options: options,
357
+ valueKey: "id",
358
+ labelKey: "name",
359
+ onSearch: onSearch || handleSearch
360
+ }));
361
+ };
362
+ const SelectFunction = withLocale(SelectFunctionInner);
363
+ SelectFunction.defaultData = defaultFunctionData;
364
+ SelectFunction.Enum = FunctionEnum;
365
+
366
+ /**
367
+ * 获取本地化标签
368
+ */
369
+ const getLabelForLocal$2 = (item, locale) => {
370
+ if (locale === 'en-US') {
371
+ return get(item, 'enName') || get(item, 'chName');
372
+ }
373
+ return get(item, 'chName');
374
+ };
375
+
376
+ /**
377
+ * 默认行业数据加载器
378
+ */
379
+ const defaultIndustryApi = {
380
+ cache: 'INDUSTRY_DATA',
381
+ isLocal: true,
382
+ ttl: 1000 * 60 * 60 * 24,
383
+ // 24小时
384
+ loader: () => {
385
+ return import('./industry-8d720d2a.js').then(module => module['__esModule'] ? module.default : module);
386
+ }
387
+ };
388
+
389
+ /**
390
+ * 行业枚举显示组件
391
+ */
392
+ const IndustryEnum = createEnumComponent({
393
+ type: 'industry',
394
+ cache: 'INDUSTRY_DATA',
395
+ getLabel: getLabelForLocal$2,
396
+ defaultApi: defaultIndustryApi
397
+ });
398
+
399
+ const _excluded$2 = ["value", "onChange", "single", "placeholder", "isPopup", "overlayWidth", "apis", "onSearch"];
400
+ const defaultIndustryData = () => {
401
+ return import('./industry-8d720d2a.js').then(module => module['__esModule'] ? module.default : module);
402
+ };
403
+ const transformToCascaderData = (data, locale) => {
404
+ // 过滤掉"全部行业"
405
+ const filteredData = data.filter(item => item.code !== '000');
406
+
407
+ // 创建映射表
408
+ const mapping = new Map();
409
+ filteredData.forEach(item => {
410
+ mapping.set(item.code, _extends({}, item, {
411
+ id: item.code,
412
+ name: getLabelForLocal$2(item, locale),
413
+ children: []
414
+ }));
415
+ });
416
+
417
+ // 构建嵌套结构
418
+ const roots = [];
419
+ filteredData.forEach(item => {
420
+ const node = mapping.get(item.code);
421
+ if (!item.parentCode || !mapping.has(item.parentCode)) {
422
+ roots.push(node);
423
+ } else {
424
+ const parent = mapping.get(item.parentCode);
425
+ parent.children.push(node);
426
+ }
427
+ });
428
+
429
+ // 清理空的 children 数组
430
+ const cleanEmptyChildren = nodes => {
431
+ nodes.forEach(node => {
432
+ if (node.children && node.children.length === 0) {
433
+ delete node.children;
434
+ } else if (node.children && node.children.length > 0) {
435
+ cleanEmptyChildren(node.children);
436
+ }
437
+ });
438
+ };
439
+ cleanEmptyChildren(roots);
440
+ return roots;
441
+ };
442
+ const SelectIndustryInner = _ref => {
443
+ let {
444
+ value,
445
+ onChange,
446
+ single = false,
447
+ placeholder,
448
+ isPopup = true,
449
+ overlayWidth = 320,
450
+ onSearch
451
+ } = _ref,
452
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
453
+ const {
454
+ locale,
455
+ formatMessage
456
+ } = useIntl();
457
+ const [data, setData] = useState([]);
458
+ useEffect(() => {
459
+ defaultIndustryData().then(result => {
460
+ setData(result.data || result);
461
+ });
462
+ }, []);
463
+ const options = useMemo(() => transformToCascaderData(data, locale), [data, locale]);
464
+ const handleSearch = (searchText, {
465
+ mapping
466
+ }) => {
467
+ if (!searchText) return Array.from(mapping.values());
468
+ const keyword = searchText.toLowerCase();
469
+ return Array.from(mapping.values()).filter(item => {
470
+ 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);
471
+ });
472
+ };
473
+ return /*#__PURE__*/jsx(SelectCascader, _extends({}, props, {
474
+ value: value,
475
+ onChange: onChange,
476
+ single: single,
477
+ placeholder: placeholder || formatMessage({
478
+ id: 'placeholder'
479
+ }, {
480
+ defaultMessage: '请选择行业'
481
+ }),
482
+ isPopup: isPopup,
483
+ menuItemWidth: 200,
484
+ style: _extends({
485
+ width: overlayWidth
486
+ }, props.style),
487
+ options: options,
488
+ valueKey: "id",
489
+ labelKey: "name",
490
+ onSearch: onSearch || handleSearch
491
+ }));
492
+ };
493
+ const SelectIndustry = withLocale(SelectIndustryInner);
494
+ SelectIndustry.defaultData = defaultIndustryData;
495
+ SelectIndustry.Enum = IndustryEnum;
496
+
497
+ const _excluded$1 = ["data", "name", "children", "displayParent"],
498
+ _excluded2 = ["displayParent"];
499
+ const getLabelForLocal$1 = (item, locale) => {
500
+ if (locale === 'en-US') {
501
+ return get(item, 'enName') || get(item, 'name');
502
+ }
503
+ return get(item, 'name');
504
+ };
505
+
506
+ /**
507
+ * 默认地址数据加载器
508
+ */
509
+ const addressDefaultApi = {
510
+ cache: 'CITY_DATA',
511
+ isLocal: true,
512
+ ttl: 1000 * 60 * 60 * 24,
513
+ // 24小时
514
+ loader: () => {
515
+ return import('./city-5444842a.js').then(module => module['__esModule'] ? module.default : module);
516
+ }
517
+ };
518
+
519
+ /**
520
+ * 地址枚举显示组件
521
+ */
522
+ const AddressEnumInner = withFetch(_ref => {
523
+ let {
524
+ data,
525
+ name,
526
+ children,
527
+ displayParent
528
+ } = _ref,
529
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
530
+ const {
531
+ locale
532
+ } = useIntl();
533
+ const addressApi = useMemo(() => createAddressApi(data), [data]);
534
+
535
+ // 获取城市数据
536
+ const cityData = addressApi.getCity(name);
537
+ const {
538
+ city,
539
+ parent
540
+ } = cityData;
541
+
542
+ // 如果提供了自定义渲染函数
543
+ if (children) {
544
+ return children(cityData, _extends({
545
+ displayParent,
546
+ locale,
547
+ getLabelForLocal: getLabelForLocal$1
548
+ }, props));
549
+ }
550
+
551
+ // 默认渲染逻辑
552
+ if (!city) {
553
+ return '';
554
+ }
555
+ if (displayParent && parent) {
556
+ return `${getLabelForLocal$1(parent, locale)}·${getLabelForLocal$1(city, locale)}`;
557
+ }
558
+ return getLabelForLocal$1(city, locale);
559
+ });
560
+ const AddressEnum = withLocale(props => {
561
+ const {
562
+ displayParent = false
563
+ } = props,
564
+ restProps = _objectWithoutPropertiesLoose(props, _excluded2);
565
+ return /*#__PURE__*/jsx(AddressEnumInner, _extends({}, addressDefaultApi, {
566
+ displayParent: displayParent
567
+ }, restProps));
568
+ });
569
+ AddressEnum.addressDefaultApi = addressDefaultApi;
570
+
571
+ function createCommonjsModule(fn) {
572
+ var module = { exports: {} };
573
+ return fn(module, module.exports), module.exports;
574
+ }
575
+
576
+ /*!
577
+ Copyright (c) 2018 Jed Watson.
578
+ Licensed under the MIT License (MIT), see
579
+ http://jedwatson.github.io/classnames
580
+ */
581
+
582
+ var classnames = createCommonjsModule(function (module) {
583
+ /* global define */
584
+
585
+ (function () {
586
+
587
+ var hasOwn = {}.hasOwnProperty;
588
+
589
+ function classNames () {
590
+ var classes = '';
591
+
592
+ for (var i = 0; i < arguments.length; i++) {
593
+ var arg = arguments[i];
594
+ if (arg) {
595
+ classes = appendClass(classes, parseValue(arg));
596
+ }
597
+ }
598
+
599
+ return classes;
600
+ }
601
+
602
+ function parseValue (arg) {
603
+ if (typeof arg === 'string' || typeof arg === 'number') {
604
+ return arg;
605
+ }
606
+
607
+ if (typeof arg !== 'object') {
608
+ return '';
609
+ }
610
+
611
+ if (Array.isArray(arg)) {
612
+ return classNames.apply(null, arg);
613
+ }
614
+
615
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
616
+ return arg.toString();
617
+ }
618
+
619
+ var classes = '';
620
+
621
+ for (var key in arg) {
622
+ if (hasOwn.call(arg, key) && arg[key]) {
623
+ classes = appendClass(classes, key);
624
+ }
625
+ }
626
+
627
+ return classes;
628
+ }
629
+
630
+ function appendClass (value, newClass) {
631
+ if (!newClass) {
632
+ return value;
633
+ }
634
+
635
+ if (value) {
636
+ return value + ' ' + newClass;
637
+ }
638
+
639
+ return value + newClass;
640
+ }
641
+
642
+ if (module.exports) {
643
+ classNames.default = classNames;
644
+ module.exports = classNames;
645
+ } else {
646
+ window.classNames = classNames;
647
+ }
648
+ }());
649
+ });
650
+
651
+ var style = {"address":"_MMoPf","is-popup":"_bYKMf","title":"_pKOHI","scroll-box":"_MObpF","scroll-plus-box":"_iKm8i","content":"_BfCap","col-left":"_BEChX","menu-list":"_gXzFG","menu-item":"_LasXn","col-right":"_1jQmu","search-input":"_YB45l","list":"_Y-MIq","list-item":"_6JEMZ","item-label":"_nlduJ"};
652
+
653
+ const _excluded = ["single", "isPopup", "showChinaQuan", "showForeignQuan"];
654
+ const getLabelForLocal = (item, locale) => {
655
+ if (locale === 'en-US') {
656
+ return get(item, 'enName') || get(item, 'name');
657
+ }
658
+ return get(item, 'name');
659
+ };
660
+ const defaultCityData = () => {
661
+ return import('./city-5444842a.js').then(module => module['__esModule'] ? module.default : module);
662
+ };
663
+ const createAddressApi = ({
664
+ city,
665
+ province,
666
+ country
667
+ }) => {
668
+ const getSearchList = memoize(() => {
669
+ const list = [];
670
+ ['gangaotai', 'municipality'].forEach(name => {
671
+ list.push(...(city.relations[name] || []));
672
+ });
673
+ ['provinces', 'continents'].forEach(name => {
674
+ (city.relations[name] || []).forEach(id => {
675
+ list.push(id);
676
+ list.push(...(city.relations[id] || []));
677
+ });
678
+ });
679
+ return list.map(id => city.list[id]).filter(Boolean);
680
+ });
681
+ const apis = {
682
+ getCity: memoize(id => {
683
+ const item = city.list[id] || apis.getCityByName(id);
684
+ if (!item) {
685
+ return {
686
+ city: null,
687
+ parent: null
688
+ };
689
+ }
690
+ return {
691
+ city: item,
692
+ parent: item.parentCode ? city.list[item.parentCode] : null
693
+ };
694
+ }),
695
+ getChinaHotCities: memoize(() => {
696
+ return (city.relations['2'] || []).map(id => city.list[id]).filter(Boolean);
697
+ }),
698
+ getChinaCities: memoize(() => {
699
+ return ['2', ...(province.relations.municipality || []), ...(province.relations.provinces || []), 'gangaotai'].map(id => Object.assign({
700
+ id
701
+ }, city.list[id])).filter(item => item.code);
702
+ }),
703
+ getCountries: memoize(() => {
704
+ return ['1', ...(country.relations.continents || [])].map(id => Object.assign({
705
+ id
706
+ }, country.list[id])).filter(item => item.code);
707
+ }),
708
+ getList: memoize((pid, options) => {
709
+ const {
710
+ showChinaQuan,
711
+ showForeignQuan
712
+ } = Object.assign({}, options);
713
+ if (pid === 'gangaotai') {
714
+ return (province.relations['gangaotai'] || []).map(id => city.list[id]).filter(Boolean);
715
+ }
716
+ const current = Object.assign({}, city.list[pid]);
717
+ if ((province.relations.municipality || []).indexOf(pid) > -1) {
718
+ current.name = `${showChinaQuan ? '全' : ''}${current.name}`;
719
+ return [current];
720
+ }
721
+ const list = (city.relations[pid] || []).map(id => city.list[id]).filter(Boolean);
722
+ if ((province.relations.provinces || []).indexOf(pid) > -1 && showChinaQuan) {
723
+ current.name = `全${current.name}`;
724
+ list.splice(0, 0, current);
725
+ }
726
+ if ((country.relations.continents || []).indexOf(pid) > -1 && showForeignQuan) {
727
+ current.name = `全${current.name}`;
728
+ list.splice(0, 0, current);
729
+ }
730
+ return list;
731
+ }),
732
+ getNationalityList: memoize(pid => {
733
+ let _city = cloneDeep(city);
734
+ if (pid === '1') {
735
+ _city.relations['1'].unshift('410');
736
+ }
737
+ if (pid === '350') {
738
+ _city.relations['350'].unshift('410');
739
+ }
740
+ return _city.relations[pid].filter(id => _city.list[id]).map(id => _city.list[id]);
741
+ }),
742
+ getCityByName: memoize(name => {
743
+ const searchList = getSearchList();
744
+ let item;
745
+ [item => item.name === name, item => item.name === name.replace(/(省|市)$/, ''), item => name.indexOf(item.name) === 0].find(func => {
746
+ item = searchList.find(func);
747
+ return item;
748
+ });
749
+ return item;
750
+ }),
751
+ combineCities: memoize((currentId, list) => {
752
+ return [...list.filter(item => {
753
+ return city.list[item].parentCode !== currentId && city.list[currentId].parentCode !== item && currentId !== item;
754
+ }), currentId];
755
+ }),
756
+ searchCities: memoize(value => {
757
+ if (!value) {
758
+ return [];
759
+ }
760
+ const searchList = getSearchList();
761
+ return searchList.filter(item => {
762
+ return ['pinyin', 'name', 'enName', 'spelling'].some(name => {
763
+ return (item[name] || '').toUpperCase().indexOf(value.toUpperCase()) > -1;
764
+ });
765
+ }).map(item => {
766
+ const parent = item.parentCode ? city.list[item.parentCode] : null;
767
+ return _extends({
768
+ label: parent ? `${parent.name}·${item.name}` : item.name,
769
+ value: item.code
770
+ }, item);
771
+ });
772
+ }),
773
+ getCityList: memoize(() => {
774
+ return Object.values(city.list).map(item => _extends({}, item, {
775
+ value: item.code,
776
+ label: item.name
777
+ }));
778
+ })
779
+ };
780
+ return apis;
781
+ };
782
+ const AddressInner = ({
783
+ value,
784
+ setValue,
785
+ props
786
+ }) => {
787
+ const {
788
+ locale,
789
+ formatMessage
790
+ } = useIntl();
791
+ const [searchText, setSearchText] = useState('');
792
+ const [menuKey, setMenuKey] = useState('2');
793
+ const [cityData, setCityData] = useState(null);
794
+ useEffect(() => {
795
+ defaultCityData().then(result => {
796
+ setCityData(result);
797
+ });
798
+ }, []);
799
+ const addressApi = useMemo(() => {
800
+ if (!cityData) return null;
801
+ return createAddressApi(cityData);
802
+ }, [cityData]);
803
+ const {
804
+ getCity,
805
+ getChinaCities,
806
+ getCountries,
807
+ getList,
808
+ searchCities
809
+ } = addressApi || {};
810
+ const onSelect = useCallback(code => {
811
+ var _cityData$city;
812
+ const cityInfo = cityData == null || (_cityData$city = cityData.city) == null || (_cityData$city = _cityData$city.list) == null ? void 0 : _cityData$city[code];
813
+ if (!cityInfo) return;
814
+ const item = _extends({
815
+ value: code,
816
+ label: cityInfo.name
817
+ }, cityInfo);
818
+ if (props.single) {
819
+ setValue([item]);
820
+ return;
821
+ }
822
+ setValue(prev => {
823
+ const newValue = prev.slice(0);
824
+ const index = newValue.findIndex(v => v.value === code);
825
+ if (index > -1) {
826
+ newValue.splice(index, 1);
827
+ } else {
828
+ newValue.push(item);
829
+ }
830
+ return newValue;
831
+ });
832
+ }, [cityData, props.single, setValue]);
833
+ if (!addressApi) {
834
+ return null;
835
+ }
836
+ const selectedValues = (value || []).map(v => v.value);
837
+ const searchInner = searchText && /*#__PURE__*/jsx("div", {
838
+ className: style['scroll-plus-box'],
839
+ children: /*#__PURE__*/jsx(List, {
840
+ className: style['list'],
841
+ size: "small",
842
+ dataSource: searchCities(searchText),
843
+ rowKey: "value",
844
+ renderItem: item => /*#__PURE__*/jsx(List.Item, {
845
+ className: style['list-item'],
846
+ onClick: () => {
847
+ onSelect(item.value);
848
+ setSearchText('');
849
+ },
850
+ children: /*#__PURE__*/jsx("span", {
851
+ className: style['item-label'],
852
+ children: item.label
853
+ })
854
+ })
855
+ })
856
+ });
857
+ const currentCity = getCity == null ? void 0 : getCity(menuKey);
858
+ return /*#__PURE__*/jsxs("div", {
859
+ className: classnames(style['address'], {
860
+ [style['is-popup']]: props.isPopup
861
+ }),
862
+ children: [/*#__PURE__*/jsx(SearchInput, {
863
+ className: classnames(style['search-input'], {
864
+ [style['is-popup']]: props.isPopup,
865
+ 'is-popup': props.isPopup
866
+ }),
867
+ placeholder: props.searchPlaceholder || formatMessage({
868
+ id: 'addressSearchPlaceholder'
869
+ }, {
870
+ defaultMessage: '搜索城市'
871
+ }),
872
+ value: searchText,
873
+ onChange: e => {
874
+ setSearchText(e.target.value);
875
+ },
876
+ onSearch: value => {
877
+ setSearchText(value);
878
+ }
879
+ }), /*#__PURE__*/jsx("div", {
880
+ className: style['content'],
881
+ children: searchInner || /*#__PURE__*/jsxs(Row, {
882
+ wrap: false,
883
+ children: [/*#__PURE__*/jsx(Col, {
884
+ className: style['col-left'],
885
+ children: /*#__PURE__*/jsx(Tabs, {
886
+ centered: true,
887
+ onChange: activeKey => {
888
+ setMenuKey(activeKey);
889
+ },
890
+ items: [{
891
+ key: '2',
892
+ label: formatMessage({
893
+ id: 'domestic'
894
+ }, {
895
+ defaultMessage: '国内'
896
+ }),
897
+ children: /*#__PURE__*/jsx("div", {
898
+ className: style['scroll-box'],
899
+ children: /*#__PURE__*/jsx(List, {
900
+ className: style['menu-list'],
901
+ dataSource: getChinaCities(),
902
+ rowKey: "id",
903
+ renderItem: item => /*#__PURE__*/jsx(List.Item, {
904
+ className: menuKey === item.id ? 'selected' : '',
905
+ onClick: () => {
906
+ setMenuKey(item.id);
907
+ },
908
+ children: getLabelForLocal(item, locale)
909
+ })
910
+ })
911
+ })
912
+ }, {
913
+ key: '1',
914
+ label: formatMessage({
915
+ id: 'abroad'
916
+ }, {
917
+ defaultMessage: '国外'
918
+ }),
919
+ children: /*#__PURE__*/jsx("div", {
920
+ className: style['scroll-box'],
921
+ children: /*#__PURE__*/jsx(List, {
922
+ className: style['menu-list'],
923
+ dataSource: getCountries(),
924
+ rowKey: "id",
925
+ renderItem: item => /*#__PURE__*/jsx(List.Item, {
926
+ className: menuKey === item.id ? 'selected' : '',
927
+ onClick: () => {
928
+ setMenuKey(item.id);
929
+ },
930
+ children: getLabelForLocal(item, locale)
931
+ })
932
+ })
933
+ })
934
+ }]
935
+ })
936
+ }), /*#__PURE__*/jsxs(Col, {
937
+ flex: 1,
938
+ className: style['col-right'],
939
+ children: [/*#__PURE__*/jsx(Divider, {
940
+ className: style['title'],
941
+ orientation: "left",
942
+ children: currentCity != null && currentCity.city ? getLabelForLocal(currentCity.city, locale) : ''
943
+ }), /*#__PURE__*/jsx("div", {
944
+ className: style['scroll-box'],
945
+ children: /*#__PURE__*/jsx(Space, {
946
+ wrap: true,
947
+ children: getList(menuKey, {
948
+ showChinaQuan: props.showChinaQuan,
949
+ showForeignQuan: props.showForeignQuan
950
+ }).map(item => /*#__PURE__*/jsx(Tag.CheckableTag, {
951
+ checked: selectedValues.indexOf(item.code) > -1,
952
+ onChange: () => {
953
+ onSelect(item.code);
954
+ },
955
+ children: getLabelForLocal(item, locale)
956
+ }, item.code))
957
+ })
958
+ })]
959
+ })]
960
+ })
961
+ })]
962
+ });
963
+ };
964
+ const SelectAddressInner = /*#__PURE__*/forwardRef((props, ref) => {
965
+ const {
966
+ formatMessage
967
+ } = useIntl();
968
+ return /*#__PURE__*/jsx(SelectInput, _extends({
969
+ ref: ref
970
+ }, props, {
971
+ placeholder: props.placeholder || formatMessage({
972
+ id: 'addressPlaceholder'
973
+ }, {
974
+ defaultMessage: '请选择城市'
975
+ }),
976
+ children: contextProps => {
977
+ const {
978
+ value,
979
+ setValue
980
+ } = contextProps;
981
+ return /*#__PURE__*/jsx(AddressInner, {
982
+ value: value,
983
+ setValue: setValue,
984
+ props: props
985
+ });
986
+ }
987
+ }));
988
+ });
989
+ const SelectAddress = withLocale(_ref => {
990
+ let {
991
+ single = false,
992
+ isPopup = true,
993
+ showChinaQuan = false,
994
+ showForeignQuan = false
995
+ } = _ref,
996
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
997
+ return /*#__PURE__*/jsx(SelectAddressInner, _extends({
998
+ single: single,
999
+ isPopup: isPopup,
1000
+ showChinaQuan: showChinaQuan,
1001
+ showForeignQuan: showForeignQuan
1002
+ }, props));
1003
+ }, 'SelectAddress');
1004
+ SelectAddress.defaultData = defaultCityData;
1005
+ SelectAddress.createAddressApi = createAddressApi;
1006
+ SelectAddress.Enum = AddressEnum;
1007
+
1008
+ // 默认导出
1009
+ var index = {
1010
+ SelectFunction,
1011
+ SelectIndustry,
1012
+ SelectAddress,
1013
+ AddressEnum,
1014
+ FunctionEnum,
1015
+ IndustryEnum,
1016
+ EnumDisplay
1017
+ };
1018
+
1019
+ export { AddressEnum, EnumDisplay, FunctionEnum, IndustryEnum, SelectAddress, SelectFunction, SelectIndustry, createAddressApi, index as default };
1020
+ //# sourceMappingURL=index.modern.js.map