@bit-sun/business-component 2.2.49 → 2.3.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/ENUM.d.ts +40 -0
- package/dist/components/Business/BsSulaQueryTable/setting.d.ts +2 -2
- package/dist/components/Business/SearchSelect/common.d.ts +9 -1
- package/dist/components/Business/TreeSearchSelect/utils.d.ts +3 -1
- package/dist/components/Functional/AddSelect/helps.d.ts +13 -0
- package/dist/components/Functional/BsAntdSula/BsCascader/index.d.ts +18 -0
- package/dist/components/Functional/BsAntdSula/index.d.ts +1 -0
- package/dist/components/Solution/RuleComponent/Formula.d.ts +8 -0
- package/dist/components/Solution/RuleComponent/services.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +10845 -11311
- package/dist/index.js +10806 -11268
- package/dist/utils/LocalstorageUtils.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/utils.d.ts +7 -0
- package/package.json +2 -1
- package/src/common/ENUM.ts +41 -0
- package/src/components/Business/AddSelectBusiness/index.md +1 -0
- package/src/components/Business/AddSelectBusiness/index.tsx +375 -176
- package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +1 -1
- package/src/components/Business/BsSulaQueryTable/index.tsx +20 -12
- package/src/components/Business/BsSulaQueryTable/setting.tsx +36 -16
- package/src/components/Business/BsSulaQueryTable/utils.tsx +31 -29
- package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +4 -0
- package/src/components/Business/JsonQueryTable/index.tsx +248 -33
- package/src/components/Business/JsonQueryTable/static.ts +5 -5
- package/src/components/Business/SearchSelect/BusinessUtils.ts +37 -7
- package/src/components/Business/SearchSelect/common.ts +23 -1
- package/src/components/Business/SearchSelect/index.md +12 -2
- package/src/components/Business/SearchSelect/index.tsx +5 -2
- package/src/components/Business/TreeSearchSelect/index.md +2 -0
- package/src/components/Business/TreeSearchSelect/index.tsx +1 -2
- package/src/components/Business/TreeSearchSelect/utils.ts +7 -1
- package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +1 -1
- package/src/components/Business/columnSettingTable/utils.tsx +30 -28
- package/src/components/Business/moreTreeTable/FixedScrollBar.tsx +1 -0
- package/src/components/Business/moreTreeTable/index.md +2 -2
- package/src/components/Business/moreTreeTable/index.tsx +24 -17
- package/src/components/Functional/AddSelect/helps.ts +65 -0
- package/src/components/Functional/AddSelect/index.tsx +13 -122
- package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -0
- package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -0
- package/src/components/Functional/BsAntdSula/index.ts +2 -0
- package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -0
- package/src/components/Functional/EllipsisTooltip/index.js +36 -0
- package/src/components/Functional/EllipsisTooltip/index.md +30 -0
- package/src/components/Functional/SearchSelect/index.tsx +97 -60
- package/src/components/Functional/TreeSearchSelect/index.tsx +44 -7
- package/src/components/Solution/RuleComponent/Formula.tsx +335 -0
- package/src/components/Solution/RuleComponent/index.d.ts +29 -0
- package/src/components/Solution/RuleComponent/index.js +2032 -0
- package/src/components/Solution/RuleComponent/index.less +230 -0
- package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -0
- package/src/components/Solution/RuleComponent/ruleFiled.js +2107 -0
- package/src/components/Solution/RuleComponent/services.ts +13 -0
- package/src/components/Solution/RuleComponent/util.js +139 -0
- package/src/index.ts +4 -0
- package/src/utils/LocalstorageUtils.ts +5 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +29 -0
|
@@ -25,6 +25,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
25
25
|
needModalTable = true,
|
|
26
26
|
getPopupContainer = undefined,
|
|
27
27
|
fieldComponent,
|
|
28
|
+
selectBusinessType,
|
|
28
29
|
} = props;
|
|
29
30
|
const {
|
|
30
31
|
url,
|
|
@@ -39,6 +40,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
39
40
|
mappingTextShowTextField,
|
|
40
41
|
init = true,// 是否初始请求
|
|
41
42
|
extralHeaders = {},// 额外请求头参数
|
|
43
|
+
specialBracket = false,// 是否使用特殊括弧显示选项 【value】text
|
|
42
44
|
} = requestConfig || {};
|
|
43
45
|
const resultSourceKey = handleSourceName(sourceName || requestConfig?.sourceName || 'supplierCode')
|
|
44
46
|
|
|
@@ -72,8 +74,10 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
72
74
|
const { run } = useDebounceFn(
|
|
73
75
|
(v?: any) => {
|
|
74
76
|
// 优化搜索参数 支持传多个
|
|
77
|
+
console.log(`🚀 => SearchSelect => v:`, v)
|
|
75
78
|
let searchParams = {};
|
|
76
|
-
|
|
79
|
+
console.log(`🚀 => SearchSelect => selectParamsKey:`, selectParamsKey)
|
|
80
|
+
if (typeof selectParamsKey === 'string' || typeof selectParamsInitKey === 'string') {
|
|
77
81
|
let selectParamsInitValue = initVal
|
|
78
82
|
if (labelInValue) {
|
|
79
83
|
selectParamsInitValue = Array.isArray(initVal) ? initVal.map((i: any) => i.value || i.key).join(',') : initVal
|
|
@@ -87,6 +91,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
87
91
|
searchParams = { ...searchParams, [i]: searchValue }
|
|
88
92
|
})
|
|
89
93
|
}
|
|
94
|
+
console.log(`🚀 => SearchSelect => searchParams:`, searchParams)
|
|
90
95
|
// 防抖函数 待定
|
|
91
96
|
getData(searchParams)
|
|
92
97
|
},
|
|
@@ -100,7 +105,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
100
105
|
const [tableData, setTableData] = useState([]);
|
|
101
106
|
const [tablePagination, setTablePagination] = useState(tableInitPagination)
|
|
102
107
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
103
|
-
const [
|
|
108
|
+
const [selectedRows, setSelectedRows] = useState([]);
|
|
104
109
|
const [checkedAll, setCheckedAll] = useState(false)
|
|
105
110
|
const [indeterminate, setIndeterminate] = useState(false)
|
|
106
111
|
const [tableFormParams, setTableFormParams] = useState({});
|
|
@@ -136,7 +141,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
136
141
|
}))
|
|
137
142
|
|
|
138
143
|
// 获取数据源 (type: 1下拉框 2/3弹框 不传值默认为下拉框)
|
|
139
|
-
const getData = (params = {}, type = 1) => {
|
|
144
|
+
const getData = (params = {}, type = 1,callback?: any) => {
|
|
140
145
|
if (!requestConfig) return;
|
|
141
146
|
|
|
142
147
|
setFetching(true)
|
|
@@ -151,9 +156,15 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
151
156
|
// 解决依赖项在弹窗中回显/更改(如果不能更改,传参fixedparamsDisabled为true即可)
|
|
152
157
|
if(type == 2 || type == 3) {
|
|
153
158
|
const fixedChangeParamVal = form.getFieldValue(item);
|
|
159
|
+
let isDependenceValueChange = false;
|
|
160
|
+
let dependenceValue = fixedParamVal;
|
|
154
161
|
// 依赖项在弹窗form中更改--①更换依赖值;②去掉依赖值
|
|
155
|
-
|
|
156
|
-
|
|
162
|
+
if(!fixedparamsDisabled) {
|
|
163
|
+
isDependenceValueChange =
|
|
164
|
+
(fixedChangeParamVal && fixedChangeParamVal !== fixedParamVal)
|
|
165
|
+
|| (type == 2 && !fixedChangeParamVal);
|
|
166
|
+
dependenceValue = isDependenceValueChange ? fixedChangeParamVal : fixedParamVal;
|
|
167
|
+
}
|
|
157
168
|
fixedParam[item] = dependenceValue;
|
|
158
169
|
form.setFieldsValue({ ...form?.getFieldsValue(), [item]: dependenceValue })
|
|
159
170
|
if(isDependenceValueChange) {
|
|
@@ -305,7 +316,9 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
305
316
|
}
|
|
306
317
|
return {
|
|
307
318
|
...item,
|
|
308
|
-
text:
|
|
319
|
+
text: specialBracket
|
|
320
|
+
? `【${item[mappingValueField]}】${item[mappingTextField]}`
|
|
321
|
+
: item[mappingTextField],
|
|
309
322
|
textShowText,
|
|
310
323
|
textShowKey: item[mappingTextShowKeyField || mappingValueField],
|
|
311
324
|
value: item[mappingValueField],
|
|
@@ -326,7 +339,9 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
326
339
|
}
|
|
327
340
|
return {
|
|
328
341
|
...item,
|
|
329
|
-
text:
|
|
342
|
+
text: specialBracket
|
|
343
|
+
? `【${item[mappingValueField]}】${item[mappingTextField]}`
|
|
344
|
+
: item[mappingTextField],
|
|
330
345
|
textShowText,
|
|
331
346
|
textShowKey: item[mappingTextShowKeyField || mappingValueField],
|
|
332
347
|
value: item[mappingValueField],
|
|
@@ -335,13 +350,17 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
335
350
|
: [];
|
|
336
351
|
}
|
|
337
352
|
source = Array.isArray(source) ? source : []
|
|
338
|
-
if
|
|
339
|
-
|
|
340
|
-
setItems(source)
|
|
341
|
-
setItemsTotal(Number(res?.total || res?.totalCount || source.length))
|
|
353
|
+
if(callback) {
|
|
354
|
+
callback(source)
|
|
342
355
|
} else {
|
|
343
|
-
|
|
344
|
-
|
|
356
|
+
if (type === 1) {
|
|
357
|
+
ctx?.form?.setFieldSource(resultSourceKey, source)
|
|
358
|
+
setItems(source)
|
|
359
|
+
setItemsTotal(Number(res?.total || res?.totalCount || source.length))
|
|
360
|
+
} else {
|
|
361
|
+
setTableData(source)
|
|
362
|
+
setTablePagination({ ...tablePagination, total: Number(res?.total || res?.totalCount || source.length), pageSize: Number(res?.size || res?.pageSize || (params?.pageSize || pageSize)), current: Number(res?.page || res?.currentPage || (params?.currentPage || currentPage)) })
|
|
363
|
+
}
|
|
345
364
|
}
|
|
346
365
|
})
|
|
347
366
|
.catch((err) => { setFetching(false) });
|
|
@@ -388,6 +407,14 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
388
407
|
makeUniqueValue();
|
|
389
408
|
}, [resultSourceKey])
|
|
390
409
|
|
|
410
|
+
useEffect(() => {
|
|
411
|
+
if (init) {
|
|
412
|
+
setItems([]);
|
|
413
|
+
setItemsTotal(0);
|
|
414
|
+
run('init')
|
|
415
|
+
}
|
|
416
|
+
},[selectBusinessType])
|
|
417
|
+
|
|
391
418
|
const showModal = () => {
|
|
392
419
|
getData({ pageSize: tableInitPageSize, currentPage: 1 }, 3)
|
|
393
420
|
setIsModalVisible(true);
|
|
@@ -395,15 +422,13 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
395
422
|
if (value) {
|
|
396
423
|
if (selectMode) {
|
|
397
424
|
setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
|
|
425
|
+
setSelectedRows(labelInValue ? value.map(i => ({ [mappingValueField]: i.key, value: i.key, text: i.label })) : value.map(i => ({ [mappingValueField]: i, value: i })))
|
|
398
426
|
setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
|
|
399
427
|
setIndeterminate(!!value.length && value.length < itemsTotal);
|
|
400
428
|
setCheckedAll(itemsTotal && value.length === itemsTotal);
|
|
401
|
-
// 需清空数据
|
|
402
|
-
if (!value.length) {
|
|
403
|
-
setDoubleArr([])
|
|
404
|
-
}
|
|
405
429
|
} else {
|
|
406
430
|
setSelectedRowKeys(labelInValue ? [value.key] : [value])
|
|
431
|
+
setSelectedRows(labelInValue ? [{ [mappingValueField]: value.key, value: value.key, text: value.label }] : [{ [mappingValueField]: value, value: value }])
|
|
407
432
|
setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
|
|
408
433
|
}
|
|
409
434
|
}
|
|
@@ -416,6 +441,9 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
416
441
|
ctx?.form?.setFieldSource(resultSourceKey, source)
|
|
417
442
|
setItems(source)
|
|
418
443
|
formaData(selectedValue, source);
|
|
444
|
+
} else {
|
|
445
|
+
const formatResult = selectMode ? [] : null
|
|
446
|
+
onChange(formatResult, selectedValue)
|
|
419
447
|
}
|
|
420
448
|
}
|
|
421
449
|
|
|
@@ -440,7 +468,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
440
468
|
setTableData([]);
|
|
441
469
|
setTablePagination(tableInitPagination);
|
|
442
470
|
setSelectedRowKeys([]);
|
|
443
|
-
|
|
471
|
+
setSelectedRows([]);
|
|
444
472
|
setCheckedAll(false);
|
|
445
473
|
setIndeterminate(false);
|
|
446
474
|
};
|
|
@@ -501,25 +529,32 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
501
529
|
getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
|
|
502
530
|
}
|
|
503
531
|
|
|
532
|
+
const onCheckAllData = (pSize) => {
|
|
533
|
+
getData({ ...tableFormParams, pageSize: pSize, currentPage: 1 }, 2,(source) => {
|
|
534
|
+
const currentItemsData = JSON.parse(JSON.stringify(source))
|
|
535
|
+
setSelectedRowKeys(currentItemsData.map(i => i.value))
|
|
536
|
+
setPopValue(currentItemsData);
|
|
537
|
+
setSelectedRows(currentItemsData)
|
|
538
|
+
})
|
|
539
|
+
}
|
|
504
540
|
const onChangeCheckAll = (e) => {
|
|
505
541
|
if (e.target.checked) {
|
|
506
542
|
// 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
|
|
507
543
|
// 如果超过100条 就默认查出所有数据
|
|
508
|
-
const currentItemsData = JSON.parse(JSON.stringify(items))
|
|
509
|
-
const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize)
|
|
510
|
-
for (let i = 0; i <= totalPage - 1; i++) {
|
|
511
|
-
doubleArr[i] = currentItemsData.slice(tablePagination?.pageSize * i, tablePagination?.pageSize * (i + 1))
|
|
512
|
-
}
|
|
513
|
-
setDoubleArr(doubleArr)
|
|
514
|
-
setSelectedRowKeys(currentItemsData.map(i => i.value))
|
|
515
|
-
setPopValue(currentItemsData);
|
|
516
544
|
if (items.length < itemsTotal) {
|
|
517
|
-
|
|
545
|
+
const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize);
|
|
546
|
+
const allPageSize = totalPage * tablePagination?.pageSize;
|
|
547
|
+
onCheckAllData(allPageSize)
|
|
548
|
+
} else {
|
|
549
|
+
const currentItemsData = JSON.parse(JSON.stringify(items))
|
|
550
|
+
setSelectedRowKeys(currentItemsData.map(i => i.value))
|
|
551
|
+
setPopValue(currentItemsData);
|
|
552
|
+
setSelectedRows(currentItemsData)
|
|
518
553
|
}
|
|
519
554
|
} else {
|
|
520
555
|
setSelectedRowKeys([])
|
|
521
556
|
setPopValue([]);
|
|
522
|
-
|
|
557
|
+
setSelectedRows([])
|
|
523
558
|
}
|
|
524
559
|
setIndeterminate(false);
|
|
525
560
|
setCheckedAll(e.target.checked);
|
|
@@ -529,13 +564,13 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
529
564
|
const {
|
|
530
565
|
filterTxt, text,
|
|
531
566
|
} = props
|
|
532
|
-
const heightLightTxt = (
|
|
567
|
+
const heightLightTxt = (text, heightTxt) => {
|
|
533
568
|
if (heightTxt === '') {
|
|
534
|
-
return
|
|
569
|
+
return text
|
|
535
570
|
}
|
|
536
571
|
// 前面filterOption 不区分大小写,这里用i
|
|
537
572
|
const regexp = new RegExp(heightTxt, 'gi')
|
|
538
|
-
return
|
|
573
|
+
return text.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
|
|
539
574
|
}
|
|
540
575
|
return (
|
|
541
576
|
<Tooltip title={text}>
|
|
@@ -566,37 +601,19 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
566
601
|
};
|
|
567
602
|
|
|
568
603
|
const onChangeSelectedKeys = (selectKeys, selectRows) => {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
let filterRows = []; // 存放拼接后的一维数组的变量
|
|
572
|
-
let sksResult = [];
|
|
604
|
+
let sksResult = selectRows.map((i) => i.value);
|
|
573
605
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
// console.log(doubleArr)
|
|
579
|
-
setDoubleArr(doubleArr)
|
|
580
|
-
// 这块扁平化成为一位数组
|
|
581
|
-
filterRows = mapRows(doubleArr);
|
|
582
|
-
// console.log(filterRows)
|
|
583
|
-
|
|
584
|
-
sksResult = filterRows.map((i) => i.value)
|
|
585
|
-
} else {
|
|
586
|
-
// 处理单选
|
|
587
|
-
filterRows = selectRows;
|
|
588
|
-
sksResult = selectRows.map((i) => i.value)
|
|
589
|
-
// 单选 默认直接选中 不需要确定 配置了modalRadioNeedFooter就需要确定
|
|
590
|
-
if(!modalTableProps?.modalRadioNeedFooter) {
|
|
591
|
-
handleSelectOver(filterRows)
|
|
592
|
-
handleCancel();
|
|
593
|
-
}
|
|
606
|
+
// 单选 默认直接选中 不需要确定 配置了modalRadioNeedFooter就需要确定
|
|
607
|
+
if(!selectMode && !modalTableProps?.modalRadioNeedFooter) {
|
|
608
|
+
handleSelectOver(selectRows)
|
|
609
|
+
handleCancel();
|
|
594
610
|
}
|
|
595
611
|
|
|
596
612
|
setSelectedRowKeys(sksResult)
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
613
|
+
setSelectedRows(selectRows)
|
|
614
|
+
setPopValue(selectRows);
|
|
615
|
+
setIndeterminate(!!selectRows.length && selectRows.length < tablePagination?.total);
|
|
616
|
+
setCheckedAll(selectRows.length === tablePagination?.total);
|
|
600
617
|
}
|
|
601
618
|
|
|
602
619
|
// 生成唯一值
|
|
@@ -609,8 +626,13 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
609
626
|
const rowSelection = {
|
|
610
627
|
type: selectMode ? 'checkbox' : 'radio',
|
|
611
628
|
selectedRowKeys,
|
|
629
|
+
preserveSelectedRowKeys: true,
|
|
612
630
|
onChange: (sks, srs) => {
|
|
613
|
-
|
|
631
|
+
// 处理翻页后,之前存储的selectedRows变为undefined
|
|
632
|
+
// selectedRows合并新数组,过滤undefined,过滤留下对应selectedRowKeys的集合
|
|
633
|
+
let tmpSelectedRows = selectedRows.concat(srs).filter(item => item != undefined);
|
|
634
|
+
let totalSelectedRows = sks.map(key => tmpSelectedRows.filter(item => item[mappingValueField] == key)[0]).filter(item => item != undefined)
|
|
635
|
+
onChangeSelectedKeys(sks, totalSelectedRows)
|
|
614
636
|
},
|
|
615
637
|
getCheckboxProps: () => {
|
|
616
638
|
return ({
|
|
@@ -716,6 +738,14 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
716
738
|
)
|
|
717
739
|
}
|
|
718
740
|
|
|
741
|
+
const handleSelectOptionsShowValue = (specialBracket: boolean, item: object) => {
|
|
742
|
+
let showText = Array.isArray(item.textShowText) &&
|
|
743
|
+
item.textShowText.join(' ') || item.textShowText;
|
|
744
|
+
return specialBracket
|
|
745
|
+
? `【${item.textShowKey}】${showText}`
|
|
746
|
+
: `${item.textShowKey} ${showText}`
|
|
747
|
+
};
|
|
748
|
+
|
|
719
749
|
return (
|
|
720
750
|
<div className={'search_select'}>
|
|
721
751
|
{fieldComponent ?
|
|
@@ -762,10 +792,17 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
|
|
|
762
792
|
maxTagPlaceholder={maxTagPlaceholder}
|
|
763
793
|
{...currentSelectProps}
|
|
764
794
|
getPopupContainer={(triggerNode) => (getPopupContainer && getPopupContainer(triggerNode)) || triggerNode.parentElement}
|
|
795
|
+
onClear={() => {
|
|
796
|
+
console.log('@清空回调');
|
|
797
|
+
run();
|
|
798
|
+
}}
|
|
765
799
|
>
|
|
766
800
|
{items.map(item => (
|
|
767
801
|
<Option key={item.value} label={item.text}>
|
|
768
|
-
{LightHeightOption({
|
|
802
|
+
{LightHeightOption({
|
|
803
|
+
text: handleSelectOptionsShowValue(specialBracket, item),
|
|
804
|
+
filterTxt: searchValue
|
|
805
|
+
})}
|
|
769
806
|
</Option>
|
|
770
807
|
))}
|
|
771
808
|
</Select>
|
|
@@ -19,7 +19,8 @@ const TreeSearchSelect = (props: any) => {
|
|
|
19
19
|
showSearch = true,
|
|
20
20
|
maxTagCount = 1,
|
|
21
21
|
multiple = false,
|
|
22
|
-
isChoose = false,
|
|
22
|
+
isChoose = false, // 默认父节点不可选;传true则不限制
|
|
23
|
+
rootDisabled = false, // 默认根节点可选
|
|
23
24
|
mode,
|
|
24
25
|
getPopupContainer,
|
|
25
26
|
labelInValue = false,
|
|
@@ -34,13 +35,15 @@ const TreeSearchSelect = (props: any) => {
|
|
|
34
35
|
|
|
35
36
|
const {
|
|
36
37
|
url,
|
|
38
|
+
headers,
|
|
37
39
|
paramsKey = 'qp-name-like',
|
|
38
40
|
resKeyValue = ['id', 'name'],
|
|
39
41
|
initialParams = {},
|
|
40
42
|
} = remoteSource;
|
|
41
43
|
|
|
42
44
|
const mapSearchTree = (treeDataItem: any) => {
|
|
43
|
-
const haveChildren = Array.isArray(treeDataItem.children) && treeDataItem.children.length > 0;
|
|
45
|
+
const haveChildren = Array.isArray(treeDataItem.children) && treeDataItem.children.length > 0; // 盘算是否为父节点
|
|
46
|
+
const isRoot = treeDataItem?.id == '0'; // 判断是否为根节点
|
|
44
47
|
return {
|
|
45
48
|
title: treeDataItem[resKeyValue[1]],
|
|
46
49
|
key: treeDataItem[resKeyValue[0]],
|
|
@@ -48,16 +51,19 @@ const TreeSearchSelect = (props: any) => {
|
|
|
48
51
|
parentId: treeDataItem.parent,
|
|
49
52
|
data: { ...treeDataItem },
|
|
50
53
|
isLeaf: !haveChildren,
|
|
51
|
-
disabled: isDisabled(haveChildren),
|
|
54
|
+
disabled: isDisabled(haveChildren,isRoot),
|
|
52
55
|
children: haveChildren ? treeDataItem.children.map((i: any) => mapSearchTree(i)) : [],
|
|
53
56
|
};
|
|
54
57
|
};
|
|
55
58
|
|
|
56
|
-
const isDisabled = (
|
|
59
|
+
const isDisabled = (isParent: boolean,isRoot: boolean) => {
|
|
57
60
|
if (isChoose) {
|
|
61
|
+
if(rootDisabled && isRoot){
|
|
62
|
+
return rootDisabled
|
|
63
|
+
}
|
|
58
64
|
return false;
|
|
59
65
|
}
|
|
60
|
-
return
|
|
66
|
+
return isParent;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
/* 实时查询 但是目前用的直接是完整数据源, 所以没有使用 */
|
|
@@ -66,7 +72,7 @@ const TreeSearchSelect = (props: any) => {
|
|
|
66
72
|
[`${paramsKey}`]: q,
|
|
67
73
|
...initialParams,
|
|
68
74
|
}
|
|
69
|
-
axios.get(`${url}?${stringify(paramsData)}
|
|
75
|
+
axios.get(`${url}?${stringify(paramsData)}`, {headers}).then(async (res: any) => {
|
|
70
76
|
const resData = res?.data || [];
|
|
71
77
|
let coverData;
|
|
72
78
|
|
|
@@ -96,9 +102,40 @@ const TreeSearchSelect = (props: any) => {
|
|
|
96
102
|
return formatResult
|
|
97
103
|
}
|
|
98
104
|
}
|
|
105
|
+
const parallelData = (data: any,result: any) => {
|
|
106
|
+
data.forEach((i: any) => {
|
|
107
|
+
result.push(i);
|
|
108
|
+
if (i.children) {
|
|
109
|
+
parallelData(i.children, result);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
const getSelectItem = (tData: any,selectValue: any) => {
|
|
115
|
+
const handleList = tData||[];
|
|
116
|
+
let result = [];
|
|
117
|
+
if(labelInValue) {
|
|
118
|
+
result = multiple||treeCheckable ? (selectValue?.map((i: any) => {
|
|
119
|
+
if(handleList.some((s: any) => s.key == i.value)){
|
|
120
|
+
return handleList.find((s: any) => s.key == i.value)
|
|
121
|
+
}
|
|
122
|
+
}) || []) : (handleList?.find((s: any) => s.key == selectValue?.value)||{})
|
|
123
|
+
} else {
|
|
124
|
+
const cValue = _.get(selectValue?.[0], 'value', selectValue);
|
|
125
|
+
result = multiple||treeCheckable ? (selectValue?.map((i: any) => {
|
|
126
|
+
if(handleList.some((s: any) => s.key == i)){
|
|
127
|
+
return handleList.find((s: any) => s.key == i)
|
|
128
|
+
}
|
|
129
|
+
}) || []) : (handleList?.find((s: any) => s.key == cValue)||{})
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
99
133
|
const handleChange = (data: any, dataName: any) => {
|
|
100
134
|
const handleData = formatData(data);
|
|
101
|
-
|
|
135
|
+
// 获取选中树节点当条数据,并返回给调用业务
|
|
136
|
+
const parallelTreeData = parallelData(treeData,[])
|
|
137
|
+
const currentItem = getSelectItem(parallelTreeData,data)
|
|
138
|
+
onChange(handleData,data,currentItem,parallelTreeData);
|
|
102
139
|
onChangeName && onChangeName(dataName);
|
|
103
140
|
getTreeData && getTreeData(treeData); // 把树节点暴露出去
|
|
104
141
|
ctx?.form?.setFieldValue(ctx.name, handleData);
|