@kne/super-select 0.1.32 → 0.1.34
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 +2001 -423
- package/dist/index.css +350 -6
- package/dist/index.css.map +1 -1
- package/dist/index.js +992 -116
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +971 -90
- package/dist/index.modern.js.map +1 -1
- package/package.json +15 -3
package/dist/index.modern.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { forwardRef,
|
|
1
|
+
import React, { useState, useRef, useLayoutEffect, forwardRef, useMemo, useImperativeHandle, useEffect, useCallback } from 'react';
|
|
2
2
|
import { createContext } from '@kne/global-context';
|
|
3
3
|
import useResize from '@kne/use-resize';
|
|
4
4
|
import useControlValue from '@kne/use-control-value';
|
|
5
5
|
import classnames from 'classnames';
|
|
6
6
|
import isEqual from 'lodash/isEqual';
|
|
7
7
|
import last from 'lodash/last';
|
|
8
|
-
import { Modal, App, Dropdown, Flex,
|
|
9
|
-
import { CloseCircleFilled, DownOutlined, CheckOutlined } from '@ant-design/icons';
|
|
8
|
+
import { Tag, Modal, App, Dropdown, Flex, Checkbox, List, Empty, Row, Col, Button, Popover, Tree, Space, Badge, Spin } from 'antd';
|
|
9
|
+
import { CloseCircleFilled, DownOutlined, CheckOutlined, RightOutlined } from '@ant-design/icons';
|
|
10
10
|
import { isNotEmpty } from '@kne/is-empty';
|
|
11
11
|
import { createWithIntlProvider, useIntl } from '@kne/react-intl';
|
|
12
12
|
import get from 'lodash/get';
|
|
@@ -46,7 +46,7 @@ const {
|
|
|
46
46
|
useContext
|
|
47
47
|
} = context;
|
|
48
48
|
|
|
49
|
-
var style$
|
|
49
|
+
var style$6 = {"select-input":"_d8lGc","disabled":"_3kjwO","wrap":"_dsTM2","select-input-inner":"_NQoX9","large":"_T8ZX8","small":"_1B72H","single-label":"_pL0tE","tag-item":"_lc4o7","tag-label":"_RJmlD","overflow-tag":"_aHua2","measure-layer":"_QoQpC","select-input-icon":"_g8QC-","placeholder":"_r3q69","overlay-content":"_zEqGe","overlay":"_ybN30","select-input-prefix":"_4Pw75","select-input-suffix":"_Wd4pE"};
|
|
50
50
|
|
|
51
51
|
const locale$1 = {
|
|
52
52
|
placeholder: '请选择',
|
|
@@ -70,8 +70,98 @@ const locale = {
|
|
|
70
70
|
removeAll: 'Remove All'
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
/**
|
|
74
|
+
* 标签溢出内部渲染组件
|
|
75
|
+
* 根据 innerWidth 计算标签显示数量
|
|
76
|
+
*/
|
|
77
|
+
const TagOverflowInner = ({
|
|
78
|
+
value,
|
|
79
|
+
innerWidth,
|
|
80
|
+
labelKey,
|
|
81
|
+
valueKey,
|
|
82
|
+
onRemove,
|
|
83
|
+
overflowTagWidth: _overflowTagWidth = 45,
|
|
84
|
+
iconSpace: _iconSpace = 20
|
|
85
|
+
}) => {
|
|
86
|
+
const [visibleCount, setVisibleCount] = useState(value.length);
|
|
87
|
+
const measureRef = useRef(null);
|
|
88
|
+
|
|
89
|
+
// 测量每个标签的实际宽度并计算可见数量
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
// innerWidth 为 0 时,保持当前状态,等待正确的宽度
|
|
92
|
+
if (!measureRef.current || innerWidth === 0 || value.length === 0) {
|
|
93
|
+
setVisibleCount(value.length);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const tagElements = measureRef.current.querySelectorAll('[data-tag-measure]');
|
|
97
|
+
if (tagElements.length === 0) return;
|
|
98
|
+
|
|
99
|
+
// 获取每个标签的实际占用宽度(包含 margin)
|
|
100
|
+
const tagWidths = Array.from(tagElements).map(el => {
|
|
101
|
+
const style = window.getComputedStyle(el);
|
|
102
|
+
const marginLeft = parseFloat(style.marginLeft) || 0;
|
|
103
|
+
const marginRight = parseFloat(style.marginRight) || 0;
|
|
104
|
+
return el.offsetWidth + marginLeft + marginRight;
|
|
105
|
+
});
|
|
106
|
+
const availableWidth = innerWidth - _iconSpace;
|
|
107
|
+
let totalWidth = 0;
|
|
108
|
+
let count = 0;
|
|
109
|
+
for (let i = 0; i < tagWidths.length; i++) {
|
|
110
|
+
// 如果不是最后一个,需要预留 +N 标签空间
|
|
111
|
+
const needOverflowSpace = i < tagWidths.length - 1;
|
|
112
|
+
const requiredWidth = tagWidths[i] + (needOverflowSpace ? _overflowTagWidth : 0);
|
|
113
|
+
if (totalWidth + requiredWidth <= availableWidth) {
|
|
114
|
+
totalWidth += tagWidths[i];
|
|
115
|
+
count++;
|
|
116
|
+
} else {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 确保至少显示一个标签
|
|
122
|
+
setVisibleCount(Math.max(1, count));
|
|
123
|
+
}, [value, innerWidth, _overflowTagWidth, _iconSpace]);
|
|
124
|
+
|
|
125
|
+
// 计算单个标签最大宽度:min(150px, innerWidth - 60),初始状态默认 150px
|
|
126
|
+
const maxTagWidth = innerWidth > 0 ? Math.min(150, Math.max(60, innerWidth - 60)) : 150;
|
|
127
|
+
const displayTags = value.slice(0, visibleCount);
|
|
128
|
+
const hiddenCount = value.length - visibleCount;
|
|
129
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
130
|
+
ref: measureRef,
|
|
131
|
+
className: style$6['measure-layer']
|
|
132
|
+
}, value.map(item => /*#__PURE__*/React.createElement(Tag, {
|
|
133
|
+
key: item[valueKey],
|
|
134
|
+
"data-tag-measure": true,
|
|
135
|
+
closable: true,
|
|
136
|
+
bordered: false,
|
|
137
|
+
className: style$6['tag-item'],
|
|
138
|
+
style: {
|
|
139
|
+
'--max-tag-width': `${maxTagWidth}px`
|
|
140
|
+
}
|
|
141
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
142
|
+
className: style$6['tag-label']
|
|
143
|
+
}, item[labelKey])))), displayTags.map(item => /*#__PURE__*/React.createElement(Tag, {
|
|
144
|
+
key: item[valueKey],
|
|
145
|
+
closable: true,
|
|
146
|
+
bordered: false,
|
|
147
|
+
className: style$6['tag-item'],
|
|
148
|
+
style: {
|
|
149
|
+
'--max-tag-width': `${maxTagWidth}px`
|
|
150
|
+
},
|
|
151
|
+
onClose: e => {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
onRemove(item);
|
|
154
|
+
}
|
|
155
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
156
|
+
className: style$6['tag-label'],
|
|
157
|
+
title: item[labelKey]
|
|
158
|
+
}, item[labelKey]))), hiddenCount > 0 && /*#__PURE__*/React.createElement(Tag, {
|
|
159
|
+
className: style$6['overflow-tag']
|
|
160
|
+
}, "+", hiddenCount));
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const _excluded$3 = ["children"];
|
|
164
|
+
const numberToPx$1 = val => {
|
|
75
165
|
return typeof val === 'number' ? `${val}px` : val;
|
|
76
166
|
};
|
|
77
167
|
const pxToNumber = value => {
|
|
@@ -86,7 +176,7 @@ const ModalContent = _ref => {
|
|
|
86
176
|
let {
|
|
87
177
|
children
|
|
88
178
|
} = _ref,
|
|
89
|
-
others = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
179
|
+
others = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
90
180
|
const {
|
|
91
181
|
open,
|
|
92
182
|
value: propsValue
|
|
@@ -154,6 +244,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
154
244
|
prefix: null,
|
|
155
245
|
suffix: null,
|
|
156
246
|
extra: null,
|
|
247
|
+
size: 'default',
|
|
157
248
|
renderModal: contextProps => {
|
|
158
249
|
const {
|
|
159
250
|
props,
|
|
@@ -201,7 +292,8 @@ const SelectInput = createWithIntlProvider({
|
|
|
201
292
|
placement,
|
|
202
293
|
renderModal,
|
|
203
294
|
labelKey,
|
|
204
|
-
valueKey
|
|
295
|
+
valueKey,
|
|
296
|
+
size
|
|
205
297
|
} = props;
|
|
206
298
|
const transformValue = value => {
|
|
207
299
|
if (single) {
|
|
@@ -226,11 +318,21 @@ const SelectInput = createWithIntlProvider({
|
|
|
226
318
|
onChange: 'onOpenChange'
|
|
227
319
|
});
|
|
228
320
|
const [hover, setHover] = useState(false);
|
|
229
|
-
const [
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
321
|
+
const [innerWidth, setInnerWidth] = useState(0);
|
|
322
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
323
|
+
const containerWidthChange = el => {
|
|
324
|
+
if (!el) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const containerWidth = el.clientWidth;
|
|
328
|
+
setContainerWidth(containerWidth);
|
|
329
|
+
const innerEl = el.querySelector('.select-input-inner');
|
|
330
|
+
setInnerWidth(innerEl.clientWidth);
|
|
331
|
+
};
|
|
332
|
+
const popupOverlayWidth = useMemo(() => {
|
|
333
|
+
return numberToPx$1(Math.max(containerWidth, pxToNumber(overlayWidth)));
|
|
334
|
+
}, [containerWidth, overlayWidth]);
|
|
335
|
+
const containerRef = useResize(containerWidthChange);
|
|
234
336
|
const {
|
|
235
337
|
message
|
|
236
338
|
} = App.useApp();
|
|
@@ -290,7 +392,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
290
392
|
searchProps,
|
|
291
393
|
setSearchProps,
|
|
292
394
|
hover,
|
|
293
|
-
inputWidth,
|
|
395
|
+
inputWidth: containerWidth,
|
|
294
396
|
onAdd,
|
|
295
397
|
onRemove,
|
|
296
398
|
onSelect,
|
|
@@ -303,10 +405,12 @@ const SelectInput = createWithIntlProvider({
|
|
|
303
405
|
return contextProps.props.inputRender(props, contextProps);
|
|
304
406
|
}
|
|
305
407
|
return /*#__PURE__*/React.createElement(Flex, _extends({}, props, {
|
|
306
|
-
ref:
|
|
307
|
-
className: classnames(className, style$
|
|
308
|
-
[style$
|
|
309
|
-
[style$
|
|
408
|
+
ref: containerRef,
|
|
409
|
+
className: classnames(className, style$6['select-input'], 'select-input', {
|
|
410
|
+
[style$6['wrap']]: labelWrap,
|
|
411
|
+
[style$6['disabled']]: disabled,
|
|
412
|
+
[style$6['small']]: size === 'small',
|
|
413
|
+
[style$6['large']]: size === 'large'
|
|
310
414
|
}),
|
|
311
415
|
justify: "space-between",
|
|
312
416
|
onMouseOver: () => {
|
|
@@ -318,27 +422,26 @@ const SelectInput = createWithIntlProvider({
|
|
|
318
422
|
}), (() => {
|
|
319
423
|
const current = typeof prefix === 'function' ? prefix(contextProps) : prefix;
|
|
320
424
|
return current && /*#__PURE__*/React.createElement("span", {
|
|
321
|
-
className: classnames(style$
|
|
425
|
+
className: classnames(style$6['select-input-prefix'], 'select-input-prefix'),
|
|
322
426
|
onClick: e => {
|
|
323
427
|
e.stopPropagation();
|
|
324
428
|
}
|
|
325
429
|
}, current);
|
|
326
430
|
})(), /*#__PURE__*/React.createElement("div", {
|
|
327
|
-
className: classnames(style$
|
|
328
|
-
}, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ?
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}, item[labelKey]);
|
|
431
|
+
className: classnames(style$6['select-input-inner'], 'select-input-inner')
|
|
432
|
+
}, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ? /*#__PURE__*/React.createElement("span", {
|
|
433
|
+
className: classnames(style$6['single-label'], 'select-input-single-label'),
|
|
434
|
+
title: value[0][labelKey]
|
|
435
|
+
}, value[0][labelKey]) : /*#__PURE__*/React.createElement(TagOverflowInner, {
|
|
436
|
+
value: value,
|
|
437
|
+
innerWidth: innerWidth,
|
|
438
|
+
labelKey: labelKey,
|
|
439
|
+
valueKey: valueKey,
|
|
440
|
+
onRemove: onRemove
|
|
338
441
|
}) : /*#__PURE__*/React.createElement("span", {
|
|
339
|
-
className: classnames(style$
|
|
442
|
+
className: classnames(style$6['placeholder'], 'select-input-placeholder')
|
|
340
443
|
}, placeholder)), /*#__PURE__*/React.createElement("div", {
|
|
341
|
-
className: classnames(style$
|
|
444
|
+
className: classnames(style$6['select-input-icon'], 'select-input-icon')
|
|
342
445
|
}, !disabled && allowClear && hover && value.length > 0 ? /*#__PURE__*/React.createElement(CloseCircleFilled, {
|
|
343
446
|
onClick: e => {
|
|
344
447
|
e.stopPropagation();
|
|
@@ -347,7 +450,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
347
450
|
}) : /*#__PURE__*/React.createElement(DownOutlined, null)), (() => {
|
|
348
451
|
const current = typeof suffix === 'function' ? suffix(contextProps) : suffix;
|
|
349
452
|
return current && /*#__PURE__*/React.createElement("span", {
|
|
350
|
-
className: classnames(style$
|
|
453
|
+
className: classnames(style$6['select-input-suffix'], 'select-input-suffix'),
|
|
351
454
|
onClick: e => {
|
|
352
455
|
e.stopPropagation();
|
|
353
456
|
}
|
|
@@ -367,13 +470,13 @@ const SelectInput = createWithIntlProvider({
|
|
|
367
470
|
onOpenChange: setOpen,
|
|
368
471
|
placement: placement,
|
|
369
472
|
arrow: false,
|
|
370
|
-
overlayClassName: classnames(style$
|
|
473
|
+
overlayClassName: classnames(style$6['overlay'], overlayClassName),
|
|
371
474
|
trigger: "click",
|
|
372
475
|
popupRender: () => /*#__PURE__*/React.createElement("div", {
|
|
373
476
|
style: {
|
|
374
477
|
'--overlay-width': popupOverlayWidth
|
|
375
478
|
},
|
|
376
|
-
className: classnames(style$
|
|
479
|
+
className: classnames(style$6['overlay-content'], 'over-content'),
|
|
377
480
|
onClick: e => {
|
|
378
481
|
e.stopPropagation();
|
|
379
482
|
}
|
|
@@ -385,7 +488,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
385
488
|
}), /*#__PURE__*/React.createElement(ModalContent, contextProps, renderModal)));
|
|
386
489
|
}));
|
|
387
490
|
|
|
388
|
-
var style$
|
|
491
|
+
var style$5 = {"selected-all":"_prlgN"};
|
|
389
492
|
|
|
390
493
|
const SelectedAll = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
391
494
|
const {
|
|
@@ -410,7 +513,7 @@ const SelectedAll = createWithIntlProvider('zh-CN', locale$1, 'super-select')(()
|
|
|
410
513
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
411
514
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
412
515
|
justify: "space-between",
|
|
413
|
-
className: classnames(style$
|
|
516
|
+
className: classnames(style$5['selected-all'], 'selected-all')
|
|
414
517
|
}, /*#__PURE__*/React.createElement(Flex, {
|
|
415
518
|
gap: 8
|
|
416
519
|
}, /*#__PURE__*/React.createElement("span", null, formatMessage({
|
|
@@ -433,7 +536,7 @@ const computedIsSelectAll = (value, selectedAllValue, valueKey = 'value') => {
|
|
|
433
536
|
return (value == null ? void 0 : value.length) === 1 && get(value, `[0][${valueKey}]`) === selectedAllValue[valueKey];
|
|
434
537
|
};
|
|
435
538
|
|
|
436
|
-
var style$
|
|
539
|
+
var style$4 = {"label":"_l3KoW","tag-list":"_CCPzb","tag-container":"_dKZHi","tag-container-inner":"_oijCI","tag":"_WmnnS","tag-inner":"_TMcFl"};
|
|
437
540
|
|
|
438
541
|
const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
439
542
|
const {
|
|
@@ -451,21 +554,21 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
451
554
|
valueKey
|
|
452
555
|
} = Object.assign({}, props);
|
|
453
556
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
454
|
-
className: classnames(style$
|
|
557
|
+
className: classnames(style$4['tag-list'], 'selected-tag-list'),
|
|
455
558
|
gap: 8
|
|
456
559
|
}, /*#__PURE__*/React.createElement("div", {
|
|
457
|
-
className: style$
|
|
560
|
+
className: style$4['label']
|
|
458
561
|
}, formatMessage({
|
|
459
562
|
id: 'selected'
|
|
460
563
|
}), !single && value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(SimpleBar, {
|
|
461
|
-
className: style$
|
|
564
|
+
className: style$4['tag-container']
|
|
462
565
|
}, /*#__PURE__*/React.createElement(Flex, {
|
|
463
566
|
gap: 8,
|
|
464
567
|
wrap: true,
|
|
465
|
-
className: style$
|
|
568
|
+
className: style$4['tag-container-inner']
|
|
466
569
|
}, value.map(item => {
|
|
467
570
|
return /*#__PURE__*/React.createElement(Tag, {
|
|
468
|
-
className: style$
|
|
571
|
+
className: style$4['tag'],
|
|
469
572
|
key: item[valueKey],
|
|
470
573
|
closable: true,
|
|
471
574
|
bordered: false,
|
|
@@ -474,19 +577,19 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
474
577
|
onRemove(item);
|
|
475
578
|
}
|
|
476
579
|
}, /*#__PURE__*/React.createElement("span", {
|
|
477
|
-
className: style$
|
|
580
|
+
className: style$4['tag-inner']
|
|
478
581
|
}, item[labelKey]));
|
|
479
582
|
}))));
|
|
480
583
|
});
|
|
481
584
|
|
|
482
|
-
var style$
|
|
585
|
+
var style$3 = {"list":"_IsXdU","is-popup":"_-dvpa","empty":"_SQZ8k","default-list":"_QD1Mz","is-selected-all":"_M-mOy","default-list-item":"_KtOsz","is-selected":"_TQhBB","single-checked":"_2rUrh","is-disabled":"_NbwX5","selected-all":"_vN2Fx","selected-tag":"_6oITk","select-search":"_iAH9D","select-list-item-description":"_TCkeJ","footer":"_v3f23"};
|
|
483
586
|
|
|
484
|
-
const _excluded$
|
|
587
|
+
const _excluded$2 = ["children"];
|
|
485
588
|
const SelectList = forwardRef((_ref, ref) => {
|
|
486
589
|
let {
|
|
487
590
|
children
|
|
488
591
|
} = _ref,
|
|
489
|
-
p = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
592
|
+
p = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
490
593
|
const fetchListRef = useRef(null);
|
|
491
594
|
const props = Object.assign({}, {
|
|
492
595
|
renderItemContent: ({
|
|
@@ -499,7 +602,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
499
602
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
500
603
|
className: 'select-list-item-label'
|
|
501
604
|
}, item[labelKey]), item.description && /*#__PURE__*/React.createElement("div", {
|
|
502
|
-
className: classnames(style$
|
|
605
|
+
className: classnames(style$3['select-list-item-description'], 'select-list-item-description')
|
|
503
606
|
}, item.description));
|
|
504
607
|
},
|
|
505
608
|
renderItem: contextProps => {
|
|
@@ -520,9 +623,9 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
520
623
|
} = props;
|
|
521
624
|
const isChecked = value.some(target => target[valueKey] === item[valueKey]);
|
|
522
625
|
return /*#__PURE__*/React.createElement(List.Item, {
|
|
523
|
-
className: classnames(style$
|
|
524
|
-
[style$
|
|
525
|
-
[style$
|
|
626
|
+
className: classnames(style$3['default-list-item'], 'select-list-item', {
|
|
627
|
+
[style$3['is-selected']]: isChecked,
|
|
628
|
+
[style$3['is-disabled']]: item.disabled
|
|
526
629
|
}),
|
|
527
630
|
key: item[valueKey],
|
|
528
631
|
onClick: () => {
|
|
@@ -550,7 +653,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
550
653
|
flex: 1,
|
|
551
654
|
className: 'select-list-item-content'
|
|
552
655
|
}, renderItemContent(contextProps)), single && /*#__PURE__*/React.createElement("div", {
|
|
553
|
-
className: style$
|
|
656
|
+
className: style$3['single-checked']
|
|
554
657
|
}, isChecked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
|
|
555
658
|
},
|
|
556
659
|
renderList: contextProps => {
|
|
@@ -564,12 +667,12 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
564
667
|
} = props;
|
|
565
668
|
if (!(list && list.length > 0)) {
|
|
566
669
|
return props.empty || /*#__PURE__*/React.createElement(Empty, {
|
|
567
|
-
className: style$
|
|
670
|
+
className: style$3['empty']
|
|
568
671
|
});
|
|
569
672
|
}
|
|
570
673
|
return /*#__PURE__*/React.createElement(List, {
|
|
571
|
-
className: classnames(style$
|
|
572
|
-
[style$
|
|
674
|
+
className: classnames(style$3['default-list'], {
|
|
675
|
+
[style$3['is-selected-all']]: isSelectedAll
|
|
573
676
|
}),
|
|
574
677
|
size: "small",
|
|
575
678
|
dataSource: list,
|
|
@@ -606,7 +709,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
606
709
|
} = props;
|
|
607
710
|
const components = {
|
|
608
711
|
search: (api && typeof getSearchProps === 'function' || options && typeof getSearchCallback === 'function') && /*#__PURE__*/React.createElement(SearchInput, {
|
|
609
|
-
className: classnames(style$
|
|
712
|
+
className: classnames(style$3['select-search'], 'select-list-search', {
|
|
610
713
|
'is-popup': isPopup
|
|
611
714
|
}),
|
|
612
715
|
placeholder: searchPlaceholder,
|
|
@@ -620,12 +723,12 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
620
723
|
showSearchButton: !isPopup
|
|
621
724
|
}),
|
|
622
725
|
selectedAll: /*#__PURE__*/React.createElement("div", {
|
|
623
|
-
className: classnames(style$
|
|
726
|
+
className: classnames(style$3['selected-all'], 'select-list-selected-all', {
|
|
624
727
|
'is-popup': isPopup
|
|
625
728
|
})
|
|
626
729
|
}, !single && allowSelectedAll && /*#__PURE__*/React.createElement(SelectedAll, null)),
|
|
627
730
|
fetchList: /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
|
|
628
|
-
className: classnames(style$
|
|
731
|
+
className: classnames(style$3['list'], 'select-list-scroll-list', {
|
|
629
732
|
'is-popup': isPopup
|
|
630
733
|
}),
|
|
631
734
|
searchProps: searchProps,
|
|
@@ -661,12 +764,12 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
661
764
|
}));
|
|
662
765
|
}),
|
|
663
766
|
selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
|
|
664
|
-
className: classnames(style$
|
|
767
|
+
className: classnames(style$3['selected-tag'], 'select-list-selected-tag', {
|
|
665
768
|
'is-popup': isPopup
|
|
666
769
|
})
|
|
667
770
|
}, /*#__PURE__*/React.createElement(SelectedTagList, null)),
|
|
668
771
|
footer: footer && /*#__PURE__*/React.createElement("div", {
|
|
669
|
-
className: classnames(style$
|
|
772
|
+
className: classnames(style$3['footer'], 'select-list-footer')
|
|
670
773
|
}, typeof footer === 'function' ? footer({
|
|
671
774
|
reload: () => {
|
|
672
775
|
fetchListRef.current && fetchListRef.current.reload();
|
|
@@ -687,7 +790,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
687
790
|
});
|
|
688
791
|
});
|
|
689
792
|
|
|
690
|
-
var style$
|
|
793
|
+
var style$2 = {"list":"_DrEYJ","is-popup":"_KgWTX","empty":"_5Tyrt","table":"_zE-14","right-options":"_UXi-g","no-padding-btn":"_iaCir","tag":"_JkYqS","tag-inner":"_VZlBL","single-checked":"_Eiz-u","select-search":"_temy6","tags-search":"_7phL2","descriptions":"_ttNK9","footer":"_lISfA"};
|
|
691
794
|
|
|
692
795
|
const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(forwardRef((p, ref) => {
|
|
693
796
|
const {
|
|
@@ -716,7 +819,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
716
819
|
return null;
|
|
717
820
|
}
|
|
718
821
|
return /*#__PURE__*/React.createElement(SearchInput, {
|
|
719
|
-
className: classnames(style$
|
|
822
|
+
className: classnames(style$2['select-search'], 'select-table-search', {
|
|
720
823
|
'is-popup': isPopup
|
|
721
824
|
}),
|
|
722
825
|
placeholder: searchPlaceholder,
|
|
@@ -776,7 +879,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
776
879
|
} = props;
|
|
777
880
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
778
881
|
const footerEl = footer && /*#__PURE__*/React.createElement("div", {
|
|
779
|
-
className: classnames(style$
|
|
882
|
+
className: classnames(style$2['footer'], 'select-table-footer')
|
|
780
883
|
}, typeof footer === 'function' ? footer({
|
|
781
884
|
reload: () => {
|
|
782
885
|
var _fetchListRef$current, _fetchListRef$current2;
|
|
@@ -791,11 +894,11 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
791
894
|
ref: bodyRef
|
|
792
895
|
}, /*#__PURE__*/React.createElement(Col, {
|
|
793
896
|
className: classnames({
|
|
794
|
-
[style$
|
|
897
|
+
[style$2['single-body']]: single
|
|
795
898
|
}),
|
|
796
899
|
span: single ? 24 : 16
|
|
797
900
|
}, /*#__PURE__*/React.createElement("div", null, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React.createElement("div", {
|
|
798
|
-
className: classnames(style$
|
|
901
|
+
className: classnames(style$2['table'], 'select-table')
|
|
799
902
|
}, /*#__PURE__*/React.createElement(TableView, {
|
|
800
903
|
columns: columns,
|
|
801
904
|
rowKey: valueKey,
|
|
@@ -813,12 +916,16 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
813
916
|
setValue(value => {
|
|
814
917
|
if (checked) {
|
|
815
918
|
var _fetchListRef$current3;
|
|
816
|
-
const newValue = value.slice(0);
|
|
817
919
|
const selectedItem = (_fetchListRef$current3 = fetchListRef.current) == null ? void 0 : _fetchListRef$current3.list.find(item => item[valueKey] === selectedKey);
|
|
818
920
|
if (selectedItem) {
|
|
921
|
+
if (single) {
|
|
922
|
+
return [selectedItem];
|
|
923
|
+
}
|
|
924
|
+
const newValue = value.slice(0);
|
|
819
925
|
newValue.push(selectedItem);
|
|
926
|
+
return newValue;
|
|
820
927
|
}
|
|
821
|
-
return
|
|
928
|
+
return value;
|
|
822
929
|
} else {
|
|
823
930
|
return value.filter(item => item[valueKey] !== selectedKey);
|
|
824
931
|
}
|
|
@@ -833,7 +940,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
833
940
|
renderBody
|
|
834
941
|
}) => {
|
|
835
942
|
return /*#__PURE__*/React.createElement(React.Fragment, null, header, /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
|
|
836
|
-
className: classnames(style$
|
|
943
|
+
className: classnames(style$2['list'], 'select-table-list-scroll-list', {
|
|
837
944
|
'is-popup': isPopup
|
|
838
945
|
}),
|
|
839
946
|
searchProps: searchProps,
|
|
@@ -871,21 +978,21 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
871
978
|
});
|
|
872
979
|
if (!(list && list.length > 0)) {
|
|
873
980
|
return props.empty || /*#__PURE__*/React.createElement(Empty, {
|
|
874
|
-
className: classnames(style$
|
|
981
|
+
className: classnames(style$2['empty'])
|
|
875
982
|
});
|
|
876
983
|
}
|
|
877
984
|
return renderBody(list, contextProps);
|
|
878
985
|
}));
|
|
879
986
|
}
|
|
880
987
|
})), single && footerEl || /*#__PURE__*/React.createElement("div", {
|
|
881
|
-
className: classnames(style$
|
|
988
|
+
className: classnames(style$2['footer'], 'select-table-footer')
|
|
882
989
|
})), !single && /*#__PURE__*/React.createElement(Col, {
|
|
883
|
-
className: classnames(style$
|
|
990
|
+
className: classnames(style$2['right-options'], {
|
|
884
991
|
'is-popup': isPopup
|
|
885
992
|
}),
|
|
886
993
|
span: 8
|
|
887
994
|
}, /*#__PURE__*/React.createElement(SearchInput, {
|
|
888
|
-
className: style$
|
|
995
|
+
className: style$2['tags-search'],
|
|
889
996
|
placeholder: searchPlaceholder,
|
|
890
997
|
value: tagSearchText,
|
|
891
998
|
onSearch: value => {
|
|
@@ -899,7 +1006,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
899
1006
|
}, /*#__PURE__*/React.createElement(Col, null, formatMessage({
|
|
900
1007
|
id: 'selected'
|
|
901
1008
|
}), value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Button, {
|
|
902
|
-
className: style$
|
|
1009
|
+
className: style$2['no-padding-btn'],
|
|
903
1010
|
type: "link",
|
|
904
1011
|
onClick: () => {
|
|
905
1012
|
setValue([]);
|
|
@@ -912,7 +1019,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
912
1019
|
}, value.filter(item => getTagSearchCallback(tagSearchText, item, targetProps)).map(item => {
|
|
913
1020
|
var _fetchListRef$current4, _fetchListRef$current5;
|
|
914
1021
|
return /*#__PURE__*/React.createElement(Tag, {
|
|
915
|
-
className: style$
|
|
1022
|
+
className: style$2['tag'],
|
|
916
1023
|
key: item[valueKey],
|
|
917
1024
|
closable: true,
|
|
918
1025
|
bordered: false,
|
|
@@ -923,7 +1030,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
923
1030
|
}, /*#__PURE__*/React.createElement(Popover, {
|
|
924
1031
|
getPopupContainer: () => bodyRef.current,
|
|
925
1032
|
content: /*#__PURE__*/React.createElement(CentralContent, {
|
|
926
|
-
className: style$
|
|
1033
|
+
className: style$2['descriptions'],
|
|
927
1034
|
columns: columns.filter(item => {
|
|
928
1035
|
if (Object.hasOwn(item, 'previewHidden')) {
|
|
929
1036
|
return !item.previewHidden;
|
|
@@ -939,15 +1046,15 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
939
1046
|
})
|
|
940
1047
|
})
|
|
941
1048
|
}, /*#__PURE__*/React.createElement("span", {
|
|
942
|
-
className: style$
|
|
1049
|
+
className: style$2['tag-inner']
|
|
943
1050
|
}, item[labelKey])));
|
|
944
1051
|
}))), footerEl));
|
|
945
1052
|
});
|
|
946
1053
|
}));
|
|
947
1054
|
|
|
948
|
-
var style = {"list":"_YTqxA","is-popup":"_TR-1a","default-list":"_IZN7r","is-selected-all":"_GCIMn","default-list-item":"_AYi0i","is-selected":"_eovZv","single-checked":"_Tr-bO","is-disabled":"_T-hri","selected-all":"_4XFtm","selected-tag":"_Whlzr","select-search":"_7zuBL","select-tree-item-description":"_R-Sye","footer":"_PjlnR"};
|
|
1055
|
+
var style$1 = {"list":"_YTqxA","is-popup":"_TR-1a","default-list":"_IZN7r","is-selected-all":"_GCIMn","default-list-item":"_AYi0i","is-selected":"_eovZv","single-checked":"_Tr-bO","is-disabled":"_T-hri","selected-all":"_4XFtm","selected-tag":"_Whlzr","select-search":"_7zuBL","select-tree-item-description":"_R-Sye","footer":"_PjlnR"};
|
|
949
1056
|
|
|
950
|
-
const _excluded = ["children"],
|
|
1057
|
+
const _excluded$1 = ["children"],
|
|
951
1058
|
_excluded2 = ["data"];
|
|
952
1059
|
const parseTreeData = memoize((data = [], {
|
|
953
1060
|
parentKey,
|
|
@@ -973,7 +1080,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
973
1080
|
let {
|
|
974
1081
|
children
|
|
975
1082
|
} = _ref,
|
|
976
|
-
p = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1083
|
+
p = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
977
1084
|
const fetchListRef = useRef(null);
|
|
978
1085
|
const [expandedKeys, setExpandedKeys] = useState([]);
|
|
979
1086
|
const props = Object.assign({}, {
|
|
@@ -1008,9 +1115,9 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1008
1115
|
} = props;
|
|
1009
1116
|
const isChecked = value.some(target => target[valueKey] === item[valueKey]);
|
|
1010
1117
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
1011
|
-
className: classnames(style['default-list-item'], 'select-tree-item', {
|
|
1012
|
-
[style['is-selected']]: isChecked,
|
|
1013
|
-
[style['is-disabled']]: item.disabled
|
|
1118
|
+
className: classnames(style$1['default-list-item'], 'select-tree-item', {
|
|
1119
|
+
[style$1['is-selected']]: isChecked,
|
|
1120
|
+
[style$1['is-disabled']]: item.disabled
|
|
1014
1121
|
}),
|
|
1015
1122
|
key: item[valueKey],
|
|
1016
1123
|
onClick: () => {
|
|
@@ -1038,7 +1145,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1038
1145
|
flex: 1,
|
|
1039
1146
|
className: 'select-tree-item-content'
|
|
1040
1147
|
}, renderItemContent(contextProps)), single && /*#__PURE__*/React.createElement("div", {
|
|
1041
|
-
className: style['single-checked']
|
|
1148
|
+
className: style$1['single-checked']
|
|
1042
1149
|
}, isChecked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
|
|
1043
1150
|
},
|
|
1044
1151
|
renderTree: contextProps => {
|
|
@@ -1066,8 +1173,8 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1066
1173
|
return props.empty || /*#__PURE__*/React.createElement(Empty, null);
|
|
1067
1174
|
}
|
|
1068
1175
|
return /*#__PURE__*/React.createElement(Tree, {
|
|
1069
|
-
className: classnames(style['default-list'], {
|
|
1070
|
-
[style['is-selected-all']]: isSelectedAll
|
|
1176
|
+
className: classnames(style$1['default-list'], {
|
|
1177
|
+
[style$1['is-selected-all']]: isSelectedAll
|
|
1071
1178
|
}),
|
|
1072
1179
|
showIcon: true,
|
|
1073
1180
|
selectable: false,
|
|
@@ -1111,7 +1218,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1111
1218
|
} = props;
|
|
1112
1219
|
const components = {
|
|
1113
1220
|
selectedAll: /*#__PURE__*/React.createElement("div", {
|
|
1114
|
-
className: classnames(style['selected-all'], 'select-tree-selected-all', {
|
|
1221
|
+
className: classnames(style$1['selected-all'], 'select-tree-selected-all', {
|
|
1115
1222
|
'is-popup': isPopup
|
|
1116
1223
|
})
|
|
1117
1224
|
}, !single && allowSelectedAll && /*#__PURE__*/React.createElement(SelectedAll, null)),
|
|
@@ -1131,7 +1238,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1131
1238
|
fetchProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
1132
1239
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
1133
1240
|
return /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1134
|
-
className: classnames(style['list'], 'select-tree-scroll-list', {
|
|
1241
|
+
className: classnames(style$1['list'], 'select-tree-scroll-list', {
|
|
1135
1242
|
'is-popup': isPopup
|
|
1136
1243
|
})
|
|
1137
1244
|
}, renderTree(Object.assign({}, fetchProps, targetProps, {
|
|
@@ -1141,12 +1248,12 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1141
1248
|
}
|
|
1142
1249
|
})),
|
|
1143
1250
|
selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
|
|
1144
|
-
className: classnames(style['selected-tag'], 'select-tree-selected-tag', {
|
|
1251
|
+
className: classnames(style$1['selected-tag'], 'select-tree-selected-tag', {
|
|
1145
1252
|
'is-popup': isPopup
|
|
1146
1253
|
})
|
|
1147
1254
|
}, /*#__PURE__*/React.createElement(SelectedTagList, null)),
|
|
1148
1255
|
footer: footer && /*#__PURE__*/React.createElement("div", {
|
|
1149
|
-
className: classnames(style['footer'], 'select-list-footer')
|
|
1256
|
+
className: classnames(style$1['footer'], 'select-list-footer')
|
|
1150
1257
|
}, typeof footer === 'function' ? footer({
|
|
1151
1258
|
reload: () => {
|
|
1152
1259
|
fetchListRef.current && fetchListRef.current.reload();
|
|
@@ -1167,5 +1274,779 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1167
1274
|
});
|
|
1168
1275
|
});
|
|
1169
1276
|
|
|
1170
|
-
|
|
1277
|
+
const createTreeUtils = mapping => {
|
|
1278
|
+
const mappingList = Array.from(mapping.values());
|
|
1279
|
+
const rootNodes = mappingList.filter(item => item.parentId === null);
|
|
1280
|
+
const delItem = (array, item) => {
|
|
1281
|
+
const index = array.indexOf(item);
|
|
1282
|
+
if (index > -1) {
|
|
1283
|
+
array.splice(index, 1);
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* 通过一个nodeId获取所有父级和所有子级的第一个元素,组成一个从最顶级到最子级的数组
|
|
1289
|
+
* */
|
|
1290
|
+
const getSelectedQueue = id => {
|
|
1291
|
+
const currentNode = mapping.get(id);
|
|
1292
|
+
if (!currentNode) {
|
|
1293
|
+
return [];
|
|
1294
|
+
}
|
|
1295
|
+
const getFirstChild = target => {
|
|
1296
|
+
if (target.children && target.children.length > 0) {
|
|
1297
|
+
return getFirstChild(target.children.find(item => item.children && target.children.length > 0) || get(target.children, '0'));
|
|
1298
|
+
}
|
|
1299
|
+
const hasChildrenItem = getAllChildren(target.parentId).find(item => item.children && item.children.length > 0);
|
|
1300
|
+
if (hasChildrenItem) {
|
|
1301
|
+
return getFirstChild(hasChildrenItem);
|
|
1302
|
+
}
|
|
1303
|
+
return target;
|
|
1304
|
+
};
|
|
1305
|
+
const getParentNodeIdList = (targetId, parents = []) => {
|
|
1306
|
+
const output = [targetId, ...parents];
|
|
1307
|
+
const node = mapping.get(targetId);
|
|
1308
|
+
if (!node || isNil(node.parentId)) {
|
|
1309
|
+
return output;
|
|
1310
|
+
}
|
|
1311
|
+
return getParentNodeIdList(node.parentId, output);
|
|
1312
|
+
};
|
|
1313
|
+
const lastLevelNode = getFirstChild(currentNode);
|
|
1314
|
+
return getParentNodeIdList(get(lastLevelNode, 'id'));
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
/**
|
|
1318
|
+
* 通过一个nodeId获得该节点的所有子级后代的id数组
|
|
1319
|
+
* */
|
|
1320
|
+
const getAllChildren = id => {
|
|
1321
|
+
const output = [];
|
|
1322
|
+
const core = id => {
|
|
1323
|
+
const node = mapping.get(id);
|
|
1324
|
+
if (!node) {
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
1328
|
+
output.push(...node.children);
|
|
1329
|
+
node.children.forEach(item => {
|
|
1330
|
+
core(item.id);
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
core(id);
|
|
1335
|
+
return output;
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* 从自身节点开始向父级查找callback返回为true的node,找到第一个返回结果
|
|
1340
|
+
* */
|
|
1341
|
+
const findInParents = (id, callback) => {
|
|
1342
|
+
const core = id => {
|
|
1343
|
+
const currentNode = mapping.get(id);
|
|
1344
|
+
if (!currentNode) {
|
|
1345
|
+
return null;
|
|
1346
|
+
}
|
|
1347
|
+
if (callback(currentNode)) {
|
|
1348
|
+
return currentNode;
|
|
1349
|
+
}
|
|
1350
|
+
if (!isNil(currentNode.parentId)) {
|
|
1351
|
+
return core(currentNode.parentId);
|
|
1352
|
+
}
|
|
1353
|
+
return null;
|
|
1354
|
+
};
|
|
1355
|
+
return core(id);
|
|
1356
|
+
};
|
|
1357
|
+
const getSiblingNode = id => {
|
|
1358
|
+
const currentNode = mapping.get(id);
|
|
1359
|
+
if (!currentNode) {
|
|
1360
|
+
return [];
|
|
1361
|
+
}
|
|
1362
|
+
const parentId = currentNode.parentId;
|
|
1363
|
+
if (isNil(parentId)) {
|
|
1364
|
+
return rootNodes;
|
|
1365
|
+
}
|
|
1366
|
+
const parentNode = mapping.get(parentId);
|
|
1367
|
+
return parentNode.children;
|
|
1368
|
+
};
|
|
1369
|
+
const setNodeChecked = (id, value = []) => {
|
|
1370
|
+
const newValue = value.slice(0);
|
|
1371
|
+
const core = id => {
|
|
1372
|
+
const node = mapping.get(id);
|
|
1373
|
+
if (!node) {
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
newValue.push(id);
|
|
1377
|
+
getAllChildren(id).forEach(node => {
|
|
1378
|
+
delItem(newValue, node.id);
|
|
1379
|
+
});
|
|
1380
|
+
const siblingNode = getSiblingNode(id);
|
|
1381
|
+
const siblingNodeIsAllChecked = siblingNode.every(node => newValue.indexOf(node.id) > -1);
|
|
1382
|
+
if (node.parentId && siblingNodeIsAllChecked) {
|
|
1383
|
+
siblingNode.forEach(node => {
|
|
1384
|
+
delItem(newValue, node.id);
|
|
1385
|
+
});
|
|
1386
|
+
core(node.parentId);
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
core(id);
|
|
1390
|
+
return newValue;
|
|
1391
|
+
};
|
|
1392
|
+
const setNodeUnchecked = (id, value = []) => {
|
|
1393
|
+
const newValue = value.slice(0);
|
|
1394
|
+
const core = id => {
|
|
1395
|
+
const node = mapping.get(id);
|
|
1396
|
+
if (!node) {
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
if (newValue.indexOf(node.id) > -1) {
|
|
1400
|
+
delItem(newValue, node.id);
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
const siblingNode = getSiblingNode(id);
|
|
1404
|
+
if (node.parentId) {
|
|
1405
|
+
siblingNode.forEach(node => {
|
|
1406
|
+
if (id !== node.id) {
|
|
1407
|
+
newValue.push(node.id);
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
core(node.parentId);
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
core(id);
|
|
1414
|
+
return newValue;
|
|
1415
|
+
};
|
|
1416
|
+
const computedCheckboxStatus = (id, value = []) => {
|
|
1417
|
+
if (!!findInParents(id, node => {
|
|
1418
|
+
return value.indexOf(node.id) > -1;
|
|
1419
|
+
})) {
|
|
1420
|
+
return {
|
|
1421
|
+
checked: true,
|
|
1422
|
+
indeterminate: false
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
const indeterminate = ((id, callback) => {
|
|
1426
|
+
const core = id => {
|
|
1427
|
+
const currentNode = mapping.get(id);
|
|
1428
|
+
if (!currentNode) {
|
|
1429
|
+
return null;
|
|
1430
|
+
}
|
|
1431
|
+
if (callback(currentNode)) {
|
|
1432
|
+
return currentNode;
|
|
1433
|
+
}
|
|
1434
|
+
if (Array.isArray(currentNode.children) && currentNode.children.length > 0) {
|
|
1435
|
+
return currentNode.children.find(item => !!core(item.id));
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
return !!core(id);
|
|
1439
|
+
})(id, node => value.indexOf(node.id) > -1);
|
|
1440
|
+
if (indeterminate) {
|
|
1441
|
+
return {
|
|
1442
|
+
checked: false,
|
|
1443
|
+
indeterminate: true
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
return {
|
|
1447
|
+
checked: false,
|
|
1448
|
+
indeterminate: false
|
|
1449
|
+
};
|
|
1450
|
+
};
|
|
1451
|
+
const transformToTreeData = () => {
|
|
1452
|
+
const core = nodeList => {
|
|
1453
|
+
if (Array.isArray(nodeList) && nodeList.length > 0) {
|
|
1454
|
+
return nodeList.map(node => {
|
|
1455
|
+
const children = mappingList.filter(item => item.parentId === node.id);
|
|
1456
|
+
return Object.assign({}, node, {
|
|
1457
|
+
children: core(children)
|
|
1458
|
+
});
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
return null;
|
|
1462
|
+
};
|
|
1463
|
+
return core(rootNodes);
|
|
1464
|
+
};
|
|
1465
|
+
const treeData = transformToTreeData();
|
|
1466
|
+
return {
|
|
1467
|
+
mapping,
|
|
1468
|
+
getSelectedQueue,
|
|
1469
|
+
getAllChildren,
|
|
1470
|
+
computedCheckboxStatus,
|
|
1471
|
+
getSiblingNode,
|
|
1472
|
+
findInParents,
|
|
1473
|
+
setNodeChecked,
|
|
1474
|
+
setNodeUnchecked,
|
|
1475
|
+
treeData,
|
|
1476
|
+
treeMapping: new Map((treeData || []).map(item => [item.id, item]))
|
|
1477
|
+
};
|
|
1478
|
+
};
|
|
1479
|
+
|
|
1480
|
+
var style = {"content":"_fHNBt","columns":"_VgpIp","content-item":"_kSkN1","last-level-area":"_1QV-l","is-popup":"_zFwDF","menu":"_s-ON4","scroll-plus-box":"_rIix2","menu-label":"_XAs20","menu-label-text":"_Y8AoQ","menu-item":"_ZwakZ","checkbox-hidden":"_0FUoe","single-mode":"_dahnB","menu-item-icon":"_AZZvN","menu-item-placeholder":"_TudTj","loading":"_ljvZk","search-input":"_FVxuS","list":"_iUhv7","is-selected":"_tx4-l","custom-menu":"_OerpL","selected":"_OUkpN"};
|
|
1481
|
+
|
|
1482
|
+
const CustomMenu = ({
|
|
1483
|
+
className,
|
|
1484
|
+
selectedKeys,
|
|
1485
|
+
items,
|
|
1486
|
+
onSelect
|
|
1487
|
+
}) => {
|
|
1488
|
+
const handleItemClick = (key, e) => {
|
|
1489
|
+
// 只阻止事件冒泡,不阻止默认行为
|
|
1490
|
+
e.stopPropagation();
|
|
1491
|
+
onSelect == null || onSelect({
|
|
1492
|
+
key,
|
|
1493
|
+
domEvent: e
|
|
1494
|
+
});
|
|
1495
|
+
};
|
|
1496
|
+
return /*#__PURE__*/React.createElement(List, {
|
|
1497
|
+
className: classnames(style['custom-menu'], className),
|
|
1498
|
+
dataSource: items,
|
|
1499
|
+
renderItem: item => {
|
|
1500
|
+
const isSelected = selectedKeys == null ? void 0 : selectedKeys.includes(item.key);
|
|
1501
|
+
return /*#__PURE__*/React.createElement(List.Item, {
|
|
1502
|
+
className: classnames(style['custom-menu-item'], {
|
|
1503
|
+
[style['selected']]: isSelected
|
|
1504
|
+
}),
|
|
1505
|
+
onClick: e => handleItemClick(item.key, e)
|
|
1506
|
+
}, item.label);
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
};
|
|
1510
|
+
|
|
1511
|
+
const _excluded = ["options", "value", "onChange", "defaultValue", "maxLength", "single", "onlyAllowLastLevel", "openLoadData", "onLoadMore", "parentIdKey", "menuItemWidth", "isPopup", "searchPlaceholder", "onSearch", "valueKey", "labelKey", "placeholder", "disabled", "size", "overlayWidth"];
|
|
1512
|
+
const numberToPx = val => {
|
|
1513
|
+
return typeof val === 'number' ? `${val}px` : val;
|
|
1514
|
+
};
|
|
1515
|
+
|
|
1516
|
+
// 级联选择内容组件
|
|
1517
|
+
const CascaderInner = ({
|
|
1518
|
+
options,
|
|
1519
|
+
value,
|
|
1520
|
+
setValue,
|
|
1521
|
+
maxLength,
|
|
1522
|
+
single,
|
|
1523
|
+
onlyAllowLastLevel,
|
|
1524
|
+
openLoadData,
|
|
1525
|
+
onLoadMore,
|
|
1526
|
+
parentIdKey,
|
|
1527
|
+
menuItemWidth,
|
|
1528
|
+
isPopup,
|
|
1529
|
+
searchPlaceholder,
|
|
1530
|
+
onSearch,
|
|
1531
|
+
valueKey,
|
|
1532
|
+
labelKey,
|
|
1533
|
+
onOpenChange,
|
|
1534
|
+
open
|
|
1535
|
+
}) => {
|
|
1536
|
+
const {
|
|
1537
|
+
message
|
|
1538
|
+
} = App.useApp();
|
|
1539
|
+
const [searchText, setSearchText] = useState('');
|
|
1540
|
+
const [loading, setLoading] = useState(false);
|
|
1541
|
+
|
|
1542
|
+
// 构建 mapping
|
|
1543
|
+
const mapping = useMemo(() => {
|
|
1544
|
+
const map = new Map();
|
|
1545
|
+
const processData = (items, parentId = null) => {
|
|
1546
|
+
items.forEach(item => {
|
|
1547
|
+
const node = _extends({}, item, {
|
|
1548
|
+
id: item[valueKey],
|
|
1549
|
+
label: item[labelKey],
|
|
1550
|
+
parentId
|
|
1551
|
+
});
|
|
1552
|
+
if (item.children && item.children.length > 0) {
|
|
1553
|
+
node.children = item.children.map(child => _extends({}, child, {
|
|
1554
|
+
id: child[valueKey],
|
|
1555
|
+
label: child[labelKey],
|
|
1556
|
+
parentId: node.id
|
|
1557
|
+
}));
|
|
1558
|
+
processData(item.children, node.id);
|
|
1559
|
+
}
|
|
1560
|
+
map.set(node.id, node);
|
|
1561
|
+
});
|
|
1562
|
+
};
|
|
1563
|
+
processData(options);
|
|
1564
|
+
return map;
|
|
1565
|
+
}, [options, valueKey, labelKey]);
|
|
1566
|
+
|
|
1567
|
+
// 创建树工具
|
|
1568
|
+
const treeUtils = useMemo(() => {
|
|
1569
|
+
return createTreeUtils(mapping);
|
|
1570
|
+
}, [mapping]);
|
|
1571
|
+
|
|
1572
|
+
// 当前选中的列
|
|
1573
|
+
const [selectedIds, setSelectedIds] = useState(() => {
|
|
1574
|
+
const initValue = value.find(item => {
|
|
1575
|
+
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
1576
|
+
return !!mapping.get(id);
|
|
1577
|
+
});
|
|
1578
|
+
if (initValue) {
|
|
1579
|
+
const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
|
|
1580
|
+
return treeUtils.getSelectedQueue(id);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// 默认选中第一列
|
|
1584
|
+
const firstNode = Array.from(mapping.values()).find(item => isNil(item.parentId));
|
|
1585
|
+
if (firstNode) {
|
|
1586
|
+
return treeUtils.getSelectedQueue(firstNode.id);
|
|
1587
|
+
}
|
|
1588
|
+
return [];
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1591
|
+
// 当 Modal 打开时,根据 value 重新初始化 selectedIds
|
|
1592
|
+
const prevOpenRef = useRef(open);
|
|
1593
|
+
useEffect(() => {
|
|
1594
|
+
// 只在非 popup 模式下且 Modal 从关闭变为打开时处理
|
|
1595
|
+
if (!isPopup && open && !prevOpenRef.current) {
|
|
1596
|
+
const initValue = value.find(item => {
|
|
1597
|
+
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
1598
|
+
return !!mapping.get(id);
|
|
1599
|
+
});
|
|
1600
|
+
if (initValue) {
|
|
1601
|
+
const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
|
|
1602
|
+
setSelectedIds(treeUtils.getSelectedQueue(id));
|
|
1603
|
+
} else {
|
|
1604
|
+
// 默认选中第一列
|
|
1605
|
+
const firstNode = Array.from(mapping.values()).find(item => isNil(item.parentId));
|
|
1606
|
+
if (firstNode) {
|
|
1607
|
+
setSelectedIds(treeUtils.getSelectedQueue(firstNode.id));
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
prevOpenRef.current = open;
|
|
1612
|
+
}, [open, value, mapping, treeUtils, valueKey, isPopup]);
|
|
1613
|
+
|
|
1614
|
+
// 懒加载支持
|
|
1615
|
+
const loadMorePropsRef = useRef({});
|
|
1616
|
+
loadMorePropsRef.current = {
|
|
1617
|
+
openLoadData,
|
|
1618
|
+
onLoadMore,
|
|
1619
|
+
parentIdKey,
|
|
1620
|
+
treeUtils
|
|
1621
|
+
};
|
|
1622
|
+
useEffect(() => {
|
|
1623
|
+
if (!openLoadData || !onLoadMore) {
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
const lastNode = mapping.get(last(selectedIds));
|
|
1627
|
+
if (!lastNode) {
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
// 检查是否需要加载子节点
|
|
1632
|
+
if (lastNode.hasOwnProperty('children') && lastNode.children !== undefined) {
|
|
1633
|
+
return;
|
|
1634
|
+
}
|
|
1635
|
+
setLoading(true);
|
|
1636
|
+
onLoadMore({
|
|
1637
|
+
[parentIdKey]: lastNode.id
|
|
1638
|
+
}).then(() => {
|
|
1639
|
+
setLoading(false);
|
|
1640
|
+
}).catch(() => {
|
|
1641
|
+
setLoading(false);
|
|
1642
|
+
});
|
|
1643
|
+
}, [selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
|
|
1644
|
+
|
|
1645
|
+
// 检查是否为非叶子节点
|
|
1646
|
+
const isNotLastNode = useCallback(id => {
|
|
1647
|
+
const node = mapping.get(id);
|
|
1648
|
+
if (!node) return false;
|
|
1649
|
+
if (openLoadData && !node.hasOwnProperty('children')) {
|
|
1650
|
+
return true;
|
|
1651
|
+
}
|
|
1652
|
+
return node.children && node.children.length > 0;
|
|
1653
|
+
}, [mapping, openLoadData]);
|
|
1654
|
+
|
|
1655
|
+
// 选择处理
|
|
1656
|
+
const onCheckedChange = useCallback((checked, id) => {
|
|
1657
|
+
const newValue = (() => {
|
|
1658
|
+
if (onlyAllowLastLevel && checked) {
|
|
1659
|
+
const _currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1660
|
+
if (_currentIds.includes(id)) return _currentIds;
|
|
1661
|
+
return [..._currentIds, id];
|
|
1662
|
+
}
|
|
1663
|
+
if (onlyAllowLastLevel) {
|
|
1664
|
+
const _currentIds2 = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1665
|
+
return _currentIds2.filter(itemId => itemId !== id);
|
|
1666
|
+
}
|
|
1667
|
+
const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1668
|
+
return checked ? treeUtils.setNodeChecked(id, currentIds) : treeUtils.setNodeUnchecked(id, currentIds);
|
|
1669
|
+
})();
|
|
1670
|
+
if (newValue.length > maxLength) {
|
|
1671
|
+
message.error(`最多只能选择 ${maxLength} 项`);
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// 转换回完整对象
|
|
1676
|
+
const newValues = newValue.map(id => {
|
|
1677
|
+
const node = mapping.get(id);
|
|
1678
|
+
// 返回完整的节点数据,保留所有原始字段
|
|
1679
|
+
return node ? _extends({}, node, {
|
|
1680
|
+
[valueKey]: node.id,
|
|
1681
|
+
[labelKey]: node.label
|
|
1682
|
+
}) : null;
|
|
1683
|
+
}).filter(Boolean);
|
|
1684
|
+
const finalValue = single && newValues.length > 0 ? [last(newValues)] : newValues;
|
|
1685
|
+
setValue(finalValue);
|
|
1686
|
+
|
|
1687
|
+
// 单选且是叶子节点且在 popup 模式下,自动关闭下拉框
|
|
1688
|
+
if (single && newValues.length > 0 && !isNotLastNode(id) && isPopup && onOpenChange) {
|
|
1689
|
+
onOpenChange(false);
|
|
1690
|
+
}
|
|
1691
|
+
}, [value, maxLength, single, onlyAllowLastLevel, treeUtils, mapping, message, valueKey, labelKey, isPopup, onOpenChange, isNotLastNode]);
|
|
1692
|
+
|
|
1693
|
+
// 搜索结果
|
|
1694
|
+
const searchResults = useMemo(() => {
|
|
1695
|
+
if (!searchText || !onSearch) return null;
|
|
1696
|
+
const keyword = searchText.toLowerCase();
|
|
1697
|
+
return Array.from(mapping.values()).filter(item => {
|
|
1698
|
+
return item.label && item.label.toLowerCase().includes(keyword);
|
|
1699
|
+
});
|
|
1700
|
+
}, [searchText, mapping, onSearch]);
|
|
1701
|
+
|
|
1702
|
+
// 搜索选择
|
|
1703
|
+
const onSearchSelect = item => {
|
|
1704
|
+
const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1705
|
+
const checked = currentIds.includes(item.id);
|
|
1706
|
+
onCheckedChange(!checked, item.id);
|
|
1707
|
+
if (!checked) {
|
|
1708
|
+
setSelectedIds(treeUtils.getSelectedQueue(item.id));
|
|
1709
|
+
}
|
|
1710
|
+
setSearchText('');
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
// 渲染搜索内容
|
|
1714
|
+
if (searchText && searchResults) {
|
|
1715
|
+
const _currentIds3 = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1716
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1717
|
+
className: classnames(style['content'], {
|
|
1718
|
+
[style['is-popup']]: isPopup
|
|
1719
|
+
})
|
|
1720
|
+
}, /*#__PURE__*/React.createElement(SearchInput, {
|
|
1721
|
+
className: classnames(style['search-input'], {
|
|
1722
|
+
'is-popup': isPopup
|
|
1723
|
+
}),
|
|
1724
|
+
placeholder: searchPlaceholder,
|
|
1725
|
+
value: searchText,
|
|
1726
|
+
onSearch: setSearchText,
|
|
1727
|
+
simple: isPopup,
|
|
1728
|
+
showSearchButton: !isPopup
|
|
1729
|
+
}), /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1730
|
+
className: style['scroll-plus-box']
|
|
1731
|
+
}, searchResults.length === 0 ? /*#__PURE__*/React.createElement(Empty, {
|
|
1732
|
+
description: "\u6682\u65E0\u6570\u636E"
|
|
1733
|
+
}) : /*#__PURE__*/React.createElement(List, {
|
|
1734
|
+
className: style['list'],
|
|
1735
|
+
size: "small",
|
|
1736
|
+
dataSource: searchResults,
|
|
1737
|
+
rowKey: "id",
|
|
1738
|
+
renderItem: item => {
|
|
1739
|
+
const checked = _currentIds3.includes(item.id);
|
|
1740
|
+
return /*#__PURE__*/React.createElement(List.Item, {
|
|
1741
|
+
className: classnames({
|
|
1742
|
+
[style['is-selected']]: checked
|
|
1743
|
+
}),
|
|
1744
|
+
onClick: () => onSearchSelect(item)
|
|
1745
|
+
}, /*#__PURE__*/React.createElement("span", null, item.label), checked && /*#__PURE__*/React.createElement("span", {
|
|
1746
|
+
style: {
|
|
1747
|
+
marginLeft: 8,
|
|
1748
|
+
color: '#1677ff'
|
|
1749
|
+
}
|
|
1750
|
+
}, "\u2713"));
|
|
1751
|
+
}
|
|
1752
|
+
})));
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
// 渲染级联列
|
|
1756
|
+
const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1757
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1758
|
+
className: classnames(style['content'], {
|
|
1759
|
+
[style['is-popup']]: isPopup,
|
|
1760
|
+
[style['has-search']]: !!onSearch
|
|
1761
|
+
}),
|
|
1762
|
+
style: {
|
|
1763
|
+
'--menu-item-width': numberToPx(menuItemWidth)
|
|
1764
|
+
}
|
|
1765
|
+
}, onSearch && /*#__PURE__*/React.createElement(SearchInput, {
|
|
1766
|
+
className: classnames(style['search-input'], {
|
|
1767
|
+
'is-popup': isPopup
|
|
1768
|
+
}),
|
|
1769
|
+
placeholder: searchPlaceholder,
|
|
1770
|
+
value: searchText,
|
|
1771
|
+
onSearch: setSearchText,
|
|
1772
|
+
simple: isPopup,
|
|
1773
|
+
showSearchButton: !isPopup
|
|
1774
|
+
}), /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1775
|
+
className: style['scroller'],
|
|
1776
|
+
options: {
|
|
1777
|
+
autoHide: false
|
|
1778
|
+
}
|
|
1779
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1780
|
+
className: style['columns']
|
|
1781
|
+
}, selectedIds.map((selectedId, index) => {
|
|
1782
|
+
const selectNode = mapping.get(selectedId);
|
|
1783
|
+
const siblingNodes = treeUtils.getSiblingNode(selectedId);
|
|
1784
|
+
const isLastLevel = !isNotLastNode(selectNode == null ? void 0 : selectNode.id) && index > 0;
|
|
1785
|
+
return /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1786
|
+
key: selectedId || index,
|
|
1787
|
+
className: classnames(style['content-item'], {
|
|
1788
|
+
[style['last-level-area']]: isLastLevel
|
|
1789
|
+
})
|
|
1790
|
+
}, isLastLevel ? /*#__PURE__*/React.createElement(Space, {
|
|
1791
|
+
wrap: true,
|
|
1792
|
+
style: {
|
|
1793
|
+
padding: 12
|
|
1794
|
+
},
|
|
1795
|
+
className: classnames({
|
|
1796
|
+
[style['single-mode']]: single
|
|
1797
|
+
})
|
|
1798
|
+
}, siblingNodes.map(node => {
|
|
1799
|
+
const {
|
|
1800
|
+
checked,
|
|
1801
|
+
indeterminate
|
|
1802
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1803
|
+
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
1804
|
+
key: node.id,
|
|
1805
|
+
checked: checked,
|
|
1806
|
+
indeterminate: indeterminate,
|
|
1807
|
+
onChange: e => onCheckedChange(e.target.checked, node.id)
|
|
1808
|
+
}, node.label);
|
|
1809
|
+
})) : /*#__PURE__*/React.createElement(CustomMenu, {
|
|
1810
|
+
className: style['menu'],
|
|
1811
|
+
selectedKeys: index === selectedIds.length - 1 ? [] : selectedIds,
|
|
1812
|
+
onSelect: ({
|
|
1813
|
+
key
|
|
1814
|
+
}) => {
|
|
1815
|
+
const node = mapping.get(key);
|
|
1816
|
+
if (!node) return;
|
|
1817
|
+
if (isNotLastNode(node.id)) {
|
|
1818
|
+
setSelectedIds(treeUtils.getSelectedQueue(node.id));
|
|
1819
|
+
} else {
|
|
1820
|
+
const {
|
|
1821
|
+
checked
|
|
1822
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1823
|
+
onCheckedChange(!checked, node.id);
|
|
1824
|
+
}
|
|
1825
|
+
},
|
|
1826
|
+
items: siblingNodes.map(node => {
|
|
1827
|
+
const {
|
|
1828
|
+
checked,
|
|
1829
|
+
indeterminate
|
|
1830
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1831
|
+
const hasChildren = isNotLastNode(node.id);
|
|
1832
|
+
|
|
1833
|
+
// 计算子级选中数量
|
|
1834
|
+
const childrenSelectedCount = hasChildren ? treeUtils.getAllChildren(node.id).filter(child => currentIds.includes(child.id)).length : 0;
|
|
1835
|
+
return {
|
|
1836
|
+
key: node.id,
|
|
1837
|
+
label: /*#__PURE__*/React.createElement(Space, {
|
|
1838
|
+
className: classnames(style['menu-item'], {
|
|
1839
|
+
[style['checkbox-hidden']]: onlyAllowLastLevel && hasChildren,
|
|
1840
|
+
[style['single-mode']]: single
|
|
1841
|
+
})
|
|
1842
|
+
}, (!onlyAllowLastLevel || !hasChildren) && /*#__PURE__*/React.createElement(Checkbox, {
|
|
1843
|
+
checked: checked,
|
|
1844
|
+
indeterminate: indeterminate,
|
|
1845
|
+
onClick: e => e.stopPropagation(),
|
|
1846
|
+
onChange: e => {
|
|
1847
|
+
e.stopPropagation();
|
|
1848
|
+
onCheckedChange(e.target.checked, node.id);
|
|
1849
|
+
}
|
|
1850
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
1851
|
+
className: style['menu-label']
|
|
1852
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1853
|
+
className: style['menu-label-text']
|
|
1854
|
+
}, node.label), hasChildren && childrenSelectedCount > 0 && /*#__PURE__*/React.createElement(Badge, {
|
|
1855
|
+
count: childrenSelectedCount,
|
|
1856
|
+
size: "small"
|
|
1857
|
+
})), hasChildren ? /*#__PURE__*/React.createElement(RightOutlined, {
|
|
1858
|
+
className: style['menu-item-icon']
|
|
1859
|
+
}) : /*#__PURE__*/React.createElement("span", {
|
|
1860
|
+
className: style['menu-item-placeholder']
|
|
1861
|
+
}))
|
|
1862
|
+
};
|
|
1863
|
+
})
|
|
1864
|
+
}));
|
|
1865
|
+
}), loading && /*#__PURE__*/React.createElement("div", {
|
|
1866
|
+
className: style['loading']
|
|
1867
|
+
}, /*#__PURE__*/React.createElement(Spin, {
|
|
1868
|
+
size: "small"
|
|
1869
|
+
})))));
|
|
1870
|
+
};
|
|
1871
|
+
|
|
1872
|
+
// 主组件
|
|
1873
|
+
const SelectCascader = _ref => {
|
|
1874
|
+
let {
|
|
1875
|
+
options = [],
|
|
1876
|
+
value,
|
|
1877
|
+
onChange,
|
|
1878
|
+
defaultValue,
|
|
1879
|
+
maxLength = Number.MAX_VALUE,
|
|
1880
|
+
single = false,
|
|
1881
|
+
onlyAllowLastLevel = false,
|
|
1882
|
+
openLoadData = false,
|
|
1883
|
+
onLoadMore,
|
|
1884
|
+
parentIdKey = 'id',
|
|
1885
|
+
menuItemWidth = 180,
|
|
1886
|
+
isPopup = true,
|
|
1887
|
+
searchPlaceholder,
|
|
1888
|
+
onSearch,
|
|
1889
|
+
valueKey = 'id',
|
|
1890
|
+
labelKey = 'label',
|
|
1891
|
+
placeholder = '请选择',
|
|
1892
|
+
disabled = false,
|
|
1893
|
+
size = 'default',
|
|
1894
|
+
overlayWidth
|
|
1895
|
+
} = _ref,
|
|
1896
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1897
|
+
// 内部始终使用数组格式处理
|
|
1898
|
+
// SelectInput 会处理 single 模式的 value 和 onChange 转换
|
|
1899
|
+
const [innerValue, setInnerValue] = useState(Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : []);
|
|
1900
|
+
|
|
1901
|
+
// currentValue 用于内部处理,始终是数组
|
|
1902
|
+
const currentValue = useMemo(() => {
|
|
1903
|
+
if (value !== undefined) {
|
|
1904
|
+
// 外部传入的 value 可能是对象(single)或数组(多选)
|
|
1905
|
+
return Array.isArray(value) ? value : value ? [value] : [];
|
|
1906
|
+
}
|
|
1907
|
+
return innerValue;
|
|
1908
|
+
}, [value, innerValue]);
|
|
1909
|
+
const setValue = useCallback(newValue => {
|
|
1910
|
+
// SelectInput 在 single 模式下会传单个对象或 null/undefined,需要转换为数组
|
|
1911
|
+
const normalizedValue = (() => {
|
|
1912
|
+
if (single) {
|
|
1913
|
+
// 单选模式:可能是单个对象、null、undefined 或数组
|
|
1914
|
+
if (Array.isArray(newValue)) {
|
|
1915
|
+
return newValue;
|
|
1916
|
+
}
|
|
1917
|
+
return isNotEmpty(newValue) ? [newValue] : [];
|
|
1918
|
+
}
|
|
1919
|
+
// 多选模式:确保是数组
|
|
1920
|
+
return Array.isArray(newValue) ? newValue : [];
|
|
1921
|
+
})();
|
|
1922
|
+
if (value === undefined) {
|
|
1923
|
+
setInnerValue(normalizedValue);
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
// 根据单选/多选模式转换输出格式
|
|
1927
|
+
if (single) {
|
|
1928
|
+
// 单选:返回单个对象或 null
|
|
1929
|
+
onChange == null || onChange(normalizedValue.length > 0 ? normalizedValue[0] : null);
|
|
1930
|
+
} else {
|
|
1931
|
+
// 多选:返回数组
|
|
1932
|
+
onChange == null || onChange(normalizedValue);
|
|
1933
|
+
}
|
|
1934
|
+
}, [value, onChange, single]);
|
|
1935
|
+
|
|
1936
|
+
// 传递给 SelectInput 的值:根据 single 参数决定格式
|
|
1937
|
+
const selectInputValue = useMemo(() => {
|
|
1938
|
+
if (single) {
|
|
1939
|
+
// single 模式:传单个对象或 undefined
|
|
1940
|
+
return currentValue.length > 0 ? currentValue[0] : undefined;
|
|
1941
|
+
}
|
|
1942
|
+
// 多选模式:传数组
|
|
1943
|
+
return currentValue;
|
|
1944
|
+
}, [currentValue, single]);
|
|
1945
|
+
|
|
1946
|
+
// 计算 label 显示
|
|
1947
|
+
useMemo(() => {
|
|
1948
|
+
// currentValue 已经是数组格式了
|
|
1949
|
+
return currentValue.map(item => {
|
|
1950
|
+
// 如果已经是对象,确保有标准化的字段
|
|
1951
|
+
if (typeof item === 'object') {
|
|
1952
|
+
// 优先使用 item[labelKey],然后是 item.label,最后是 item.name
|
|
1953
|
+
const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
|
|
1954
|
+
return _extends({}, item, {
|
|
1955
|
+
[valueKey]: item[valueKey] || item.id,
|
|
1956
|
+
[labelKey]: label
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
// 如果是值,从 options 中查找
|
|
1960
|
+
const findLabel = items => {
|
|
1961
|
+
for (const node of items) {
|
|
1962
|
+
if (node[valueKey] === item) {
|
|
1963
|
+
return {
|
|
1964
|
+
[valueKey]: item,
|
|
1965
|
+
[labelKey]: node[labelKey] || node.name || String(item)
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
if (node.children) {
|
|
1969
|
+
const found = findLabel(node.children);
|
|
1970
|
+
if (found) return found;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
return null;
|
|
1974
|
+
};
|
|
1975
|
+
return findLabel(options) || {
|
|
1976
|
+
[valueKey]: item,
|
|
1977
|
+
[labelKey]: String(item)
|
|
1978
|
+
};
|
|
1979
|
+
}).filter(Boolean);
|
|
1980
|
+
}, [currentValue, options, valueKey, labelKey]);
|
|
1981
|
+
return /*#__PURE__*/React.createElement(SelectInput, _extends({}, props, {
|
|
1982
|
+
value: selectInputValue,
|
|
1983
|
+
onChange: setValue,
|
|
1984
|
+
single: single,
|
|
1985
|
+
maxLength: maxLength,
|
|
1986
|
+
isPopup: isPopup,
|
|
1987
|
+
placeholder: placeholder,
|
|
1988
|
+
disabled: disabled,
|
|
1989
|
+
size: size,
|
|
1990
|
+
valueKey: valueKey,
|
|
1991
|
+
labelKey: labelKey,
|
|
1992
|
+
overlayWidth: overlayWidth || menuItemWidth * 2
|
|
1993
|
+
}), contextProps => {
|
|
1994
|
+
// 使用 contextProps 中的 value 和 setValue,支持 Modal 模式下的内部状态管理
|
|
1995
|
+
const contextValue = contextProps.value;
|
|
1996
|
+
const contextSetValue = contextProps.setValue;
|
|
1997
|
+
|
|
1998
|
+
// 计算当前显示的 value
|
|
1999
|
+
const currentDisplayValue = contextValue.map(item => {
|
|
2000
|
+
// 如果已经是对象,确保有标准化的字段
|
|
2001
|
+
if (typeof item === 'object') {
|
|
2002
|
+
const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
|
|
2003
|
+
return _extends({}, item, {
|
|
2004
|
+
[valueKey]: item[valueKey] || item.id,
|
|
2005
|
+
[labelKey]: label
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
// 如果是值,从 options 中查找
|
|
2009
|
+
const findLabel = items => {
|
|
2010
|
+
for (const node of items) {
|
|
2011
|
+
if (node[valueKey] === item) {
|
|
2012
|
+
return {
|
|
2013
|
+
[valueKey]: item,
|
|
2014
|
+
[labelKey]: node[labelKey] || node.name || String(item)
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
if (node.children) {
|
|
2018
|
+
const found = findLabel(node.children);
|
|
2019
|
+
if (found) return found;
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
return null;
|
|
2023
|
+
};
|
|
2024
|
+
return findLabel(options) || {
|
|
2025
|
+
[valueKey]: item,
|
|
2026
|
+
[labelKey]: String(item)
|
|
2027
|
+
};
|
|
2028
|
+
}).filter(Boolean);
|
|
2029
|
+
return /*#__PURE__*/React.createElement(CascaderInner, {
|
|
2030
|
+
options: options,
|
|
2031
|
+
value: currentDisplayValue,
|
|
2032
|
+
setValue: contextSetValue,
|
|
2033
|
+
maxLength: maxLength,
|
|
2034
|
+
single: single,
|
|
2035
|
+
onlyAllowLastLevel: onlyAllowLastLevel,
|
|
2036
|
+
openLoadData: openLoadData,
|
|
2037
|
+
onLoadMore: onLoadMore,
|
|
2038
|
+
parentIdKey: parentIdKey,
|
|
2039
|
+
menuItemWidth: menuItemWidth,
|
|
2040
|
+
isPopup: isPopup,
|
|
2041
|
+
searchPlaceholder: searchPlaceholder,
|
|
2042
|
+
onSearch: onSearch,
|
|
2043
|
+
valueKey: valueKey,
|
|
2044
|
+
labelKey: labelKey,
|
|
2045
|
+
onOpenChange: contextProps.onOpenChange,
|
|
2046
|
+
open: contextProps.open
|
|
2047
|
+
});
|
|
2048
|
+
});
|
|
2049
|
+
};
|
|
2050
|
+
|
|
2051
|
+
export { SelectCascader, SelectInput, SelectTableList, SelectTree, SelectedAll, SelectedTagList, createTreeUtils, SelectList as default };
|
|
1171
2052
|
//# sourceMappingURL=index.modern.js.map
|