@bit-sun/business-component 2.4.31-alpha.9 → 2.4.32

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.
Files changed (210) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -5
  3. package/.gitlab-ci.yml +179 -179
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/index.d.ts +0 -1
  9. package/dist/index.esm.js +950 -1044
  10. package/dist/index.js +954 -1051
  11. package/dist/utils/auth.d.ts +0 -1
  12. package/docs/index.md +21 -21
  13. package/lib/assets/drag.svg +17 -17
  14. package/lib/assets/exportFail.svg +37 -37
  15. package/lib/assets/exportProcessing.svg +28 -28
  16. package/lib/assets/exportSuccess.svg +34 -34
  17. package/lib/assets/label_icon_bottom.svg +25 -25
  18. package/lib/assets/upExport.svg +22 -22
  19. package/package.json +80 -83
  20. package/src/assets/32.svg +27 -27
  21. package/src/assets/addIcon.svg +17 -17
  22. package/src/assets/allfunc.svg +27 -27
  23. package/src/assets/arrowRight.svg +24 -24
  24. package/src/assets/btn-delete.svg +29 -29
  25. package/src/assets/btn-edit.svg +19 -19
  26. package/src/assets/btn-more.svg +17 -17
  27. package/src/assets/btn-submit.svg +19 -19
  28. package/src/assets/caidan.svg +11 -11
  29. package/src/assets/close.svg +26 -26
  30. package/src/assets/drag.svg +17 -17
  31. package/src/assets/exportFail.svg +37 -37
  32. package/src/assets/exportProcessing.svg +28 -28
  33. package/src/assets/exportSuccess.svg +34 -34
  34. package/src/assets/fixed-left-active.svg +11 -11
  35. package/src/assets/fixed-left.svg +15 -15
  36. package/src/assets/fixed-right-active.svg +11 -11
  37. package/src/assets/fixed-right.svg +15 -15
  38. package/src/assets/guanbi.svg +15 -15
  39. package/src/assets/icon-quanping.svg +15 -15
  40. package/src/assets/icon-shezhi.svg +17 -17
  41. package/src/assets/label_icon_bottom.svg +25 -25
  42. package/src/assets/list-no-img.svg +21 -21
  43. package/src/assets/morentouxiang-32.svg +23 -23
  44. package/src/assets/scanning.svg +24 -24
  45. package/src/assets/upExport.svg +22 -22
  46. package/src/common/ENUM.ts +41 -41
  47. package/src/components/Business/AddSelectBusiness/index.md +162 -398
  48. package/src/components/Business/AddSelectBusiness/index.tsx +1062 -1099
  49. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +112 -112
  50. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  51. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  52. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  53. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  54. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  55. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  56. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  57. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  58. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  59. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  60. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  61. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  62. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +158 -157
  63. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  64. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  65. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +155 -155
  66. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  67. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  68. package/src/components/Business/BsLayouts/index.less +79 -79
  69. package/src/components/Business/BsLayouts/index.tsx +1484 -1572
  70. package/src/components/Business/BsLayouts/service.ts +10 -10
  71. package/src/components/Business/BsLayouts/utils.tsx +203 -205
  72. package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +566 -566
  73. package/src/components/Business/BsSulaQueryTable/index.less +221 -221
  74. package/src/components/Business/BsSulaQueryTable/index.tsx +606 -560
  75. package/src/components/Business/BsSulaQueryTable/setting.tsx +854 -854
  76. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  77. package/src/components/Business/BsSulaQueryTable/utils.tsx +690 -690
  78. package/src/components/Business/CommodityEntry/index.md +70 -84
  79. package/src/components/Business/CommodityEntry/index.tsx +81 -82
  80. package/src/components/Business/CommonAlert/index.tsx +23 -23
  81. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  82. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  83. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  84. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  85. package/src/components/Business/DetailPageWrapper/index.tsx +315 -316
  86. package/src/components/Business/DetailPageWrapper/utils.tsx +164 -164
  87. package/src/components/Business/HomePageWrapper/index.less +33 -33
  88. package/src/components/Business/HomePageWrapper/index.md +45 -45
  89. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  90. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +824 -824
  91. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +205 -205
  92. package/src/components/Business/JsonQueryTable/components/Formula.tsx +206 -206
  93. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  94. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  95. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  96. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  97. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  98. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  99. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  100. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  101. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  102. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  103. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  104. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  105. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  106. package/src/components/Business/JsonQueryTable/index.less +16 -16
  107. package/src/components/Business/JsonQueryTable/index.md +328 -328
  108. package/src/components/Business/JsonQueryTable/index.tsx +537 -537
  109. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  110. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  111. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  112. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  113. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  114. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  115. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  116. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  117. package/src/components/Business/JsonQueryTable/static.ts +450 -450
  118. package/src/components/Business/SearchSelect/BusinessUtils.tsx +2120 -2120
  119. package/src/components/Business/SearchSelect/common.ts +134 -134
  120. package/src/components/Business/SearchSelect/index.md +1503 -1512
  121. package/src/components/Business/SearchSelect/index.tsx +55 -55
  122. package/src/components/Business/SearchSelect/utils.ts +101 -101
  123. package/src/components/Business/StateFlow/index.less +130 -130
  124. package/src/components/Business/StateFlow/index.md +60 -60
  125. package/src/components/Business/StateFlow/index.tsx +29 -29
  126. package/src/components/Business/TreeSearchSelect/index.md +185 -185
  127. package/src/components/Business/TreeSearchSelect/index.tsx +33 -33
  128. package/src/components/Business/TreeSearchSelect/utils.ts +104 -104
  129. package/src/components/Business/columnSettingTable/columnSetting.tsx +766 -766
  130. package/src/components/Business/columnSettingTable/index.less +247 -247
  131. package/src/components/Business/columnSettingTable/index.md +357 -357
  132. package/src/components/Business/columnSettingTable/index.tsx +235 -235
  133. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +243 -243
  134. package/src/components/Business/columnSettingTable/utils.tsx +71 -71
  135. package/src/components/Business/moreTreeTable/FixedScrollBar.tsx +87 -87
  136. package/src/components/Business/moreTreeTable/hooks/useSticky.ts +21 -21
  137. package/src/components/Business/moreTreeTable/index.less +99 -99
  138. package/src/components/Business/moreTreeTable/index.md +448 -448
  139. package/src/components/Business/moreTreeTable/index.tsx +387 -387
  140. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  141. package/src/components/Functional/AddSelect/helps.ts +80 -80
  142. package/src/components/Functional/AddSelect/index.less +367 -367
  143. package/src/components/Functional/AddSelect/index.md +155 -155
  144. package/src/components/Functional/AddSelect/index.tsx +1171 -1011
  145. package/src/components/Functional/BillEntry/index.less +371 -371
  146. package/src/components/Functional/BillEntry/index.md +39 -39
  147. package/src/components/Functional/BillEntry/index.tsx +773 -773
  148. package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -62
  149. package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -178
  150. package/src/components/Functional/BsAntdSula/index.ts +2 -2
  151. package/src/components/Functional/DataImport/index.less +63 -63
  152. package/src/components/Functional/DataImport/index.md +44 -44
  153. package/src/components/Functional/DataImport/index.tsx +696 -701
  154. package/src/components/Functional/DataValidation/index.less +63 -63
  155. package/src/components/Functional/DataValidation/index.md +39 -52
  156. package/src/components/Functional/DataValidation/index.tsx +688 -701
  157. package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -5
  158. package/src/components/Functional/EllipsisTooltip/index.js +36 -36
  159. package/src/components/Functional/EllipsisTooltip/index.md +30 -30
  160. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  161. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +60 -60
  162. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  163. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  164. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  165. package/src/components/Functional/SearchSelect/index.less +115 -115
  166. package/src/components/Functional/SearchSelect/index.md +141 -141
  167. package/src/components/Functional/SearchSelect/index.tsx +897 -896
  168. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  169. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  170. package/src/components/Functional/TreeSearchSelect/index.tsx +204 -204
  171. package/src/components/Solution/RuleComponent/Formula.tsx +335 -335
  172. package/src/components/Solution/RuleComponent/InnerSelect.tsx +62 -62
  173. package/src/components/Solution/RuleComponent/index.d.ts +29 -29
  174. package/src/components/Solution/RuleComponent/index.js +2103 -2103
  175. package/src/components/Solution/RuleComponent/index.less +229 -229
  176. package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -99
  177. package/src/components/Solution/RuleComponent/ruleFiled.js +2293 -2293
  178. package/src/components/Solution/RuleComponent/services.ts +13 -13
  179. package/src/components/Solution/RuleComponent/util.js +143 -143
  180. package/src/components/Solution/RuleSetter/RuleInstance.tsx +6 -6
  181. package/src/components/Solution/RuleSetter/baseRule.tsx +368 -368
  182. package/src/components/Solution/RuleSetter/function.ts +336 -336
  183. package/src/components/Solution/RuleSetter/index.less +221 -221
  184. package/src/components/Solution/RuleSetter/index.tsx +208 -208
  185. package/src/components/Solution/RuleSetter/service.js +276 -276
  186. package/src/index.ts +40 -41
  187. package/src/plugin/TableColumnSetting/index.less +247 -247
  188. package/src/plugin/TableColumnSetting/index.md +50 -50
  189. package/src/plugin/TableColumnSetting/index.tsx +725 -725
  190. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  191. package/src/styles/bsDefault.less +1912 -1912
  192. package/src/utils/CheckOneUser/index.md +39 -39
  193. package/src/utils/CheckOneUser/index.ts +51 -51
  194. package/src/utils/CustomLoginInfo.ts +55 -55
  195. package/src/utils/LocalstorageUtils.ts +128 -128
  196. package/src/utils/TableUtils.tsx +18 -18
  197. package/src/utils/auth.ts +32 -38
  198. package/src/utils/checkUtils.ts +39 -39
  199. package/src/utils/enumConfig.ts +16 -16
  200. package/src/utils/getFormMode.js +12 -12
  201. package/src/utils/index.ts +12 -12
  202. package/src/utils/requestUtils.ts +166 -166
  203. package/src/utils/serialize.js +7 -7
  204. package/src/utils/utils.ts +195 -195
  205. package/tsconfig.json +29 -29
  206. package/typings.d.ts +4 -4
  207. package/dist/components/Functional/AccessWrapper/index.d.ts +0 -5
  208. package/dist/components/Functional/AuthButton/index.d.ts +0 -3
  209. package/src/components/Functional/AccessWrapper/index.tsx +0 -34
  210. package/src/components/Functional/AuthButton/index.tsx +0 -15
@@ -1,896 +1,897 @@
1
- // @ts-nocheck
2
- import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
3
- import { useDebounceFn } from 'ahooks';
4
- import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
- import { SearchOutlined, CopyOutlined, CaretLeftOutlined } from '@ant-design/icons';
6
- import axios from 'axios';
7
- import { stringify } from 'querystring';
8
- import _ from "lodash"
9
- import './index.less';
10
- import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
- import { handleSourceName } from './utils';
12
- import { judgeIsRequestError } from '@/utils/requestUtils';
13
-
14
- const { Option } = Select;
15
-
16
- const SearchSelect = forwardRef((props: any, ref: any) => {
17
- const {
18
- value, // 必传
19
- onChange: onChangeTemp,
20
- selectProps = {},
21
- modalTableProps = {},
22
- labelInValue = false,
23
- requestConfig,
24
- ctx,
25
- sourceName,
26
- needModalTable = true,
27
- getPopupContainer = undefined,
28
- fieldComponent,
29
- selectBusinessType,
30
- } = props;
31
- const {
32
- url,
33
- otherParams,// 默认参数
34
- isMap,
35
- fixedparameter,
36
- fieldValToParam,
37
- fixedparamsDisabled = false,
38
- mappingTextField = 'name',
39
- mappingTextShowKeyField,
40
- mappingValueField = 'code',
41
- mappingTextShowTextField,
42
- init = true,// 是否初始请求
43
- extralHeaders = {},// 额外请求头参数
44
- specialBracket = false,// 是否使用特殊括弧显示选项 【value】text
45
- noNeedSplit = false,// label显示不需要任何特殊化
46
- } = requestConfig || {};
47
- const resultSourceKey = handleSourceName(sourceName || requestConfig?.sourceName || ctx?.name || 'supplierCode')
48
-
49
- const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
50
- const initVal = value || (selectMode ? [] : null);
51
- const pageSize = 100 // 下拉框默认分页 条数
52
- const tableInitPageSize = 10 // 弹框默认分页 条数
53
- const currentPage = 1
54
- const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
55
- const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
56
- const currentSelectProps = {
57
- ...selectProps,
58
- // 以下属性不可更改----设计配置项
59
- showSearch: false,
60
- filterOption: false,
61
- allowClear: true,
62
- listHeight: 160,
63
- optionLabelProp: "label",
64
- autoClearSearchValue: false
65
- }
66
- const tableInitPagination = { showQuickJumper: true, total: 0, current: 1, pageSize: tableInitPageSize }
67
-
68
- const [items, setItems] = useState([]);
69
- const [scrollPage, setScrollPage] = useState(1);
70
- const [itemsTotal, setItemsTotal] = useState(0);
71
- const [fetching, setFetching] = useState(false);
72
- const [searchValue, setSearchValue] = useState('');
73
- const [isModalVisible, setIsModalVisible] = useState(false);
74
- const [popvalue, setPopValue] = useState(initVal);
75
- const [uniqueValue, setUniqueValue] = useState(resultSourceKey)
76
- const { run } = useDebounceFn(
77
- (v?: any) => {
78
- // 优化搜索参数 支持传多个
79
- let searchParams = {};
80
- if (typeof selectParamsKey === 'string') {
81
- let selectParamsInitValue = initVal
82
- if (labelInValue) {
83
- selectParamsInitValue = Array.isArray(initVal) ? initVal.map((i: any) => i.value || i.key).join(',') : initVal
84
- } else {
85
- selectParamsInitValue = Array.isArray(initVal) ? initVal.join(',') : initVal
86
- }
87
- searchParams = v ? { [selectParamsInitKey]: selectParamsInitValue } : { [selectParamsKey]: searchValue }
88
- }
89
- if (Array.isArray(selectParamsKey)) {
90
- selectParamsKey.forEach((i: any) => {
91
- searchParams = { ...searchParams, [i]: searchValue }
92
- })
93
- }
94
- // 防抖函数 待定
95
- getData(searchParams)
96
- },
97
- {
98
- wait: 1000,
99
- },
100
- );
101
-
102
- const [form] = Form.useForm();
103
- const [caretLeftFlag, setCaretLeftFlag] = useState(true);
104
- const [tableData, setTableData] = useState([]);
105
- const [tablePagination, setTablePagination] = useState(tableInitPagination)
106
- const [selectedRowKeys, setSelectedRowKeys] = useState([]);
107
- const [selectedRows, setSelectedRows] = useState([]);
108
- const [checkedAll, setCheckedAll] = useState(false)
109
- const [indeterminate, setIndeterminate] = useState(false)
110
- const [tableFormParams, setTableFormParams] = useState({});
111
- const [tooltipVisible, setTooltipVisible] = useState(false);
112
-
113
- useImperativeHandle(ref, () => ({
114
- refreshDataSource: (reset: boolean = false) => {
115
- if (reset) {
116
- if (init) {
117
- run('init');
118
- } else {
119
- setItems([]);
120
- setItemsTotal(0);
121
- }
122
- } else {
123
- run();
124
- }
125
- },
126
- clearDataSource: () => {
127
- setItems([]);
128
- setItemsTotal(0);
129
- },
130
- getTableFormRef: () => form,
131
- // 解决下拉框数据源的问题
132
- getSelectDataSource: () => items,
133
- setSelectDataSource: (list: any, listTotal: number) => {
134
- setItems(list);
135
- setItemsTotal(listTotal);
136
- },
137
- refreshSelectDataSource: () => {
138
- refreshItems()
139
- }
140
- }))
141
-
142
- // 获取数据源 (type: 1下拉框 2/3弹框 不传值默认为下拉框)
143
- const getData = (params = {}, type = 1,callback?: any) => {
144
- if (!requestConfig) return;
145
-
146
- setFetching(true)
147
-
148
- // 处理dependence参数
149
- const fixedParam = {};
150
- if (fixedparameter && fieldValToParam && ctx) {
151
- fixedparameter.forEach((item: any, index: any) => {
152
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
153
- if(fixedParamVal) {
154
- fixedParam[item] = fixedParamVal;
155
- // 解决依赖项在弹窗中回显/更改(如果不能更改,传参fixedparamsDisabled为true即可)
156
- if(type == 2 || type == 3) {
157
- const fixedChangeParamVal = form.getFieldValue(item);
158
- let isDependenceValueChange = false;
159
- let dependenceValue = fixedParamVal;
160
- // 依赖项在弹窗form中更改--①更换依赖值;②去掉依赖值
161
- if(!fixedparamsDisabled) {
162
- isDependenceValueChange =
163
- (fixedChangeParamVal && fixedChangeParamVal !== fixedParamVal)
164
- || (type == 2 && !fixedChangeParamVal);
165
- dependenceValue = isDependenceValueChange ? fixedChangeParamVal : fixedParamVal;
166
- }
167
- fixedParam[item] = dependenceValue;
168
- form.setFieldsValue({ ...form?.getFieldsValue(), [item]: dependenceValue })
169
- if(isDependenceValueChange) {
170
- ctx.form.setFieldValue(fieldValToParam[index],fixedChangeParamVal) // 更改依赖项
171
- ctx.form.setFieldValue(resultSourceKey,null) // 同时清空之前依赖项对应的选择项
172
- refreshItems()
173
- }
174
- }
175
- }
176
- });
177
- }
178
-
179
- // 数组对象处理,对带有特殊标记的name进行处理
180
- for (const key in params) {
181
- if (Object.prototype.hasOwnProperty.call(params, key)) {
182
- const element = params[key];
183
- if (element && key.indexOf('*number*') >= 0) {
184
- const dataParams = key.split('*number*');
185
- dataParams.forEach((value, index) => {
186
- params[value] = element[index];
187
- });
188
- delete params[key];
189
- } else if (element && key.indexOf('*address*') >= 0) {
190
- const dataParams = key.split('*address*');
191
- dataParams.forEach((value, index) => {
192
- params[value] = element.PCDCode[index];
193
- });
194
- delete params[key];
195
- } else if (element && key.indexOf('*costType*') >= 0) {
196
- const dataParams = key.split('*costType*');
197
- // eslint-disable-next-line prefer-destructuring
198
- params[dataParams[0]] = element[1];
199
- delete params[key];
200
- } else if (element && key.indexOf('*fullDate*') >= 0) {
201
- const dataParams = key.split('*fullDate*');
202
- dataParams.forEach((value, index) => {
203
- if (index === 0) {
204
- params[value] = moment(element[index])
205
- .millisecond(0)
206
- .second(0)
207
- .minute(0)
208
- .hour(0)
209
- .format('YYYY-MM-DD HH:mm:ss');
210
- } else {
211
- params[value] = moment(element[index])
212
- .millisecond(59)
213
- .second(59)
214
- .minute(59)
215
- .hour(23)
216
- .format('YYYY-MM-DD HH:mm:ss');
217
- }
218
- });
219
- delete params[key];
220
- } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
221
- const dataParams = key.split('*checkBox*');
222
- if (element) {
223
- params[dataParams[0]] = 0
224
- }
225
- delete params[key];
226
- } else if (element && key.indexOf('*cascader*') >= 0) {
227
- const dataParams = key.split('*cascader*');
228
- params[dataParams[0]] = element[element.length - 1]
229
- delete params[key];
230
- } else if (element && key.indexOf('*date*') >= 0) {
231
- const dataParams = key.split('*date*')
232
- dataParams.forEach((value, index) => {
233
- if (index === 0) {
234
- params[value] = moment(element[index])
235
- .format('YYYY-MM-DD');
236
- } else {
237
- params[value] = moment(element[index])
238
- .format('YYYY-MM-DD');
239
- }
240
- });
241
- delete params[key];
242
- }
243
- else if (element && key.indexOf('*') >= 0) {
244
- const dataParams = key.split('*');
245
- dataParams.forEach((value, index) => {
246
- params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
247
- });
248
- delete params[key];
249
- } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
250
- const dataParams = key.split('_selectNumberRange')[0]
251
- if (params[key][0] === 'range') {
252
- if (params[key][1][0]) {
253
- params[`qp-${dataParams}-ge`] = params[key][1][0]
254
- }
255
- if (params[key][1][1]) {
256
- params[`qp-${dataParams}-le`] = params[key][1][1]
257
- }
258
- } else {
259
- params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
260
- }
261
- delete params[key]
262
- } else if (Array.isArray(element)) {
263
- params[key] = element.join(',');
264
- } else if (element == null || element === undefined || String(element).trim() === '') {
265
- delete params[key]
266
- }
267
- }
268
- }
269
-
270
- const queryParams = {
271
- pageSize,
272
- currentPage,
273
- ...otherParams, // 默认参数
274
- ...fixedParam,
275
- ...params,
276
- }
277
-
278
- axios
279
- .get(
280
- `${url}?${stringify(queryParams)}`,
281
- {
282
- headers: { ...extralHeaders }
283
- })
284
- .then((result: any) => {
285
- setFetching(false)
286
- result = result.data;
287
- if (judgeIsRequestError(result)) {
288
- message.error(result.msg);
289
- return;
290
- }
291
- const res = result.data;
292
- let source = [];
293
- if (isMap) {
294
- source = Object.keys(res).map((d, i) => {
295
- return {
296
- text: Object.values(res)[i],
297
- value: d,
298
- };
299
- });
300
- } else {
301
- const keys = res.list ? 'list' : 'items';
302
- source = res
303
- ? res[keys]
304
- ? res[keys].map((item: any) => {
305
- let textShowText = item[mappingTextField]
306
- if (mappingTextShowTextField) {
307
- textShowText = []
308
- if (Array.isArray(mappingTextShowTextField)) {
309
- mappingTextShowTextField.forEach((r: any) => {
310
- textShowText.push(item[r])
311
- })
312
- } else {
313
- textShowText = item[mappingTextShowTextField]
314
- }
315
- }
316
- return {
317
- ...item,
318
- text: specialBracket
319
- ? `【${item[mappingValueField]}】${item[mappingTextField]}`
320
- : item[mappingTextField],
321
- textShowText,
322
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
323
- value: item[mappingValueField],
324
- };
325
- })
326
- : Array.isArray(res) &&
327
- res?.map((item: Record<string, any>) => {
328
- let textShowText = item[mappingTextField]
329
- if (mappingTextShowTextField) {
330
- textShowText = []
331
- if (Array.isArray(mappingTextShowTextField)) {
332
- mappingTextShowTextField.forEach((r: any) => {
333
- textShowText.push(item[r])
334
- })
335
- } else {
336
- textShowText = item[mappingTextShowTextField]
337
- }
338
- }
339
- return {
340
- ...item,
341
- text: specialBracket
342
- ? `【${item[mappingValueField]}】${item[mappingTextField]}`
343
- : item[mappingTextField],
344
- textShowText,
345
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
346
- value: item[mappingValueField],
347
- };
348
- })
349
- : [];
350
- }
351
- source = Array.isArray(source) ? source : []
352
- if(callback) {
353
- callback(source)
354
- } else {
355
- if (type === 1) {
356
- ctx?.form?.setFieldSource(resultSourceKey, source)
357
- setItems(source)
358
- setItemsTotal(Number(res?.total || res?.totalCount || source.length))
359
- } else {
360
- setTableData(source)
361
- 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)) })
362
- }
363
- }
364
- })
365
- .catch((err) => { setFetching(false) });
366
- }
367
-
368
- const SelectScroll = e => {
369
- e.persist();
370
- const { target } = e;
371
- const totalPage = Math.ceil(itemsTotal / pageSize)
372
- // 判断是否滑动到底部
373
- const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
374
- // 判断数据是否还没有加载到了最后一页
375
- const canPageAdd = scrollPage < totalPage
376
- if (isTouchGround && canPageAdd) {
377
- const nextScrollPage = scrollPage + 1;
378
- setScrollPage(nextScrollPage);
379
- getData({ currentPage: nextScrollPage }); // 调用api方法
380
- }
381
-
382
- //判断是否滑动到顶部
383
- const isTouchTop = target.scrollTop === 0 // <=0
384
- // 判断数据是否到第一页
385
- const canPageJian = scrollPage > 1
386
- if (isTouchTop && canPageJian) {
387
- const preScrollPage = scrollPage - 1;
388
- setScrollPage(preScrollPage);
389
- getData({ currentPage: preScrollPage }); // 调用api方法
390
- }
391
- }
392
-
393
- // 下拉框改变事件
394
- const onChange = (...arg) => {
395
- onChangeTemp(...arg)
396
- if(props?.selectChangeCallback){
397
- props.selectChangeCallback(...arg)
398
- }
399
- if(props?.selectProps?.selectChangeCallback) {
400
- props.selectProps.selectChangeCallback(...arg)
401
- }
402
- }
403
-
404
- useEffect(() => {
405
- if (init) {
406
- run('init')
407
- }
408
- }, [])
409
-
410
- useEffect(() => {
411
- if (value) {
412
- setPopValue(value);
413
- }
414
- }, [value]);
415
-
416
- useEffect(() => {
417
- makeUniqueValue();
418
- }, [resultSourceKey])
419
-
420
- useEffect(() => {
421
- if (init) {
422
- setItems([]);
423
- setItemsTotal(0);
424
- run('init')
425
- }
426
- },[selectBusinessType])
427
-
428
- const showModal = () => {
429
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 3)
430
- setIsModalVisible(true);
431
- // 回显
432
- if (value) {
433
- if (selectMode) {
434
- setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
435
- setSelectedRows(labelInValue ? value.map(i => ({ [mappingValueField]: i.key, value: i.key, text: i.label })) : value.map(i => ({ [mappingValueField]: i, value: i })))
436
- setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
437
- setIndeterminate(!!value.length && value.length < itemsTotal);
438
- setCheckedAll(itemsTotal && value.length === itemsTotal);
439
- } else {
440
- setSelectedRowKeys(labelInValue ? [value.key] : [value])
441
- setSelectedRows(labelInValue ? [{ [mappingValueField]: value.key, value: value.key, text: value.label }] : [{ [mappingValueField]: value, value: value }])
442
- setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
443
- }
444
- }
445
- };
446
-
447
- const handleSelectOver = (selectedValue: any) => {
448
- if (selectedValue?.length) {
449
- // 解决选择最后1页的sku,返回后,不显示名称问题
450
- const source = _.uniqBy(items.concat(selectedValue), 'value')
451
- ctx?.form?.setFieldSource(resultSourceKey, source)
452
- setItems(source)
453
- formaData(selectedValue, source);
454
- } else {
455
- const formatResult = selectMode ? [] : null
456
- onChange(formatResult, selectedValue)
457
- }
458
- }
459
-
460
- const handleOk = () => {
461
- handleSelectOver(popvalue)
462
- handleCancel();
463
- };
464
-
465
- const formaData = (value: any, source: any) => {
466
- if (labelInValue) {
467
- const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
468
- onChange(selectMode ? formatResult : formatResult[0], value,source)
469
- } else {
470
- const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
471
- onChange(formatResult, value,source)
472
- }
473
- };
474
-
475
- const clearModalTable = () => {
476
- form.resetFields();
477
- setTableFormParams({});
478
- setTableData([]);
479
- setTablePagination(tableInitPagination);
480
- setSelectedRowKeys([]);
481
- setSelectedRows([]);
482
- setCheckedAll(false);
483
- setIndeterminate(false);
484
- };
485
-
486
- const handleCancel = () => {
487
- clearModalTable();
488
- setIsModalVisible(false);
489
- if (selectMode) {
490
- run();
491
- }
492
- };
493
-
494
- const refreshItems = () => {
495
- // 查看是否存在关联值 如果有关联值 就查询 没有就不能查询
496
- if (fieldValToParam && ctx && fixedparamsDisabled) {
497
- let formValueList = [];
498
- fieldValToParam.forEach((item: any, index: any) => {
499
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
500
- formValueList.push(fixedParamVal);
501
- });
502
- if (formValueList.filter((item: any) => item).length > 0) {
503
- run();
504
- } else {
505
- setItems([]);
506
- setItemsTotal(0);
507
- }
508
- } else {
509
- run();
510
- }
511
- }
512
-
513
- const onSearchChange = (e) => {
514
- setSearchValue(e.target.value);
515
- refreshItems();
516
- }
517
-
518
- const onSearchBlur = () => {
519
- setSearchValue('');
520
- refreshItems();
521
- }
522
-
523
- const onSearchTable = () => {
524
- const params = form.getFieldsValue();
525
- setTableFormParams(params);
526
- getData({ ...params, pageSize: tableInitPageSize }, 2)
527
- if (selectMode) {
528
- getData(params)
529
- }
530
- }
531
-
532
- const onResetTable = () => {
533
- form.resetFields();
534
- setTableFormParams({});
535
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
536
- }
537
-
538
- const handleTableChange = (pagination) => {
539
- getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
540
- }
541
-
542
- const onCheckAllData = (pSize) => {
543
- getData({ ...tableFormParams, pageSize: pSize, currentPage: 1 }, 2,(source) => {
544
- const currentItemsData = JSON.parse(JSON.stringify(source))
545
- setSelectedRowKeys(currentItemsData.map(i => i.value))
546
- setPopValue(currentItemsData);
547
- setSelectedRows(currentItemsData)
548
- })
549
- }
550
- const onChangeCheckAll = (e) => {
551
- if (e.target.checked) {
552
- // 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
553
- // 如果超过100条 就默认查出所有数据
554
- if (items.length < itemsTotal) {
555
- const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize);
556
- const allPageSize = totalPage * tablePagination?.pageSize;
557
- onCheckAllData(allPageSize)
558
- } else {
559
- const currentItemsData = JSON.parse(JSON.stringify(items))
560
- setSelectedRowKeys(currentItemsData.map(i => i.value))
561
- setPopValue(currentItemsData);
562
- setSelectedRows(currentItemsData)
563
- }
564
- } else {
565
- setSelectedRowKeys([])
566
- setPopValue([]);
567
- setSelectedRows([])
568
- }
569
- setIndeterminate(false);
570
- setCheckedAll(e.target.checked);
571
- }
572
-
573
- const LightHeightOption = (props) => {
574
- const {
575
- filterTxt, text,
576
- } = props
577
- const heightLightTxt = (text, heightTxt) => {
578
- if (heightTxt === '') {
579
- return text
580
- }
581
- // 前面filterOption 不区分大小写,这里用i
582
- const regexp = new RegExp(heightTxt, 'gi')
583
- return text.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
584
- }
585
- return (
586
- <Tooltip title={text}>
587
- <div ref={(nodeElement) => {
588
- if (nodeElement) {
589
- nodeElement.innerHTML = heightLightTxt(text, filterTxt)
590
- }
591
- }}
592
- />
593
- </Tooltip>
594
- )
595
- }
596
-
597
- // 扁平化二维数组的方法
598
- const mapRows = params => {
599
- var res = [];
600
- for (var i = 0; i < params.length; i++) {
601
- if (Array.isArray(params[i])) {
602
- // 去重
603
- res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
604
- } else {
605
- res.push(params[i]);
606
- // 去重
607
- res = _.uniqBy(res, 'value')
608
- }
609
- }
610
- return res.filter(Boolean); //去掉undefined的情况
611
- };
612
-
613
- const onChangeSelectedKeys = (selectKeys, selectRows) => {
614
- let sksResult = selectRows.map((i) => i.value);
615
-
616
- // 单选 默认直接选中 不需要确定 配置了modalRadioNeedFooter就需要确定
617
- if(!selectMode && !modalTableProps?.modalRadioNeedFooter) {
618
- handleSelectOver(selectRows)
619
- handleCancel();
620
- }
621
-
622
- setSelectedRowKeys(sksResult)
623
- setSelectedRows(selectRows)
624
- setPopValue(selectRows);
625
- setIndeterminate(!!selectRows.length && selectRows.length < tablePagination?.total);
626
- setCheckedAll(selectRows.length === tablePagination?.total);
627
- }
628
-
629
- // 生成唯一值
630
- const makeUniqueValue = () => {
631
- const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
632
- setUniqueValue(generateUnitKey);
633
- return generateUnitKey;
634
- }
635
-
636
- const rowSelection = {
637
- type: selectMode ? 'checkbox' : 'radio',
638
- selectedRowKeys,
639
- preserveSelectedRowKeys: true,
640
- onChange: (sks, srs) => {
641
- // 处理翻页后,之前存储的selectedRows变为undefined
642
- // selectedRows合并新数组,过滤undefined,过滤留下对应selectedRowKeys的集合
643
- let tmpSelectedRows = selectedRows.concat(srs).filter(item => item != undefined);
644
- let totalSelectedRows = sks.map(key => tmpSelectedRows.filter(item => item[mappingValueField] == key)[0]).filter(item => item != undefined)
645
- onChangeSelectedKeys(sks, totalSelectedRows)
646
- },
647
- getCheckboxProps: selectProps?.getCheckboxProps ? selectProps?.getCheckboxProps : () => {
648
- return ({
649
- disabled: selectProps?.disabled || props?.disabled || (!items.length && !tableData.length),
650
- })
651
- },
652
- };
653
-
654
- const onDoubleClickSelect = (e, record) => {
655
- if (!selectMode && !(selectProps?.disabled || props?.disabled || (!items.length && !tableData.length))) {
656
- const srs = [JSON.parse(JSON.stringify(record))]
657
- const sks = srs.map((i: any) => i.value)
658
- onChangeSelectedKeys(sks, srs)
659
- }
660
- }
661
-
662
- const themeColor = { color: '#1890ff' }
663
-
664
- const formItem = (list) => {
665
- if (isModalVisible && list?.length) {
666
- const setDisabled = (name: any) => {
667
- if (fixedparamsDisabled && fixedparameter?.length && fixedparameter.find((item: any) => item === name)) {
668
- return true
669
- } else {
670
- return false
671
- }
672
- };
673
- return list.map((i: any) => {
674
- if (i?.type === 'select' || i?.field?.type === 'select') {
675
- return (
676
- <Form.Item name={i.name} label={i.label} key={i.name}>
677
- <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}>
678
- {i?.initialSource?.length && i?.initialSource.map((m: any) => (
679
- <Option value={m.value} key={m.value}>{m.text}</Option>
680
- ))}
681
- </Select>
682
- </Form.Item>
683
- )
684
- }
685
-
686
- if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
687
- return (
688
- <Form.Item name={i.name} label={i.label} key={i.name}>
689
- <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></TreeSelect>
690
- </Form.Item>
691
- )
692
- }
693
-
694
- if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
695
- return (
696
- <div>
697
- <Form.Item name={i.name} label={i.label} key={i.name}>
698
- <BusinessSearchSelect {...i.field.props} disabled={setDisabled(i.name)} />
699
- </Form.Item>
700
- </div>
701
- )
702
- }
703
-
704
- if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
705
- return (
706
- <div>
707
- <Form.Item name={i.name} label={i.label} key={i.name}>
708
- <QueryMutipleInput onValueChange={(value) => {
709
- form.setFieldsValue({
710
- [i.name]: value
711
- })
712
- }} />
713
- </Form.Item>
714
- </div>
715
- );
716
- }
717
-
718
- // 默认type是input
719
- return (
720
- <Form.Item name={i.name} label={i.label} key={i.name}>
721
- <Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} disabled={setDisabled(i.name)} />
722
- </Form.Item>
723
- )
724
- })
725
- } else {
726
- return null
727
- }
728
- }
729
-
730
- const maxTagPlaceholder = (selectedValues) => {
731
- const onClose = (e: any, item: any) => {
732
- e.preventDefault();
733
- 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)
734
- onChange(newValue);
735
- }
736
- return (
737
- <Tooltip title={selectedValues.map((i: any) => (
738
- <Tag
739
- closable={true}
740
- onClose={(e) => onClose(e, i)}
741
- style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
742
- >
743
- {i.label}
744
- </Tag>
745
- ))}>
746
- {`+ ${selectedValues?.length}`}
747
- </Tooltip>
748
- )
749
- }
750
-
751
- const handleSelectOptionsShowValue = (specialBracket: boolean, noNeedSplit: boolean, item: object) => {
752
- let showText = Array.isArray(item.textShowText) &&
753
- item.textShowText.join(' ') || item.textShowText;
754
- if (noNeedSplit) {
755
- return item.text;
756
- } else {
757
- return specialBracket
758
- ? `【${item.textShowKey}】${showText}`
759
- : `${item.textShowKey} ${showText}`
760
- }
761
- };
762
-
763
- return (
764
- <div className={'search_select'}>
765
- {fieldComponent ?
766
- (<div onClick={() => {
767
- fieldComponent.props?.onClick?.()
768
- showModal()
769
- }}>{fieldComponent}</div>) :
770
- (<div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
771
- <Select
772
- virtual
773
- labelInValue={labelInValue}
774
- value={value}
775
- onChange={onChange}
776
- disabled={props.disabled}
777
- dropdownRender={menu => (
778
- <>
779
- <Input
780
- value={searchValue}
781
- style={{ width: '98%', marginLeft: '1%' }}
782
- placeholder="请输入"
783
- onChange={e => onSearchChange(e)}
784
- onBlur={onSearchBlur}
785
- onKeyDown={(e) => {
786
- // 阻止多选的冒泡
787
- e.stopPropagation()
788
- }}
789
- />
790
- <Divider style={{ margin: '8px 0' }} />
791
- {menu}
792
- </>
793
- )}
794
- notFoundContent={
795
- fetching ? <Spin size="small" /> :
796
- <div style={{ textAlign: 'center' }}>
797
- <div style={{ marginBottom: 16 }}>
798
- <CopyOutlined style={{ fontSize: '50px' }} />
799
- </div>
800
- <div>无匹配结果,请更换其他内容再试</div>
801
- </div>
802
- }
803
- onPopupScroll={SelectScroll}
804
- style={{ width: needModalTable ? 'calc(100% - 30px)' : 'calc(100%)' }}
805
- placeholder="请选择"
806
- maxTagPlaceholder={maxTagPlaceholder}
807
- {...currentSelectProps}
808
- getPopupContainer={(triggerNode) => (getPopupContainer && getPopupContainer(triggerNode)) || triggerNode.parentElement}
809
- >
810
- {items.map(item => (
811
- <Option key={item.value} label={item.text}>
812
- {LightHeightOption({
813
- text: handleSelectOptionsShowValue(specialBracket, noNeedSplit, item),
814
- filterTxt: searchValue
815
- })}
816
- </Option>
817
- ))}
818
- </Select>
819
- {needModalTable && (
820
- <Button style={{ width: '30px', padding: '2px', height: 'auto' }} onClick={showModal} type="primary">
821
- <SearchOutlined />
822
- </Button>
823
- )}
824
- </div>)}
825
- {needModalTable && isModalVisible && (
826
- <Modal
827
- width='80%'
828
- title={modalTableProps?.modalTableTitle}
829
- visible={isModalVisible}
830
- onOk={handleOk}
831
- onCancel={handleCancel}
832
- footer={(selectMode || modalTableProps?.modalRadioNeedFooter) ? [
833
- <Button key="back" onClick={handleCancel}>
834
- 取消
835
- </Button>,
836
- <Button
837
- key="submit"
838
- type="primary"
839
- onClick={handleOk}
840
- disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
841
- >
842
- 确定
843
- </Button>,
844
- ] : null}
845
- {...(modalTableProps?.modalProps || {})}
846
- >
847
- <div className={'search_select_wrapper'}>
848
- <div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
849
- <CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1'} />
850
- </div>
851
- <div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
852
- <div className={'select_list_columns'}>
853
- <div className={'select_list_columns_tips'}>搜索</div>
854
- <div className={'select_list_columns_formItems'}>
855
- <Form form={form} layout='vertical' key='modalForm'>
856
- {formItem(modalTableProps?.tableSearchForm)}
857
- </Form>
858
- </div>
859
- </div>
860
- <div className={'select_list_searchButton'}>
861
- <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
862
- <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
863
- </div>
864
- </div>
865
- <div className={caretLeftFlag ? 'search_select_wrapper_right' : 'search_select_wrapper_right1'}>
866
- <div>
867
- <div className={'select_list_selectTips'}>
868
- <div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
869
- <div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或点击单选图标完成选择'}</div>
870
- </div>
871
- <Table
872
- size='small'
873
- rowSelection={rowSelection}
874
- columns={modalTableProps?.tableColumns}
875
- dataSource={tableData}
876
- pagination={tablePagination}
877
- onChange={handleTableChange}
878
- rowKey={mappingValueField}
879
- scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
880
- onRow={record => {
881
- return {
882
- onDoubleClick: event => onDoubleClickSelect(event, record),
883
- };
884
- }}
885
- />
886
- {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
887
- </div>
888
- </div>
889
- </div>
890
- </Modal>
891
- )}
892
- </div>
893
- );
894
- });
895
-
896
- export default SearchSelect;
1
+ // @ts-nocheck
2
+ import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
3
+ import { useDebounceFn } from 'ahooks';
4
+ import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
+ import { SearchOutlined, CopyOutlined, CaretLeftOutlined } from '@ant-design/icons';
6
+ import axios from 'axios';
7
+ import { stringify } from 'querystring';
8
+ import _, { escapeRegExp } from "lodash";
9
+ import './index.less';
10
+ import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
+ import { handleSourceName } from './utils';
12
+ import { judgeIsRequestError } from '@/utils/requestUtils';
13
+
14
+ const { Option } = Select;
15
+
16
+ const SearchSelect = forwardRef((props: any, ref: any) => {
17
+ const {
18
+ value, // 必传
19
+ onChange: onChangeTemp,
20
+ selectProps = {},
21
+ modalTableProps = {},
22
+ labelInValue = false,
23
+ requestConfig,
24
+ ctx,
25
+ sourceName,
26
+ needModalTable = true,
27
+ getPopupContainer = undefined,
28
+ fieldComponent,
29
+ selectBusinessType,
30
+ } = props;
31
+ const {
32
+ url,
33
+ otherParams,// 默认参数
34
+ isMap,
35
+ fixedparameter,
36
+ fieldValToParam,
37
+ fixedparamsDisabled = false,
38
+ mappingTextField = 'name',
39
+ mappingTextShowKeyField,
40
+ mappingValueField = 'code',
41
+ mappingTextShowTextField,
42
+ init = true,// 是否初始请求
43
+ extralHeaders = {},// 额外请求头参数
44
+ specialBracket = false,// 是否使用特殊括弧显示选项 【value】text
45
+ noNeedSplit = false,// label显示不需要任何特殊化
46
+ } = requestConfig || {};
47
+ const resultSourceKey = handleSourceName(sourceName || requestConfig?.sourceName || 'supplierCode')
48
+
49
+ const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
50
+ const initVal = value || (selectMode ? [] : null);
51
+ const pageSize = 100 // 下拉框默认分页 条数
52
+ const tableInitPageSize = 10 // 弹框默认分页 条数
53
+ const currentPage = 1
54
+ const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
55
+ const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
56
+ const currentSelectProps = {
57
+ ...selectProps,
58
+ // 以下属性不可更改----设计配置项
59
+ showSearch: false,
60
+ filterOption: false,
61
+ allowClear: true,
62
+ listHeight: 160,
63
+ optionLabelProp: "label",
64
+ autoClearSearchValue: false
65
+ }
66
+ const tableInitPagination = { showQuickJumper: true, total: 0, current: 1, pageSize: tableInitPageSize }
67
+
68
+ const [items, setItems] = useState([]);
69
+ const [scrollPage, setScrollPage] = useState(1);
70
+ const [itemsTotal, setItemsTotal] = useState(0);
71
+ const [fetching, setFetching] = useState(false);
72
+ const [searchValue, setSearchValue] = useState('');
73
+ const [isModalVisible, setIsModalVisible] = useState(false);
74
+ const [popvalue, setPopValue] = useState(initVal);
75
+ const [uniqueValue, setUniqueValue] = useState(resultSourceKey)
76
+ const { run } = useDebounceFn(
77
+ (v?: any) => {
78
+ // 优化搜索参数 支持传多个
79
+ let searchParams = {};
80
+ if (typeof selectParamsKey === 'string') {
81
+ let selectParamsInitValue = initVal
82
+ if (labelInValue) {
83
+ selectParamsInitValue = Array.isArray(initVal) ? initVal.map((i: any) => i.value || i.key).join(',') : initVal
84
+ } else {
85
+ selectParamsInitValue = Array.isArray(initVal) ? initVal.join(',') : initVal
86
+ }
87
+ searchParams = v ? { [selectParamsInitKey]: selectParamsInitValue } : { [selectParamsKey]: searchValue }
88
+ }
89
+ if (Array.isArray(selectParamsKey)) {
90
+ selectParamsKey.forEach((i: any) => {
91
+ searchParams = { ...searchParams, [i]: searchValue }
92
+ })
93
+ }
94
+ // 防抖函数 待定
95
+ getData(searchParams)
96
+ },
97
+ {
98
+ wait: 1000,
99
+ },
100
+ );
101
+
102
+ const [form] = Form.useForm();
103
+ const [caretLeftFlag, setCaretLeftFlag] = useState(true);
104
+ const [tableData, setTableData] = useState([]);
105
+ const [tablePagination, setTablePagination] = useState(tableInitPagination)
106
+ const [selectedRowKeys, setSelectedRowKeys] = useState([]);
107
+ const [selectedRows, setSelectedRows] = useState([]);
108
+ const [checkedAll, setCheckedAll] = useState(false)
109
+ const [indeterminate, setIndeterminate] = useState(false)
110
+ const [tableFormParams, setTableFormParams] = useState({});
111
+ const [tooltipVisible, setTooltipVisible] = useState(false);
112
+
113
+ useImperativeHandle(ref, () => ({
114
+ refreshDataSource: (reset: boolean = false) => {
115
+ if (reset) {
116
+ if (init) {
117
+ run('init');
118
+ } else {
119
+ setItems([]);
120
+ setItemsTotal(0);
121
+ }
122
+ } else {
123
+ run();
124
+ }
125
+ },
126
+ clearDataSource: () => {
127
+ setItems([]);
128
+ setItemsTotal(0);
129
+ },
130
+ getTableFormRef: () => form,
131
+ // 解决下拉框数据源的问题
132
+ getSelectDataSource: () => items,
133
+ setSelectDataSource: (list: any, listTotal: number) => {
134
+ setItems(list);
135
+ setItemsTotal(listTotal);
136
+ },
137
+ refreshSelectDataSource: () => {
138
+ refreshItems()
139
+ }
140
+ }))
141
+
142
+ // 获取数据源 (type: 1下拉框 2/3弹框 不传值默认为下拉框)
143
+ const getData = (params = {}, type = 1,callback?: any) => {
144
+ if (!requestConfig) return;
145
+
146
+ setFetching(true)
147
+
148
+ // 处理dependence参数
149
+ const fixedParam = {};
150
+ if (fixedparameter && fieldValToParam && ctx) {
151
+ fixedparameter.forEach((item: any, index: any) => {
152
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
153
+ if(fixedParamVal) {
154
+ fixedParam[item] = fixedParamVal;
155
+ // 解决依赖项在弹窗中回显/更改(如果不能更改,传参fixedparamsDisabled为true即可)
156
+ if(type == 2 || type == 3) {
157
+ const fixedChangeParamVal = form.getFieldValue(item);
158
+ let isDependenceValueChange = false;
159
+ let dependenceValue = fixedParamVal;
160
+ // 依赖项在弹窗form中更改--①更换依赖值;②去掉依赖值
161
+ if(!fixedparamsDisabled) {
162
+ isDependenceValueChange =
163
+ (fixedChangeParamVal && fixedChangeParamVal !== fixedParamVal)
164
+ || (type == 2 && !fixedChangeParamVal);
165
+ dependenceValue = isDependenceValueChange ? fixedChangeParamVal : fixedParamVal;
166
+ }
167
+ fixedParam[item] = dependenceValue;
168
+ form.setFieldsValue({ ...form?.getFieldsValue(), [item]: dependenceValue })
169
+ if(isDependenceValueChange) {
170
+ ctx.form.setFieldValue(fieldValToParam[index],fixedChangeParamVal) // 更改依赖项
171
+ ctx.form.setFieldValue(resultSourceKey,null) // 同时清空之前依赖项对应的选择项
172
+ refreshItems()
173
+ }
174
+ }
175
+ }
176
+ });
177
+ }
178
+
179
+ // 数组对象处理,对带有特殊标记的name进行处理
180
+ for (const key in params) {
181
+ if (Object.prototype.hasOwnProperty.call(params, key)) {
182
+ const element = params[key];
183
+ if (element && key.indexOf('*number*') >= 0) {
184
+ const dataParams = key.split('*number*');
185
+ dataParams.forEach((value, index) => {
186
+ params[value] = element[index];
187
+ });
188
+ delete params[key];
189
+ } else if (element && key.indexOf('*address*') >= 0) {
190
+ const dataParams = key.split('*address*');
191
+ dataParams.forEach((value, index) => {
192
+ params[value] = element.PCDCode[index];
193
+ });
194
+ delete params[key];
195
+ } else if (element && key.indexOf('*costType*') >= 0) {
196
+ const dataParams = key.split('*costType*');
197
+ // eslint-disable-next-line prefer-destructuring
198
+ params[dataParams[0]] = element[1];
199
+ delete params[key];
200
+ } else if (element && key.indexOf('*fullDate*') >= 0) {
201
+ const dataParams = key.split('*fullDate*');
202
+ dataParams.forEach((value, index) => {
203
+ if (index === 0) {
204
+ params[value] = moment(element[index])
205
+ .millisecond(0)
206
+ .second(0)
207
+ .minute(0)
208
+ .hour(0)
209
+ .format('YYYY-MM-DD HH:mm:ss');
210
+ } else {
211
+ params[value] = moment(element[index])
212
+ .millisecond(59)
213
+ .second(59)
214
+ .minute(59)
215
+ .hour(23)
216
+ .format('YYYY-MM-DD HH:mm:ss');
217
+ }
218
+ });
219
+ delete params[key];
220
+ } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
221
+ const dataParams = key.split('*checkBox*');
222
+ if (element) {
223
+ params[dataParams[0]] = 0
224
+ }
225
+ delete params[key];
226
+ } else if (element && key.indexOf('*cascader*') >= 0) {
227
+ const dataParams = key.split('*cascader*');
228
+ params[dataParams[0]] = element[element.length - 1]
229
+ delete params[key];
230
+ } else if (element && key.indexOf('*date*') >= 0) {
231
+ const dataParams = key.split('*date*')
232
+ dataParams.forEach((value, index) => {
233
+ if (index === 0) {
234
+ params[value] = moment(element[index])
235
+ .format('YYYY-MM-DD');
236
+ } else {
237
+ params[value] = moment(element[index])
238
+ .format('YYYY-MM-DD');
239
+ }
240
+ });
241
+ delete params[key];
242
+ }
243
+ else if (element && key.indexOf('*') >= 0) {
244
+ const dataParams = key.split('*');
245
+ dataParams.forEach((value, index) => {
246
+ params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
247
+ });
248
+ delete params[key];
249
+ } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
250
+ const dataParams = key.split('_selectNumberRange')[0]
251
+ if (params[key][0] === 'range') {
252
+ if (params[key][1][0]) {
253
+ params[`qp-${dataParams}-ge`] = params[key][1][0]
254
+ }
255
+ if (params[key][1][1]) {
256
+ params[`qp-${dataParams}-le`] = params[key][1][1]
257
+ }
258
+ } else {
259
+ params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
260
+ }
261
+ delete params[key]
262
+ } else if (Array.isArray(element)) {
263
+ params[key] = element.join(',');
264
+ } else if (element == null || element === undefined || String(element).trim() === '') {
265
+ delete params[key]
266
+ }
267
+ }
268
+ }
269
+
270
+ const queryParams = {
271
+ pageSize,
272
+ currentPage,
273
+ ...otherParams, // 默认参数
274
+ ...fixedParam,
275
+ ...params,
276
+ }
277
+
278
+ axios
279
+ .get(
280
+ `${url}?${stringify(queryParams)}`,
281
+ {
282
+ headers: { ...extralHeaders }
283
+ })
284
+ .then((result: any) => {
285
+ setFetching(false)
286
+ result = result.data;
287
+ if (judgeIsRequestError(result)) {
288
+ message.error(result.msg);
289
+ return;
290
+ }
291
+ const res = result.data;
292
+ let source = [];
293
+ if (isMap) {
294
+ source = Object.keys(res).map((d, i) => {
295
+ return {
296
+ text: Object.values(res)[i],
297
+ value: d,
298
+ };
299
+ });
300
+ } else {
301
+ const keys = res.list ? 'list' : 'items';
302
+ source = res
303
+ ? res[keys]
304
+ ? res[keys].map((item: any) => {
305
+ let textShowText = item[mappingTextField]
306
+ if (mappingTextShowTextField) {
307
+ textShowText = []
308
+ if (Array.isArray(mappingTextShowTextField)) {
309
+ mappingTextShowTextField.forEach((r: any) => {
310
+ textShowText.push(item[r])
311
+ })
312
+ } else {
313
+ textShowText = item[mappingTextShowTextField]
314
+ }
315
+ }
316
+ return {
317
+ ...item,
318
+ text: specialBracket
319
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
320
+ : item[mappingTextField],
321
+ textShowText,
322
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
323
+ value: item[mappingValueField],
324
+ };
325
+ })
326
+ : Array.isArray(res) &&
327
+ res?.map((item: Record<string, any>) => {
328
+ let textShowText = item[mappingTextField]
329
+ if (mappingTextShowTextField) {
330
+ textShowText = []
331
+ if (Array.isArray(mappingTextShowTextField)) {
332
+ mappingTextShowTextField.forEach((r: any) => {
333
+ textShowText.push(item[r])
334
+ })
335
+ } else {
336
+ textShowText = item[mappingTextShowTextField]
337
+ }
338
+ }
339
+ return {
340
+ ...item,
341
+ text: specialBracket
342
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
343
+ : item[mappingTextField],
344
+ textShowText,
345
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
346
+ value: item[mappingValueField],
347
+ };
348
+ })
349
+ : [];
350
+ }
351
+ source = Array.isArray(source) ? source : []
352
+ if(callback) {
353
+ callback(source)
354
+ } else {
355
+ if (type === 1) {
356
+ ctx?.form?.setFieldSource(resultSourceKey, source)
357
+ setItems(source)
358
+ setItemsTotal(Number(res?.total || res?.totalCount || source.length))
359
+ } else {
360
+ setTableData(source)
361
+ 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)) })
362
+ }
363
+ }
364
+ })
365
+ .catch((err) => { setFetching(false) });
366
+ }
367
+
368
+ const SelectScroll = e => {
369
+ e.persist();
370
+ const { target } = e;
371
+ const totalPage = Math.ceil(itemsTotal / pageSize)
372
+ // 判断是否滑动到底部
373
+ const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
374
+ // 判断数据是否还没有加载到了最后一页
375
+ const canPageAdd = scrollPage < totalPage
376
+ if (isTouchGround && canPageAdd) {
377
+ const nextScrollPage = scrollPage + 1;
378
+ setScrollPage(nextScrollPage);
379
+ getData({ currentPage: nextScrollPage }); // 调用api方法
380
+ }
381
+
382
+ //判断是否滑动到顶部
383
+ const isTouchTop = target.scrollTop === 0 // <=0
384
+ // 判断数据是否到第一页
385
+ const canPageJian = scrollPage > 1
386
+ if (isTouchTop && canPageJian) {
387
+ const preScrollPage = scrollPage - 1;
388
+ setScrollPage(preScrollPage);
389
+ getData({ currentPage: preScrollPage }); // 调用api方法
390
+ }
391
+ }
392
+
393
+ // 下拉框改变事件
394
+ const onChange = (...arg) => {
395
+ onChangeTemp(...arg)
396
+ if(props?.selectChangeCallback){
397
+ props.selectChangeCallback(...arg)
398
+ }
399
+ if(props?.selectProps?.selectChangeCallback) {
400
+ props.selectProps.selectChangeCallback(...arg)
401
+ }
402
+ }
403
+
404
+ useEffect(() => {
405
+ if (init) {
406
+ run('init')
407
+ }
408
+ }, [])
409
+
410
+ useEffect(() => {
411
+ if (value) {
412
+ setPopValue(value);
413
+ }
414
+ }, [value]);
415
+
416
+ useEffect(() => {
417
+ makeUniqueValue();
418
+ }, [resultSourceKey])
419
+
420
+ useEffect(() => {
421
+ if (init) {
422
+ setItems([]);
423
+ setItemsTotal(0);
424
+ run('init')
425
+ }
426
+ },[selectBusinessType])
427
+
428
+ const showModal = () => {
429
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 3)
430
+ setIsModalVisible(true);
431
+ // 回显
432
+ if (value) {
433
+ if (selectMode) {
434
+ setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
435
+ setSelectedRows(labelInValue ? value.map(i => ({ [mappingValueField]: i.key, value: i.key, text: i.label })) : value.map(i => ({ [mappingValueField]: i, value: i })))
436
+ setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
437
+ setIndeterminate(!!value.length && value.length < itemsTotal);
438
+ setCheckedAll(itemsTotal && value.length === itemsTotal);
439
+ } else {
440
+ setSelectedRowKeys(labelInValue ? [value.key] : [value])
441
+ setSelectedRows(labelInValue ? [{ [mappingValueField]: value.key, value: value.key, text: value.label }] : [{ [mappingValueField]: value, value: value }])
442
+ setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
443
+ }
444
+ }
445
+ };
446
+
447
+ const handleSelectOver = (selectedValue: any) => {
448
+ if (selectedValue?.length) {
449
+ // 解决选择最后1页的sku,返回后,不显示名称问题
450
+ const source = _.uniqBy(items.concat(selectedValue), 'value')
451
+ ctx?.form?.setFieldSource(resultSourceKey, source)
452
+ setItems(source)
453
+ formaData(selectedValue, source);
454
+ } else {
455
+ const formatResult = selectMode ? [] : null
456
+ onChange(formatResult, selectedValue)
457
+ }
458
+ }
459
+
460
+ const handleOk = () => {
461
+ handleSelectOver(popvalue)
462
+ handleCancel();
463
+ };
464
+
465
+ const formaData = (value: any, source: any) => {
466
+ if (labelInValue) {
467
+ const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
468
+ onChange(selectMode ? formatResult : formatResult[0], value,source)
469
+ } else {
470
+ const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
471
+ onChange(formatResult, value,source)
472
+ }
473
+ };
474
+
475
+ const clearModalTable = () => {
476
+ form.resetFields();
477
+ setTableFormParams({});
478
+ setTableData([]);
479
+ setTablePagination(tableInitPagination);
480
+ setSelectedRowKeys([]);
481
+ setSelectedRows([]);
482
+ setCheckedAll(false);
483
+ setIndeterminate(false);
484
+ };
485
+
486
+ const handleCancel = () => {
487
+ clearModalTable();
488
+ setIsModalVisible(false);
489
+ if (selectMode) {
490
+ run();
491
+ }
492
+ };
493
+
494
+ const refreshItems = () => {
495
+ // 查看是否存在关联值 如果有关联值 就查询 没有就不能查询
496
+ if (fieldValToParam && ctx && fixedparamsDisabled) {
497
+ let formValueList = [];
498
+ fieldValToParam.forEach((item: any, index: any) => {
499
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
500
+ formValueList.push(fixedParamVal);
501
+ });
502
+ if (formValueList.filter((item: any) => item).length > 0) {
503
+ run();
504
+ } else {
505
+ setItems([]);
506
+ setItemsTotal(0);
507
+ }
508
+ } else {
509
+ run();
510
+ }
511
+ }
512
+
513
+ const onSearchChange = (e) => {
514
+ setSearchValue(e.target.value);
515
+ refreshItems();
516
+ }
517
+
518
+ const onSearchBlur = () => {
519
+ setSearchValue('');
520
+ refreshItems();
521
+ }
522
+
523
+ const onSearchTable = () => {
524
+ const params = form.getFieldsValue();
525
+ setTableFormParams(params);
526
+ getData({ ...params, pageSize: tableInitPageSize }, 2)
527
+ if (selectMode) {
528
+ getData(params)
529
+ }
530
+ }
531
+
532
+ const onResetTable = () => {
533
+ form.resetFields();
534
+ setTableFormParams({});
535
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
536
+ }
537
+
538
+ const handleTableChange = (pagination) => {
539
+ getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
540
+ }
541
+
542
+ const onCheckAllData = (pSize) => {
543
+ getData({ ...tableFormParams, pageSize: pSize, currentPage: 1 }, 2,(source) => {
544
+ const currentItemsData = JSON.parse(JSON.stringify(source))
545
+ setSelectedRowKeys(currentItemsData.map(i => i.value))
546
+ setPopValue(currentItemsData);
547
+ setSelectedRows(currentItemsData)
548
+ })
549
+ }
550
+ const onChangeCheckAll = (e) => {
551
+ if (e.target.checked) {
552
+ // 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
553
+ // 如果超过100条 就默认查出所有数据
554
+ if (items.length < itemsTotal) {
555
+ const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize);
556
+ const allPageSize = totalPage * tablePagination?.pageSize;
557
+ onCheckAllData(allPageSize)
558
+ } else {
559
+ const currentItemsData = JSON.parse(JSON.stringify(items))
560
+ setSelectedRowKeys(currentItemsData.map(i => i.value))
561
+ setPopValue(currentItemsData);
562
+ setSelectedRows(currentItemsData)
563
+ }
564
+ } else {
565
+ setSelectedRowKeys([])
566
+ setPopValue([]);
567
+ setSelectedRows([])
568
+ }
569
+ setIndeterminate(false);
570
+ setCheckedAll(e.target.checked);
571
+ }
572
+
573
+ const LightHeightOption = (props) => {
574
+ const {
575
+ filterTxt, text,
576
+ } = props
577
+ const heightLightTxt = (text, heightTxt) => {
578
+ if (heightTxt === '') {
579
+ return text
580
+ }
581
+ const searchString = escapeRegExp(heightTxt);
582
+ // 前面filterOption 不区分大小写,这里用i
583
+ const regexp = new RegExp(searchString, 'gi')
584
+ return text.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
585
+ }
586
+ return (
587
+ <Tooltip title={text}>
588
+ <div ref={(nodeElement) => {
589
+ if (nodeElement) {
590
+ nodeElement.innerHTML = heightLightTxt(text, filterTxt)
591
+ }
592
+ }}
593
+ />
594
+ </Tooltip>
595
+ )
596
+ }
597
+
598
+ // 扁平化二维数组的方法
599
+ const mapRows = params => {
600
+ var res = [];
601
+ for (var i = 0; i < params.length; i++) {
602
+ if (Array.isArray(params[i])) {
603
+ // 去重
604
+ res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
605
+ } else {
606
+ res.push(params[i]);
607
+ // 去重
608
+ res = _.uniqBy(res, 'value')
609
+ }
610
+ }
611
+ return res.filter(Boolean); //去掉undefined的情况
612
+ };
613
+
614
+ const onChangeSelectedKeys = (selectKeys, selectRows) => {
615
+ let sksResult = selectRows.map((i) => i.value);
616
+
617
+ // 单选 默认直接选中 不需要确定 配置了modalRadioNeedFooter就需要确定
618
+ if(!selectMode && !modalTableProps?.modalRadioNeedFooter) {
619
+ handleSelectOver(selectRows)
620
+ handleCancel();
621
+ }
622
+
623
+ setSelectedRowKeys(sksResult)
624
+ setSelectedRows(selectRows)
625
+ setPopValue(selectRows);
626
+ setIndeterminate(!!selectRows.length && selectRows.length < tablePagination?.total);
627
+ setCheckedAll(selectRows.length === tablePagination?.total);
628
+ }
629
+
630
+ // 生成唯一值
631
+ const makeUniqueValue = () => {
632
+ const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
633
+ setUniqueValue(generateUnitKey);
634
+ return generateUnitKey;
635
+ }
636
+
637
+ const rowSelection = {
638
+ type: selectMode ? 'checkbox' : 'radio',
639
+ selectedRowKeys,
640
+ preserveSelectedRowKeys: true,
641
+ onChange: (sks, srs) => {
642
+ // 处理翻页后,之前存储的selectedRows变为undefined
643
+ // selectedRows合并新数组,过滤undefined,过滤留下对应selectedRowKeys的集合
644
+ let tmpSelectedRows = selectedRows.concat(srs).filter(item => item != undefined);
645
+ let totalSelectedRows = sks.map(key => tmpSelectedRows.filter(item => item[mappingValueField] == key)[0]).filter(item => item != undefined)
646
+ onChangeSelectedKeys(sks, totalSelectedRows)
647
+ },
648
+ getCheckboxProps: selectProps?.getCheckboxProps ? selectProps?.getCheckboxProps : () => {
649
+ return ({
650
+ disabled: selectProps?.disabled || props?.disabled || (!items.length && !tableData.length),
651
+ })
652
+ },
653
+ };
654
+
655
+ const onDoubleClickSelect = (e, record) => {
656
+ if (!selectMode && !(selectProps?.disabled || props?.disabled || (!items.length && !tableData.length))) {
657
+ const srs = [JSON.parse(JSON.stringify(record))]
658
+ const sks = srs.map((i: any) => i.value)
659
+ onChangeSelectedKeys(sks, srs)
660
+ }
661
+ }
662
+
663
+ const themeColor = { color: '#1890ff' }
664
+
665
+ const formItem = (list) => {
666
+ if (isModalVisible && list?.length) {
667
+ const setDisabled = (name: any) => {
668
+ if (fixedparamsDisabled && fixedparameter?.length && fixedparameter.find((item: any) => item === name)) {
669
+ return true
670
+ } else {
671
+ return false
672
+ }
673
+ };
674
+ return list.map((i: any) => {
675
+ if (i?.type === 'select' || i?.field?.type === 'select') {
676
+ return (
677
+ <Form.Item name={i.name} label={i.label} key={i.name}>
678
+ <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}>
679
+ {i?.initialSource?.length && i?.initialSource.map((m: any) => (
680
+ <Option value={m.value} key={m.value}>{m.text}</Option>
681
+ ))}
682
+ </Select>
683
+ </Form.Item>
684
+ )
685
+ }
686
+
687
+ if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
688
+ return (
689
+ <Form.Item name={i.name} label={i.label} key={i.name}>
690
+ <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></TreeSelect>
691
+ </Form.Item>
692
+ )
693
+ }
694
+
695
+ if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
696
+ return (
697
+ <div>
698
+ <Form.Item name={i.name} label={i.label} key={i.name}>
699
+ <BusinessSearchSelect {...i.field.props} disabled={setDisabled(i.name)} />
700
+ </Form.Item>
701
+ </div>
702
+ )
703
+ }
704
+
705
+ if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
706
+ return (
707
+ <div>
708
+ <Form.Item name={i.name} label={i.label} key={i.name}>
709
+ <QueryMutipleInput onValueChange={(value) => {
710
+ form.setFieldsValue({
711
+ [i.name]: value
712
+ })
713
+ }} />
714
+ </Form.Item>
715
+ </div>
716
+ );
717
+ }
718
+
719
+ // 默认type是input
720
+ return (
721
+ <Form.Item name={i.name} label={i.label} key={i.name}>
722
+ <Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} disabled={setDisabled(i.name)} />
723
+ </Form.Item>
724
+ )
725
+ })
726
+ } else {
727
+ return null
728
+ }
729
+ }
730
+
731
+ const maxTagPlaceholder = (selectedValues) => {
732
+ const onClose = (e: any, item: any) => {
733
+ e.preventDefault();
734
+ 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)
735
+ onChange(newValue);
736
+ }
737
+ return (
738
+ <Tooltip title={selectedValues.map((i: any) => (
739
+ <Tag
740
+ closable={true}
741
+ onClose={(e) => onClose(e, i)}
742
+ style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
743
+ >
744
+ {i.label}
745
+ </Tag>
746
+ ))}>
747
+ {`+ ${selectedValues?.length}`}
748
+ </Tooltip>
749
+ )
750
+ }
751
+
752
+ const handleSelectOptionsShowValue = (specialBracket: boolean, noNeedSplit: boolean, item: object) => {
753
+ let showText = Array.isArray(item.textShowText) &&
754
+ item.textShowText.join(' ') || item.textShowText;
755
+ if (noNeedSplit) {
756
+ return item.text;
757
+ } else {
758
+ return specialBracket
759
+ ? `【${item.textShowKey}】${showText}`
760
+ : `${item.textShowKey} ${showText}`
761
+ }
762
+ };
763
+
764
+ return (
765
+ <div className={'search_select'}>
766
+ {fieldComponent ?
767
+ (<div onClick={() => {
768
+ fieldComponent.props?.onClick?.()
769
+ showModal()
770
+ }}>{fieldComponent}</div>) :
771
+ (<div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
772
+ <Select
773
+ virtual
774
+ labelInValue={labelInValue}
775
+ value={value}
776
+ onChange={onChange}
777
+ disabled={props.disabled}
778
+ dropdownRender={menu => (
779
+ <>
780
+ <Input
781
+ value={searchValue}
782
+ style={{ width: '98%', marginLeft: '1%' }}
783
+ placeholder="请输入"
784
+ onChange={e => onSearchChange(e)}
785
+ onBlur={onSearchBlur}
786
+ onKeyDown={(e) => {
787
+ // 阻止多选的冒泡
788
+ e.stopPropagation()
789
+ }}
790
+ />
791
+ <Divider style={{ margin: '8px 0' }} />
792
+ {menu}
793
+ </>
794
+ )}
795
+ notFoundContent={
796
+ fetching ? <Spin size="small" /> :
797
+ <div style={{ textAlign: 'center' }}>
798
+ <div style={{ marginBottom: 16 }}>
799
+ <CopyOutlined style={{ fontSize: '50px' }} />
800
+ </div>
801
+ <div>无匹配结果,请更换其他内容再试</div>
802
+ </div>
803
+ }
804
+ onPopupScroll={SelectScroll}
805
+ style={{ width: needModalTable ? 'calc(100% - 30px)' : 'calc(100%)' }}
806
+ placeholder="请选择"
807
+ maxTagPlaceholder={maxTagPlaceholder}
808
+ {...currentSelectProps}
809
+ getPopupContainer={(triggerNode) => (getPopupContainer && getPopupContainer(triggerNode)) || triggerNode.parentElement}
810
+ >
811
+ {items.map(item => (
812
+ <Option key={item.value} label={item.text}>
813
+ {LightHeightOption({
814
+ text: handleSelectOptionsShowValue(specialBracket, noNeedSplit, item),
815
+ filterTxt: searchValue
816
+ })}
817
+ </Option>
818
+ ))}
819
+ </Select>
820
+ {needModalTable && (
821
+ <Button style={{ width: '30px', padding: '2px', height: 'auto' }} onClick={showModal} type="primary">
822
+ <SearchOutlined />
823
+ </Button>
824
+ )}
825
+ </div>)}
826
+ {needModalTable && isModalVisible && (
827
+ <Modal
828
+ width='80%'
829
+ title={modalTableProps?.modalTableTitle}
830
+ visible={isModalVisible}
831
+ onOk={handleOk}
832
+ onCancel={handleCancel}
833
+ footer={(selectMode || modalTableProps?.modalRadioNeedFooter) ? [
834
+ <Button key="back" onClick={handleCancel}>
835
+ 取消
836
+ </Button>,
837
+ <Button
838
+ key="submit"
839
+ type="primary"
840
+ onClick={handleOk}
841
+ disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
842
+ >
843
+ 确定
844
+ </Button>,
845
+ ] : null}
846
+ {...(modalTableProps?.modalProps || {})}
847
+ >
848
+ <div className={'search_select_wrapper'}>
849
+ <div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
850
+ <CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1'} />
851
+ </div>
852
+ <div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
853
+ <div className={'select_list_columns'}>
854
+ <div className={'select_list_columns_tips'}>搜索</div>
855
+ <div className={'select_list_columns_formItems'}>
856
+ <Form form={form} layout='vertical' key='modalForm'>
857
+ {formItem(modalTableProps?.tableSearchForm)}
858
+ </Form>
859
+ </div>
860
+ </div>
861
+ <div className={'select_list_searchButton'}>
862
+ <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
863
+ <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
864
+ </div>
865
+ </div>
866
+ <div className={caretLeftFlag ? 'search_select_wrapper_right' : 'search_select_wrapper_right1'}>
867
+ <div>
868
+ <div className={'select_list_selectTips'}>
869
+ <div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
870
+ <div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或点击单选图标完成选择'}</div>
871
+ </div>
872
+ <Table
873
+ size='small'
874
+ rowSelection={rowSelection}
875
+ columns={modalTableProps?.tableColumns}
876
+ dataSource={tableData}
877
+ pagination={tablePagination}
878
+ onChange={handleTableChange}
879
+ rowKey={mappingValueField}
880
+ scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
881
+ onRow={record => {
882
+ return {
883
+ onDoubleClick: event => onDoubleClickSelect(event, record),
884
+ };
885
+ }}
886
+ />
887
+ {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
888
+ </div>
889
+ </div>
890
+ </div>
891
+ </Modal>
892
+ )}
893
+ </div>
894
+ );
895
+ });
896
+
897
+ export default SearchSelect;