@bit-sun/business-component 1.1.1 → 1.1.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/package.json +2 -2
- package/src/components/QueryMutipleInput/index.tsx +1 -1
- package/src/components/SearchSelect/index.less +115 -0
- package/src/components/SearchSelect/index.md +130 -0
- package/src/components/SearchSelect/index.tsx +422 -0
- package/src/index.ts +2 -1
- package/dist/components/DataValidation/index.d.ts +0 -144
- package/dist/components/QueryMutipleInput/index.d.ts +0 -5
- package/dist/index.d.ts +0 -3
- package/dist/index.esm.js +0 -2386
- package/dist/index.js +0 -2399
- package/dist/utils/CheckOneUser/index.d.ts +0 -2
package/package.json
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
.search_select {
|
|
2
|
+
&_show {
|
|
3
|
+
display: flex;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
&_expand_button {
|
|
7
|
+
position: relative;
|
|
8
|
+
width: 30px;
|
|
9
|
+
color: #ffffff;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
|
|
12
|
+
span {
|
|
13
|
+
position: absolute;
|
|
14
|
+
height: 20px;
|
|
15
|
+
line-height: 14px;
|
|
16
|
+
left: 50%;
|
|
17
|
+
top: 50%;
|
|
18
|
+
transform: translate(-50%, -50%);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&_wrapper {
|
|
23
|
+
position: relative;
|
|
24
|
+
display: flex;
|
|
25
|
+
min-height: 60vh;
|
|
26
|
+
max-height: 60vh;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
font-size: 14px;
|
|
29
|
+
|
|
30
|
+
&_click_flag {
|
|
31
|
+
position: absolute;
|
|
32
|
+
z-index: 10;
|
|
33
|
+
&_arrow {
|
|
34
|
+
transform: rotate(0deg);
|
|
35
|
+
transition: transform 0.5s;
|
|
36
|
+
}
|
|
37
|
+
&_arrow_1 {
|
|
38
|
+
transform: rotate(-180deg);
|
|
39
|
+
transition: transform 0.5s;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&_left {
|
|
44
|
+
width: 28%;
|
|
45
|
+
overflow-y: hidden;
|
|
46
|
+
//background-color: yellow;
|
|
47
|
+
transition: all 0.3s;
|
|
48
|
+
margin-left: 20px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&_left1 {
|
|
52
|
+
width: 0;
|
|
53
|
+
height: 0;
|
|
54
|
+
transition: all 0.3s;
|
|
55
|
+
display: none;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&_right {
|
|
59
|
+
width: 70%;
|
|
60
|
+
margin-left: 1%;
|
|
61
|
+
//background-color: pink;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&_right1 {
|
|
65
|
+
width: 100%;
|
|
66
|
+
margin-left: 20px;
|
|
67
|
+
//background-color: green;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&_right, _right1 {
|
|
71
|
+
overflow-x: auto;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.select_list_columns {
|
|
75
|
+
width: 100%;
|
|
76
|
+
height: calc(60vh - 60px);
|
|
77
|
+
overflow-y: auto;
|
|
78
|
+
border: 1px solid #d8d8d8;
|
|
79
|
+
&_tips {
|
|
80
|
+
background: #eee;
|
|
81
|
+
padding: 6px 20px;
|
|
82
|
+
margin-bottom: 10px;
|
|
83
|
+
}
|
|
84
|
+
&_formItems {
|
|
85
|
+
padding: 0 20px;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
.select_list_searchButton {
|
|
89
|
+
display: flex;
|
|
90
|
+
margin: 10px 0px;
|
|
91
|
+
justify-content: flex-end;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.select_list_button_space {
|
|
95
|
+
margin-right: 10px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.select_list_selectTips {
|
|
99
|
+
display: flex;
|
|
100
|
+
justify-content: space-between;
|
|
101
|
+
height: 34px;
|
|
102
|
+
line-height: 32px;
|
|
103
|
+
background-color: #eee;
|
|
104
|
+
margin-bottom: 10px;
|
|
105
|
+
padding: 0 12px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.select_list_selectAll {
|
|
109
|
+
position: relative;
|
|
110
|
+
top: -40px;
|
|
111
|
+
left: 20px;
|
|
112
|
+
width: 160px;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
nav:
|
|
3
|
+
title: '组件'
|
|
4
|
+
order: 1
|
|
5
|
+
group:
|
|
6
|
+
title: 组件
|
|
7
|
+
order: 0
|
|
8
|
+
title: 档案选择器
|
|
9
|
+
order: 2
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## SearchSelect
|
|
13
|
+
|
|
14
|
+
Demo:
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import React, { useRef } from 'react';
|
|
18
|
+
import { SearchSelect } from '@bit-sun/business-component';
|
|
19
|
+
|
|
20
|
+
export default () => {
|
|
21
|
+
const selectProps = {
|
|
22
|
+
mode: 'multiple',
|
|
23
|
+
maxTagCount: 1,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const DictionaryUC000013 = [{ text: '共享', value: '10' }, { text: '私有', value: '20' }]
|
|
27
|
+
const modalTableProps = {
|
|
28
|
+
modalTableTitle: '选择供应商',
|
|
29
|
+
tableSearchForm:[
|
|
30
|
+
{ name: 'qp-name-like', label: '客户名称' }, // field: { type: 'input', props: { placeholder: '8888'}}
|
|
31
|
+
{ name: 'qp-code-like', label: '客户编码' },
|
|
32
|
+
{ name: 'qp-conglomerateCode-in', type: 'select', label: '归属集团', field: {
|
|
33
|
+
type: 'select',
|
|
34
|
+
props: {
|
|
35
|
+
mode: 'multiple',
|
|
36
|
+
notFoundContent: '暂无数据',
|
|
37
|
+
allowClear: true,
|
|
38
|
+
showSearch: true,
|
|
39
|
+
showArrow: true,
|
|
40
|
+
maxTagCount: 1,
|
|
41
|
+
optionFilterProp: 'children',
|
|
42
|
+
filterOption: (input: string, option: { props: { children: string } }) =>
|
|
43
|
+
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
initialSource: [{ text: '英伦宝贝儿童用品有限公司', value: 'A0001' }]
|
|
47
|
+
},
|
|
48
|
+
{ name: 'qp-accountingCode-in', type: 'select', label: '归属核算主体', field: {
|
|
49
|
+
type: 'select',
|
|
50
|
+
props: {
|
|
51
|
+
mode: 'multiple',
|
|
52
|
+
notFoundContent: '暂无数据',
|
|
53
|
+
allowClear: true,
|
|
54
|
+
showSearch: true,
|
|
55
|
+
showArrow: true,
|
|
56
|
+
maxTagCount: 1,
|
|
57
|
+
optionFilterProp: 'children',
|
|
58
|
+
filterOption: (input: string, option: { props: { children: string } }) =>
|
|
59
|
+
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
initialSource: [{ text: '上海哲雄母婴用品有限公司', value: 'F002' }, { text: '上海英伦宝贝儿童用品有限公司', value: 'F001' }]
|
|
63
|
+
},
|
|
64
|
+
{ name: 'qp-companyCode-in', type: 'select', label: '归属法人公司', field: {
|
|
65
|
+
type: 'select',
|
|
66
|
+
props: {
|
|
67
|
+
mode: 'multiple',
|
|
68
|
+
notFoundContent: '暂无数据',
|
|
69
|
+
allowClear: true,
|
|
70
|
+
showSearch: true,
|
|
71
|
+
showArrow: true,
|
|
72
|
+
maxTagCount: 1,
|
|
73
|
+
optionFilterProp: 'children',
|
|
74
|
+
filterOption: (input: string, option: { props: { children: string } }) =>
|
|
75
|
+
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
initialSource: [{ text: '上海哲雄母婴用品有限公司', value: 'F002' }, { text: '上海英伦宝贝儿童用品有限公司', value: 'F001' }]
|
|
79
|
+
},
|
|
80
|
+
{ name: 'qp-sharingType-eq', type: 'select', label: '共享类型', initialSource: DictionaryUC000013 }, // 页面可以直接使用getDictionarySource('UC000013')
|
|
81
|
+
],
|
|
82
|
+
tableColumns: [
|
|
83
|
+
{
|
|
84
|
+
title: '客户编码',
|
|
85
|
+
dataIndex: 'code',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
title: '客户名称',
|
|
89
|
+
dataIndex: 'name',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
title: '归属集团',
|
|
93
|
+
dataIndex: 'conglomerateName',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
title: '归属法人公司',
|
|
97
|
+
dataIndex: 'legalCompanyName',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
title: '归属核算主体',
|
|
101
|
+
dataIndex: 'accountingName',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
title: '共享类型',
|
|
105
|
+
dataIndex: 'sharingType',
|
|
106
|
+
render: (text) => DictionaryUC000013?.find((i) => i.value === text)?.text, // getDictionaryTextByValue('UC000013', text)
|
|
107
|
+
},
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const onValueChange = (value) => {
|
|
112
|
+
console.log(value)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div>
|
|
117
|
+
<SearchSelect
|
|
118
|
+
// initValue={{value: '20220105001', label: 'LH公司'}} // 单选
|
|
119
|
+
// initValue={[{value: '20220105001', label: 'LH公司'}]} // 多选
|
|
120
|
+
selectProps={selectProps}
|
|
121
|
+
modalTableProps={modalTableProps}
|
|
122
|
+
selectDataUrl='http://test.i-baby.net/bop/api/supplier'
|
|
123
|
+
onValueChange={onValueChange}
|
|
124
|
+
/>
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
More skills for writing demo: https://d.umijs.org/guide/demo-principle
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import React, { useState, useEffect } from 'react';
|
|
3
|
+
import { useDebounceFn } from 'ahooks';
|
|
4
|
+
import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox } from 'antd';
|
|
5
|
+
import { SearchOutlined, CopyOutlined, CaretLeftOutlined } from '@ant-design/icons';
|
|
6
|
+
import { QueryMutipleInput } from '@bit-sun/business-component';
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
import { stringify } from 'querystring';
|
|
9
|
+
import _ from "loadsh"
|
|
10
|
+
import './index.less';
|
|
11
|
+
|
|
12
|
+
const { Option } = Select;
|
|
13
|
+
|
|
14
|
+
// initValue: { value: string | number, label?: ReactNode }
|
|
15
|
+
const SearchSelect = ({ onValueChange, selectProps={}, selectDataUrl, initValue, modalTableProps={} }) => {
|
|
16
|
+
const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
|
|
17
|
+
const initVal = initValue || (selectMode ? [] : null)
|
|
18
|
+
const pageSize = 100 // 下拉框默认分页 条数
|
|
19
|
+
const tableInitPageSize = 10 // 弹框默认分页 条数
|
|
20
|
+
const currentPage = 1
|
|
21
|
+
const currentSelectProps = {
|
|
22
|
+
...selectProps,
|
|
23
|
+
showSearch: false,
|
|
24
|
+
filterOption: false,
|
|
25
|
+
allowClear: true,
|
|
26
|
+
listHeight: 160,
|
|
27
|
+
optionLabelProp: "label",
|
|
28
|
+
autoClearSearchValue: false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const [items, setItems] = useState([]);
|
|
32
|
+
const [scrollPage, setScrollPage] = useState(1);
|
|
33
|
+
const [itemsTotal, setItemsTotal] = useState(0);
|
|
34
|
+
const [fetching, setFetching] = useState(false);
|
|
35
|
+
const [searchValue, setSearchValue] = useState('');
|
|
36
|
+
const [isModalVisible, setIsModalVisible] = useState(false);
|
|
37
|
+
const [value, setValue] = useState(initVal);
|
|
38
|
+
const [popvalue, setPopValue] = useState(initVal);
|
|
39
|
+
const { run } = useDebounceFn(
|
|
40
|
+
() => {
|
|
41
|
+
// 防抖函数 待定
|
|
42
|
+
getData({ 'qp-name-like': searchValue })
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
wait: 1000,
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const [form] = Form.useForm();
|
|
50
|
+
const [caretLeftFlag, setCaretLeftFlag] = useState(true);
|
|
51
|
+
const [tableData, setTableData] = useState([]);
|
|
52
|
+
const [tablePagination, setTablePagination] = useState({ showQuickJumper: true, total: 0, current: 1, pageSize: tableInitPageSize })
|
|
53
|
+
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
54
|
+
const [selectedRows, setSelectedRows] = useState([]);
|
|
55
|
+
const [doubleArr, setDoubleArr] = useState([]); // 存放双数组的数组
|
|
56
|
+
const [filterRows, setFilterRows] = useState([]); // 存放拼接后的一维数组的变量
|
|
57
|
+
const [checkedAll, setCheckedAll] = useState(false)
|
|
58
|
+
const [indeterminate, setIndeterminate] = useState(false)
|
|
59
|
+
|
|
60
|
+
// 获取数据源 (type: 1下拉框 2弹框 不传值默认为下拉框)
|
|
61
|
+
const getData = (initParams, type=1) => {
|
|
62
|
+
setFetching(true)
|
|
63
|
+
const queryParams = {
|
|
64
|
+
pageSize,
|
|
65
|
+
currentPage,
|
|
66
|
+
...initParams,
|
|
67
|
+
sorter: 'desc-createTime'
|
|
68
|
+
}
|
|
69
|
+
axios
|
|
70
|
+
.get(`${selectDataUrl}?${stringify(queryParams)}`)
|
|
71
|
+
.then((result) => {
|
|
72
|
+
setFetching(false)
|
|
73
|
+
result = result.data;
|
|
74
|
+
if (result.status !== '0') {
|
|
75
|
+
message.error(result.msg);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const res = result.data?.items || [];
|
|
79
|
+
if(type === 1) {
|
|
80
|
+
setItems(res)
|
|
81
|
+
setItemsTotal(Number(result.data?.total))
|
|
82
|
+
} else {
|
|
83
|
+
setTableData(res)
|
|
84
|
+
setTablePagination({...tablePagination, total: Number(result.data?.total), pageSize: Number(result.data?.size), current: Number(result.data?.page)})
|
|
85
|
+
// if(checkedAll) {
|
|
86
|
+
// onChangeSelectedKeys(res.map((i) => i.code), res, result.data?.page, 'show')
|
|
87
|
+
// }
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
.catch((err) => { setFetching(false) });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const SelectScroll = e => {
|
|
94
|
+
e.persist();
|
|
95
|
+
const { target } = e;
|
|
96
|
+
const totalPage = Math.ceil(itemsTotal / pageSize)
|
|
97
|
+
// 判断是否滑动到底部
|
|
98
|
+
const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight
|
|
99
|
+
// 判断数据是否还没有加载到了最后一页
|
|
100
|
+
const canPageAdd = scrollPage < totalPage
|
|
101
|
+
if (isTouchGround && canPageAdd) {
|
|
102
|
+
const nextScrollPage = scrollPage + 1;
|
|
103
|
+
setScrollPage(nextScrollPage);
|
|
104
|
+
getData({currentPage: nextScrollPage}); // 调用api方法
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
getData()
|
|
110
|
+
}, [])
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
setPopValue(value);
|
|
114
|
+
onValueChange(value);
|
|
115
|
+
}, [value]);
|
|
116
|
+
|
|
117
|
+
const showModal = () => {
|
|
118
|
+
getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
|
|
119
|
+
setIsModalVisible(true);
|
|
120
|
+
// 回显
|
|
121
|
+
if(value) {
|
|
122
|
+
if(selectMode) {
|
|
123
|
+
setSelectedRowKeys(value.map(i => i.key))
|
|
124
|
+
setSelectedRows(value.map(i => ({ code: i.key, name: i.label })))
|
|
125
|
+
setPopValue(value.map(i => ({ code: i.key, name: i.label })));
|
|
126
|
+
setIndeterminate(!!value.length && value.length < itemsTotal);
|
|
127
|
+
setCheckedAll(value.length === itemsTotal);
|
|
128
|
+
} else {
|
|
129
|
+
setSelectedRowKeys([value.key])
|
|
130
|
+
setSelectedRows([{ code: value.key, name: value.label }])
|
|
131
|
+
setPopValue([{ code: value.key, name: value.label }]);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const handleOk = () => {
|
|
137
|
+
if(popvalue?.length) {
|
|
138
|
+
formaData(popvalue);
|
|
139
|
+
}
|
|
140
|
+
setIsModalVisible(false);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const formaData = (value) => {
|
|
144
|
+
const formatResult = value.map((i: any) => ({ key: i.code, label: i.name, value: i.code }))
|
|
145
|
+
setValue(selectMode ? formatResult : formatResult[0])
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const handleCancel = () => {
|
|
149
|
+
setIsModalVisible(false);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const onSearchChange = (e) => {
|
|
153
|
+
setSearchValue(e.target.value);
|
|
154
|
+
run();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const onSearchBlur = () => {
|
|
158
|
+
setSearchValue('')
|
|
159
|
+
run();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//( 多选模式下 选中数据再搜索 删除部分搜索内容会优先触发这个函数 删除掉已选中内容才会去触发onSearchChange函数进行搜索)
|
|
163
|
+
const outerChange = (sValue) => {
|
|
164
|
+
setValue(sValue);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const onSearchTable = () => {
|
|
168
|
+
const params = form.getFieldsValue();
|
|
169
|
+
getData({ ...params, pageSize: tableInitPageSize }, 2)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const onResetTable = () => {
|
|
173
|
+
form.resetFields();
|
|
174
|
+
handleTableChange({ pageSize: tableInitPageSize, currentPage: 1 })
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const handleTableChange = (pagination) => {
|
|
178
|
+
getData({ pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const onChangeCheckAll = (e) => {
|
|
182
|
+
if(e.target.checked) {
|
|
183
|
+
// 方案一:此种方案存在的问题是,数据不真实 回显下拉框有问题
|
|
184
|
+
// const currentTableData = JSON.parse(JSON.stringify(tableData))
|
|
185
|
+
// onChangeSelectedKeys(currentTableData.map((i) => i.code),currentTableData,tablePagination.current, 'checkAll')
|
|
186
|
+
// 方案二:如果下拉框有所有数据就处理选中所有,如果没有 就默认查出所有数据
|
|
187
|
+
if(items.length === itemsTotal) {
|
|
188
|
+
const currentItemsData = JSON.parse(JSON.stringify(items))
|
|
189
|
+
setSelectedRowKeys(currentItemsData.map(i => i.code))
|
|
190
|
+
setSelectedRows(currentItemsData)
|
|
191
|
+
setPopValue(currentItemsData);
|
|
192
|
+
} else {
|
|
193
|
+
// TODO 请求接口获取所有数据
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
setSelectedRowKeys([])
|
|
197
|
+
setSelectedRows([])
|
|
198
|
+
setPopValue([]);
|
|
199
|
+
}
|
|
200
|
+
setIndeterminate(false);
|
|
201
|
+
setCheckedAll(e.target.checked);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const LightHeightOption = (props) => {
|
|
205
|
+
const {
|
|
206
|
+
filterTxt, text,
|
|
207
|
+
} = props
|
|
208
|
+
const heightLightTxt = (txt, heightTxt) => {
|
|
209
|
+
if (heightTxt === '') {
|
|
210
|
+
return txt
|
|
211
|
+
}
|
|
212
|
+
// 前面filterOption 不区分大小写,这里用i
|
|
213
|
+
const regexp = new RegExp(heightTxt, 'gi')
|
|
214
|
+
return txt.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
|
|
215
|
+
}
|
|
216
|
+
return (
|
|
217
|
+
<div ref={(nodeElement) => {
|
|
218
|
+
if (nodeElement) {
|
|
219
|
+
nodeElement.innerHTML = heightLightTxt(text, filterTxt)
|
|
220
|
+
}
|
|
221
|
+
}}
|
|
222
|
+
/>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 扁平化二维数组的方法
|
|
227
|
+
const mapRows = params => {
|
|
228
|
+
var res = [];
|
|
229
|
+
for (var i = 0; i < params.length; i++) {
|
|
230
|
+
if (Array.isArray(params[i])) {
|
|
231
|
+
// 去重
|
|
232
|
+
res = _.uniqBy(res.concat(mapRows(params[i])), 'code');
|
|
233
|
+
} else {
|
|
234
|
+
res.push(params[i]);
|
|
235
|
+
// 去重
|
|
236
|
+
res = _.uniqBy(res, 'code')
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return res.filter(Boolean); //去掉undefined的情况
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const onChangeSelectedKeys=(selectKeys,selectRows, nowPage, type) => {
|
|
243
|
+
// 处理全选 & 全选时进入某一页首次展示
|
|
244
|
+
// if(type === 'checkAll') {
|
|
245
|
+
// const totalFullPage = Math.floor(tablePagination.total / tableInitPageSize) // 整数页
|
|
246
|
+
// const lastPage = tablePagination.total % tableInitPageSize // 最后一页剩余条数
|
|
247
|
+
// const currentTableData = JSON.parse(JSON.stringify(tableData))
|
|
248
|
+
// // 选中非最后一页
|
|
249
|
+
// if(currentTableData.length === tableInitPageSize) {
|
|
250
|
+
// for(var i = 0; i < totalFullPage; i++) {
|
|
251
|
+
// doubleArr[i] = JSON.parse(JSON.stringify(tableData.map(i => ({ ...i, code: _.uniqueId('custom_') }))))
|
|
252
|
+
// }
|
|
253
|
+
// if(lastPage > 0) {
|
|
254
|
+
// // 深拷贝 避免splice时候更改了tableData的指向地址
|
|
255
|
+
// doubleArr[totalFullPage] = currentTableData.splice(0, lastPage)
|
|
256
|
+
// }
|
|
257
|
+
// } else {
|
|
258
|
+
// for(var i = 0; i < totalFullPage; i++) {
|
|
259
|
+
// const SwallowDigits = tableInitPageSize-currentTableData.length; // 需要补足位数
|
|
260
|
+
// const SwallowDigitsArray = Array.from({length: SwallowDigits }); // 生成补足数组
|
|
261
|
+
// doubleArr[i] = JSON.parse(JSON.stringify(tableData.concat(SwallowDigitsArray).map(i => ({ ...i, code: _.uniqueId('custom_') }))))
|
|
262
|
+
// }
|
|
263
|
+
// }
|
|
264
|
+
// }
|
|
265
|
+
// if(type === 'show') {}
|
|
266
|
+
|
|
267
|
+
// 勾选生成二维数组
|
|
268
|
+
doubleArr[nowPage ? nowPage - 1 : 0] = selectRows
|
|
269
|
+
// console.log(doubleArr)
|
|
270
|
+
setDoubleArr(doubleArr)
|
|
271
|
+
// 这块扁平化成为一位数组
|
|
272
|
+
const filterRows = mapRows(doubleArr);
|
|
273
|
+
// console.log(filterRows)
|
|
274
|
+
setFilterRows(filterRows)
|
|
275
|
+
|
|
276
|
+
const sksResult = filterRows.map((i) => i.code)
|
|
277
|
+
setSelectedRowKeys(sksResult)
|
|
278
|
+
setSelectedRows(filterRows)
|
|
279
|
+
setPopValue(filterRows);
|
|
280
|
+
|
|
281
|
+
if(type === 'change') {
|
|
282
|
+
setIndeterminate(!!filterRows.length && filterRows.length < tablePagination?.total);
|
|
283
|
+
setCheckedAll(filterRows.length === tablePagination?.total);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const rowSelection = {
|
|
288
|
+
type: selectMode ? 'checkbox' : 'radio',
|
|
289
|
+
selectedRowKeys,
|
|
290
|
+
onChange: (sks, srs) => {
|
|
291
|
+
onChangeSelectedKeys(sks, srs, tablePagination?.current, 'change')
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const themeColor = { color: '#1890ff' }
|
|
296
|
+
|
|
297
|
+
const formItem = (list) => {
|
|
298
|
+
if(isModalVisible && list?.length) {
|
|
299
|
+
return list.map((i: any) => {
|
|
300
|
+
if(i?.type === 'select' || i?.field?.type === 'select') {
|
|
301
|
+
return (
|
|
302
|
+
<Form.Item name={i.name} label={i.label} key={i.name}>
|
|
303
|
+
<Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}>
|
|
304
|
+
{i?.initialSource?.length && i?.initialSource.map((m: any) => (
|
|
305
|
+
<Option value={m.value} key={m.value}>{m.text}</Option>
|
|
306
|
+
))}
|
|
307
|
+
</Select>
|
|
308
|
+
</Form.Item>
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// 默认type是input
|
|
313
|
+
return (
|
|
314
|
+
<Form.Item name={i.name} label={i.label} key={i.name}>
|
|
315
|
+
<Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} />
|
|
316
|
+
</Form.Item>
|
|
317
|
+
)
|
|
318
|
+
})
|
|
319
|
+
} else {
|
|
320
|
+
return null
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return (
|
|
325
|
+
<div className={'search_select'}>
|
|
326
|
+
<div className="search_select_show" id='search_select_div'>
|
|
327
|
+
<Select
|
|
328
|
+
virtual
|
|
329
|
+
labelInValue
|
|
330
|
+
value={value}
|
|
331
|
+
onChange={outerChange}
|
|
332
|
+
dropdownRender={menu => (
|
|
333
|
+
<>
|
|
334
|
+
<Input value={searchValue} style={{ width: '98%', marginLeft: '1%' }} placeholder="请输入" onChange={e=> onSearchChange(e)} onBlur={onSearchBlur} />
|
|
335
|
+
<Divider style={{ margin: '8px 0' }} />
|
|
336
|
+
{menu}
|
|
337
|
+
</>
|
|
338
|
+
)}
|
|
339
|
+
notFoundContent={
|
|
340
|
+
fetching ? <Spin size="small" /> :
|
|
341
|
+
<div style={{ textAlign: 'center'}}>
|
|
342
|
+
<div style={{ marginBottom: 16 }}>
|
|
343
|
+
<CopyOutlined style={{ fontSize: '50px' }} />
|
|
344
|
+
</div>
|
|
345
|
+
<div>无匹配结果,请更换其他内容再试</div>
|
|
346
|
+
</div>
|
|
347
|
+
}
|
|
348
|
+
onPopupScroll={SelectScroll}
|
|
349
|
+
{...currentSelectProps}
|
|
350
|
+
getPopupContainer={() => document.getElementById('search_select_div')}
|
|
351
|
+
style={{ width: 'calc(100% - 30px)' }}
|
|
352
|
+
placeholder="请选择"
|
|
353
|
+
>
|
|
354
|
+
{items.map(item => (
|
|
355
|
+
<Option key={item.code} label={item.name}>
|
|
356
|
+
{LightHeightOption({ text: `${item.code} ${item.name}`, filterTxt: searchValue })}
|
|
357
|
+
</Option>
|
|
358
|
+
))}
|
|
359
|
+
</Select>
|
|
360
|
+
<Button style={{width: '30px', padding: '2px', height: 'auto'}} onClick={showModal} type="primary">
|
|
361
|
+
<SearchOutlined />
|
|
362
|
+
</Button>
|
|
363
|
+
</div>
|
|
364
|
+
<Modal
|
|
365
|
+
width='80%'
|
|
366
|
+
title={modalTableProps?.modalTableTitle}
|
|
367
|
+
visible={isModalVisible}
|
|
368
|
+
onOk={handleOk}
|
|
369
|
+
onCancel={handleCancel}
|
|
370
|
+
footer={[
|
|
371
|
+
<Button key="back" onClick={handleCancel}>
|
|
372
|
+
取消
|
|
373
|
+
</Button>,
|
|
374
|
+
<Button key="submit" type="primary" onClick={handleOk}>
|
|
375
|
+
确定
|
|
376
|
+
</Button>,
|
|
377
|
+
]}
|
|
378
|
+
>
|
|
379
|
+
<div className={'search_select_wrapper'}>
|
|
380
|
+
<div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
|
|
381
|
+
<CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1' } />
|
|
382
|
+
</div>
|
|
383
|
+
<div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
|
|
384
|
+
<div className={'select_list_columns'}>
|
|
385
|
+
<div className={'select_list_columns_tips'}>搜索</div>
|
|
386
|
+
<div className={'select_list_columns_formItems'}>
|
|
387
|
+
<Form form={form} layout='vertical'>
|
|
388
|
+
{formItem(modalTableProps?.tableSearchForm)}
|
|
389
|
+
</Form>
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
392
|
+
<div className={'select_list_searchButton'}>
|
|
393
|
+
<Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
|
|
394
|
+
<Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
<div className={caretLeftFlag ? 'search_select_wrapper_right': 'search_select_wrapper_right1'}>
|
|
398
|
+
<div>
|
|
399
|
+
<div className={'select_list_selectTips'}>
|
|
400
|
+
<div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
|
|
401
|
+
<div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或单击按钮完成选择'}</div>
|
|
402
|
+
</div>
|
|
403
|
+
<Table
|
|
404
|
+
size='small'
|
|
405
|
+
rowSelection={rowSelection}
|
|
406
|
+
columns={modalTableProps?.tableColumns}
|
|
407
|
+
dataSource={tableData}
|
|
408
|
+
pagination={tablePagination}
|
|
409
|
+
onChange={handleTableChange}
|
|
410
|
+
rowKey='code'
|
|
411
|
+
scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
|
|
412
|
+
/>
|
|
413
|
+
{selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} /> 全选所有页面</div> : ''}
|
|
414
|
+
</div>
|
|
415
|
+
</div>
|
|
416
|
+
</div>
|
|
417
|
+
</Modal>
|
|
418
|
+
</div>
|
|
419
|
+
);
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
export default SearchSelect;
|