@bit-sun/business-component 1.1.26 → 1.1.29
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/components/Business/SearchSelect/BusinessUtils.d.ts +3 -21
- package/dist/index.esm.js +271 -139
- package/dist/index.js +272 -140
- package/package.json +1 -1
- package/src/components/Business/SearchSelect/BusinessUtils.ts +84 -24
- package/src/components/Business/SearchSelect/index.md +107 -9
- package/src/components/Business/SearchSelect/index.tsx +13 -5
- package/src/components/Functional/SearchSelect/index.tsx +146 -81
|
@@ -7,12 +7,13 @@ import axios from 'axios';
|
|
|
7
7
|
import { stringify } from 'querystring';
|
|
8
8
|
import _ from "loadsh"
|
|
9
9
|
import './index.less';
|
|
10
|
+
import { BusinessSearchSelect } from '@/index';
|
|
10
11
|
|
|
11
12
|
const { Option } = Select;
|
|
12
13
|
|
|
13
14
|
const SearchSelect = (props: any) => {
|
|
14
15
|
const {
|
|
15
|
-
value,
|
|
16
|
+
value, // 必传
|
|
16
17
|
onChange,
|
|
17
18
|
selectProps={},
|
|
18
19
|
modalTableProps={},
|
|
@@ -21,8 +22,9 @@ const SearchSelect = (props: any) => {
|
|
|
21
22
|
ctx,
|
|
22
23
|
sourceName,
|
|
23
24
|
needModalTable=true,
|
|
25
|
+
getPopupContainer=undefined
|
|
24
26
|
} = props;
|
|
25
|
-
const { url, otherParams, isMap, fixedparameter, fieldValToParam, mappingTextField='name', mappingTextShowKeyField,mappingValueField='code' } = requestConfig || {};
|
|
27
|
+
const { url, otherParams, isMap, fixedparameter, fieldValToParam, mappingTextField='name', mappingTextShowKeyField,mappingValueField='code', mappingTextShowTextField } = requestConfig || {};
|
|
26
28
|
const resultSourceKey = sourceName || requestConfig?.sourceName || 'supplierCode'
|
|
27
29
|
|
|
28
30
|
const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
|
|
@@ -183,6 +185,8 @@ const SearchSelect = (props: any) => {
|
|
|
183
185
|
delete params[key]
|
|
184
186
|
}else if (Array.isArray(element)) {
|
|
185
187
|
params[key] = element.join(',');
|
|
188
|
+
} else if(element == null || element === undefined || String(element).trim() === '') {
|
|
189
|
+
delete params[key]
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
192
|
}
|
|
@@ -218,18 +222,42 @@ const SearchSelect = (props: any) => {
|
|
|
218
222
|
source = res
|
|
219
223
|
? res[keys]
|
|
220
224
|
? res[keys].map((item: any) => {
|
|
225
|
+
let textShowText = item[mappingTextField]
|
|
226
|
+
if(mappingTextShowTextField) {
|
|
227
|
+
textShowText = []
|
|
228
|
+
if(Array.isArray(mappingTextShowTextField)) {
|
|
229
|
+
mappingTextShowTextField.forEach((r: any) => {
|
|
230
|
+
textShowText.push(item[r])
|
|
231
|
+
})
|
|
232
|
+
} else {
|
|
233
|
+
textShowText = item[mappingTextShowTextField]
|
|
234
|
+
}
|
|
235
|
+
}
|
|
221
236
|
return {
|
|
222
237
|
...item,
|
|
223
238
|
text: item[mappingTextField],
|
|
239
|
+
textShowText,
|
|
224
240
|
textShowKey: item[mappingTextShowKeyField || mappingValueField],
|
|
225
241
|
value: item[mappingValueField],
|
|
226
242
|
};
|
|
227
243
|
})
|
|
228
244
|
: Array.isArray(res) &&
|
|
229
245
|
res?.map((item: Record<string, any>) => {
|
|
246
|
+
let textShowText = item[mappingTextField]
|
|
247
|
+
if(mappingTextShowTextField) {
|
|
248
|
+
textShowText = []
|
|
249
|
+
if(Array.isArray(mappingTextShowTextField)) {
|
|
250
|
+
mappingTextShowTextField.forEach((r: any) => {
|
|
251
|
+
textShowText.push(item[r])
|
|
252
|
+
})
|
|
253
|
+
} else {
|
|
254
|
+
textShowText = item[mappingTextShowTextField]
|
|
255
|
+
}
|
|
256
|
+
}
|
|
230
257
|
return {
|
|
231
258
|
...item,
|
|
232
259
|
text: item[mappingTextField],
|
|
260
|
+
textShowText,
|
|
233
261
|
textShowKey: item[mappingTextShowKeyField || mappingValueField],
|
|
234
262
|
value: item[mappingValueField],
|
|
235
263
|
};
|
|
@@ -254,7 +282,7 @@ const SearchSelect = (props: any) => {
|
|
|
254
282
|
const { target } = e;
|
|
255
283
|
const totalPage = Math.ceil(itemsTotal / pageSize)
|
|
256
284
|
// 判断是否滑动到底部
|
|
257
|
-
const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight
|
|
285
|
+
const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
|
|
258
286
|
// 判断数据是否还没有加载到了最后一页
|
|
259
287
|
const canPageAdd = scrollPage < totalPage
|
|
260
288
|
if (isTouchGround && canPageAdd) {
|
|
@@ -262,6 +290,16 @@ const SearchSelect = (props: any) => {
|
|
|
262
290
|
setScrollPage(nextScrollPage);
|
|
263
291
|
getData({currentPage: nextScrollPage}); // 调用api方法
|
|
264
292
|
}
|
|
293
|
+
|
|
294
|
+
//判断是否滑动到顶部
|
|
295
|
+
const isTouchTop = target.scrollTop ===0 // <=0
|
|
296
|
+
// 判断数据是否到第一页
|
|
297
|
+
const canPageJian = scrollPage > 1
|
|
298
|
+
if (isTouchTop && canPageJian) {
|
|
299
|
+
const preScrollPage = scrollPage - 1;
|
|
300
|
+
setScrollPage(preScrollPage);
|
|
301
|
+
getData({currentPage: preScrollPage}); // 调用api方法
|
|
302
|
+
}
|
|
265
303
|
}
|
|
266
304
|
|
|
267
305
|
useEffect(() => {
|
|
@@ -288,7 +326,7 @@ const SearchSelect = (props: any) => {
|
|
|
288
326
|
setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
|
|
289
327
|
setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
|
|
290
328
|
setIndeterminate(!!value.length && value.length < itemsTotal);
|
|
291
|
-
setCheckedAll(value.length === itemsTotal);
|
|
329
|
+
setCheckedAll(itemsTotal && value.length === itemsTotal);
|
|
292
330
|
// 需清空数据
|
|
293
331
|
if(!value.length) {
|
|
294
332
|
setDoubleArr([])
|
|
@@ -300,14 +338,18 @@ const SearchSelect = (props: any) => {
|
|
|
300
338
|
}
|
|
301
339
|
};
|
|
302
340
|
|
|
303
|
-
const
|
|
304
|
-
if(
|
|
305
|
-
formaData(
|
|
341
|
+
const handleSelectOver = (selectedValue: any) => {
|
|
342
|
+
if(selectedValue?.length) {
|
|
343
|
+
formaData(selectedValue);
|
|
306
344
|
// 解决选择最后1页的sku,返回后,不显示名称问题
|
|
307
|
-
const source = _.uniqBy(items.concat(
|
|
345
|
+
const source = _.uniqBy(items.concat(selectedValue), 'value')
|
|
308
346
|
ctx?.form?.setFieldSource(resultSourceKey, source)
|
|
309
347
|
setItems(source)
|
|
310
348
|
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const handleOk = () => {
|
|
352
|
+
handleSelectOver(popvalue)
|
|
311
353
|
handleCancel();
|
|
312
354
|
};
|
|
313
355
|
|
|
@@ -325,6 +367,9 @@ const SearchSelect = (props: any) => {
|
|
|
325
367
|
form.resetFields();
|
|
326
368
|
setTableFormParams({});
|
|
327
369
|
setIsModalVisible(false);
|
|
370
|
+
if(selectMode) {
|
|
371
|
+
run();
|
|
372
|
+
}
|
|
328
373
|
};
|
|
329
374
|
|
|
330
375
|
const onSearchChange = (e) => {
|
|
@@ -341,6 +386,9 @@ const SearchSelect = (props: any) => {
|
|
|
341
386
|
const params = form.getFieldsValue();
|
|
342
387
|
setTableFormParams(params);
|
|
343
388
|
getData({ ...params, pageSize: tableInitPageSize }, 2)
|
|
389
|
+
if(selectMode){
|
|
390
|
+
getData(params)
|
|
391
|
+
}
|
|
344
392
|
}
|
|
345
393
|
|
|
346
394
|
const onResetTable = () => {
|
|
@@ -355,12 +403,17 @@ const SearchSelect = (props: any) => {
|
|
|
355
403
|
|
|
356
404
|
const onChangeCheckAll = (e) => {
|
|
357
405
|
if(e.target.checked) {
|
|
358
|
-
//
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
406
|
+
// 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
|
|
407
|
+
// 如果超过100条 就默认查出所有数据
|
|
408
|
+
const currentItemsData = JSON.parse(JSON.stringify(items))
|
|
409
|
+
const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize)
|
|
410
|
+
for(let i=0; i <= totalPage-1; i++){
|
|
411
|
+
doubleArr[i] = currentItemsData.slice(tablePagination?.pageSize*i,tablePagination?.pageSize*(i+1))
|
|
412
|
+
}
|
|
413
|
+
setDoubleArr(doubleArr)
|
|
414
|
+
setSelectedRowKeys(currentItemsData.map(i => i.value))
|
|
415
|
+
setPopValue(currentItemsData);
|
|
416
|
+
if(items.length < itemsTotal) {
|
|
364
417
|
// TODO 请求接口获取所有数据
|
|
365
418
|
}
|
|
366
419
|
} else {
|
|
@@ -385,12 +438,14 @@ const SearchSelect = (props: any) => {
|
|
|
385
438
|
return txt.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
|
|
386
439
|
}
|
|
387
440
|
return (
|
|
388
|
-
<
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
441
|
+
<Tooltip title={text}>
|
|
442
|
+
<div ref={(nodeElement) => {
|
|
443
|
+
if (nodeElement) {
|
|
444
|
+
nodeElement.innerHTML = heightLightTxt(text, filterTxt)
|
|
445
|
+
}
|
|
446
|
+
}}
|
|
447
|
+
/>
|
|
448
|
+
</Tooltip>
|
|
394
449
|
)
|
|
395
450
|
}
|
|
396
451
|
|
|
@@ -431,6 +486,9 @@ const SearchSelect = (props: any) => {
|
|
|
431
486
|
// 处理单选
|
|
432
487
|
filterRows = selectRows;
|
|
433
488
|
sksResult = selectRows.map((i) => i.value)
|
|
489
|
+
// 单选直接选中 不需要确定
|
|
490
|
+
handleSelectOver(filterRows)
|
|
491
|
+
handleCancel();
|
|
434
492
|
}
|
|
435
493
|
|
|
436
494
|
setSelectedRowKeys(sksResult)
|
|
@@ -487,6 +545,16 @@ const SearchSelect = (props: any) => {
|
|
|
487
545
|
)
|
|
488
546
|
}
|
|
489
547
|
|
|
548
|
+
if(i?.type === 'businessSearchSelect') {
|
|
549
|
+
return (
|
|
550
|
+
<div>
|
|
551
|
+
<Form.Item name={i.name} label={i.label} key={i.name}>
|
|
552
|
+
<BusinessSearchSelect {...i.field.props} />
|
|
553
|
+
</Form.Item>
|
|
554
|
+
</div>
|
|
555
|
+
)
|
|
556
|
+
}
|
|
557
|
+
|
|
490
558
|
// 默认type是input
|
|
491
559
|
return (
|
|
492
560
|
<Form.Item name={i.name} label={i.label} key={i.name}>
|
|
@@ -499,77 +567,74 @@ const SearchSelect = (props: any) => {
|
|
|
499
567
|
}
|
|
500
568
|
}
|
|
501
569
|
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
return listSelected?.length && listSelected.map((i: any) => (
|
|
570
|
+
const maxTagPlaceholder = (selectedValues) => {
|
|
571
|
+
const onClose = (e: any,item: any) => {
|
|
572
|
+
e.preventDefault();
|
|
573
|
+
const newValue = labelInValue ? JSON.parse(JSON.stringify(value)).filter((i: any) => i.value !== item.value): JSON.parse(JSON.stringify(value)).filter((i: any) => i !== item.value)
|
|
574
|
+
onChange(newValue);
|
|
575
|
+
}
|
|
576
|
+
return (
|
|
577
|
+
<Tooltip title={selectedValues.map((i: any) => (
|
|
511
578
|
<Tag
|
|
512
579
|
closable={true}
|
|
513
580
|
onClose={(e) => onClose(e,i)}
|
|
514
581
|
style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
|
|
515
582
|
>
|
|
516
|
-
{i.
|
|
583
|
+
{i.label}
|
|
517
584
|
</Tag>
|
|
518
|
-
))
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return ''
|
|
585
|
+
))}>
|
|
586
|
+
{`+ ${selectedValues?.length}`}
|
|
587
|
+
</Tooltip>
|
|
588
|
+
)
|
|
523
589
|
}
|
|
524
590
|
|
|
525
591
|
return (
|
|
526
592
|
<div className={'search_select'}>
|
|
527
593
|
<div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
|
|
528
|
-
<
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
<div style={{
|
|
554
|
-
<
|
|
555
|
-
<CopyOutlined style={{ fontSize: '50px' }} />
|
|
556
|
-
</div>
|
|
557
|
-
<div>无匹配结果,请更换其他内容再试</div>
|
|
594
|
+
<Select
|
|
595
|
+
virtual
|
|
596
|
+
labelInValue={labelInValue}
|
|
597
|
+
value={value}
|
|
598
|
+
onChange={onChange}
|
|
599
|
+
dropdownRender={menu => (
|
|
600
|
+
<>
|
|
601
|
+
<Input
|
|
602
|
+
value={searchValue}
|
|
603
|
+
style={{ width: '98%', marginLeft: '1%' }}
|
|
604
|
+
placeholder="请输入"
|
|
605
|
+
onChange={e=> onSearchChange(e)}
|
|
606
|
+
onBlur={onSearchBlur}
|
|
607
|
+
onKeyDown={(e) => {
|
|
608
|
+
// 阻止多选的冒泡
|
|
609
|
+
e.stopPropagation()
|
|
610
|
+
}}
|
|
611
|
+
/>
|
|
612
|
+
<Divider style={{ margin: '8px 0' }} />
|
|
613
|
+
{menu}
|
|
614
|
+
</>
|
|
615
|
+
)}
|
|
616
|
+
notFoundContent={
|
|
617
|
+
fetching ? <Spin size="small" /> :
|
|
618
|
+
<div style={{ textAlign: 'center'}}>
|
|
619
|
+
<div style={{ marginBottom: 16 }}>
|
|
620
|
+
<CopyOutlined style={{ fontSize: '50px' }} />
|
|
558
621
|
</div>
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
622
|
+
<div>无匹配结果,请更换其他内容再试</div>
|
|
623
|
+
</div>
|
|
624
|
+
}
|
|
625
|
+
onPopupScroll={SelectScroll}
|
|
626
|
+
style={{ width: needModalTable?'calc(100% - 30px)':'calc(100%)' }}
|
|
627
|
+
placeholder="请选择"
|
|
628
|
+
maxTagPlaceholder={maxTagPlaceholder}
|
|
629
|
+
{...currentSelectProps}
|
|
630
|
+
getPopupContainer={() => (getPopupContainer && getPopupContainer()) || document.getElementById(`search_select_div_${uniqueValue}`)}
|
|
631
|
+
>
|
|
632
|
+
{items.map(item => (
|
|
633
|
+
<Option key={item.value} label={item.text}>
|
|
634
|
+
{LightHeightOption({ text: `${item.textShowKey} ${Array.isArray(item.textShowText) && item.textShowText.join(' ') || item.textShowText}`, filterTxt: searchValue })}
|
|
635
|
+
</Option>
|
|
636
|
+
))}
|
|
637
|
+
</Select>
|
|
573
638
|
{needModalTable && (
|
|
574
639
|
<Button style={{width: '30px', padding: '2px', height: 'auto'}} onClick={showModal} type="primary">
|
|
575
640
|
<SearchOutlined />
|
|
@@ -583,7 +648,7 @@ const SearchSelect = (props: any) => {
|
|
|
583
648
|
visible={isModalVisible}
|
|
584
649
|
onOk={handleOk}
|
|
585
650
|
onCancel={handleCancel}
|
|
586
|
-
footer={[
|
|
651
|
+
footer={selectMode?[
|
|
587
652
|
<Button key="back" onClick={handleCancel}>
|
|
588
653
|
取消
|
|
589
654
|
</Button>,
|
|
@@ -595,7 +660,7 @@ const SearchSelect = (props: any) => {
|
|
|
595
660
|
>
|
|
596
661
|
确定
|
|
597
662
|
</Button>,
|
|
598
|
-
]}
|
|
663
|
+
]:null}
|
|
599
664
|
>
|
|
600
665
|
<div className={'search_select_wrapper'}>
|
|
601
666
|
<div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
|