@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.js
CHANGED
|
@@ -45,15 +45,6 @@ function _extends() {
|
|
|
45
45
|
return n;
|
|
46
46
|
}, _extends.apply(null, arguments);
|
|
47
47
|
}
|
|
48
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
49
|
-
if (null == r) return {};
|
|
50
|
-
var t = {};
|
|
51
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
52
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
53
|
-
t[n] = r[n];
|
|
54
|
-
}
|
|
55
|
-
return t;
|
|
56
|
-
}
|
|
57
48
|
|
|
58
49
|
const context = globalContext.createContext();
|
|
59
50
|
const {
|
|
@@ -61,7 +52,7 @@ const {
|
|
|
61
52
|
useContext
|
|
62
53
|
} = context;
|
|
63
54
|
|
|
64
|
-
var style$
|
|
55
|
+
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"};
|
|
65
56
|
|
|
66
57
|
const locale$1 = {
|
|
67
58
|
placeholder: '请选择',
|
|
@@ -85,9 +76,98 @@ const locale = {
|
|
|
85
76
|
removeAll: 'Remove All'
|
|
86
77
|
};
|
|
87
78
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
/**
|
|
80
|
+
* 标签溢出内部渲染组件
|
|
81
|
+
* 根据 innerWidth 计算标签显示数量
|
|
82
|
+
*/
|
|
83
|
+
const TagOverflowInner = ({
|
|
84
|
+
value,
|
|
85
|
+
innerWidth,
|
|
86
|
+
labelKey,
|
|
87
|
+
valueKey,
|
|
88
|
+
onRemove,
|
|
89
|
+
overflowTagWidth = 45,
|
|
90
|
+
iconSpace = 20
|
|
91
|
+
}) => {
|
|
92
|
+
const [visibleCount, setVisibleCount] = React.useState(value.length);
|
|
93
|
+
const measureRef = React.useRef(null);
|
|
94
|
+
|
|
95
|
+
// 测量每个标签的实际宽度并计算可见数量
|
|
96
|
+
React.useLayoutEffect(() => {
|
|
97
|
+
// innerWidth 为 0 时,保持当前状态,等待正确的宽度
|
|
98
|
+
if (!measureRef.current || innerWidth === 0 || value.length === 0) {
|
|
99
|
+
setVisibleCount(value.length);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const tagElements = measureRef.current.querySelectorAll('[data-tag-measure]');
|
|
103
|
+
if (tagElements.length === 0) return;
|
|
104
|
+
|
|
105
|
+
// 获取每个标签的实际占用宽度(包含 margin)
|
|
106
|
+
const tagWidths = Array.from(tagElements).map(el => {
|
|
107
|
+
const style = window.getComputedStyle(el);
|
|
108
|
+
const marginLeft = parseFloat(style.marginLeft) || 0;
|
|
109
|
+
const marginRight = parseFloat(style.marginRight) || 0;
|
|
110
|
+
return el.offsetWidth + marginLeft + marginRight;
|
|
111
|
+
});
|
|
112
|
+
const availableWidth = innerWidth - iconSpace;
|
|
113
|
+
let totalWidth = 0;
|
|
114
|
+
let count = 0;
|
|
115
|
+
for (let i = 0; i < tagWidths.length; i++) {
|
|
116
|
+
// 如果不是最后一个,需要预留 +N 标签空间
|
|
117
|
+
const needOverflowSpace = i < tagWidths.length - 1;
|
|
118
|
+
const requiredWidth = tagWidths[i] + (needOverflowSpace ? overflowTagWidth : 0);
|
|
119
|
+
if (totalWidth + requiredWidth <= availableWidth) {
|
|
120
|
+
totalWidth += tagWidths[i];
|
|
121
|
+
count++;
|
|
122
|
+
} else {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 确保至少显示一个标签
|
|
128
|
+
setVisibleCount(Math.max(1, count));
|
|
129
|
+
}, [value, innerWidth, overflowTagWidth, iconSpace]);
|
|
130
|
+
|
|
131
|
+
// 计算单个标签最大宽度:min(150px, innerWidth - 60),初始状态默认 150px
|
|
132
|
+
const maxTagWidth = innerWidth > 0 ? Math.min(150, Math.max(60, innerWidth - 60)) : 150;
|
|
133
|
+
const displayTags = value.slice(0, visibleCount);
|
|
134
|
+
const hiddenCount = value.length - visibleCount;
|
|
135
|
+
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
136
|
+
ref: measureRef,
|
|
137
|
+
className: style$6['measure-layer']
|
|
138
|
+
}, value.map(item => /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
|
|
139
|
+
key: item[valueKey],
|
|
140
|
+
"data-tag-measure": true,
|
|
141
|
+
closable: true,
|
|
142
|
+
bordered: false,
|
|
143
|
+
className: style$6['tag-item'],
|
|
144
|
+
style: {
|
|
145
|
+
'--max-tag-width': `${maxTagWidth}px`
|
|
146
|
+
}
|
|
147
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
148
|
+
className: style$6['tag-label']
|
|
149
|
+
}, item[labelKey])))), displayTags.map(item => /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
|
|
150
|
+
key: item[valueKey],
|
|
151
|
+
closable: true,
|
|
152
|
+
bordered: false,
|
|
153
|
+
className: style$6['tag-item'],
|
|
154
|
+
style: {
|
|
155
|
+
'--max-tag-width': `${maxTagWidth}px`
|
|
156
|
+
},
|
|
157
|
+
onClose: e => {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
onRemove(item);
|
|
160
|
+
}
|
|
161
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
162
|
+
className: style$6['tag-label'],
|
|
163
|
+
title: item[labelKey]
|
|
164
|
+
}, item[labelKey]))), hiddenCount > 0 && /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
|
|
165
|
+
className: style$6['overflow-tag']
|
|
166
|
+
}, "+", hiddenCount));
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const numberToPx$1 = val => {
|
|
170
|
+
return typeof val === 'number' ? `${val}px` : val;
|
|
91
171
|
};
|
|
92
172
|
const pxToNumber = value => {
|
|
93
173
|
if (!value) return 0;
|
|
@@ -99,9 +179,9 @@ const pxToNumber = value => {
|
|
|
99
179
|
};
|
|
100
180
|
const ModalContent = _ref => {
|
|
101
181
|
let {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
182
|
+
children,
|
|
183
|
+
...others
|
|
184
|
+
} = _ref;
|
|
105
185
|
const {
|
|
106
186
|
open,
|
|
107
187
|
value: propsValue
|
|
@@ -169,6 +249,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
169
249
|
prefix: null,
|
|
170
250
|
suffix: null,
|
|
171
251
|
extra: null,
|
|
252
|
+
size: 'default',
|
|
172
253
|
renderModal: contextProps => {
|
|
173
254
|
const {
|
|
174
255
|
props,
|
|
@@ -216,7 +297,8 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
216
297
|
placement,
|
|
217
298
|
renderModal,
|
|
218
299
|
labelKey,
|
|
219
|
-
valueKey
|
|
300
|
+
valueKey,
|
|
301
|
+
size
|
|
220
302
|
} = props;
|
|
221
303
|
const transformValue = value => {
|
|
222
304
|
if (single) {
|
|
@@ -241,11 +323,21 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
241
323
|
onChange: 'onOpenChange'
|
|
242
324
|
});
|
|
243
325
|
const [hover, setHover] = React.useState(false);
|
|
244
|
-
const [
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
326
|
+
const [innerWidth, setInnerWidth] = React.useState(0);
|
|
327
|
+
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
328
|
+
const containerWidthChange = el => {
|
|
329
|
+
if (!el) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const containerWidth = el.clientWidth;
|
|
333
|
+
setContainerWidth(containerWidth);
|
|
334
|
+
const innerEl = el.querySelector('.select-input-inner');
|
|
335
|
+
setInnerWidth(innerEl.clientWidth);
|
|
336
|
+
};
|
|
337
|
+
const popupOverlayWidth = React.useMemo(() => {
|
|
338
|
+
return numberToPx$1(Math.max(containerWidth, pxToNumber(overlayWidth)));
|
|
339
|
+
}, [containerWidth, overlayWidth]);
|
|
340
|
+
const containerRef = useResize__default["default"](containerWidthChange);
|
|
249
341
|
const {
|
|
250
342
|
message
|
|
251
343
|
} = antd.App.useApp();
|
|
@@ -305,7 +397,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
305
397
|
searchProps,
|
|
306
398
|
setSearchProps,
|
|
307
399
|
hover,
|
|
308
|
-
inputWidth,
|
|
400
|
+
inputWidth: containerWidth,
|
|
309
401
|
onAdd,
|
|
310
402
|
onRemove,
|
|
311
403
|
onSelect,
|
|
@@ -321,10 +413,12 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
321
413
|
return contextProps.props.inputRender(props, contextProps);
|
|
322
414
|
}
|
|
323
415
|
return /*#__PURE__*/React__default["default"].createElement(antd.Flex, _extends({}, props, {
|
|
324
|
-
ref:
|
|
325
|
-
className: classnames__default["default"](className, style$
|
|
326
|
-
[style$
|
|
327
|
-
[style$
|
|
416
|
+
ref: containerRef,
|
|
417
|
+
className: classnames__default["default"](className, style$6['select-input'], 'select-input', {
|
|
418
|
+
[style$6['wrap']]: labelWrap,
|
|
419
|
+
[style$6['disabled']]: disabled,
|
|
420
|
+
[style$6['small']]: size === 'small',
|
|
421
|
+
[style$6['large']]: size === 'large'
|
|
328
422
|
}),
|
|
329
423
|
justify: "space-between",
|
|
330
424
|
onMouseOver: () => {
|
|
@@ -336,27 +430,26 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
336
430
|
}), (() => {
|
|
337
431
|
const current = typeof prefix === 'function' ? prefix(contextProps) : prefix;
|
|
338
432
|
return current && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
339
|
-
className: classnames__default["default"](style$
|
|
433
|
+
className: classnames__default["default"](style$6['select-input-prefix'], 'select-input-prefix'),
|
|
340
434
|
onClick: e => {
|
|
341
435
|
e.stopPropagation();
|
|
342
436
|
}
|
|
343
437
|
}, current);
|
|
344
438
|
})(), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
345
|
-
className: classnames__default["default"](style$
|
|
346
|
-
}, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ?
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}, item[labelKey]);
|
|
439
|
+
className: classnames__default["default"](style$6['select-input-inner'], 'select-input-inner')
|
|
440
|
+
}, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ? /*#__PURE__*/React__default["default"].createElement("span", {
|
|
441
|
+
className: classnames__default["default"](style$6['single-label'], 'select-input-single-label'),
|
|
442
|
+
title: value[0][labelKey]
|
|
443
|
+
}, value[0][labelKey]) : /*#__PURE__*/React__default["default"].createElement(TagOverflowInner, {
|
|
444
|
+
value: value,
|
|
445
|
+
innerWidth: innerWidth,
|
|
446
|
+
labelKey: labelKey,
|
|
447
|
+
valueKey: valueKey,
|
|
448
|
+
onRemove: onRemove
|
|
356
449
|
}) : /*#__PURE__*/React__default["default"].createElement("span", {
|
|
357
|
-
className: classnames__default["default"](style$
|
|
450
|
+
className: classnames__default["default"](style$6['placeholder'], 'select-input-placeholder')
|
|
358
451
|
}, placeholder)), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
359
|
-
className: classnames__default["default"](style$
|
|
452
|
+
className: classnames__default["default"](style$6['select-input-icon'], 'select-input-icon')
|
|
360
453
|
}, !disabled && allowClear && hover && value.length > 0 ? /*#__PURE__*/React__default["default"].createElement(icons.CloseCircleFilled, {
|
|
361
454
|
onClick: e => {
|
|
362
455
|
e.stopPropagation();
|
|
@@ -365,7 +458,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
365
458
|
}) : /*#__PURE__*/React__default["default"].createElement(icons.DownOutlined, null)), (() => {
|
|
366
459
|
const current = typeof suffix === 'function' ? suffix(contextProps) : suffix;
|
|
367
460
|
return current && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
368
|
-
className: classnames__default["default"](style$
|
|
461
|
+
className: classnames__default["default"](style$6['select-input-suffix'], 'select-input-suffix'),
|
|
369
462
|
onClick: e => {
|
|
370
463
|
e.stopPropagation();
|
|
371
464
|
}
|
|
@@ -385,13 +478,13 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
385
478
|
onOpenChange: setOpen,
|
|
386
479
|
placement: placement,
|
|
387
480
|
arrow: false,
|
|
388
|
-
overlayClassName: classnames__default["default"](style$
|
|
481
|
+
overlayClassName: classnames__default["default"](style$6['overlay'], overlayClassName),
|
|
389
482
|
trigger: "click",
|
|
390
483
|
popupRender: () => /*#__PURE__*/React__default["default"].createElement("div", {
|
|
391
484
|
style: {
|
|
392
485
|
'--overlay-width': popupOverlayWidth
|
|
393
486
|
},
|
|
394
|
-
className: classnames__default["default"](style$
|
|
487
|
+
className: classnames__default["default"](style$6['overlay-content'], 'over-content'),
|
|
395
488
|
onClick: e => {
|
|
396
489
|
e.stopPropagation();
|
|
397
490
|
}
|
|
@@ -403,7 +496,7 @@ const SelectInput = reactIntl.createWithIntlProvider({
|
|
|
403
496
|
}), /*#__PURE__*/React__default["default"].createElement(ModalContent, contextProps, renderModal)));
|
|
404
497
|
}));
|
|
405
498
|
|
|
406
|
-
var style$
|
|
499
|
+
var style$5 = {"selected-all":"_prlgN"};
|
|
407
500
|
|
|
408
501
|
const SelectedAll = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
409
502
|
const {
|
|
@@ -428,7 +521,7 @@ const SelectedAll = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-s
|
|
|
428
521
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
429
522
|
return /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
|
|
430
523
|
justify: "space-between",
|
|
431
|
-
className: classnames__default["default"](style$
|
|
524
|
+
className: classnames__default["default"](style$5['selected-all'], 'selected-all')
|
|
432
525
|
}, /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
|
|
433
526
|
gap: 8
|
|
434
527
|
}, /*#__PURE__*/React__default["default"].createElement("span", null, formatMessage({
|
|
@@ -451,10 +544,10 @@ const computedIsSelectAll = function (value, selectedAllValue, valueKey) {
|
|
|
451
544
|
if (valueKey === void 0) {
|
|
452
545
|
valueKey = 'value';
|
|
453
546
|
}
|
|
454
|
-
return
|
|
547
|
+
return value?.length === 1 && get__default["default"](value, `[0][${valueKey}]`) === selectedAllValue[valueKey];
|
|
455
548
|
};
|
|
456
549
|
|
|
457
|
-
var style$
|
|
550
|
+
var style$4 = {"label":"_l3KoW","tag-list":"_CCPzb","tag-container":"_dKZHi","tag-container-inner":"_oijCI","tag":"_WmnnS","tag-inner":"_TMcFl"};
|
|
458
551
|
|
|
459
552
|
const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
460
553
|
const {
|
|
@@ -472,21 +565,21 @@ const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
472
565
|
valueKey
|
|
473
566
|
} = Object.assign({}, props);
|
|
474
567
|
return /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
|
|
475
|
-
className: classnames__default["default"](style$
|
|
568
|
+
className: classnames__default["default"](style$4['tag-list'], 'selected-tag-list'),
|
|
476
569
|
gap: 8
|
|
477
570
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
478
|
-
className: style$
|
|
571
|
+
className: style$4['label']
|
|
479
572
|
}, formatMessage({
|
|
480
573
|
id: 'selected'
|
|
481
|
-
}), !single && value.length > 0 &&
|
|
482
|
-
className: style$
|
|
574
|
+
}), !single && value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
|
|
575
|
+
className: style$4['tag-container']
|
|
483
576
|
}, /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
|
|
484
577
|
gap: 8,
|
|
485
578
|
wrap: true,
|
|
486
|
-
className: style$
|
|
579
|
+
className: style$4['tag-container-inner']
|
|
487
580
|
}, value.map(item => {
|
|
488
581
|
return /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
|
|
489
|
-
className: style$
|
|
582
|
+
className: style$4['tag'],
|
|
490
583
|
key: item[valueKey],
|
|
491
584
|
closable: true,
|
|
492
585
|
bordered: false,
|
|
@@ -495,19 +588,18 @@ const SelectedTagList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
495
588
|
onRemove(item);
|
|
496
589
|
}
|
|
497
590
|
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
498
|
-
className: style$
|
|
591
|
+
className: style$4['tag-inner']
|
|
499
592
|
}, item[labelKey]));
|
|
500
593
|
}))));
|
|
501
594
|
});
|
|
502
595
|
|
|
503
|
-
var style$
|
|
596
|
+
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"};
|
|
504
597
|
|
|
505
|
-
const _excluded$1 = ["children"];
|
|
506
598
|
const SelectList = React.forwardRef((_ref, ref) => {
|
|
507
599
|
let {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
600
|
+
children,
|
|
601
|
+
...p
|
|
602
|
+
} = _ref;
|
|
511
603
|
const fetchListRef = React.useRef(null);
|
|
512
604
|
const props = Object.assign({}, {
|
|
513
605
|
renderItemContent: _ref2 => {
|
|
@@ -521,7 +613,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
521
613
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
522
614
|
className: 'select-list-item-label'
|
|
523
615
|
}, item[labelKey]), item.description && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
524
|
-
className: classnames__default["default"](style$
|
|
616
|
+
className: classnames__default["default"](style$3['select-list-item-description'], 'select-list-item-description')
|
|
525
617
|
}, item.description));
|
|
526
618
|
},
|
|
527
619
|
renderItem: contextProps => {
|
|
@@ -542,9 +634,9 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
542
634
|
} = props;
|
|
543
635
|
const isChecked = value.some(target => target[valueKey] === item[valueKey]);
|
|
544
636
|
return /*#__PURE__*/React__default["default"].createElement(antd.List.Item, {
|
|
545
|
-
className: classnames__default["default"](style$
|
|
546
|
-
[style$
|
|
547
|
-
[style$
|
|
637
|
+
className: classnames__default["default"](style$3['default-list-item'], 'select-list-item', {
|
|
638
|
+
[style$3['is-selected']]: isChecked,
|
|
639
|
+
[style$3['is-disabled']]: item.disabled
|
|
548
640
|
}),
|
|
549
641
|
key: item[valueKey],
|
|
550
642
|
onClick: () => {
|
|
@@ -572,7 +664,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
572
664
|
flex: 1,
|
|
573
665
|
className: 'select-list-item-content'
|
|
574
666
|
}, renderItemContent(contextProps)), single && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
575
|
-
className: style$
|
|
667
|
+
className: style$3['single-checked']
|
|
576
668
|
}, isChecked && /*#__PURE__*/React__default["default"].createElement(icons.CheckOutlined, null)));
|
|
577
669
|
},
|
|
578
670
|
renderList: contextProps => {
|
|
@@ -586,12 +678,12 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
586
678
|
} = props;
|
|
587
679
|
if (!(list && list.length > 0)) {
|
|
588
680
|
return props.empty || /*#__PURE__*/React__default["default"].createElement(antd.Empty, {
|
|
589
|
-
className: style$
|
|
681
|
+
className: style$3['empty']
|
|
590
682
|
});
|
|
591
683
|
}
|
|
592
684
|
return /*#__PURE__*/React__default["default"].createElement(antd.List, {
|
|
593
|
-
className: classnames__default["default"](style$
|
|
594
|
-
[style$
|
|
685
|
+
className: classnames__default["default"](style$3['default-list'], {
|
|
686
|
+
[style$3['is-selected-all']]: isSelectedAll
|
|
595
687
|
}),
|
|
596
688
|
size: "small",
|
|
597
689
|
dataSource: list,
|
|
@@ -628,7 +720,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
628
720
|
} = props;
|
|
629
721
|
const components = {
|
|
630
722
|
search: (api && typeof getSearchProps === 'function' || options && typeof getSearchCallback === 'function') && /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
|
|
631
|
-
className: classnames__default["default"](style$
|
|
723
|
+
className: classnames__default["default"](style$3['select-search'], 'select-list-search', {
|
|
632
724
|
'is-popup': isPopup
|
|
633
725
|
}),
|
|
634
726
|
placeholder: searchPlaceholder,
|
|
@@ -642,12 +734,12 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
642
734
|
showSearchButton: !isPopup
|
|
643
735
|
}),
|
|
644
736
|
selectedAll: /*#__PURE__*/React__default["default"].createElement("div", {
|
|
645
|
-
className: classnames__default["default"](style$
|
|
737
|
+
className: classnames__default["default"](style$3['selected-all'], 'select-list-selected-all', {
|
|
646
738
|
'is-popup': isPopup
|
|
647
739
|
})
|
|
648
740
|
}, !single && allowSelectedAll && /*#__PURE__*/React__default["default"].createElement(SelectedAll, null)),
|
|
649
741
|
fetchList: /*#__PURE__*/React__default["default"].createElement(scrollLoader.FetchScrollLoader, _extends({}, props, {
|
|
650
|
-
className: classnames__default["default"](style$
|
|
742
|
+
className: classnames__default["default"](style$3['list'], 'select-list-scroll-list', {
|
|
651
743
|
'is-popup': isPopup
|
|
652
744
|
}),
|
|
653
745
|
searchProps: searchProps,
|
|
@@ -684,12 +776,12 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
684
776
|
}));
|
|
685
777
|
}),
|
|
686
778
|
selectedTag: showSelectedTag && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
687
|
-
className: classnames__default["default"](style$
|
|
779
|
+
className: classnames__default["default"](style$3['selected-tag'], 'select-list-selected-tag', {
|
|
688
780
|
'is-popup': isPopup
|
|
689
781
|
})
|
|
690
782
|
}, /*#__PURE__*/React__default["default"].createElement(SelectedTagList, null)),
|
|
691
783
|
footer: footer && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
692
|
-
className: classnames__default["default"](style$
|
|
784
|
+
className: classnames__default["default"](style$3['footer'], 'select-list-footer')
|
|
693
785
|
}, typeof footer === 'function' ? footer({
|
|
694
786
|
reload: () => {
|
|
695
787
|
fetchListRef.current && fetchListRef.current.reload();
|
|
@@ -710,7 +802,7 @@ const SelectList = React.forwardRef((_ref, ref) => {
|
|
|
710
802
|
});
|
|
711
803
|
});
|
|
712
804
|
|
|
713
|
-
var style$
|
|
805
|
+
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"};
|
|
714
806
|
|
|
715
807
|
const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'super-select')(React.forwardRef((p, ref) => {
|
|
716
808
|
const {
|
|
@@ -739,7 +831,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
739
831
|
return null;
|
|
740
832
|
}
|
|
741
833
|
return /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
|
|
742
|
-
className: classnames__default["default"](style$
|
|
834
|
+
className: classnames__default["default"](style$2['select-search'], 'select-table-search', {
|
|
743
835
|
'is-popup': isPopup
|
|
744
836
|
}),
|
|
745
837
|
placeholder: searchPlaceholder,
|
|
@@ -799,11 +891,10 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
799
891
|
} = props;
|
|
800
892
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
801
893
|
const footerEl = footer && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
802
|
-
className: classnames__default["default"](style$
|
|
894
|
+
className: classnames__default["default"](style$2['footer'], 'select-table-footer')
|
|
803
895
|
}, typeof footer === 'function' ? footer({
|
|
804
896
|
reload: () => {
|
|
805
|
-
|
|
806
|
-
((_fetchListRef$current = fetchListRef.current) == null ? void 0 : _fetchListRef$current.fetchApi) && ((_fetchListRef$current2 = fetchListRef.current) == null ? void 0 : _fetchListRef$current2.fetchApi.reload());
|
|
897
|
+
fetchListRef.current?.fetchApi && fetchListRef.current?.fetchApi.reload();
|
|
807
898
|
},
|
|
808
899
|
close: () => {
|
|
809
900
|
onOpenChange(false);
|
|
@@ -814,11 +905,11 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
814
905
|
ref: bodyRef
|
|
815
906
|
}, /*#__PURE__*/React__default["default"].createElement(antd.Col, {
|
|
816
907
|
className: classnames__default["default"]({
|
|
817
|
-
[style$
|
|
908
|
+
[style$2['single-body']]: single
|
|
818
909
|
}),
|
|
819
910
|
span: single ? 24 : 16
|
|
820
911
|
}, /*#__PURE__*/React__default["default"].createElement("div", null, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
821
|
-
className: classnames__default["default"](style$
|
|
912
|
+
className: classnames__default["default"](style$2['table'], 'select-table')
|
|
822
913
|
}, /*#__PURE__*/React__default["default"].createElement(infoPage.TableView, {
|
|
823
914
|
columns: columns,
|
|
824
915
|
rowKey: valueKey,
|
|
@@ -836,13 +927,16 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
836
927
|
} = _ref;
|
|
837
928
|
setValue(value => {
|
|
838
929
|
if (checked) {
|
|
839
|
-
|
|
840
|
-
const newValue = value.slice(0);
|
|
841
|
-
const selectedItem = (_fetchListRef$current3 = fetchListRef.current) == null ? void 0 : _fetchListRef$current3.list.find(item => item[valueKey] === selectedKey);
|
|
930
|
+
const selectedItem = fetchListRef.current?.list.find(item => item[valueKey] === selectedKey);
|
|
842
931
|
if (selectedItem) {
|
|
932
|
+
if (single) {
|
|
933
|
+
return [selectedItem];
|
|
934
|
+
}
|
|
935
|
+
const newValue = value.slice(0);
|
|
843
936
|
newValue.push(selectedItem);
|
|
937
|
+
return newValue;
|
|
844
938
|
}
|
|
845
|
-
return
|
|
939
|
+
return value;
|
|
846
940
|
} else {
|
|
847
941
|
return value.filter(item => item[valueKey] !== selectedKey);
|
|
848
942
|
}
|
|
@@ -858,7 +952,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
858
952
|
renderBody
|
|
859
953
|
} = _ref2;
|
|
860
954
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, header, /*#__PURE__*/React__default["default"].createElement(scrollLoader.FetchScrollLoader, _extends({}, props, {
|
|
861
|
-
className: classnames__default["default"](style$
|
|
955
|
+
className: classnames__default["default"](style$2['list'], 'select-table-list-scroll-list', {
|
|
862
956
|
'is-popup': isPopup
|
|
863
957
|
}),
|
|
864
958
|
searchProps: searchProps,
|
|
@@ -897,21 +991,21 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
897
991
|
});
|
|
898
992
|
if (!(list && list.length > 0)) {
|
|
899
993
|
return props.empty || /*#__PURE__*/React__default["default"].createElement(antd.Empty, {
|
|
900
|
-
className: classnames__default["default"](style$
|
|
994
|
+
className: classnames__default["default"](style$2['empty'])
|
|
901
995
|
});
|
|
902
996
|
}
|
|
903
997
|
return renderBody(list, contextProps);
|
|
904
998
|
}));
|
|
905
999
|
}
|
|
906
1000
|
})), single && footerEl || /*#__PURE__*/React__default["default"].createElement("div", {
|
|
907
|
-
className: classnames__default["default"](style$
|
|
1001
|
+
className: classnames__default["default"](style$2['footer'], 'select-table-footer')
|
|
908
1002
|
})), !single && /*#__PURE__*/React__default["default"].createElement(antd.Col, {
|
|
909
|
-
className: classnames__default["default"](style$
|
|
1003
|
+
className: classnames__default["default"](style$2['right-options'], {
|
|
910
1004
|
'is-popup': isPopup
|
|
911
1005
|
}),
|
|
912
1006
|
span: 8
|
|
913
1007
|
}, /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
|
|
914
|
-
className: style$
|
|
1008
|
+
className: style$2['tags-search'],
|
|
915
1009
|
placeholder: searchPlaceholder,
|
|
916
1010
|
value: tagSearchText,
|
|
917
1011
|
onSearch: value => {
|
|
@@ -924,8 +1018,8 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
924
1018
|
align: 'middle'
|
|
925
1019
|
}, /*#__PURE__*/React__default["default"].createElement(antd.Col, null, formatMessage({
|
|
926
1020
|
id: 'selected'
|
|
927
|
-
}), value.length > 0 &&
|
|
928
|
-
className: style$
|
|
1021
|
+
}), value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React__default["default"].createElement(antd.Col, null, /*#__PURE__*/React__default["default"].createElement(antd.Button, {
|
|
1022
|
+
className: style$2['no-padding-btn'],
|
|
929
1023
|
type: "link",
|
|
930
1024
|
onClick: () => {
|
|
931
1025
|
setValue([]);
|
|
@@ -936,9 +1030,8 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
936
1030
|
wrap: true,
|
|
937
1031
|
gap: 8
|
|
938
1032
|
}, value.filter(item => getTagSearchCallback(tagSearchText, item, targetProps)).map(item => {
|
|
939
|
-
var _fetchListRef$current4, _fetchListRef$current5;
|
|
940
1033
|
return /*#__PURE__*/React__default["default"].createElement(antd.Tag, {
|
|
941
|
-
className: style$
|
|
1034
|
+
className: style$2['tag'],
|
|
942
1035
|
key: item[valueKey],
|
|
943
1036
|
closable: true,
|
|
944
1037
|
bordered: false,
|
|
@@ -949,7 +1042,7 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
949
1042
|
}, /*#__PURE__*/React__default["default"].createElement(antd.Popover, {
|
|
950
1043
|
getPopupContainer: () => bodyRef.current,
|
|
951
1044
|
content: /*#__PURE__*/React__default["default"].createElement(infoPage.CentralContent, {
|
|
952
|
-
className: style$
|
|
1045
|
+
className: style$2['descriptions'],
|
|
953
1046
|
columns: columns.filter(item => {
|
|
954
1047
|
if (Object.hasOwn(item, 'previewHidden')) {
|
|
955
1048
|
return !item.previewHidden;
|
|
@@ -960,21 +1053,19 @@ const SelectTableList = reactIntl.createWithIntlProvider('zh-CN', locale$1, 'sup
|
|
|
960
1053
|
})),
|
|
961
1054
|
dataSource: Object.assign({}, item),
|
|
962
1055
|
context: Object.assign({}, targetProps, {
|
|
963
|
-
fetchApi:
|
|
964
|
-
list:
|
|
1056
|
+
fetchApi: fetchListRef.current?.fetchApi,
|
|
1057
|
+
list: fetchListRef.current?.list
|
|
965
1058
|
})
|
|
966
1059
|
})
|
|
967
1060
|
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
968
|
-
className: style$
|
|
1061
|
+
className: style$2['tag-inner']
|
|
969
1062
|
}, item[labelKey])));
|
|
970
1063
|
}))), footerEl));
|
|
971
1064
|
});
|
|
972
1065
|
}));
|
|
973
1066
|
|
|
974
|
-
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"};
|
|
1067
|
+
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"};
|
|
975
1068
|
|
|
976
|
-
const _excluded = ["children"],
|
|
977
|
-
_excluded2 = ["data"];
|
|
978
1069
|
const parseTreeData = memoize__default["default"](function (data, _ref) {
|
|
979
1070
|
if (data === void 0) {
|
|
980
1071
|
data = [];
|
|
@@ -1001,9 +1092,9 @@ const parseTreeData = memoize__default["default"](function (data, _ref) {
|
|
|
1001
1092
|
});
|
|
1002
1093
|
const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
1003
1094
|
let {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1095
|
+
children,
|
|
1096
|
+
...p
|
|
1097
|
+
} = _ref2;
|
|
1007
1098
|
const fetchListRef = React.useRef(null);
|
|
1008
1099
|
const [expandedKeys, setExpandedKeys] = React.useState([]);
|
|
1009
1100
|
const props = Object.assign({}, {
|
|
@@ -1039,9 +1130,9 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
|
1039
1130
|
} = props;
|
|
1040
1131
|
const isChecked = value.some(target => target[valueKey] === item[valueKey]);
|
|
1041
1132
|
return /*#__PURE__*/React__default["default"].createElement(antd.Flex, {
|
|
1042
|
-
className: classnames__default["default"](style['default-list-item'], 'select-tree-item', {
|
|
1043
|
-
[style['is-selected']]: isChecked,
|
|
1044
|
-
[style['is-disabled']]: item.disabled
|
|
1133
|
+
className: classnames__default["default"](style$1['default-list-item'], 'select-tree-item', {
|
|
1134
|
+
[style$1['is-selected']]: isChecked,
|
|
1135
|
+
[style$1['is-disabled']]: item.disabled
|
|
1045
1136
|
}),
|
|
1046
1137
|
key: item[valueKey],
|
|
1047
1138
|
onClick: () => {
|
|
@@ -1069,7 +1160,7 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
|
1069
1160
|
flex: 1,
|
|
1070
1161
|
className: 'select-tree-item-content'
|
|
1071
1162
|
}, renderItemContent(contextProps)), single && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1072
|
-
className: style['single-checked']
|
|
1163
|
+
className: style$1['single-checked']
|
|
1073
1164
|
}, isChecked && /*#__PURE__*/React__default["default"].createElement(icons.CheckOutlined, null)));
|
|
1074
1165
|
},
|
|
1075
1166
|
renderTree: contextProps => {
|
|
@@ -1097,8 +1188,8 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
|
1097
1188
|
return props.empty || /*#__PURE__*/React__default["default"].createElement(antd.Empty, null);
|
|
1098
1189
|
}
|
|
1099
1190
|
return /*#__PURE__*/React__default["default"].createElement(antd.Tree, {
|
|
1100
|
-
className: classnames__default["default"](style['default-list'], {
|
|
1101
|
-
[style['is-selected-all']]: isSelectedAll
|
|
1191
|
+
className: classnames__default["default"](style$1['default-list'], {
|
|
1192
|
+
[style$1['is-selected-all']]: isSelectedAll
|
|
1102
1193
|
}),
|
|
1103
1194
|
showIcon: true,
|
|
1104
1195
|
selectable: false,
|
|
@@ -1142,7 +1233,7 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
|
1142
1233
|
} = props;
|
|
1143
1234
|
const components = {
|
|
1144
1235
|
selectedAll: /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1145
|
-
className: classnames__default["default"](style['selected-all'], 'select-tree-selected-all', {
|
|
1236
|
+
className: classnames__default["default"](style$1['selected-all'], 'select-tree-selected-all', {
|
|
1146
1237
|
'is-popup': isPopup
|
|
1147
1238
|
})
|
|
1148
1239
|
}, !single && allowSelectedAll && /*#__PURE__*/React__default["default"].createElement(SelectedAll, null)),
|
|
@@ -1160,12 +1251,12 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
|
1160
1251
|
ref: fetchListRef,
|
|
1161
1252
|
render: _ref5 => {
|
|
1162
1253
|
let {
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1254
|
+
data,
|
|
1255
|
+
...fetchProps
|
|
1256
|
+
} = _ref5;
|
|
1166
1257
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
1167
1258
|
return /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
|
|
1168
|
-
className: classnames__default["default"](style['list'], 'select-tree-scroll-list', {
|
|
1259
|
+
className: classnames__default["default"](style$1['list'], 'select-tree-scroll-list', {
|
|
1169
1260
|
'is-popup': isPopup
|
|
1170
1261
|
})
|
|
1171
1262
|
}, renderTree(Object.assign({}, fetchProps, targetProps, {
|
|
@@ -1175,12 +1266,12 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
|
1175
1266
|
}
|
|
1176
1267
|
})),
|
|
1177
1268
|
selectedTag: showSelectedTag && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1178
|
-
className: classnames__default["default"](style['selected-tag'], 'select-tree-selected-tag', {
|
|
1269
|
+
className: classnames__default["default"](style$1['selected-tag'], 'select-tree-selected-tag', {
|
|
1179
1270
|
'is-popup': isPopup
|
|
1180
1271
|
})
|
|
1181
1272
|
}, /*#__PURE__*/React__default["default"].createElement(SelectedTagList, null)),
|
|
1182
1273
|
footer: footer && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1183
|
-
className: classnames__default["default"](style['footer'], 'select-list-footer')
|
|
1274
|
+
className: classnames__default["default"](style$1['footer'], 'select-list-footer')
|
|
1184
1275
|
}, typeof footer === 'function' ? footer({
|
|
1185
1276
|
reload: () => {
|
|
1186
1277
|
fetchListRef.current && fetchListRef.current.reload();
|
|
@@ -1201,10 +1292,795 @@ const SelectTree = React.forwardRef((_ref2, ref) => {
|
|
|
1201
1292
|
});
|
|
1202
1293
|
});
|
|
1203
1294
|
|
|
1295
|
+
const createTreeUtils = mapping => {
|
|
1296
|
+
const mappingList = Array.from(mapping.values());
|
|
1297
|
+
const rootNodes = mappingList.filter(item => item.parentId === null);
|
|
1298
|
+
const delItem = (array, item) => {
|
|
1299
|
+
const index = array.indexOf(item);
|
|
1300
|
+
if (index > -1) {
|
|
1301
|
+
array.splice(index, 1);
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* 通过一个nodeId获取所有父级和所有子级的第一个元素,组成一个从最顶级到最子级的数组
|
|
1307
|
+
* */
|
|
1308
|
+
const getSelectedQueue = id => {
|
|
1309
|
+
const currentNode = mapping.get(id);
|
|
1310
|
+
if (!currentNode) {
|
|
1311
|
+
return [];
|
|
1312
|
+
}
|
|
1313
|
+
const getFirstChild = target => {
|
|
1314
|
+
if (target.children && target.children.length > 0) {
|
|
1315
|
+
return getFirstChild(target.children.find(item => item.children && target.children.length > 0) || get__default["default"](target.children, '0'));
|
|
1316
|
+
}
|
|
1317
|
+
const hasChildrenItem = getAllChildren(target.parentId).find(item => item.children && item.children.length > 0);
|
|
1318
|
+
if (hasChildrenItem) {
|
|
1319
|
+
return getFirstChild(hasChildrenItem);
|
|
1320
|
+
}
|
|
1321
|
+
return target;
|
|
1322
|
+
};
|
|
1323
|
+
const getParentNodeIdList = (targetId, parents = []) => {
|
|
1324
|
+
const output = [targetId, ...parents];
|
|
1325
|
+
const node = mapping.get(targetId);
|
|
1326
|
+
if (!node || isNil__default["default"](node.parentId)) {
|
|
1327
|
+
return output;
|
|
1328
|
+
}
|
|
1329
|
+
return getParentNodeIdList(node.parentId, output);
|
|
1330
|
+
};
|
|
1331
|
+
const lastLevelNode = getFirstChild(currentNode);
|
|
1332
|
+
return getParentNodeIdList(get__default["default"](lastLevelNode, 'id'));
|
|
1333
|
+
};
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* 通过一个nodeId获得该节点的所有子级后代的id数组
|
|
1337
|
+
* */
|
|
1338
|
+
const getAllChildren = id => {
|
|
1339
|
+
const output = [];
|
|
1340
|
+
const core = id => {
|
|
1341
|
+
const node = mapping.get(id);
|
|
1342
|
+
if (!node) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
1346
|
+
output.push(...node.children);
|
|
1347
|
+
node.children.forEach(item => {
|
|
1348
|
+
core(item.id);
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
core(id);
|
|
1353
|
+
return output;
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* 从自身节点开始向父级查找callback返回为true的node,找到第一个返回结果
|
|
1358
|
+
* */
|
|
1359
|
+
const findInParents = (id, callback) => {
|
|
1360
|
+
const core = id => {
|
|
1361
|
+
const currentNode = mapping.get(id);
|
|
1362
|
+
if (!currentNode) {
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
if (callback(currentNode)) {
|
|
1366
|
+
return currentNode;
|
|
1367
|
+
}
|
|
1368
|
+
if (!isNil__default["default"](currentNode.parentId)) {
|
|
1369
|
+
return core(currentNode.parentId);
|
|
1370
|
+
}
|
|
1371
|
+
return null;
|
|
1372
|
+
};
|
|
1373
|
+
return core(id);
|
|
1374
|
+
};
|
|
1375
|
+
const getSiblingNode = id => {
|
|
1376
|
+
const currentNode = mapping.get(id);
|
|
1377
|
+
if (!currentNode) {
|
|
1378
|
+
return [];
|
|
1379
|
+
}
|
|
1380
|
+
const parentId = currentNode.parentId;
|
|
1381
|
+
if (isNil__default["default"](parentId)) {
|
|
1382
|
+
return rootNodes;
|
|
1383
|
+
}
|
|
1384
|
+
const parentNode = mapping.get(parentId);
|
|
1385
|
+
return parentNode.children;
|
|
1386
|
+
};
|
|
1387
|
+
const setNodeChecked = (id, value = []) => {
|
|
1388
|
+
const newValue = value.slice(0);
|
|
1389
|
+
const core = id => {
|
|
1390
|
+
const node = mapping.get(id);
|
|
1391
|
+
if (!node) {
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
newValue.push(id);
|
|
1395
|
+
getAllChildren(id).forEach(node => {
|
|
1396
|
+
delItem(newValue, node.id);
|
|
1397
|
+
});
|
|
1398
|
+
const siblingNode = getSiblingNode(id);
|
|
1399
|
+
const siblingNodeIsAllChecked = siblingNode.every(node => newValue.indexOf(node.id) > -1);
|
|
1400
|
+
if (node.parentId && siblingNodeIsAllChecked) {
|
|
1401
|
+
siblingNode.forEach(node => {
|
|
1402
|
+
delItem(newValue, node.id);
|
|
1403
|
+
});
|
|
1404
|
+
core(node.parentId);
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
core(id);
|
|
1408
|
+
return newValue;
|
|
1409
|
+
};
|
|
1410
|
+
const setNodeUnchecked = (id, value = []) => {
|
|
1411
|
+
const newValue = value.slice(0);
|
|
1412
|
+
const core = id => {
|
|
1413
|
+
const node = mapping.get(id);
|
|
1414
|
+
if (!node) {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
if (newValue.indexOf(node.id) > -1) {
|
|
1418
|
+
delItem(newValue, node.id);
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
const siblingNode = getSiblingNode(id);
|
|
1422
|
+
if (node.parentId) {
|
|
1423
|
+
siblingNode.forEach(node => {
|
|
1424
|
+
if (id !== node.id) {
|
|
1425
|
+
newValue.push(node.id);
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
core(node.parentId);
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
core(id);
|
|
1432
|
+
return newValue;
|
|
1433
|
+
};
|
|
1434
|
+
const computedCheckboxStatus = (id, value = []) => {
|
|
1435
|
+
if (!!findInParents(id, node => {
|
|
1436
|
+
return value.indexOf(node.id) > -1;
|
|
1437
|
+
})) {
|
|
1438
|
+
return {
|
|
1439
|
+
checked: true,
|
|
1440
|
+
indeterminate: false
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
const indeterminate = ((id, callback) => {
|
|
1444
|
+
const core = id => {
|
|
1445
|
+
const currentNode = mapping.get(id);
|
|
1446
|
+
if (!currentNode) {
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
if (callback(currentNode)) {
|
|
1450
|
+
return currentNode;
|
|
1451
|
+
}
|
|
1452
|
+
if (Array.isArray(currentNode.children) && currentNode.children.length > 0) {
|
|
1453
|
+
return currentNode.children.find(item => !!core(item.id));
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
return !!core(id);
|
|
1457
|
+
})(id, node => value.indexOf(node.id) > -1);
|
|
1458
|
+
if (indeterminate) {
|
|
1459
|
+
return {
|
|
1460
|
+
checked: false,
|
|
1461
|
+
indeterminate: true
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
return {
|
|
1465
|
+
checked: false,
|
|
1466
|
+
indeterminate: false
|
|
1467
|
+
};
|
|
1468
|
+
};
|
|
1469
|
+
const transformToTreeData = () => {
|
|
1470
|
+
const core = nodeList => {
|
|
1471
|
+
if (Array.isArray(nodeList) && nodeList.length > 0) {
|
|
1472
|
+
return nodeList.map(node => {
|
|
1473
|
+
const children = mappingList.filter(item => item.parentId === node.id);
|
|
1474
|
+
return Object.assign({}, node, {
|
|
1475
|
+
children: core(children)
|
|
1476
|
+
});
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
return null;
|
|
1480
|
+
};
|
|
1481
|
+
return core(rootNodes);
|
|
1482
|
+
};
|
|
1483
|
+
const treeData = transformToTreeData();
|
|
1484
|
+
return {
|
|
1485
|
+
mapping,
|
|
1486
|
+
getSelectedQueue,
|
|
1487
|
+
getAllChildren,
|
|
1488
|
+
computedCheckboxStatus,
|
|
1489
|
+
getSiblingNode,
|
|
1490
|
+
findInParents,
|
|
1491
|
+
setNodeChecked,
|
|
1492
|
+
setNodeUnchecked,
|
|
1493
|
+
treeData,
|
|
1494
|
+
treeMapping: new Map((treeData || []).map(item => [item.id, item]))
|
|
1495
|
+
};
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1498
|
+
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"};
|
|
1499
|
+
|
|
1500
|
+
const CustomMenu = ({
|
|
1501
|
+
className,
|
|
1502
|
+
selectedKeys,
|
|
1503
|
+
items,
|
|
1504
|
+
onSelect
|
|
1505
|
+
}) => {
|
|
1506
|
+
const handleItemClick = (key, e) => {
|
|
1507
|
+
// 只阻止事件冒泡,不阻止默认行为
|
|
1508
|
+
e.stopPropagation();
|
|
1509
|
+
onSelect?.({
|
|
1510
|
+
key,
|
|
1511
|
+
domEvent: e
|
|
1512
|
+
});
|
|
1513
|
+
};
|
|
1514
|
+
return /*#__PURE__*/React__default["default"].createElement(antd.List, {
|
|
1515
|
+
className: classnames__default["default"](style['custom-menu'], className),
|
|
1516
|
+
dataSource: items,
|
|
1517
|
+
renderItem: item => {
|
|
1518
|
+
const isSelected = selectedKeys?.includes(item.key);
|
|
1519
|
+
return /*#__PURE__*/React__default["default"].createElement(antd.List.Item, {
|
|
1520
|
+
className: classnames__default["default"](style['custom-menu-item'], {
|
|
1521
|
+
[style['selected']]: isSelected
|
|
1522
|
+
}),
|
|
1523
|
+
onClick: e => handleItemClick(item.key, e)
|
|
1524
|
+
}, item.label);
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
const numberToPx = val => {
|
|
1530
|
+
return typeof val === 'number' ? `${val}px` : val;
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1533
|
+
// 级联选择内容组件
|
|
1534
|
+
const CascaderInner = _ref => {
|
|
1535
|
+
let {
|
|
1536
|
+
options,
|
|
1537
|
+
value,
|
|
1538
|
+
setValue,
|
|
1539
|
+
maxLength,
|
|
1540
|
+
single,
|
|
1541
|
+
onlyAllowLastLevel,
|
|
1542
|
+
openLoadData,
|
|
1543
|
+
onLoadMore,
|
|
1544
|
+
parentIdKey,
|
|
1545
|
+
menuItemWidth,
|
|
1546
|
+
isPopup,
|
|
1547
|
+
searchPlaceholder,
|
|
1548
|
+
onSearch,
|
|
1549
|
+
valueKey,
|
|
1550
|
+
labelKey,
|
|
1551
|
+
onOpenChange,
|
|
1552
|
+
open
|
|
1553
|
+
} = _ref;
|
|
1554
|
+
const {
|
|
1555
|
+
message
|
|
1556
|
+
} = antd.App.useApp();
|
|
1557
|
+
const [searchText, setSearchText] = React.useState('');
|
|
1558
|
+
const [loading, setLoading] = React.useState(false);
|
|
1559
|
+
|
|
1560
|
+
// 构建 mapping
|
|
1561
|
+
const mapping = React.useMemo(() => {
|
|
1562
|
+
const map = new Map();
|
|
1563
|
+
const processData = function (items, parentId) {
|
|
1564
|
+
if (parentId === void 0) {
|
|
1565
|
+
parentId = null;
|
|
1566
|
+
}
|
|
1567
|
+
items.forEach(item => {
|
|
1568
|
+
const node = {
|
|
1569
|
+
...item,
|
|
1570
|
+
id: item[valueKey],
|
|
1571
|
+
label: item[labelKey],
|
|
1572
|
+
parentId
|
|
1573
|
+
};
|
|
1574
|
+
if (item.children && item.children.length > 0) {
|
|
1575
|
+
node.children = item.children.map(child => ({
|
|
1576
|
+
...child,
|
|
1577
|
+
id: child[valueKey],
|
|
1578
|
+
label: child[labelKey],
|
|
1579
|
+
parentId: node.id
|
|
1580
|
+
}));
|
|
1581
|
+
processData(item.children, node.id);
|
|
1582
|
+
}
|
|
1583
|
+
map.set(node.id, node);
|
|
1584
|
+
});
|
|
1585
|
+
};
|
|
1586
|
+
processData(options);
|
|
1587
|
+
return map;
|
|
1588
|
+
}, [options, valueKey, labelKey]);
|
|
1589
|
+
|
|
1590
|
+
// 创建树工具
|
|
1591
|
+
const treeUtils = React.useMemo(() => {
|
|
1592
|
+
return createTreeUtils(mapping);
|
|
1593
|
+
}, [mapping]);
|
|
1594
|
+
|
|
1595
|
+
// 当前选中的列
|
|
1596
|
+
const [selectedIds, setSelectedIds] = React.useState(() => {
|
|
1597
|
+
const initValue = value.find(item => {
|
|
1598
|
+
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
1599
|
+
return !!mapping.get(id);
|
|
1600
|
+
});
|
|
1601
|
+
if (initValue) {
|
|
1602
|
+
const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
|
|
1603
|
+
return treeUtils.getSelectedQueue(id);
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
// 默认选中第一列
|
|
1607
|
+
const firstNode = Array.from(mapping.values()).find(item => isNil__default["default"](item.parentId));
|
|
1608
|
+
if (firstNode) {
|
|
1609
|
+
return treeUtils.getSelectedQueue(firstNode.id);
|
|
1610
|
+
}
|
|
1611
|
+
return [];
|
|
1612
|
+
});
|
|
1613
|
+
|
|
1614
|
+
// 当 Modal 打开时,根据 value 重新初始化 selectedIds
|
|
1615
|
+
const prevOpenRef = React.useRef(open);
|
|
1616
|
+
React.useEffect(() => {
|
|
1617
|
+
// 只在非 popup 模式下且 Modal 从关闭变为打开时处理
|
|
1618
|
+
if (!isPopup && open && !prevOpenRef.current) {
|
|
1619
|
+
const initValue = value.find(item => {
|
|
1620
|
+
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
1621
|
+
return !!mapping.get(id);
|
|
1622
|
+
});
|
|
1623
|
+
if (initValue) {
|
|
1624
|
+
const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
|
|
1625
|
+
setSelectedIds(treeUtils.getSelectedQueue(id));
|
|
1626
|
+
} else {
|
|
1627
|
+
// 默认选中第一列
|
|
1628
|
+
const firstNode = Array.from(mapping.values()).find(item => isNil__default["default"](item.parentId));
|
|
1629
|
+
if (firstNode) {
|
|
1630
|
+
setSelectedIds(treeUtils.getSelectedQueue(firstNode.id));
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
prevOpenRef.current = open;
|
|
1635
|
+
}, [open, value, mapping, treeUtils, valueKey, isPopup]);
|
|
1636
|
+
|
|
1637
|
+
// 懒加载支持
|
|
1638
|
+
const loadMorePropsRef = React.useRef({});
|
|
1639
|
+
loadMorePropsRef.current = {
|
|
1640
|
+
openLoadData,
|
|
1641
|
+
onLoadMore,
|
|
1642
|
+
parentIdKey,
|
|
1643
|
+
treeUtils
|
|
1644
|
+
};
|
|
1645
|
+
React.useEffect(() => {
|
|
1646
|
+
if (!openLoadData || !onLoadMore) {
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
const lastNode = mapping.get(last__default["default"](selectedIds));
|
|
1650
|
+
if (!lastNode) {
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// 检查是否需要加载子节点
|
|
1655
|
+
if (lastNode.hasOwnProperty('children') && lastNode.children !== undefined) {
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
setLoading(true);
|
|
1659
|
+
onLoadMore({
|
|
1660
|
+
[parentIdKey]: lastNode.id
|
|
1661
|
+
}).then(() => {
|
|
1662
|
+
setLoading(false);
|
|
1663
|
+
}).catch(() => {
|
|
1664
|
+
setLoading(false);
|
|
1665
|
+
});
|
|
1666
|
+
}, [selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
|
|
1667
|
+
|
|
1668
|
+
// 检查是否为非叶子节点
|
|
1669
|
+
const isNotLastNode = React.useCallback(id => {
|
|
1670
|
+
const node = mapping.get(id);
|
|
1671
|
+
if (!node) return false;
|
|
1672
|
+
if (openLoadData && !node.hasOwnProperty('children')) {
|
|
1673
|
+
return true;
|
|
1674
|
+
}
|
|
1675
|
+
return node.children && node.children.length > 0;
|
|
1676
|
+
}, [mapping, openLoadData]);
|
|
1677
|
+
|
|
1678
|
+
// 选择处理
|
|
1679
|
+
const onCheckedChange = React.useCallback((checked, id) => {
|
|
1680
|
+
const newValue = (() => {
|
|
1681
|
+
if (onlyAllowLastLevel && checked) {
|
|
1682
|
+
const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1683
|
+
if (currentIds.includes(id)) return currentIds;
|
|
1684
|
+
return [...currentIds, id];
|
|
1685
|
+
}
|
|
1686
|
+
if (onlyAllowLastLevel) {
|
|
1687
|
+
const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1688
|
+
return currentIds.filter(itemId => itemId !== id);
|
|
1689
|
+
}
|
|
1690
|
+
const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1691
|
+
return checked ? treeUtils.setNodeChecked(id, currentIds) : treeUtils.setNodeUnchecked(id, currentIds);
|
|
1692
|
+
})();
|
|
1693
|
+
if (newValue.length > maxLength) {
|
|
1694
|
+
message.error(`最多只能选择 ${maxLength} 项`);
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
// 转换回完整对象
|
|
1699
|
+
const newValues = newValue.map(id => {
|
|
1700
|
+
const node = mapping.get(id);
|
|
1701
|
+
// 返回完整的节点数据,保留所有原始字段
|
|
1702
|
+
return node ? {
|
|
1703
|
+
...node,
|
|
1704
|
+
[valueKey]: node.id,
|
|
1705
|
+
[labelKey]: node.label
|
|
1706
|
+
} : null;
|
|
1707
|
+
}).filter(Boolean);
|
|
1708
|
+
const finalValue = single && newValues.length > 0 ? [last__default["default"](newValues)] : newValues;
|
|
1709
|
+
setValue(finalValue);
|
|
1710
|
+
|
|
1711
|
+
// 单选且是叶子节点且在 popup 模式下,自动关闭下拉框
|
|
1712
|
+
if (single && newValues.length > 0 && !isNotLastNode(id) && isPopup && onOpenChange) {
|
|
1713
|
+
onOpenChange(false);
|
|
1714
|
+
}
|
|
1715
|
+
}, [value, maxLength, single, onlyAllowLastLevel, treeUtils, mapping, message, valueKey, labelKey, isPopup, onOpenChange, isNotLastNode]);
|
|
1716
|
+
|
|
1717
|
+
// 搜索结果
|
|
1718
|
+
const searchResults = React.useMemo(() => {
|
|
1719
|
+
if (!searchText || !onSearch) return null;
|
|
1720
|
+
const keyword = searchText.toLowerCase();
|
|
1721
|
+
return Array.from(mapping.values()).filter(item => {
|
|
1722
|
+
return item.label && item.label.toLowerCase().includes(keyword);
|
|
1723
|
+
});
|
|
1724
|
+
}, [searchText, mapping, onSearch]);
|
|
1725
|
+
|
|
1726
|
+
// 搜索选择
|
|
1727
|
+
const onSearchSelect = item => {
|
|
1728
|
+
const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1729
|
+
const checked = currentIds.includes(item.id);
|
|
1730
|
+
onCheckedChange(!checked, item.id);
|
|
1731
|
+
if (!checked) {
|
|
1732
|
+
setSelectedIds(treeUtils.getSelectedQueue(item.id));
|
|
1733
|
+
}
|
|
1734
|
+
setSearchText('');
|
|
1735
|
+
};
|
|
1736
|
+
|
|
1737
|
+
// 渲染搜索内容
|
|
1738
|
+
if (searchText && searchResults) {
|
|
1739
|
+
const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1740
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1741
|
+
className: classnames__default["default"](style['content'], {
|
|
1742
|
+
[style['is-popup']]: isPopup
|
|
1743
|
+
})
|
|
1744
|
+
}, /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
|
|
1745
|
+
className: classnames__default["default"](style['search-input'], {
|
|
1746
|
+
'is-popup': isPopup
|
|
1747
|
+
}),
|
|
1748
|
+
placeholder: searchPlaceholder,
|
|
1749
|
+
value: searchText,
|
|
1750
|
+
onSearch: setSearchText,
|
|
1751
|
+
simple: isPopup,
|
|
1752
|
+
showSearchButton: !isPopup
|
|
1753
|
+
}), /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
|
|
1754
|
+
className: style['scroll-plus-box']
|
|
1755
|
+
}, searchResults.length === 0 ? /*#__PURE__*/React__default["default"].createElement(antd.Empty, {
|
|
1756
|
+
description: "\u6682\u65E0\u6570\u636E"
|
|
1757
|
+
}) : /*#__PURE__*/React__default["default"].createElement(antd.List, {
|
|
1758
|
+
className: style['list'],
|
|
1759
|
+
size: "small",
|
|
1760
|
+
dataSource: searchResults,
|
|
1761
|
+
rowKey: "id",
|
|
1762
|
+
renderItem: item => {
|
|
1763
|
+
const checked = currentIds.includes(item.id);
|
|
1764
|
+
return /*#__PURE__*/React__default["default"].createElement(antd.List.Item, {
|
|
1765
|
+
className: classnames__default["default"]({
|
|
1766
|
+
[style['is-selected']]: checked
|
|
1767
|
+
}),
|
|
1768
|
+
onClick: () => onSearchSelect(item)
|
|
1769
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", null, item.label), checked && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1770
|
+
style: {
|
|
1771
|
+
marginLeft: 8,
|
|
1772
|
+
color: '#1677ff'
|
|
1773
|
+
}
|
|
1774
|
+
}, "\u2713"));
|
|
1775
|
+
}
|
|
1776
|
+
})));
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
// 渲染级联列
|
|
1780
|
+
const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1781
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1782
|
+
className: classnames__default["default"](style['content'], {
|
|
1783
|
+
[style['is-popup']]: isPopup,
|
|
1784
|
+
[style['has-search']]: !!onSearch
|
|
1785
|
+
}),
|
|
1786
|
+
style: {
|
|
1787
|
+
'--menu-item-width': numberToPx(menuItemWidth)
|
|
1788
|
+
}
|
|
1789
|
+
}, onSearch && /*#__PURE__*/React__default["default"].createElement(SearchInput__default["default"], {
|
|
1790
|
+
className: classnames__default["default"](style['search-input'], {
|
|
1791
|
+
'is-popup': isPopup
|
|
1792
|
+
}),
|
|
1793
|
+
placeholder: searchPlaceholder,
|
|
1794
|
+
value: searchText,
|
|
1795
|
+
onSearch: setSearchText,
|
|
1796
|
+
simple: isPopup,
|
|
1797
|
+
showSearchButton: !isPopup
|
|
1798
|
+
}), /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
|
|
1799
|
+
className: style['scroller'],
|
|
1800
|
+
options: {
|
|
1801
|
+
autoHide: false
|
|
1802
|
+
}
|
|
1803
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1804
|
+
className: style['columns']
|
|
1805
|
+
}, selectedIds.map((selectedId, index) => {
|
|
1806
|
+
const selectNode = mapping.get(selectedId);
|
|
1807
|
+
const siblingNodes = treeUtils.getSiblingNode(selectedId);
|
|
1808
|
+
const isLastLevel = !isNotLastNode(selectNode?.id) && index > 0;
|
|
1809
|
+
return /*#__PURE__*/React__default["default"].createElement(SimpleBar__default["default"], {
|
|
1810
|
+
key: selectedId || index,
|
|
1811
|
+
className: classnames__default["default"](style['content-item'], {
|
|
1812
|
+
[style['last-level-area']]: isLastLevel
|
|
1813
|
+
})
|
|
1814
|
+
}, isLastLevel ? /*#__PURE__*/React__default["default"].createElement(antd.Space, {
|
|
1815
|
+
wrap: true,
|
|
1816
|
+
style: {
|
|
1817
|
+
padding: 12
|
|
1818
|
+
},
|
|
1819
|
+
className: classnames__default["default"]({
|
|
1820
|
+
[style['single-mode']]: single
|
|
1821
|
+
})
|
|
1822
|
+
}, siblingNodes.map(node => {
|
|
1823
|
+
const {
|
|
1824
|
+
checked,
|
|
1825
|
+
indeterminate
|
|
1826
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1827
|
+
return /*#__PURE__*/React__default["default"].createElement(antd.Checkbox, {
|
|
1828
|
+
key: node.id,
|
|
1829
|
+
checked: checked,
|
|
1830
|
+
indeterminate: indeterminate,
|
|
1831
|
+
onChange: e => onCheckedChange(e.target.checked, node.id)
|
|
1832
|
+
}, node.label);
|
|
1833
|
+
})) : /*#__PURE__*/React__default["default"].createElement(CustomMenu, {
|
|
1834
|
+
className: style['menu'],
|
|
1835
|
+
selectedKeys: index === selectedIds.length - 1 ? [] : selectedIds,
|
|
1836
|
+
onSelect: _ref2 => {
|
|
1837
|
+
let {
|
|
1838
|
+
key
|
|
1839
|
+
} = _ref2;
|
|
1840
|
+
const node = mapping.get(key);
|
|
1841
|
+
if (!node) return;
|
|
1842
|
+
if (isNotLastNode(node.id)) {
|
|
1843
|
+
setSelectedIds(treeUtils.getSelectedQueue(node.id));
|
|
1844
|
+
} else {
|
|
1845
|
+
const {
|
|
1846
|
+
checked
|
|
1847
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1848
|
+
onCheckedChange(!checked, node.id);
|
|
1849
|
+
}
|
|
1850
|
+
},
|
|
1851
|
+
items: siblingNodes.map(node => {
|
|
1852
|
+
const {
|
|
1853
|
+
checked,
|
|
1854
|
+
indeterminate
|
|
1855
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1856
|
+
const hasChildren = isNotLastNode(node.id);
|
|
1857
|
+
|
|
1858
|
+
// 计算子级选中数量
|
|
1859
|
+
const childrenSelectedCount = hasChildren ? treeUtils.getAllChildren(node.id).filter(child => currentIds.includes(child.id)).length : 0;
|
|
1860
|
+
return {
|
|
1861
|
+
key: node.id,
|
|
1862
|
+
label: /*#__PURE__*/React__default["default"].createElement(antd.Space, {
|
|
1863
|
+
className: classnames__default["default"](style['menu-item'], {
|
|
1864
|
+
[style['checkbox-hidden']]: onlyAllowLastLevel && hasChildren,
|
|
1865
|
+
[style['single-mode']]: single
|
|
1866
|
+
})
|
|
1867
|
+
}, (!onlyAllowLastLevel || !hasChildren) && /*#__PURE__*/React__default["default"].createElement(antd.Checkbox, {
|
|
1868
|
+
checked: checked,
|
|
1869
|
+
indeterminate: indeterminate,
|
|
1870
|
+
onClick: e => e.stopPropagation(),
|
|
1871
|
+
onChange: e => {
|
|
1872
|
+
e.stopPropagation();
|
|
1873
|
+
onCheckedChange(e.target.checked, node.id);
|
|
1874
|
+
}
|
|
1875
|
+
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1876
|
+
className: style['menu-label']
|
|
1877
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1878
|
+
className: style['menu-label-text']
|
|
1879
|
+
}, node.label), hasChildren && childrenSelectedCount > 0 && /*#__PURE__*/React__default["default"].createElement(antd.Badge, {
|
|
1880
|
+
count: childrenSelectedCount,
|
|
1881
|
+
size: "small"
|
|
1882
|
+
})), hasChildren ? /*#__PURE__*/React__default["default"].createElement(icons.RightOutlined, {
|
|
1883
|
+
className: style['menu-item-icon']
|
|
1884
|
+
}) : /*#__PURE__*/React__default["default"].createElement("span", {
|
|
1885
|
+
className: style['menu-item-placeholder']
|
|
1886
|
+
}))
|
|
1887
|
+
};
|
|
1888
|
+
})
|
|
1889
|
+
}));
|
|
1890
|
+
}), loading && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1891
|
+
className: style['loading']
|
|
1892
|
+
}, /*#__PURE__*/React__default["default"].createElement(antd.Spin, {
|
|
1893
|
+
size: "small"
|
|
1894
|
+
})))));
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1897
|
+
// 主组件
|
|
1898
|
+
const SelectCascader = _ref3 => {
|
|
1899
|
+
let {
|
|
1900
|
+
options = [],
|
|
1901
|
+
value,
|
|
1902
|
+
onChange,
|
|
1903
|
+
defaultValue,
|
|
1904
|
+
maxLength = Number.MAX_VALUE,
|
|
1905
|
+
single = false,
|
|
1906
|
+
onlyAllowLastLevel = false,
|
|
1907
|
+
openLoadData = false,
|
|
1908
|
+
onLoadMore,
|
|
1909
|
+
parentIdKey = 'id',
|
|
1910
|
+
menuItemWidth = 180,
|
|
1911
|
+
isPopup = true,
|
|
1912
|
+
searchPlaceholder,
|
|
1913
|
+
onSearch,
|
|
1914
|
+
valueKey = 'id',
|
|
1915
|
+
labelKey = 'label',
|
|
1916
|
+
placeholder = '请选择',
|
|
1917
|
+
disabled = false,
|
|
1918
|
+
size = 'default',
|
|
1919
|
+
overlayWidth,
|
|
1920
|
+
...props
|
|
1921
|
+
} = _ref3;
|
|
1922
|
+
// 内部始终使用数组格式处理
|
|
1923
|
+
// SelectInput 会处理 single 模式的 value 和 onChange 转换
|
|
1924
|
+
const [innerValue, setInnerValue] = React.useState(Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : []);
|
|
1925
|
+
|
|
1926
|
+
// currentValue 用于内部处理,始终是数组
|
|
1927
|
+
const currentValue = React.useMemo(() => {
|
|
1928
|
+
if (value !== undefined) {
|
|
1929
|
+
// 外部传入的 value 可能是对象(single)或数组(多选)
|
|
1930
|
+
return Array.isArray(value) ? value : value ? [value] : [];
|
|
1931
|
+
}
|
|
1932
|
+
return innerValue;
|
|
1933
|
+
}, [value, innerValue]);
|
|
1934
|
+
const setValue = React.useCallback(newValue => {
|
|
1935
|
+
// SelectInput 在 single 模式下会传单个对象或 null/undefined,需要转换为数组
|
|
1936
|
+
const normalizedValue = (() => {
|
|
1937
|
+
if (single) {
|
|
1938
|
+
// 单选模式:可能是单个对象、null、undefined 或数组
|
|
1939
|
+
if (Array.isArray(newValue)) {
|
|
1940
|
+
return newValue;
|
|
1941
|
+
}
|
|
1942
|
+
return isEmpty.isNotEmpty(newValue) ? [newValue] : [];
|
|
1943
|
+
}
|
|
1944
|
+
// 多选模式:确保是数组
|
|
1945
|
+
return Array.isArray(newValue) ? newValue : [];
|
|
1946
|
+
})();
|
|
1947
|
+
if (value === undefined) {
|
|
1948
|
+
setInnerValue(normalizedValue);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
// 根据单选/多选模式转换输出格式
|
|
1952
|
+
if (single) {
|
|
1953
|
+
// 单选:返回单个对象或 null
|
|
1954
|
+
onChange?.(normalizedValue.length > 0 ? normalizedValue[0] : null);
|
|
1955
|
+
} else {
|
|
1956
|
+
// 多选:返回数组
|
|
1957
|
+
onChange?.(normalizedValue);
|
|
1958
|
+
}
|
|
1959
|
+
}, [value, onChange, single]);
|
|
1960
|
+
|
|
1961
|
+
// 传递给 SelectInput 的值:根据 single 参数决定格式
|
|
1962
|
+
const selectInputValue = React.useMemo(() => {
|
|
1963
|
+
if (single) {
|
|
1964
|
+
// single 模式:传单个对象或 undefined
|
|
1965
|
+
return currentValue.length > 0 ? currentValue[0] : undefined;
|
|
1966
|
+
}
|
|
1967
|
+
// 多选模式:传数组
|
|
1968
|
+
return currentValue;
|
|
1969
|
+
}, [currentValue, single]);
|
|
1970
|
+
|
|
1971
|
+
// 计算 label 显示
|
|
1972
|
+
React.useMemo(() => {
|
|
1973
|
+
// currentValue 已经是数组格式了
|
|
1974
|
+
return currentValue.map(item => {
|
|
1975
|
+
// 如果已经是对象,确保有标准化的字段
|
|
1976
|
+
if (typeof item === 'object') {
|
|
1977
|
+
// 优先使用 item[labelKey],然后是 item.label,最后是 item.name
|
|
1978
|
+
const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
|
|
1979
|
+
return {
|
|
1980
|
+
...item,
|
|
1981
|
+
[valueKey]: item[valueKey] || item.id,
|
|
1982
|
+
[labelKey]: label
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
// 如果是值,从 options 中查找
|
|
1986
|
+
const findLabel = items => {
|
|
1987
|
+
for (const node of items) {
|
|
1988
|
+
if (node[valueKey] === item) {
|
|
1989
|
+
return {
|
|
1990
|
+
[valueKey]: item,
|
|
1991
|
+
[labelKey]: node[labelKey] || node.name || String(item)
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
if (node.children) {
|
|
1995
|
+
const found = findLabel(node.children);
|
|
1996
|
+
if (found) return found;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
return null;
|
|
2000
|
+
};
|
|
2001
|
+
return findLabel(options) || {
|
|
2002
|
+
[valueKey]: item,
|
|
2003
|
+
[labelKey]: String(item)
|
|
2004
|
+
};
|
|
2005
|
+
}).filter(Boolean);
|
|
2006
|
+
}, [currentValue, options, valueKey, labelKey]);
|
|
2007
|
+
return /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({}, props, {
|
|
2008
|
+
value: selectInputValue,
|
|
2009
|
+
onChange: setValue,
|
|
2010
|
+
single: single,
|
|
2011
|
+
maxLength: maxLength,
|
|
2012
|
+
isPopup: isPopup,
|
|
2013
|
+
placeholder: placeholder,
|
|
2014
|
+
disabled: disabled,
|
|
2015
|
+
size: size,
|
|
2016
|
+
valueKey: valueKey,
|
|
2017
|
+
labelKey: labelKey,
|
|
2018
|
+
overlayWidth: overlayWidth || menuItemWidth * 2
|
|
2019
|
+
}), contextProps => {
|
|
2020
|
+
// 使用 contextProps 中的 value 和 setValue,支持 Modal 模式下的内部状态管理
|
|
2021
|
+
const contextValue = contextProps.value;
|
|
2022
|
+
const contextSetValue = contextProps.setValue;
|
|
2023
|
+
|
|
2024
|
+
// 计算当前显示的 value
|
|
2025
|
+
const currentDisplayValue = contextValue.map(item => {
|
|
2026
|
+
// 如果已经是对象,确保有标准化的字段
|
|
2027
|
+
if (typeof item === 'object') {
|
|
2028
|
+
const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
|
|
2029
|
+
return {
|
|
2030
|
+
...item,
|
|
2031
|
+
[valueKey]: item[valueKey] || item.id,
|
|
2032
|
+
[labelKey]: label
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
// 如果是值,从 options 中查找
|
|
2036
|
+
const findLabel = items => {
|
|
2037
|
+
for (const node of items) {
|
|
2038
|
+
if (node[valueKey] === item) {
|
|
2039
|
+
return {
|
|
2040
|
+
[valueKey]: item,
|
|
2041
|
+
[labelKey]: node[labelKey] || node.name || String(item)
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
if (node.children) {
|
|
2045
|
+
const found = findLabel(node.children);
|
|
2046
|
+
if (found) return found;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
return null;
|
|
2050
|
+
};
|
|
2051
|
+
return findLabel(options) || {
|
|
2052
|
+
[valueKey]: item,
|
|
2053
|
+
[labelKey]: String(item)
|
|
2054
|
+
};
|
|
2055
|
+
}).filter(Boolean);
|
|
2056
|
+
return /*#__PURE__*/React__default["default"].createElement(CascaderInner, {
|
|
2057
|
+
options: options,
|
|
2058
|
+
value: currentDisplayValue,
|
|
2059
|
+
setValue: contextSetValue,
|
|
2060
|
+
maxLength: maxLength,
|
|
2061
|
+
single: single,
|
|
2062
|
+
onlyAllowLastLevel: onlyAllowLastLevel,
|
|
2063
|
+
openLoadData: openLoadData,
|
|
2064
|
+
onLoadMore: onLoadMore,
|
|
2065
|
+
parentIdKey: parentIdKey,
|
|
2066
|
+
menuItemWidth: menuItemWidth,
|
|
2067
|
+
isPopup: isPopup,
|
|
2068
|
+
searchPlaceholder: searchPlaceholder,
|
|
2069
|
+
onSearch: onSearch,
|
|
2070
|
+
valueKey: valueKey,
|
|
2071
|
+
labelKey: labelKey,
|
|
2072
|
+
onOpenChange: contextProps.onOpenChange,
|
|
2073
|
+
open: contextProps.open
|
|
2074
|
+
});
|
|
2075
|
+
});
|
|
2076
|
+
};
|
|
2077
|
+
|
|
2078
|
+
exports.SelectCascader = SelectCascader;
|
|
1204
2079
|
exports.SelectInput = SelectInput;
|
|
1205
2080
|
exports.SelectTableList = SelectTableList;
|
|
1206
2081
|
exports.SelectTree = SelectTree;
|
|
1207
2082
|
exports.SelectedAll = SelectedAll;
|
|
1208
2083
|
exports.SelectedTagList = SelectedTagList;
|
|
2084
|
+
exports.createTreeUtils = createTreeUtils;
|
|
1209
2085
|
exports["default"] = SelectList;
|
|
1210
2086
|
//# sourceMappingURL=index.js.map
|