@bit-sun/business-component 2.3.18 → 2.3.20

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