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