@kne/super-select 0.1.33 → 0.1.35
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 +875 -75
- package/dist/index.css +428 -100
- package/dist/index.css.map +1 -1
- package/dist/index.js +1231 -388
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +973 -90
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
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":"kne-super-select_d8lGc","disabled":"kne-super-select_3kjwO","wrap":"kne-super-select_dsTM2","select-input-inner":"kne-super-select_NQoX9","large":"kne-super-select_T8ZX8","small":"kne-super-select_1B72H","single-label":"kne-super-select_pL0tE","tag-item":"kne-super-select_lc4o7","tag-label":"kne-super-select_RJmlD","overflow-tag":"kne-super-select_aHua2","measure-layer":"kne-super-select_QoQpC","select-input-icon":"kne-super-select_g8QC-","placeholder":"kne-super-select_r3q69","overlay-content":"kne-super-select_zEqGe","overlay":"kne-super-select_ybN30","select-input-prefix":"kne-super-select_4Pw75","select-input-suffix":"kne-super-select_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
|
|
@@ -164,9 +254,11 @@ const SelectInput = createWithIntlProvider({
|
|
|
164
254
|
} = contextProps;
|
|
165
255
|
const {
|
|
166
256
|
placeholder,
|
|
167
|
-
children
|
|
257
|
+
children,
|
|
258
|
+
overlayClassName
|
|
168
259
|
} = props;
|
|
169
260
|
return /*#__PURE__*/React.createElement(Modal, {
|
|
261
|
+
className: overlayClassName,
|
|
170
262
|
width: 1000,
|
|
171
263
|
open: open,
|
|
172
264
|
title: placeholder,
|
|
@@ -191,6 +283,10 @@ const SelectInput = createWithIntlProvider({
|
|
|
191
283
|
className,
|
|
192
284
|
maxLength,
|
|
193
285
|
overlayClassName,
|
|
286
|
+
overlayStyle,
|
|
287
|
+
align,
|
|
288
|
+
autoAdjustOverflow,
|
|
289
|
+
transitionName,
|
|
194
290
|
single,
|
|
195
291
|
labelWrap,
|
|
196
292
|
isPopup,
|
|
@@ -228,11 +324,21 @@ const SelectInput = createWithIntlProvider({
|
|
|
228
324
|
onChange: 'onOpenChange'
|
|
229
325
|
});
|
|
230
326
|
const [hover, setHover] = useState(false);
|
|
231
|
-
const [
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
327
|
+
const [innerWidth, setInnerWidth] = useState(0);
|
|
328
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
329
|
+
const containerWidthChange = el => {
|
|
330
|
+
if (!el) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const containerWidth = el.clientWidth;
|
|
334
|
+
setContainerWidth(containerWidth);
|
|
335
|
+
const innerEl = el.querySelector('.select-input-inner');
|
|
336
|
+
setInnerWidth(innerEl.clientWidth);
|
|
337
|
+
};
|
|
338
|
+
const popupOverlayWidth = useMemo(() => {
|
|
339
|
+
return numberToPx$1(Math.max(containerWidth, pxToNumber(overlayWidth)));
|
|
340
|
+
}, [containerWidth, overlayWidth]);
|
|
341
|
+
const containerRef = useResize(containerWidthChange);
|
|
236
342
|
const {
|
|
237
343
|
message
|
|
238
344
|
} = App.useApp();
|
|
@@ -292,7 +398,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
292
398
|
searchProps,
|
|
293
399
|
setSearchProps,
|
|
294
400
|
hover,
|
|
295
|
-
inputWidth,
|
|
401
|
+
inputWidth: containerWidth,
|
|
296
402
|
onAdd,
|
|
297
403
|
onRemove,
|
|
298
404
|
onSelect,
|
|
@@ -305,12 +411,12 @@ const SelectInput = createWithIntlProvider({
|
|
|
305
411
|
return contextProps.props.inputRender(props, contextProps);
|
|
306
412
|
}
|
|
307
413
|
return /*#__PURE__*/React.createElement(Flex, _extends({}, props, {
|
|
308
|
-
ref:
|
|
309
|
-
className: classnames(className, style$
|
|
310
|
-
[style$
|
|
311
|
-
[style$
|
|
312
|
-
[style$
|
|
313
|
-
[style$
|
|
414
|
+
ref: containerRef,
|
|
415
|
+
className: classnames(className, style$6['select-input'], 'select-input', {
|
|
416
|
+
[style$6['wrap']]: labelWrap,
|
|
417
|
+
[style$6['disabled']]: disabled,
|
|
418
|
+
[style$6['small']]: size === 'small',
|
|
419
|
+
[style$6['large']]: size === 'large'
|
|
314
420
|
}),
|
|
315
421
|
justify: "space-between",
|
|
316
422
|
onMouseOver: () => {
|
|
@@ -322,27 +428,26 @@ const SelectInput = createWithIntlProvider({
|
|
|
322
428
|
}), (() => {
|
|
323
429
|
const current = typeof prefix === 'function' ? prefix(contextProps) : prefix;
|
|
324
430
|
return current && /*#__PURE__*/React.createElement("span", {
|
|
325
|
-
className: classnames(style$
|
|
431
|
+
className: classnames(style$6['select-input-prefix'], 'select-input-prefix'),
|
|
326
432
|
onClick: e => {
|
|
327
433
|
e.stopPropagation();
|
|
328
434
|
}
|
|
329
435
|
}, current);
|
|
330
436
|
})(), /*#__PURE__*/React.createElement("div", {
|
|
331
|
-
className: classnames(style$
|
|
332
|
-
}, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ?
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}, item[labelKey]);
|
|
437
|
+
className: classnames(style$6['select-input-inner'], 'select-input-inner')
|
|
438
|
+
}, value.length > 0 ? single || value[0][valueKey] === selectedAllValue[valueKey] ? /*#__PURE__*/React.createElement("span", {
|
|
439
|
+
className: classnames(style$6['single-label'], 'select-input-single-label'),
|
|
440
|
+
title: value[0][labelKey]
|
|
441
|
+
}, value[0][labelKey]) : /*#__PURE__*/React.createElement(TagOverflowInner, {
|
|
442
|
+
value: value,
|
|
443
|
+
innerWidth: innerWidth,
|
|
444
|
+
labelKey: labelKey,
|
|
445
|
+
valueKey: valueKey,
|
|
446
|
+
onRemove: onRemove
|
|
342
447
|
}) : /*#__PURE__*/React.createElement("span", {
|
|
343
|
-
className: classnames(style$
|
|
448
|
+
className: classnames(style$6['placeholder'], 'select-input-placeholder')
|
|
344
449
|
}, placeholder)), /*#__PURE__*/React.createElement("div", {
|
|
345
|
-
className: classnames(style$
|
|
450
|
+
className: classnames(style$6['select-input-icon'], 'select-input-icon')
|
|
346
451
|
}, !disabled && allowClear && hover && value.length > 0 ? /*#__PURE__*/React.createElement(CloseCircleFilled, {
|
|
347
452
|
onClick: e => {
|
|
348
453
|
e.stopPropagation();
|
|
@@ -351,7 +456,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
351
456
|
}) : /*#__PURE__*/React.createElement(DownOutlined, null)), (() => {
|
|
352
457
|
const current = typeof suffix === 'function' ? suffix(contextProps) : suffix;
|
|
353
458
|
return current && /*#__PURE__*/React.createElement("span", {
|
|
354
|
-
className: classnames(style$
|
|
459
|
+
className: classnames(style$6['select-input-suffix'], 'select-input-suffix'),
|
|
355
460
|
onClick: e => {
|
|
356
461
|
e.stopPropagation();
|
|
357
462
|
}
|
|
@@ -371,13 +476,17 @@ const SelectInput = createWithIntlProvider({
|
|
|
371
476
|
onOpenChange: setOpen,
|
|
372
477
|
placement: placement,
|
|
373
478
|
arrow: false,
|
|
374
|
-
overlayClassName: classnames(style$
|
|
479
|
+
overlayClassName: classnames(style$6['overlay'], overlayClassName),
|
|
480
|
+
overlayStyle: overlayStyle,
|
|
481
|
+
align: align,
|
|
482
|
+
autoAdjustOverflow: autoAdjustOverflow,
|
|
483
|
+
transitionName: transitionName,
|
|
375
484
|
trigger: "click",
|
|
376
485
|
popupRender: () => /*#__PURE__*/React.createElement("div", {
|
|
377
486
|
style: {
|
|
378
487
|
'--overlay-width': popupOverlayWidth
|
|
379
488
|
},
|
|
380
|
-
className: classnames(style$
|
|
489
|
+
className: classnames(style$6['overlay-content'], 'over-content'),
|
|
381
490
|
onClick: e => {
|
|
382
491
|
e.stopPropagation();
|
|
383
492
|
}
|
|
@@ -389,7 +498,7 @@ const SelectInput = createWithIntlProvider({
|
|
|
389
498
|
}), /*#__PURE__*/React.createElement(ModalContent, contextProps, renderModal)));
|
|
390
499
|
}));
|
|
391
500
|
|
|
392
|
-
var style$
|
|
501
|
+
var style$5 = {"selected-all":"kne-super-select_prlgN"};
|
|
393
502
|
|
|
394
503
|
const SelectedAll = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
395
504
|
const {
|
|
@@ -414,7 +523,7 @@ const SelectedAll = createWithIntlProvider('zh-CN', locale$1, 'super-select')(()
|
|
|
414
523
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
415
524
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
416
525
|
justify: "space-between",
|
|
417
|
-
className: classnames(style$
|
|
526
|
+
className: classnames(style$5['selected-all'], 'selected-all')
|
|
418
527
|
}, /*#__PURE__*/React.createElement(Flex, {
|
|
419
528
|
gap: 8
|
|
420
529
|
}, /*#__PURE__*/React.createElement("span", null, formatMessage({
|
|
@@ -437,7 +546,7 @@ const computedIsSelectAll = (value, selectedAllValue, valueKey = 'value') => {
|
|
|
437
546
|
return (value == null ? void 0 : value.length) === 1 && get(value, `[0][${valueKey}]`) === selectedAllValue[valueKey];
|
|
438
547
|
};
|
|
439
548
|
|
|
440
|
-
var style$
|
|
549
|
+
var style$4 = {"label":"kne-super-select_l3KoW","tag-list":"kne-super-select_CCPzb","tag-container":"kne-super-select_dKZHi","tag-container-inner":"kne-super-select_oijCI","tag":"kne-super-select_WmnnS","tag-inner":"kne-super-select_TMcFl"};
|
|
441
550
|
|
|
442
551
|
const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(() => {
|
|
443
552
|
const {
|
|
@@ -455,21 +564,21 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
455
564
|
valueKey
|
|
456
565
|
} = Object.assign({}, props);
|
|
457
566
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
458
|
-
className: classnames(style$
|
|
567
|
+
className: classnames(style$4['tag-list'], 'selected-tag-list'),
|
|
459
568
|
gap: 8
|
|
460
569
|
}, /*#__PURE__*/React.createElement("div", {
|
|
461
|
-
className: style$
|
|
570
|
+
className: style$4['label']
|
|
462
571
|
}, formatMessage({
|
|
463
572
|
id: 'selected'
|
|
464
573
|
}), !single && value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(SimpleBar, {
|
|
465
|
-
className: style$
|
|
574
|
+
className: style$4['tag-container']
|
|
466
575
|
}, /*#__PURE__*/React.createElement(Flex, {
|
|
467
576
|
gap: 8,
|
|
468
577
|
wrap: true,
|
|
469
|
-
className: style$
|
|
578
|
+
className: style$4['tag-container-inner']
|
|
470
579
|
}, value.map(item => {
|
|
471
580
|
return /*#__PURE__*/React.createElement(Tag, {
|
|
472
|
-
className: style$
|
|
581
|
+
className: style$4['tag'],
|
|
473
582
|
key: item[valueKey],
|
|
474
583
|
closable: true,
|
|
475
584
|
bordered: false,
|
|
@@ -478,19 +587,19 @@ const SelectedTagList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
478
587
|
onRemove(item);
|
|
479
588
|
}
|
|
480
589
|
}, /*#__PURE__*/React.createElement("span", {
|
|
481
|
-
className: style$
|
|
590
|
+
className: style$4['tag-inner']
|
|
482
591
|
}, item[labelKey]));
|
|
483
592
|
}))));
|
|
484
593
|
});
|
|
485
594
|
|
|
486
|
-
var style$
|
|
595
|
+
var style$3 = {"list":"kne-super-select_IsXdU","is-popup":"kne-super-select_-dvpa","empty":"kne-super-select_SQZ8k","default-list":"kne-super-select_QD1Mz","is-selected-all":"kne-super-select_M-mOy","default-list-item":"kne-super-select_KtOsz","is-selected":"kne-super-select_TQhBB","single-checked":"kne-super-select_2rUrh","is-disabled":"kne-super-select_NbwX5","selected-all":"kne-super-select_vN2Fx","selected-tag":"kne-super-select_6oITk","select-search":"kne-super-select_iAH9D","select-list-item-description":"kne-super-select_TCkeJ","footer":"kne-super-select_v3f23"};
|
|
487
596
|
|
|
488
|
-
const _excluded$
|
|
597
|
+
const _excluded$2 = ["children"];
|
|
489
598
|
const SelectList = forwardRef((_ref, ref) => {
|
|
490
599
|
let {
|
|
491
600
|
children
|
|
492
601
|
} = _ref,
|
|
493
|
-
p = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
602
|
+
p = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
494
603
|
const fetchListRef = useRef(null);
|
|
495
604
|
const props = Object.assign({}, {
|
|
496
605
|
renderItemContent: ({
|
|
@@ -503,7 +612,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
503
612
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
504
613
|
className: 'select-list-item-label'
|
|
505
614
|
}, item[labelKey]), item.description && /*#__PURE__*/React.createElement("div", {
|
|
506
|
-
className: classnames(style$
|
|
615
|
+
className: classnames(style$3['select-list-item-description'], 'select-list-item-description')
|
|
507
616
|
}, item.description));
|
|
508
617
|
},
|
|
509
618
|
renderItem: contextProps => {
|
|
@@ -524,9 +633,9 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
524
633
|
} = props;
|
|
525
634
|
const isChecked = value.some(target => target[valueKey] === item[valueKey]);
|
|
526
635
|
return /*#__PURE__*/React.createElement(List.Item, {
|
|
527
|
-
className: classnames(style$
|
|
528
|
-
[style$
|
|
529
|
-
[style$
|
|
636
|
+
className: classnames(style$3['default-list-item'], 'select-list-item', {
|
|
637
|
+
[style$3['is-selected']]: isChecked,
|
|
638
|
+
[style$3['is-disabled']]: item.disabled
|
|
530
639
|
}),
|
|
531
640
|
key: item[valueKey],
|
|
532
641
|
onClick: () => {
|
|
@@ -554,7 +663,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
554
663
|
flex: 1,
|
|
555
664
|
className: 'select-list-item-content'
|
|
556
665
|
}, renderItemContent(contextProps)), single && /*#__PURE__*/React.createElement("div", {
|
|
557
|
-
className: style$
|
|
666
|
+
className: style$3['single-checked']
|
|
558
667
|
}, isChecked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
|
|
559
668
|
},
|
|
560
669
|
renderList: contextProps => {
|
|
@@ -568,12 +677,12 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
568
677
|
} = props;
|
|
569
678
|
if (!(list && list.length > 0)) {
|
|
570
679
|
return props.empty || /*#__PURE__*/React.createElement(Empty, {
|
|
571
|
-
className: style$
|
|
680
|
+
className: style$3['empty']
|
|
572
681
|
});
|
|
573
682
|
}
|
|
574
683
|
return /*#__PURE__*/React.createElement(List, {
|
|
575
|
-
className: classnames(style$
|
|
576
|
-
[style$
|
|
684
|
+
className: classnames(style$3['default-list'], {
|
|
685
|
+
[style$3['is-selected-all']]: isSelectedAll
|
|
577
686
|
}),
|
|
578
687
|
size: "small",
|
|
579
688
|
dataSource: list,
|
|
@@ -610,7 +719,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
610
719
|
} = props;
|
|
611
720
|
const components = {
|
|
612
721
|
search: (api && typeof getSearchProps === 'function' || options && typeof getSearchCallback === 'function') && /*#__PURE__*/React.createElement(SearchInput, {
|
|
613
|
-
className: classnames(style$
|
|
722
|
+
className: classnames(style$3['select-search'], 'select-list-search', {
|
|
614
723
|
'is-popup': isPopup
|
|
615
724
|
}),
|
|
616
725
|
placeholder: searchPlaceholder,
|
|
@@ -624,12 +733,12 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
624
733
|
showSearchButton: !isPopup
|
|
625
734
|
}),
|
|
626
735
|
selectedAll: /*#__PURE__*/React.createElement("div", {
|
|
627
|
-
className: classnames(style$
|
|
736
|
+
className: classnames(style$3['selected-all'], 'select-list-selected-all', {
|
|
628
737
|
'is-popup': isPopup
|
|
629
738
|
})
|
|
630
739
|
}, !single && allowSelectedAll && /*#__PURE__*/React.createElement(SelectedAll, null)),
|
|
631
740
|
fetchList: /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
|
|
632
|
-
className: classnames(style$
|
|
741
|
+
className: classnames(style$3['list'], 'select-list-scroll-list', {
|
|
633
742
|
'is-popup': isPopup
|
|
634
743
|
}),
|
|
635
744
|
searchProps: searchProps,
|
|
@@ -665,12 +774,12 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
665
774
|
}));
|
|
666
775
|
}),
|
|
667
776
|
selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
|
|
668
|
-
className: classnames(style$
|
|
777
|
+
className: classnames(style$3['selected-tag'], 'select-list-selected-tag', {
|
|
669
778
|
'is-popup': isPopup
|
|
670
779
|
})
|
|
671
780
|
}, /*#__PURE__*/React.createElement(SelectedTagList, null)),
|
|
672
781
|
footer: footer && /*#__PURE__*/React.createElement("div", {
|
|
673
|
-
className: classnames(style$
|
|
782
|
+
className: classnames(style$3['footer'], 'select-list-footer')
|
|
674
783
|
}, typeof footer === 'function' ? footer({
|
|
675
784
|
reload: () => {
|
|
676
785
|
fetchListRef.current && fetchListRef.current.reload();
|
|
@@ -691,7 +800,7 @@ const SelectList = forwardRef((_ref, ref) => {
|
|
|
691
800
|
});
|
|
692
801
|
});
|
|
693
802
|
|
|
694
|
-
var style$
|
|
803
|
+
var style$2 = {"list":"kne-super-select_DrEYJ","is-popup":"kne-super-select_KgWTX","empty":"kne-super-select_5Tyrt","table":"kne-super-select_zE-14","right-options":"kne-super-select_UXi-g","no-padding-btn":"kne-super-select_iaCir","tag":"kne-super-select_JkYqS","tag-inner":"kne-super-select_VZlBL","single-checked":"kne-super-select_Eiz-u","select-search":"kne-super-select_temy6","tags-search":"kne-super-select_7phL2","descriptions":"kne-super-select_ttNK9","footer":"kne-super-select_lISfA"};
|
|
695
804
|
|
|
696
805
|
const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select')(forwardRef((p, ref) => {
|
|
697
806
|
const {
|
|
@@ -720,7 +829,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
720
829
|
return null;
|
|
721
830
|
}
|
|
722
831
|
return /*#__PURE__*/React.createElement(SearchInput, {
|
|
723
|
-
className: classnames(style$
|
|
832
|
+
className: classnames(style$2['select-search'], 'select-table-search', {
|
|
724
833
|
'is-popup': isPopup
|
|
725
834
|
}),
|
|
726
835
|
placeholder: searchPlaceholder,
|
|
@@ -780,7 +889,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
780
889
|
} = props;
|
|
781
890
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
782
891
|
const footerEl = footer && /*#__PURE__*/React.createElement("div", {
|
|
783
|
-
className: classnames(style$
|
|
892
|
+
className: classnames(style$2['footer'], 'select-table-footer')
|
|
784
893
|
}, typeof footer === 'function' ? footer({
|
|
785
894
|
reload: () => {
|
|
786
895
|
var _fetchListRef$current, _fetchListRef$current2;
|
|
@@ -795,11 +904,11 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
795
904
|
ref: bodyRef
|
|
796
905
|
}, /*#__PURE__*/React.createElement(Col, {
|
|
797
906
|
className: classnames({
|
|
798
|
-
[style$
|
|
907
|
+
[style$2['single-body']]: single
|
|
799
908
|
}),
|
|
800
909
|
span: single ? 24 : 16
|
|
801
910
|
}, /*#__PURE__*/React.createElement("div", null, filterRender(Object.assign({}, targetProps))), /*#__PURE__*/React.createElement("div", {
|
|
802
|
-
className: classnames(style$
|
|
911
|
+
className: classnames(style$2['table'], 'select-table')
|
|
803
912
|
}, /*#__PURE__*/React.createElement(TableView, {
|
|
804
913
|
columns: columns,
|
|
805
914
|
rowKey: valueKey,
|
|
@@ -841,7 +950,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
841
950
|
renderBody
|
|
842
951
|
}) => {
|
|
843
952
|
return /*#__PURE__*/React.createElement(React.Fragment, null, header, /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
|
|
844
|
-
className: classnames(style$
|
|
953
|
+
className: classnames(style$2['list'], 'select-table-list-scroll-list', {
|
|
845
954
|
'is-popup': isPopup
|
|
846
955
|
}),
|
|
847
956
|
searchProps: searchProps,
|
|
@@ -879,21 +988,21 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
879
988
|
});
|
|
880
989
|
if (!(list && list.length > 0)) {
|
|
881
990
|
return props.empty || /*#__PURE__*/React.createElement(Empty, {
|
|
882
|
-
className: classnames(style$
|
|
991
|
+
className: classnames(style$2['empty'])
|
|
883
992
|
});
|
|
884
993
|
}
|
|
885
994
|
return renderBody(list, contextProps);
|
|
886
995
|
}));
|
|
887
996
|
}
|
|
888
997
|
})), single && footerEl || /*#__PURE__*/React.createElement("div", {
|
|
889
|
-
className: classnames(style$
|
|
998
|
+
className: classnames(style$2['footer'], 'select-table-footer')
|
|
890
999
|
})), !single && /*#__PURE__*/React.createElement(Col, {
|
|
891
|
-
className: classnames(style$
|
|
1000
|
+
className: classnames(style$2['right-options'], {
|
|
892
1001
|
'is-popup': isPopup
|
|
893
1002
|
}),
|
|
894
1003
|
span: 8
|
|
895
1004
|
}, /*#__PURE__*/React.createElement(SearchInput, {
|
|
896
|
-
className: style$
|
|
1005
|
+
className: style$2['tags-search'],
|
|
897
1006
|
placeholder: searchPlaceholder,
|
|
898
1007
|
value: tagSearchText,
|
|
899
1008
|
onSearch: value => {
|
|
@@ -907,7 +1016,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
907
1016
|
}, /*#__PURE__*/React.createElement(Col, null, formatMessage({
|
|
908
1017
|
id: 'selected'
|
|
909
1018
|
}), value.length > 0 && `(${value.length}${Number.isInteger(maxLength) ? `/${maxLength}` : ''})`, ":"), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Button, {
|
|
910
|
-
className: style$
|
|
1019
|
+
className: style$2['no-padding-btn'],
|
|
911
1020
|
type: "link",
|
|
912
1021
|
onClick: () => {
|
|
913
1022
|
setValue([]);
|
|
@@ -920,7 +1029,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
920
1029
|
}, value.filter(item => getTagSearchCallback(tagSearchText, item, targetProps)).map(item => {
|
|
921
1030
|
var _fetchListRef$current4, _fetchListRef$current5;
|
|
922
1031
|
return /*#__PURE__*/React.createElement(Tag, {
|
|
923
|
-
className: style$
|
|
1032
|
+
className: style$2['tag'],
|
|
924
1033
|
key: item[valueKey],
|
|
925
1034
|
closable: true,
|
|
926
1035
|
bordered: false,
|
|
@@ -931,7 +1040,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
931
1040
|
}, /*#__PURE__*/React.createElement(Popover, {
|
|
932
1041
|
getPopupContainer: () => bodyRef.current,
|
|
933
1042
|
content: /*#__PURE__*/React.createElement(CentralContent, {
|
|
934
|
-
className: style$
|
|
1043
|
+
className: style$2['descriptions'],
|
|
935
1044
|
columns: columns.filter(item => {
|
|
936
1045
|
if (Object.hasOwn(item, 'previewHidden')) {
|
|
937
1046
|
return !item.previewHidden;
|
|
@@ -947,15 +1056,15 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
|
|
|
947
1056
|
})
|
|
948
1057
|
})
|
|
949
1058
|
}, /*#__PURE__*/React.createElement("span", {
|
|
950
|
-
className: style$
|
|
1059
|
+
className: style$2['tag-inner']
|
|
951
1060
|
}, item[labelKey])));
|
|
952
1061
|
}))), footerEl));
|
|
953
1062
|
});
|
|
954
1063
|
}));
|
|
955
1064
|
|
|
956
|
-
var style = {"list":"
|
|
1065
|
+
var style$1 = {"list":"kne-super-select_YTqxA","is-popup":"kne-super-select_TR-1a","default-list":"kne-super-select_IZN7r","is-selected-all":"kne-super-select_GCIMn","default-list-item":"kne-super-select_AYi0i","is-selected":"kne-super-select_eovZv","single-checked":"kne-super-select_Tr-bO","is-disabled":"kne-super-select_T-hri","selected-all":"kne-super-select_4XFtm","selected-tag":"kne-super-select_Whlzr","select-search":"kne-super-select_7zuBL","select-tree-item-description":"kne-super-select_R-Sye","footer":"kne-super-select_PjlnR"};
|
|
957
1066
|
|
|
958
|
-
const _excluded = ["children"],
|
|
1067
|
+
const _excluded$1 = ["children"],
|
|
959
1068
|
_excluded2 = ["data"];
|
|
960
1069
|
const parseTreeData = memoize((data = [], {
|
|
961
1070
|
parentKey,
|
|
@@ -981,7 +1090,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
981
1090
|
let {
|
|
982
1091
|
children
|
|
983
1092
|
} = _ref,
|
|
984
|
-
p = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1093
|
+
p = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
985
1094
|
const fetchListRef = useRef(null);
|
|
986
1095
|
const [expandedKeys, setExpandedKeys] = useState([]);
|
|
987
1096
|
const props = Object.assign({}, {
|
|
@@ -1016,9 +1125,9 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1016
1125
|
} = props;
|
|
1017
1126
|
const isChecked = value.some(target => target[valueKey] === item[valueKey]);
|
|
1018
1127
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
1019
|
-
className: classnames(style['default-list-item'], 'select-tree-item', {
|
|
1020
|
-
[style['is-selected']]: isChecked,
|
|
1021
|
-
[style['is-disabled']]: item.disabled
|
|
1128
|
+
className: classnames(style$1['default-list-item'], 'select-tree-item', {
|
|
1129
|
+
[style$1['is-selected']]: isChecked,
|
|
1130
|
+
[style$1['is-disabled']]: item.disabled
|
|
1022
1131
|
}),
|
|
1023
1132
|
key: item[valueKey],
|
|
1024
1133
|
onClick: () => {
|
|
@@ -1046,7 +1155,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1046
1155
|
flex: 1,
|
|
1047
1156
|
className: 'select-tree-item-content'
|
|
1048
1157
|
}, renderItemContent(contextProps)), single && /*#__PURE__*/React.createElement("div", {
|
|
1049
|
-
className: style['single-checked']
|
|
1158
|
+
className: style$1['single-checked']
|
|
1050
1159
|
}, isChecked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
|
|
1051
1160
|
},
|
|
1052
1161
|
renderTree: contextProps => {
|
|
@@ -1074,8 +1183,8 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1074
1183
|
return props.empty || /*#__PURE__*/React.createElement(Empty, null);
|
|
1075
1184
|
}
|
|
1076
1185
|
return /*#__PURE__*/React.createElement(Tree, {
|
|
1077
|
-
className: classnames(style['default-list'], {
|
|
1078
|
-
[style['is-selected-all']]: isSelectedAll
|
|
1186
|
+
className: classnames(style$1['default-list'], {
|
|
1187
|
+
[style$1['is-selected-all']]: isSelectedAll
|
|
1079
1188
|
}),
|
|
1080
1189
|
showIcon: true,
|
|
1081
1190
|
selectable: false,
|
|
@@ -1119,7 +1228,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1119
1228
|
} = props;
|
|
1120
1229
|
const components = {
|
|
1121
1230
|
selectedAll: /*#__PURE__*/React.createElement("div", {
|
|
1122
|
-
className: classnames(style['selected-all'], 'select-tree-selected-all', {
|
|
1231
|
+
className: classnames(style$1['selected-all'], 'select-tree-selected-all', {
|
|
1123
1232
|
'is-popup': isPopup
|
|
1124
1233
|
})
|
|
1125
1234
|
}, !single && allowSelectedAll && /*#__PURE__*/React.createElement(SelectedAll, null)),
|
|
@@ -1139,7 +1248,7 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1139
1248
|
fetchProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
1140
1249
|
const isSelectedAll = computedIsSelectAll(value, selectedAllValue, valueKey);
|
|
1141
1250
|
return /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1142
|
-
className: classnames(style['list'], 'select-tree-scroll-list', {
|
|
1251
|
+
className: classnames(style$1['list'], 'select-tree-scroll-list', {
|
|
1143
1252
|
'is-popup': isPopup
|
|
1144
1253
|
})
|
|
1145
1254
|
}, renderTree(Object.assign({}, fetchProps, targetProps, {
|
|
@@ -1149,12 +1258,12 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1149
1258
|
}
|
|
1150
1259
|
})),
|
|
1151
1260
|
selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
|
|
1152
|
-
className: classnames(style['selected-tag'], 'select-tree-selected-tag', {
|
|
1261
|
+
className: classnames(style$1['selected-tag'], 'select-tree-selected-tag', {
|
|
1153
1262
|
'is-popup': isPopup
|
|
1154
1263
|
})
|
|
1155
1264
|
}, /*#__PURE__*/React.createElement(SelectedTagList, null)),
|
|
1156
1265
|
footer: footer && /*#__PURE__*/React.createElement("div", {
|
|
1157
|
-
className: classnames(style['footer'], 'select-list-footer')
|
|
1266
|
+
className: classnames(style$1['footer'], 'select-list-footer')
|
|
1158
1267
|
}, typeof footer === 'function' ? footer({
|
|
1159
1268
|
reload: () => {
|
|
1160
1269
|
fetchListRef.current && fetchListRef.current.reload();
|
|
@@ -1175,5 +1284,779 @@ const SelectTree = forwardRef((_ref, ref) => {
|
|
|
1175
1284
|
});
|
|
1176
1285
|
});
|
|
1177
1286
|
|
|
1178
|
-
|
|
1287
|
+
const createTreeUtils = mapping => {
|
|
1288
|
+
const mappingList = Array.from(mapping.values());
|
|
1289
|
+
const rootNodes = mappingList.filter(item => item.parentId === null);
|
|
1290
|
+
const delItem = (array, item) => {
|
|
1291
|
+
const index = array.indexOf(item);
|
|
1292
|
+
if (index > -1) {
|
|
1293
|
+
array.splice(index, 1);
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
/**
|
|
1298
|
+
* 通过一个nodeId获取所有父级和所有子级的第一个元素,组成一个从最顶级到最子级的数组
|
|
1299
|
+
* */
|
|
1300
|
+
const getSelectedQueue = id => {
|
|
1301
|
+
const currentNode = mapping.get(id);
|
|
1302
|
+
if (!currentNode) {
|
|
1303
|
+
return [];
|
|
1304
|
+
}
|
|
1305
|
+
const getFirstChild = target => {
|
|
1306
|
+
if (target.children && target.children.length > 0) {
|
|
1307
|
+
return getFirstChild(target.children.find(item => item.children && target.children.length > 0) || get(target.children, '0'));
|
|
1308
|
+
}
|
|
1309
|
+
const hasChildrenItem = getAllChildren(target.parentId).find(item => item.children && item.children.length > 0);
|
|
1310
|
+
if (hasChildrenItem) {
|
|
1311
|
+
return getFirstChild(hasChildrenItem);
|
|
1312
|
+
}
|
|
1313
|
+
return target;
|
|
1314
|
+
};
|
|
1315
|
+
const getParentNodeIdList = (targetId, parents = []) => {
|
|
1316
|
+
const output = [targetId, ...parents];
|
|
1317
|
+
const node = mapping.get(targetId);
|
|
1318
|
+
if (!node || isNil(node.parentId)) {
|
|
1319
|
+
return output;
|
|
1320
|
+
}
|
|
1321
|
+
return getParentNodeIdList(node.parentId, output);
|
|
1322
|
+
};
|
|
1323
|
+
const lastLevelNode = getFirstChild(currentNode);
|
|
1324
|
+
return getParentNodeIdList(get(lastLevelNode, 'id'));
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* 通过一个nodeId获得该节点的所有子级后代的id数组
|
|
1329
|
+
* */
|
|
1330
|
+
const getAllChildren = id => {
|
|
1331
|
+
const output = [];
|
|
1332
|
+
const core = id => {
|
|
1333
|
+
const node = mapping.get(id);
|
|
1334
|
+
if (!node) {
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
1338
|
+
output.push(...node.children);
|
|
1339
|
+
node.children.forEach(item => {
|
|
1340
|
+
core(item.id);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
core(id);
|
|
1345
|
+
return output;
|
|
1346
|
+
};
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* 从自身节点开始向父级查找callback返回为true的node,找到第一个返回结果
|
|
1350
|
+
* */
|
|
1351
|
+
const findInParents = (id, callback) => {
|
|
1352
|
+
const core = id => {
|
|
1353
|
+
const currentNode = mapping.get(id);
|
|
1354
|
+
if (!currentNode) {
|
|
1355
|
+
return null;
|
|
1356
|
+
}
|
|
1357
|
+
if (callback(currentNode)) {
|
|
1358
|
+
return currentNode;
|
|
1359
|
+
}
|
|
1360
|
+
if (!isNil(currentNode.parentId)) {
|
|
1361
|
+
return core(currentNode.parentId);
|
|
1362
|
+
}
|
|
1363
|
+
return null;
|
|
1364
|
+
};
|
|
1365
|
+
return core(id);
|
|
1366
|
+
};
|
|
1367
|
+
const getSiblingNode = id => {
|
|
1368
|
+
const currentNode = mapping.get(id);
|
|
1369
|
+
if (!currentNode) {
|
|
1370
|
+
return [];
|
|
1371
|
+
}
|
|
1372
|
+
const parentId = currentNode.parentId;
|
|
1373
|
+
if (isNil(parentId)) {
|
|
1374
|
+
return rootNodes;
|
|
1375
|
+
}
|
|
1376
|
+
const parentNode = mapping.get(parentId);
|
|
1377
|
+
return parentNode.children;
|
|
1378
|
+
};
|
|
1379
|
+
const setNodeChecked = (id, value = []) => {
|
|
1380
|
+
const newValue = value.slice(0);
|
|
1381
|
+
const core = id => {
|
|
1382
|
+
const node = mapping.get(id);
|
|
1383
|
+
if (!node) {
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
newValue.push(id);
|
|
1387
|
+
getAllChildren(id).forEach(node => {
|
|
1388
|
+
delItem(newValue, node.id);
|
|
1389
|
+
});
|
|
1390
|
+
const siblingNode = getSiblingNode(id);
|
|
1391
|
+
const siblingNodeIsAllChecked = siblingNode.every(node => newValue.indexOf(node.id) > -1);
|
|
1392
|
+
if (node.parentId && siblingNodeIsAllChecked) {
|
|
1393
|
+
siblingNode.forEach(node => {
|
|
1394
|
+
delItem(newValue, node.id);
|
|
1395
|
+
});
|
|
1396
|
+
core(node.parentId);
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
core(id);
|
|
1400
|
+
return newValue;
|
|
1401
|
+
};
|
|
1402
|
+
const setNodeUnchecked = (id, value = []) => {
|
|
1403
|
+
const newValue = value.slice(0);
|
|
1404
|
+
const core = id => {
|
|
1405
|
+
const node = mapping.get(id);
|
|
1406
|
+
if (!node) {
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
if (newValue.indexOf(node.id) > -1) {
|
|
1410
|
+
delItem(newValue, node.id);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
const siblingNode = getSiblingNode(id);
|
|
1414
|
+
if (node.parentId) {
|
|
1415
|
+
siblingNode.forEach(node => {
|
|
1416
|
+
if (id !== node.id) {
|
|
1417
|
+
newValue.push(node.id);
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
core(node.parentId);
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
core(id);
|
|
1424
|
+
return newValue;
|
|
1425
|
+
};
|
|
1426
|
+
const computedCheckboxStatus = (id, value = []) => {
|
|
1427
|
+
if (!!findInParents(id, node => {
|
|
1428
|
+
return value.indexOf(node.id) > -1;
|
|
1429
|
+
})) {
|
|
1430
|
+
return {
|
|
1431
|
+
checked: true,
|
|
1432
|
+
indeterminate: false
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
const indeterminate = ((id, callback) => {
|
|
1436
|
+
const core = id => {
|
|
1437
|
+
const currentNode = mapping.get(id);
|
|
1438
|
+
if (!currentNode) {
|
|
1439
|
+
return null;
|
|
1440
|
+
}
|
|
1441
|
+
if (callback(currentNode)) {
|
|
1442
|
+
return currentNode;
|
|
1443
|
+
}
|
|
1444
|
+
if (Array.isArray(currentNode.children) && currentNode.children.length > 0) {
|
|
1445
|
+
return currentNode.children.find(item => !!core(item.id));
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
return !!core(id);
|
|
1449
|
+
})(id, node => value.indexOf(node.id) > -1);
|
|
1450
|
+
if (indeterminate) {
|
|
1451
|
+
return {
|
|
1452
|
+
checked: false,
|
|
1453
|
+
indeterminate: true
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
return {
|
|
1457
|
+
checked: false,
|
|
1458
|
+
indeterminate: false
|
|
1459
|
+
};
|
|
1460
|
+
};
|
|
1461
|
+
const transformToTreeData = () => {
|
|
1462
|
+
const core = nodeList => {
|
|
1463
|
+
if (Array.isArray(nodeList) && nodeList.length > 0) {
|
|
1464
|
+
return nodeList.map(node => {
|
|
1465
|
+
const children = mappingList.filter(item => item.parentId === node.id);
|
|
1466
|
+
return Object.assign({}, node, {
|
|
1467
|
+
children: core(children)
|
|
1468
|
+
});
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
return null;
|
|
1472
|
+
};
|
|
1473
|
+
return core(rootNodes);
|
|
1474
|
+
};
|
|
1475
|
+
const treeData = transformToTreeData();
|
|
1476
|
+
return {
|
|
1477
|
+
mapping,
|
|
1478
|
+
getSelectedQueue,
|
|
1479
|
+
getAllChildren,
|
|
1480
|
+
computedCheckboxStatus,
|
|
1481
|
+
getSiblingNode,
|
|
1482
|
+
findInParents,
|
|
1483
|
+
setNodeChecked,
|
|
1484
|
+
setNodeUnchecked,
|
|
1485
|
+
treeData,
|
|
1486
|
+
treeMapping: new Map((treeData || []).map(item => [item.id, item]))
|
|
1487
|
+
};
|
|
1488
|
+
};
|
|
1489
|
+
|
|
1490
|
+
var style = {"content":"kne-super-select_fHNBt","columns":"kne-super-select_VgpIp","content-item":"kne-super-select_kSkN1","last-level-area":"kne-super-select_1QV-l","is-popup":"kne-super-select_zFwDF","menu":"kne-super-select_s-ON4","scroll-plus-box":"kne-super-select_rIix2","menu-label":"kne-super-select_XAs20","menu-label-text":"kne-super-select_Y8AoQ","menu-item":"kne-super-select_ZwakZ","checkbox-hidden":"kne-super-select_0FUoe","single-mode":"kne-super-select_dahnB","menu-item-icon":"kne-super-select_AZZvN","menu-item-placeholder":"kne-super-select_TudTj","loading":"kne-super-select_ljvZk","search-input":"kne-super-select_FVxuS","list":"kne-super-select_iUhv7","is-selected":"kne-super-select_tx4-l","custom-menu":"kne-super-select_OerpL","selected":"kne-super-select_OUkpN"};
|
|
1491
|
+
|
|
1492
|
+
const CustomMenu = ({
|
|
1493
|
+
className,
|
|
1494
|
+
selectedKeys,
|
|
1495
|
+
items,
|
|
1496
|
+
onSelect
|
|
1497
|
+
}) => {
|
|
1498
|
+
const handleItemClick = (key, e) => {
|
|
1499
|
+
// 只阻止事件冒泡,不阻止默认行为
|
|
1500
|
+
e.stopPropagation();
|
|
1501
|
+
onSelect == null || onSelect({
|
|
1502
|
+
key,
|
|
1503
|
+
domEvent: e
|
|
1504
|
+
});
|
|
1505
|
+
};
|
|
1506
|
+
return /*#__PURE__*/React.createElement(List, {
|
|
1507
|
+
className: classnames(style['custom-menu'], className),
|
|
1508
|
+
dataSource: items,
|
|
1509
|
+
renderItem: item => {
|
|
1510
|
+
const isSelected = selectedKeys == null ? void 0 : selectedKeys.includes(item.key);
|
|
1511
|
+
return /*#__PURE__*/React.createElement(List.Item, {
|
|
1512
|
+
className: classnames(style['custom-menu-item'], {
|
|
1513
|
+
[style['selected']]: isSelected
|
|
1514
|
+
}),
|
|
1515
|
+
onClick: e => handleItemClick(item.key, e)
|
|
1516
|
+
}, item.label);
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1521
|
+
const _excluded = ["options", "value", "onChange", "defaultValue", "maxLength", "single", "onlyAllowLastLevel", "openLoadData", "onLoadMore", "parentIdKey", "menuItemWidth", "isPopup", "searchPlaceholder", "onSearch", "valueKey", "labelKey", "placeholder", "disabled", "size", "overlayWidth"];
|
|
1522
|
+
const numberToPx = val => {
|
|
1523
|
+
return typeof val === 'number' ? `${val}px` : val;
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
// 级联选择内容组件
|
|
1527
|
+
const CascaderInner = ({
|
|
1528
|
+
options,
|
|
1529
|
+
value,
|
|
1530
|
+
setValue,
|
|
1531
|
+
maxLength,
|
|
1532
|
+
single,
|
|
1533
|
+
onlyAllowLastLevel,
|
|
1534
|
+
openLoadData,
|
|
1535
|
+
onLoadMore,
|
|
1536
|
+
parentIdKey,
|
|
1537
|
+
menuItemWidth,
|
|
1538
|
+
isPopup,
|
|
1539
|
+
searchPlaceholder,
|
|
1540
|
+
onSearch,
|
|
1541
|
+
valueKey,
|
|
1542
|
+
labelKey,
|
|
1543
|
+
onOpenChange,
|
|
1544
|
+
open
|
|
1545
|
+
}) => {
|
|
1546
|
+
const {
|
|
1547
|
+
message
|
|
1548
|
+
} = App.useApp();
|
|
1549
|
+
const [searchText, setSearchText] = useState('');
|
|
1550
|
+
const [loading, setLoading] = useState(false);
|
|
1551
|
+
|
|
1552
|
+
// 构建 mapping
|
|
1553
|
+
const mapping = useMemo(() => {
|
|
1554
|
+
const map = new Map();
|
|
1555
|
+
const processData = (items, parentId = null) => {
|
|
1556
|
+
items.forEach(item => {
|
|
1557
|
+
const node = _extends({}, item, {
|
|
1558
|
+
id: item[valueKey],
|
|
1559
|
+
label: item[labelKey],
|
|
1560
|
+
parentId
|
|
1561
|
+
});
|
|
1562
|
+
if (item.children && item.children.length > 0) {
|
|
1563
|
+
node.children = item.children.map(child => _extends({}, child, {
|
|
1564
|
+
id: child[valueKey],
|
|
1565
|
+
label: child[labelKey],
|
|
1566
|
+
parentId: node.id
|
|
1567
|
+
}));
|
|
1568
|
+
processData(item.children, node.id);
|
|
1569
|
+
}
|
|
1570
|
+
map.set(node.id, node);
|
|
1571
|
+
});
|
|
1572
|
+
};
|
|
1573
|
+
processData(options);
|
|
1574
|
+
return map;
|
|
1575
|
+
}, [options, valueKey, labelKey]);
|
|
1576
|
+
|
|
1577
|
+
// 创建树工具
|
|
1578
|
+
const treeUtils = useMemo(() => {
|
|
1579
|
+
return createTreeUtils(mapping);
|
|
1580
|
+
}, [mapping]);
|
|
1581
|
+
|
|
1582
|
+
// 当前选中的列
|
|
1583
|
+
const [selectedIds, setSelectedIds] = useState(() => {
|
|
1584
|
+
const initValue = value.find(item => {
|
|
1585
|
+
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
1586
|
+
return !!mapping.get(id);
|
|
1587
|
+
});
|
|
1588
|
+
if (initValue) {
|
|
1589
|
+
const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
|
|
1590
|
+
return treeUtils.getSelectedQueue(id);
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// 默认选中第一列
|
|
1594
|
+
const firstNode = Array.from(mapping.values()).find(item => isNil(item.parentId));
|
|
1595
|
+
if (firstNode) {
|
|
1596
|
+
return treeUtils.getSelectedQueue(firstNode.id);
|
|
1597
|
+
}
|
|
1598
|
+
return [];
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1601
|
+
// 当 Modal 打开时,根据 value 重新初始化 selectedIds
|
|
1602
|
+
const prevOpenRef = useRef(open);
|
|
1603
|
+
useEffect(() => {
|
|
1604
|
+
// 只在非 popup 模式下且 Modal 从关闭变为打开时处理
|
|
1605
|
+
if (!isPopup && open && !prevOpenRef.current) {
|
|
1606
|
+
const initValue = value.find(item => {
|
|
1607
|
+
const id = typeof item === 'object' ? item[valueKey] : item;
|
|
1608
|
+
return !!mapping.get(id);
|
|
1609
|
+
});
|
|
1610
|
+
if (initValue) {
|
|
1611
|
+
const id = typeof initValue === 'object' ? initValue[valueKey] : initValue;
|
|
1612
|
+
setSelectedIds(treeUtils.getSelectedQueue(id));
|
|
1613
|
+
} else {
|
|
1614
|
+
// 默认选中第一列
|
|
1615
|
+
const firstNode = Array.from(mapping.values()).find(item => isNil(item.parentId));
|
|
1616
|
+
if (firstNode) {
|
|
1617
|
+
setSelectedIds(treeUtils.getSelectedQueue(firstNode.id));
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
prevOpenRef.current = open;
|
|
1622
|
+
}, [open, value, mapping, treeUtils, valueKey, isPopup]);
|
|
1623
|
+
|
|
1624
|
+
// 懒加载支持
|
|
1625
|
+
const loadMorePropsRef = useRef({});
|
|
1626
|
+
loadMorePropsRef.current = {
|
|
1627
|
+
openLoadData,
|
|
1628
|
+
onLoadMore,
|
|
1629
|
+
parentIdKey,
|
|
1630
|
+
treeUtils
|
|
1631
|
+
};
|
|
1632
|
+
useEffect(() => {
|
|
1633
|
+
if (!openLoadData || !onLoadMore) {
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
const lastNode = mapping.get(last(selectedIds));
|
|
1637
|
+
if (!lastNode) {
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
// 检查是否需要加载子节点
|
|
1642
|
+
if (lastNode.hasOwnProperty('children') && lastNode.children !== undefined) {
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
setLoading(true);
|
|
1646
|
+
onLoadMore({
|
|
1647
|
+
[parentIdKey]: lastNode.id
|
|
1648
|
+
}).then(() => {
|
|
1649
|
+
setLoading(false);
|
|
1650
|
+
}).catch(() => {
|
|
1651
|
+
setLoading(false);
|
|
1652
|
+
});
|
|
1653
|
+
}, [selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
|
|
1654
|
+
|
|
1655
|
+
// 检查是否为非叶子节点
|
|
1656
|
+
const isNotLastNode = useCallback(id => {
|
|
1657
|
+
const node = mapping.get(id);
|
|
1658
|
+
if (!node) return false;
|
|
1659
|
+
if (openLoadData && !node.hasOwnProperty('children')) {
|
|
1660
|
+
return true;
|
|
1661
|
+
}
|
|
1662
|
+
return node.children && node.children.length > 0;
|
|
1663
|
+
}, [mapping, openLoadData]);
|
|
1664
|
+
|
|
1665
|
+
// 选择处理
|
|
1666
|
+
const onCheckedChange = useCallback((checked, id) => {
|
|
1667
|
+
const newValue = (() => {
|
|
1668
|
+
if (onlyAllowLastLevel && checked) {
|
|
1669
|
+
const _currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1670
|
+
if (_currentIds.includes(id)) return _currentIds;
|
|
1671
|
+
return [..._currentIds, id];
|
|
1672
|
+
}
|
|
1673
|
+
if (onlyAllowLastLevel) {
|
|
1674
|
+
const _currentIds2 = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1675
|
+
return _currentIds2.filter(itemId => itemId !== id);
|
|
1676
|
+
}
|
|
1677
|
+
const currentIds = value.map(item => typeof item === 'object' ? item[valueKey] : item);
|
|
1678
|
+
return checked ? treeUtils.setNodeChecked(id, currentIds) : treeUtils.setNodeUnchecked(id, currentIds);
|
|
1679
|
+
})();
|
|
1680
|
+
if (newValue.length > maxLength) {
|
|
1681
|
+
message.error(`最多只能选择 ${maxLength} 项`);
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
// 转换回完整对象
|
|
1686
|
+
const newValues = newValue.map(id => {
|
|
1687
|
+
const node = mapping.get(id);
|
|
1688
|
+
// 返回完整的节点数据,保留所有原始字段
|
|
1689
|
+
return node ? _extends({}, node, {
|
|
1690
|
+
[valueKey]: node.id,
|
|
1691
|
+
[labelKey]: node.label
|
|
1692
|
+
}) : null;
|
|
1693
|
+
}).filter(Boolean);
|
|
1694
|
+
const finalValue = single && newValues.length > 0 ? [last(newValues)] : newValues;
|
|
1695
|
+
setValue(finalValue);
|
|
1696
|
+
|
|
1697
|
+
// 单选且是叶子节点且在 popup 模式下,自动关闭下拉框
|
|
1698
|
+
if (single && newValues.length > 0 && !isNotLastNode(id) && isPopup && onOpenChange) {
|
|
1699
|
+
onOpenChange(false);
|
|
1700
|
+
}
|
|
1701
|
+
}, [value, maxLength, single, onlyAllowLastLevel, treeUtils, mapping, message, valueKey, labelKey, isPopup, onOpenChange, isNotLastNode]);
|
|
1702
|
+
|
|
1703
|
+
// 搜索结果
|
|
1704
|
+
const searchResults = useMemo(() => {
|
|
1705
|
+
if (!searchText || !onSearch) return null;
|
|
1706
|
+
const keyword = searchText.toLowerCase();
|
|
1707
|
+
return Array.from(mapping.values()).filter(item => {
|
|
1708
|
+
return item.label && item.label.toLowerCase().includes(keyword);
|
|
1709
|
+
});
|
|
1710
|
+
}, [searchText, mapping, onSearch]);
|
|
1711
|
+
|
|
1712
|
+
// 搜索选择
|
|
1713
|
+
const onSearchSelect = item => {
|
|
1714
|
+
const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1715
|
+
const checked = currentIds.includes(item.id);
|
|
1716
|
+
onCheckedChange(!checked, item.id);
|
|
1717
|
+
if (!checked) {
|
|
1718
|
+
setSelectedIds(treeUtils.getSelectedQueue(item.id));
|
|
1719
|
+
}
|
|
1720
|
+
setSearchText('');
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1723
|
+
// 渲染搜索内容
|
|
1724
|
+
if (searchText && searchResults) {
|
|
1725
|
+
const _currentIds3 = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1726
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1727
|
+
className: classnames(style['content'], {
|
|
1728
|
+
[style['is-popup']]: isPopup
|
|
1729
|
+
})
|
|
1730
|
+
}, /*#__PURE__*/React.createElement(SearchInput, {
|
|
1731
|
+
className: classnames(style['search-input'], {
|
|
1732
|
+
'is-popup': isPopup
|
|
1733
|
+
}),
|
|
1734
|
+
placeholder: searchPlaceholder,
|
|
1735
|
+
value: searchText,
|
|
1736
|
+
onSearch: setSearchText,
|
|
1737
|
+
simple: isPopup,
|
|
1738
|
+
showSearchButton: !isPopup
|
|
1739
|
+
}), /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1740
|
+
className: style['scroll-plus-box']
|
|
1741
|
+
}, searchResults.length === 0 ? /*#__PURE__*/React.createElement(Empty, {
|
|
1742
|
+
description: "\u6682\u65E0\u6570\u636E"
|
|
1743
|
+
}) : /*#__PURE__*/React.createElement(List, {
|
|
1744
|
+
className: style['list'],
|
|
1745
|
+
size: "small",
|
|
1746
|
+
dataSource: searchResults,
|
|
1747
|
+
rowKey: "id",
|
|
1748
|
+
renderItem: item => {
|
|
1749
|
+
const checked = _currentIds3.includes(item.id);
|
|
1750
|
+
return /*#__PURE__*/React.createElement(List.Item, {
|
|
1751
|
+
className: classnames({
|
|
1752
|
+
[style['is-selected']]: checked
|
|
1753
|
+
}),
|
|
1754
|
+
onClick: () => onSearchSelect(item)
|
|
1755
|
+
}, /*#__PURE__*/React.createElement("span", null, item.label), checked && /*#__PURE__*/React.createElement("span", {
|
|
1756
|
+
style: {
|
|
1757
|
+
marginLeft: 8,
|
|
1758
|
+
color: '#1677ff'
|
|
1759
|
+
}
|
|
1760
|
+
}, "\u2713"));
|
|
1761
|
+
}
|
|
1762
|
+
})));
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
// 渲染级联列
|
|
1766
|
+
const currentIds = value.map(v => typeof v === 'object' ? v[valueKey] : v);
|
|
1767
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1768
|
+
className: classnames(style['content'], {
|
|
1769
|
+
[style['is-popup']]: isPopup,
|
|
1770
|
+
[style['has-search']]: !!onSearch
|
|
1771
|
+
}),
|
|
1772
|
+
style: {
|
|
1773
|
+
'--menu-item-width': numberToPx(menuItemWidth)
|
|
1774
|
+
}
|
|
1775
|
+
}, onSearch && /*#__PURE__*/React.createElement(SearchInput, {
|
|
1776
|
+
className: classnames(style['search-input'], {
|
|
1777
|
+
'is-popup': isPopup
|
|
1778
|
+
}),
|
|
1779
|
+
placeholder: searchPlaceholder,
|
|
1780
|
+
value: searchText,
|
|
1781
|
+
onSearch: setSearchText,
|
|
1782
|
+
simple: isPopup,
|
|
1783
|
+
showSearchButton: !isPopup
|
|
1784
|
+
}), /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1785
|
+
className: style['scroller'],
|
|
1786
|
+
options: {
|
|
1787
|
+
autoHide: false
|
|
1788
|
+
}
|
|
1789
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1790
|
+
className: style['columns']
|
|
1791
|
+
}, selectedIds.map((selectedId, index) => {
|
|
1792
|
+
const selectNode = mapping.get(selectedId);
|
|
1793
|
+
const siblingNodes = treeUtils.getSiblingNode(selectedId);
|
|
1794
|
+
const isLastLevel = !isNotLastNode(selectNode == null ? void 0 : selectNode.id) && index > 0;
|
|
1795
|
+
return /*#__PURE__*/React.createElement(SimpleBar, {
|
|
1796
|
+
key: selectedId || index,
|
|
1797
|
+
className: classnames(style['content-item'], {
|
|
1798
|
+
[style['last-level-area']]: isLastLevel
|
|
1799
|
+
})
|
|
1800
|
+
}, isLastLevel ? /*#__PURE__*/React.createElement(Space, {
|
|
1801
|
+
wrap: true,
|
|
1802
|
+
style: {
|
|
1803
|
+
padding: 12
|
|
1804
|
+
},
|
|
1805
|
+
className: classnames({
|
|
1806
|
+
[style['single-mode']]: single
|
|
1807
|
+
})
|
|
1808
|
+
}, siblingNodes.map(node => {
|
|
1809
|
+
const {
|
|
1810
|
+
checked,
|
|
1811
|
+
indeterminate
|
|
1812
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1813
|
+
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
1814
|
+
key: node.id,
|
|
1815
|
+
checked: checked,
|
|
1816
|
+
indeterminate: indeterminate,
|
|
1817
|
+
onChange: e => onCheckedChange(e.target.checked, node.id)
|
|
1818
|
+
}, node.label);
|
|
1819
|
+
})) : /*#__PURE__*/React.createElement(CustomMenu, {
|
|
1820
|
+
className: style['menu'],
|
|
1821
|
+
selectedKeys: index === selectedIds.length - 1 ? [] : selectedIds,
|
|
1822
|
+
onSelect: ({
|
|
1823
|
+
key
|
|
1824
|
+
}) => {
|
|
1825
|
+
const node = mapping.get(key);
|
|
1826
|
+
if (!node) return;
|
|
1827
|
+
if (isNotLastNode(node.id)) {
|
|
1828
|
+
setSelectedIds(treeUtils.getSelectedQueue(node.id));
|
|
1829
|
+
} else {
|
|
1830
|
+
const {
|
|
1831
|
+
checked
|
|
1832
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1833
|
+
onCheckedChange(!checked, node.id);
|
|
1834
|
+
}
|
|
1835
|
+
},
|
|
1836
|
+
items: siblingNodes.map(node => {
|
|
1837
|
+
const {
|
|
1838
|
+
checked,
|
|
1839
|
+
indeterminate
|
|
1840
|
+
} = treeUtils.computedCheckboxStatus(node.id, currentIds);
|
|
1841
|
+
const hasChildren = isNotLastNode(node.id);
|
|
1842
|
+
|
|
1843
|
+
// 计算子级选中数量
|
|
1844
|
+
const childrenSelectedCount = hasChildren ? treeUtils.getAllChildren(node.id).filter(child => currentIds.includes(child.id)).length : 0;
|
|
1845
|
+
return {
|
|
1846
|
+
key: node.id,
|
|
1847
|
+
label: /*#__PURE__*/React.createElement(Space, {
|
|
1848
|
+
className: classnames(style['menu-item'], {
|
|
1849
|
+
[style['checkbox-hidden']]: onlyAllowLastLevel && hasChildren,
|
|
1850
|
+
[style['single-mode']]: single
|
|
1851
|
+
})
|
|
1852
|
+
}, (!onlyAllowLastLevel || !hasChildren) && /*#__PURE__*/React.createElement(Checkbox, {
|
|
1853
|
+
checked: checked,
|
|
1854
|
+
indeterminate: indeterminate,
|
|
1855
|
+
onClick: e => e.stopPropagation(),
|
|
1856
|
+
onChange: e => {
|
|
1857
|
+
e.stopPropagation();
|
|
1858
|
+
onCheckedChange(e.target.checked, node.id);
|
|
1859
|
+
}
|
|
1860
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
1861
|
+
className: style['menu-label']
|
|
1862
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1863
|
+
className: style['menu-label-text']
|
|
1864
|
+
}, node.label), hasChildren && childrenSelectedCount > 0 && /*#__PURE__*/React.createElement(Badge, {
|
|
1865
|
+
count: childrenSelectedCount,
|
|
1866
|
+
size: "small"
|
|
1867
|
+
})), hasChildren ? /*#__PURE__*/React.createElement(RightOutlined, {
|
|
1868
|
+
className: style['menu-item-icon']
|
|
1869
|
+
}) : /*#__PURE__*/React.createElement("span", {
|
|
1870
|
+
className: style['menu-item-placeholder']
|
|
1871
|
+
}))
|
|
1872
|
+
};
|
|
1873
|
+
})
|
|
1874
|
+
}));
|
|
1875
|
+
}), loading && /*#__PURE__*/React.createElement("div", {
|
|
1876
|
+
className: style['loading']
|
|
1877
|
+
}, /*#__PURE__*/React.createElement(Spin, {
|
|
1878
|
+
size: "small"
|
|
1879
|
+
})))));
|
|
1880
|
+
};
|
|
1881
|
+
|
|
1882
|
+
// 主组件
|
|
1883
|
+
const SelectCascader = _ref => {
|
|
1884
|
+
let {
|
|
1885
|
+
options = [],
|
|
1886
|
+
value,
|
|
1887
|
+
onChange,
|
|
1888
|
+
defaultValue,
|
|
1889
|
+
maxLength = Number.MAX_VALUE,
|
|
1890
|
+
single = false,
|
|
1891
|
+
onlyAllowLastLevel = false,
|
|
1892
|
+
openLoadData = false,
|
|
1893
|
+
onLoadMore,
|
|
1894
|
+
parentIdKey = 'id',
|
|
1895
|
+
menuItemWidth = 180,
|
|
1896
|
+
isPopup = true,
|
|
1897
|
+
searchPlaceholder,
|
|
1898
|
+
onSearch,
|
|
1899
|
+
valueKey = 'id',
|
|
1900
|
+
labelKey = 'label',
|
|
1901
|
+
placeholder = '请选择',
|
|
1902
|
+
disabled = false,
|
|
1903
|
+
size = 'default',
|
|
1904
|
+
overlayWidth
|
|
1905
|
+
} = _ref,
|
|
1906
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1907
|
+
// 内部始终使用数组格式处理
|
|
1908
|
+
// SelectInput 会处理 single 模式的 value 和 onChange 转换
|
|
1909
|
+
const [innerValue, setInnerValue] = useState(Array.isArray(defaultValue) ? defaultValue : defaultValue ? [defaultValue] : []);
|
|
1910
|
+
|
|
1911
|
+
// currentValue 用于内部处理,始终是数组
|
|
1912
|
+
const currentValue = useMemo(() => {
|
|
1913
|
+
if (value !== undefined) {
|
|
1914
|
+
// 外部传入的 value 可能是对象(single)或数组(多选)
|
|
1915
|
+
return Array.isArray(value) ? value : value ? [value] : [];
|
|
1916
|
+
}
|
|
1917
|
+
return innerValue;
|
|
1918
|
+
}, [value, innerValue]);
|
|
1919
|
+
const setValue = useCallback(newValue => {
|
|
1920
|
+
// SelectInput 在 single 模式下会传单个对象或 null/undefined,需要转换为数组
|
|
1921
|
+
const normalizedValue = (() => {
|
|
1922
|
+
if (single) {
|
|
1923
|
+
// 单选模式:可能是单个对象、null、undefined 或数组
|
|
1924
|
+
if (Array.isArray(newValue)) {
|
|
1925
|
+
return newValue;
|
|
1926
|
+
}
|
|
1927
|
+
return isNotEmpty(newValue) ? [newValue] : [];
|
|
1928
|
+
}
|
|
1929
|
+
// 多选模式:确保是数组
|
|
1930
|
+
return Array.isArray(newValue) ? newValue : [];
|
|
1931
|
+
})();
|
|
1932
|
+
if (value === undefined) {
|
|
1933
|
+
setInnerValue(normalizedValue);
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
// 根据单选/多选模式转换输出格式
|
|
1937
|
+
if (single) {
|
|
1938
|
+
// 单选:返回单个对象或 null
|
|
1939
|
+
onChange == null || onChange(normalizedValue.length > 0 ? normalizedValue[0] : null);
|
|
1940
|
+
} else {
|
|
1941
|
+
// 多选:返回数组
|
|
1942
|
+
onChange == null || onChange(normalizedValue);
|
|
1943
|
+
}
|
|
1944
|
+
}, [value, onChange, single]);
|
|
1945
|
+
|
|
1946
|
+
// 传递给 SelectInput 的值:根据 single 参数决定格式
|
|
1947
|
+
const selectInputValue = useMemo(() => {
|
|
1948
|
+
if (single) {
|
|
1949
|
+
// single 模式:传单个对象或 undefined
|
|
1950
|
+
return currentValue.length > 0 ? currentValue[0] : undefined;
|
|
1951
|
+
}
|
|
1952
|
+
// 多选模式:传数组
|
|
1953
|
+
return currentValue;
|
|
1954
|
+
}, [currentValue, single]);
|
|
1955
|
+
|
|
1956
|
+
// 计算 label 显示
|
|
1957
|
+
useMemo(() => {
|
|
1958
|
+
// currentValue 已经是数组格式了
|
|
1959
|
+
return currentValue.map(item => {
|
|
1960
|
+
// 如果已经是对象,确保有标准化的字段
|
|
1961
|
+
if (typeof item === 'object') {
|
|
1962
|
+
// 优先使用 item[labelKey],然后是 item.label,最后是 item.name
|
|
1963
|
+
const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
|
|
1964
|
+
return _extends({}, item, {
|
|
1965
|
+
[valueKey]: item[valueKey] || item.id,
|
|
1966
|
+
[labelKey]: label
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
// 如果是值,从 options 中查找
|
|
1970
|
+
const findLabel = items => {
|
|
1971
|
+
for (const node of items) {
|
|
1972
|
+
if (node[valueKey] === item) {
|
|
1973
|
+
return {
|
|
1974
|
+
[valueKey]: item,
|
|
1975
|
+
[labelKey]: node[labelKey] || node.name || String(item)
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
if (node.children) {
|
|
1979
|
+
const found = findLabel(node.children);
|
|
1980
|
+
if (found) return found;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
return null;
|
|
1984
|
+
};
|
|
1985
|
+
return findLabel(options) || {
|
|
1986
|
+
[valueKey]: item,
|
|
1987
|
+
[labelKey]: String(item)
|
|
1988
|
+
};
|
|
1989
|
+
}).filter(Boolean);
|
|
1990
|
+
}, [currentValue, options, valueKey, labelKey]);
|
|
1991
|
+
return /*#__PURE__*/React.createElement(SelectInput, _extends({}, props, {
|
|
1992
|
+
value: selectInputValue,
|
|
1993
|
+
onChange: setValue,
|
|
1994
|
+
single: single,
|
|
1995
|
+
maxLength: maxLength,
|
|
1996
|
+
isPopup: isPopup,
|
|
1997
|
+
placeholder: placeholder,
|
|
1998
|
+
disabled: disabled,
|
|
1999
|
+
size: size,
|
|
2000
|
+
valueKey: valueKey,
|
|
2001
|
+
labelKey: labelKey,
|
|
2002
|
+
overlayWidth: overlayWidth || menuItemWidth * 2
|
|
2003
|
+
}), contextProps => {
|
|
2004
|
+
// 使用 contextProps 中的 value 和 setValue,支持 Modal 模式下的内部状态管理
|
|
2005
|
+
const contextValue = contextProps.value;
|
|
2006
|
+
const contextSetValue = contextProps.setValue;
|
|
2007
|
+
|
|
2008
|
+
// 计算当前显示的 value
|
|
2009
|
+
const currentDisplayValue = contextValue.map(item => {
|
|
2010
|
+
// 如果已经是对象,确保有标准化的字段
|
|
2011
|
+
if (typeof item === 'object') {
|
|
2012
|
+
const label = item[labelKey] || item.label || item.name || String(item[valueKey] || '');
|
|
2013
|
+
return _extends({}, item, {
|
|
2014
|
+
[valueKey]: item[valueKey] || item.id,
|
|
2015
|
+
[labelKey]: label
|
|
2016
|
+
});
|
|
2017
|
+
}
|
|
2018
|
+
// 如果是值,从 options 中查找
|
|
2019
|
+
const findLabel = items => {
|
|
2020
|
+
for (const node of items) {
|
|
2021
|
+
if (node[valueKey] === item) {
|
|
2022
|
+
return {
|
|
2023
|
+
[valueKey]: item,
|
|
2024
|
+
[labelKey]: node[labelKey] || node.name || String(item)
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
if (node.children) {
|
|
2028
|
+
const found = findLabel(node.children);
|
|
2029
|
+
if (found) return found;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
return null;
|
|
2033
|
+
};
|
|
2034
|
+
return findLabel(options) || {
|
|
2035
|
+
[valueKey]: item,
|
|
2036
|
+
[labelKey]: String(item)
|
|
2037
|
+
};
|
|
2038
|
+
}).filter(Boolean);
|
|
2039
|
+
return /*#__PURE__*/React.createElement(CascaderInner, {
|
|
2040
|
+
options: options,
|
|
2041
|
+
value: currentDisplayValue,
|
|
2042
|
+
setValue: contextSetValue,
|
|
2043
|
+
maxLength: maxLength,
|
|
2044
|
+
single: single,
|
|
2045
|
+
onlyAllowLastLevel: onlyAllowLastLevel,
|
|
2046
|
+
openLoadData: openLoadData,
|
|
2047
|
+
onLoadMore: onLoadMore,
|
|
2048
|
+
parentIdKey: parentIdKey,
|
|
2049
|
+
menuItemWidth: menuItemWidth,
|
|
2050
|
+
isPopup: isPopup,
|
|
2051
|
+
searchPlaceholder: searchPlaceholder,
|
|
2052
|
+
onSearch: onSearch,
|
|
2053
|
+
valueKey: valueKey,
|
|
2054
|
+
labelKey: labelKey,
|
|
2055
|
+
onOpenChange: contextProps.onOpenChange,
|
|
2056
|
+
open: contextProps.open
|
|
2057
|
+
});
|
|
2058
|
+
});
|
|
2059
|
+
};
|
|
2060
|
+
|
|
2061
|
+
export { SelectCascader, SelectInput, SelectTableList, SelectTree, SelectedAll, SelectedTagList, createTreeUtils, SelectList as default };
|
|
1179
2062
|
//# sourceMappingURL=index.modern.js.map
|