@bit-sun/business-component 2.2.21 → 2.2.23

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 (178) 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.esm.js +34 -31
  9. package/dist/index.js +34 -31
  10. package/docs/index.md +21 -21
  11. package/lib/assets/drag.svg +17 -17
  12. package/lib/assets/exportFail.svg +37 -37
  13. package/lib/assets/exportProcessing.svg +28 -28
  14. package/lib/assets/exportSuccess.svg +34 -34
  15. package/lib/assets/label_icon_bottom.svg +25 -25
  16. package/lib/assets/upExport.svg +22 -22
  17. package/package.json +77 -77
  18. package/src/assets/32.svg +27 -27
  19. package/src/assets/addIcon.svg +17 -17
  20. package/src/assets/allfunc.svg +27 -27
  21. package/src/assets/arrowRight.svg +24 -24
  22. package/src/assets/arrow_top.svg +17 -17
  23. package/src/assets/btn-delete.svg +29 -29
  24. package/src/assets/btn-edit.svg +19 -19
  25. package/src/assets/btn-more.svg +17 -17
  26. package/src/assets/btn-submit.svg +19 -19
  27. package/src/assets/caidan.svg +11 -11
  28. package/src/assets/close.svg +26 -26
  29. package/src/assets/drag.svg +17 -17
  30. package/src/assets/exportFail.svg +37 -37
  31. package/src/assets/exportProcessing.svg +28 -28
  32. package/src/assets/exportSuccess.svg +34 -34
  33. package/src/assets/fixed-left-active.svg +11 -11
  34. package/src/assets/fixed-left.svg +15 -15
  35. package/src/assets/fixed-right-active.svg +11 -11
  36. package/src/assets/fixed-right.svg +15 -15
  37. package/src/assets/guanbi.svg +15 -15
  38. package/src/assets/icon-quanping.svg +15 -15
  39. package/src/assets/icon-shezhi.svg +17 -17
  40. package/src/assets/label_icon_bottom.svg +25 -25
  41. package/src/assets/list-no-img.svg +21 -21
  42. package/src/assets/morentouxiang-32.svg +23 -23
  43. package/src/assets/scanning.svg +24 -24
  44. package/src/assets/upExport.svg +22 -22
  45. package/src/components/Business/AddSelectBusiness/index.md +129 -129
  46. package/src/components/Business/AddSelectBusiness/index.tsx +835 -835
  47. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +111 -111
  48. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  49. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  50. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  51. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  52. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  53. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  54. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  55. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  56. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  57. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  58. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  59. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  60. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +157 -157
  61. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  62. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  63. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +155 -155
  64. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  65. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  66. package/src/components/Business/BsLayouts/index.less +79 -79
  67. package/src/components/Business/BsLayouts/index.tsx +1480 -1479
  68. package/src/components/Business/BsLayouts/service.ts +10 -10
  69. package/src/components/Business/BsLayouts/utils.tsx +203 -203
  70. package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +538 -538
  71. package/src/components/Business/BsSulaQueryTable/index.less +219 -219
  72. package/src/components/Business/BsSulaQueryTable/index.tsx +527 -527
  73. package/src/components/Business/BsSulaQueryTable/setting.tsx +802 -802
  74. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  75. package/src/components/Business/BsSulaQueryTable/utils.tsx +688 -688
  76. package/src/components/Business/CommodityEntry/index.md +70 -70
  77. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  78. package/src/components/Business/CommonAlert/index.tsx +23 -23
  79. package/src/components/Business/CommonGuideWrapper/index.less +113 -113
  80. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  81. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  82. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  83. package/src/components/Business/DetailPageWrapper/index.tsx +313 -313
  84. package/src/components/Business/DetailPageWrapper/utils.tsx +100 -100
  85. package/src/components/Business/HomePageWrapper/index.less +33 -33
  86. package/src/components/Business/HomePageWrapper/index.md +45 -45
  87. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  88. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +824 -824
  89. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +201 -201
  90. package/src/components/Business/JsonQueryTable/components/Formula.tsx +205 -205
  91. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  92. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  93. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  94. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  95. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  96. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  97. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  98. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  99. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  100. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  101. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  102. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  103. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  104. package/src/components/Business/JsonQueryTable/index.less +16 -16
  105. package/src/components/Business/JsonQueryTable/index.md +328 -328
  106. package/src/components/Business/JsonQueryTable/index.tsx +320 -320
  107. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  108. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  109. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  110. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  111. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  112. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  113. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  114. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  115. package/src/components/Business/JsonQueryTable/static.ts +390 -390
  116. package/src/components/Business/SearchSelect/BusinessUtils.ts +1730 -1730
  117. package/src/components/Business/SearchSelect/common.ts +53 -53
  118. package/src/components/Business/SearchSelect/index.md +1310 -1310
  119. package/src/components/Business/SearchSelect/index.tsx +51 -51
  120. package/src/components/Business/SearchSelect/utils.ts +100 -100
  121. package/src/components/Business/StateFlow/index.less +151 -151
  122. package/src/components/Business/StateFlow/index.md +60 -60
  123. package/src/components/Business/StateFlow/index.tsx +32 -32
  124. package/src/components/Business/TreeSearchSelect/index.md +154 -154
  125. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  126. package/src/components/Business/TreeSearchSelect/utils.ts +69 -69
  127. package/src/components/Business/columnSettingTable/columnSetting.tsx +764 -764
  128. package/src/components/Business/columnSettingTable/index.less +247 -247
  129. package/src/components/Business/columnSettingTable/index.md +357 -357
  130. package/src/components/Business/columnSettingTable/index.tsx +232 -232
  131. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +240 -240
  132. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  133. package/src/components/Business/moreTreeTable/index.less +99 -99
  134. package/src/components/Business/moreTreeTable/index.md +448 -448
  135. package/src/components/Business/moreTreeTable/index.tsx +361 -361
  136. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  137. package/src/components/Functional/AddSelect/index.less +367 -367
  138. package/src/components/Functional/AddSelect/index.md +155 -155
  139. package/src/components/Functional/AddSelect/index.tsx +1203 -1203
  140. package/src/components/Functional/BillEntry/index.less +371 -371
  141. package/src/components/Functional/BillEntry/index.md +39 -39
  142. package/src/components/Functional/BillEntry/index.tsx +766 -766
  143. package/src/components/Functional/DataImport/index.less +63 -63
  144. package/src/components/Functional/DataImport/index.md +44 -44
  145. package/src/components/Functional/DataImport/index.tsx +695 -695
  146. package/src/components/Functional/DataValidation/index.less +63 -63
  147. package/src/components/Functional/DataValidation/index.md +39 -39
  148. package/src/components/Functional/DataValidation/index.tsx +687 -687
  149. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  150. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  151. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  152. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  153. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  154. package/src/components/Functional/SearchSelect/index.less +115 -115
  155. package/src/components/Functional/SearchSelect/index.md +141 -141
  156. package/src/components/Functional/SearchSelect/index.tsx +846 -846
  157. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  158. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  159. package/src/components/Functional/TreeSearchSelect/index.tsx +162 -160
  160. package/src/index.ts +34 -34
  161. package/src/plugin/TableColumnSetting/index.less +247 -247
  162. package/src/plugin/TableColumnSetting/index.md +50 -50
  163. package/src/plugin/TableColumnSetting/index.tsx +724 -724
  164. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  165. package/src/styles/bsDefault.less +1912 -1912
  166. package/src/utils/CheckOneUser/index.md +39 -39
  167. package/src/utils/CheckOneUser/index.ts +51 -51
  168. package/src/utils/LocalstorageUtils.ts +90 -90
  169. package/src/utils/TableUtils.tsx +18 -18
  170. package/src/utils/checkUtils.ts +39 -39
  171. package/src/utils/enumConfig.ts +11 -11
  172. package/src/utils/getFormMode.js +12 -12
  173. package/src/utils/index.ts +3 -3
  174. package/src/utils/requestUtils.ts +34 -34
  175. package/src/utils/serialize.js +7 -7
  176. package/src/utils/utils.ts +183 -183
  177. package/tsconfig.json +29 -29
  178. package/typings.d.ts +4 -4
@@ -1,802 +1,802 @@
1
- // @ts-nocheck
2
- import React from 'react';
3
- import {
4
- Table,
5
- message,
6
- Checkbox,
7
- Modal,
8
- Input,
9
- Button,
10
- Tooltip,
11
- } from 'antd';
12
- import {
13
- SortableContainer,
14
- SortableElement,
15
- SortableHandle,
16
- } from 'react-sortable-hoc';
17
- import axios from 'axios';
18
- import { SearchOutlined } from '@ant-design/icons';
19
- import { arrayMoveImmutable } from 'array-move';
20
- import shezhi from '../../../assets/icon-shezhi.svg';
21
- import close from '../../../assets/close.svg';
22
- import drag from '../../../assets/drag.svg';
23
- import fixedLeft from '../../../assets/fixed-left.svg';
24
- import fixedLeftActive from '../../../assets/fixed-left-active.svg';
25
- import fixedRight from '../../../assets/fixed-right.svg';
26
- import fixedRightActive from '../../../assets/fixed-right-active.svg';
27
- import './index.less';
28
- import ENUM from '@/utils/enumConfig';
29
-
30
- const DragHandle = SortableHandle(() => <img src={drag} />);
31
-
32
- const SortableItem = SortableElement((props) => <tr {...props} />);
33
- const SortableBody = SortableContainer((props) => <tbody {...props} />);
34
-
35
- class SortableTable extends React.Component {
36
- state = {
37
- dataSource: [],
38
- columns: [],
39
- sortDataSource: [],
40
- setVisible: false,
41
- searchDataSource: false,
42
- onSearchSort: false,
43
- isDefaultValue: false,
44
- defaultValue: [],
45
- bsTableCode: '', //设置table 列的标识
46
- };
47
-
48
- patchUserColumnConfig = (config) => {
49
- let that = this;
50
- let configvalue = config
51
- ? config.map((item) => ({
52
- key: item.key,
53
- dataIndex: item.dataIndex,
54
- width: item.width,
55
- hidden: item.hidden,
56
- fixed: item.fixed,
57
- }))
58
- : '';
59
- axios({
60
- url: '/user/appConfig/saveUserOrder',
61
- method: 'POST',
62
- data: {
63
- code: that.state.bsTableCode,
64
- detail: configvalue ? JSON.stringify(configvalue) : '',
65
- },
66
- }).then((res:any) => {
67
- if (res?.data?.status === '0') {
68
- this.patchConfigToLocalstorage(configvalue)
69
- } else {
70
- message.error('保存表头列自定义失败,请稍后尝试');
71
- }
72
- })
73
- };
74
-
75
- getConfigFromlocalstorage = () => {
76
- let config = localStorage.getItem(ENUM.BROWSER_CACHE.COLUMN_CONDITION) || '[]';
77
- let configArray = JSON.parse(config);
78
- let configSetting = configArray.filter(
79
- (item) => item.code === this.state.bsTableCode,
80
- );
81
-
82
- if (configSetting.length && configSetting[0].detail) {
83
- return JSON.parse(configSetting[0].detail);
84
- }
85
- return [];
86
- };
87
-
88
- patchConfigToLocalstorage = (configvalue) => {
89
- const { setShowColumns } = this.props;
90
- const { sortDataSource, bsTableCode } = this.state;
91
- let config = localStorage.getItem(ENUM.BROWSER_CACHE.COLUMN_CONDITION) || '[]'
92
- let configArray = JSON.parse(config)
93
- let currentSetting = configArray.filter(item => item.code === bsTableCode)
94
- if (currentSetting.length) {
95
- currentSetting[0].detail = JSON.stringify(configvalue)
96
- } else {
97
- configArray.push({
98
- "code": bsTableCode,
99
- "detail": JSON.stringify(configvalue)
100
- })
101
- }
102
-
103
- localStorage.setItem(ENUM.BROWSER_CACHE.COLUMN_CONDITION, JSON.stringify(configArray));
104
- this.setState({
105
- visible: false,
106
- });
107
- setShowColumns([...sortDataSource]);
108
- };
109
-
110
- setInitValue = (isClick = false) => {
111
- const { datasource, showColumn }: any =
112
- this.props;
113
- let config = this.getConfigFromlocalstorage();
114
-
115
- this.setState({
116
- isDefaultValue: true,
117
- dataSource: datasource.map((item) => {
118
- let innerItem = config.filter(
119
- (inneritem) => {
120
- let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
121
- let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
122
- return innerKey && innerKey === itemKey;
123
- }
124
- );
125
- return {
126
- ...item,
127
- key: item.key || item.dataIndex,
128
- width: innerItem[0]?.width || item.width,
129
- hidden: config.length ? !innerItem.length : item.hidden,
130
- };
131
- }),
132
- defaultValue: datasource.map((item) => {
133
- let innerItem = config.filter(
134
- (inneritem) => {
135
- let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
136
- let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
137
- return innerKey && innerKey === itemKey;
138
- }
139
- );
140
- return {
141
- ...item,
142
- key: item.key || item.dataIndex,
143
- width: innerItem[0]?.width || item.width,
144
- hidden: config.length ? !innerItem.length : item.hidden,
145
- };
146
- }),
147
- sortDataSource: [...showColumn]
148
- });
149
- };
150
-
151
- componentDidMount() {
152
- const { datasource, showColumn, bsTableCode }: any =
153
- this.props;
154
- let config = this.getConfigFromlocalstorage();
155
-
156
- this.setState({
157
- dataSource: datasource.map((item) => {
158
- let innerItem = config.filter(
159
- (inneritem) => {
160
- let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
161
- let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
162
- return innerKey && innerKey === itemKey;
163
- }
164
- );
165
- return {
166
- ...item,
167
- key: item.key || item.dataIndex,
168
- width: innerItem[0]?.width || item.width,
169
- hidden: config.length ? !innerItem.length : item.hidden,
170
- };
171
- }),
172
- defaultValue: datasource.map((item) => {
173
- let innerItem = config.filter(
174
- (inneritem) => {
175
- let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
176
- let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
177
- return innerKey && innerKey === itemKey;
178
- }
179
- );
180
- return {
181
- ...item,
182
- key: item.key || item.dataIndex,
183
- width: innerItem[0]?.width || item.width,
184
- hidden: config.length ? !innerItem.length : item.hidden,
185
- };
186
- }),
187
- sortDataSource: datasource
188
- .filter((item) => !item.hidden)
189
- .map((item) => ({
190
- ...item,
191
- key: item.key || item.dataIndex,
192
- width:
193
- showColumn.filter(
194
- (inneritem) => {
195
- let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
196
- let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
197
- return innerKey && innerKey === itemKey;
198
- }
199
- )[0]?.width || item.width,
200
- })),
201
- bsTableCode
202
- });
203
- }
204
-
205
- columns = [
206
- {
207
- title: '列名称',
208
- dataIndex: 'title',
209
- className: 'drag-visible',
210
- width: 100,
211
- },
212
- {
213
- title: '列首',
214
- dataIndex: 'fixedLeft',
215
- render: (text, record) => {
216
- return (
217
- <span
218
- onClick={() => {
219
- const { sortDataSource } = this.state;
220
- if (record?.fixed !== 'left') {
221
- let newSortData = sortDataSource.map((item) => {
222
- if (item.title === record.title) {
223
- return {
224
- ...item,
225
- fixed: 'left',
226
- };
227
- }
228
- return item;
229
- });
230
- this.setState({
231
- sortDataSource: [
232
- ...newSortData.filter((item) => item.fixed === 'left'),
233
- ...newSortData.filter((item) => !item.fixed),
234
- ...newSortData.filter((item) => item.fixed === 'right'),
235
- ],
236
- isDefaultValue: false,
237
- dataSource: [
238
- ...this.state.dataSource.map((item) => {
239
- if (item.title === record.title) {
240
- return {
241
- ...item,
242
- fixed: 'left',
243
- };
244
- }
245
- return item;
246
- }),
247
- ],
248
- });
249
- } else {
250
- let newSortData = sortDataSource.map((item) => {
251
- if (item.title === record.title) {
252
- return {
253
- ...item,
254
- fixed: null,
255
- };
256
- }
257
- return item;
258
- });
259
- this.setState({
260
- sortDataSource: [
261
- ...newSortData.filter((item) => item.fixed === 'left'),
262
- ...newSortData.filter((item) => !item.fixed),
263
- ...newSortData.filter((item) => item.fixed === 'right'),
264
- ],
265
- isDefaultValue: false,
266
- dataSource: [
267
- ...this.state.dataSource.map((item) => {
268
- if (item.title === record.title) {
269
- return {
270
- ...item,
271
- fixed: null,
272
- };
273
- }
274
- return item;
275
- }),
276
- ],
277
- });
278
- }
279
- }}
280
- >
281
- <Tooltip
282
- placement="top"
283
- title={record?.fixed === 'left' ? '取消固定' : '固定列首'}
284
- >
285
- <img
286
- src={record?.fixed === 'left' ? fixedLeftActive : fixedLeft}
287
- />
288
- </Tooltip>
289
- </span>
290
- );
291
- },
292
- },
293
- {
294
- title: '列尾',
295
- dataIndex: 'fixedRight',
296
- render: (text, record) => {
297
- return (
298
- <span
299
- onClick={() => {
300
- const { sortDataSource } = this.state;
301
- if (record?.fixed !== 'right') {
302
- let newSortData = sortDataSource.map((item) => {
303
- if (item.title === record.title) {
304
- return {
305
- ...item,
306
- fixed: 'right',
307
- };
308
- }
309
- return item;
310
- });
311
- this.setState({
312
- sortDataSource: [
313
- ...newSortData.filter((item) => item.fixed === 'left'),
314
- ...newSortData.filter((item) => !item.fixed),
315
- ...newSortData.filter((item) => item.fixed === 'right'),
316
- ],
317
- isDefaultValue: false,
318
- dataSource: [
319
- ...this.state.dataSource.map((item) => {
320
- if (item.title === record.title) {
321
- return {
322
- ...item,
323
- fixed: 'right',
324
- };
325
- }
326
- return item;
327
- }),
328
- ],
329
- });
330
- } else {
331
- let newSortData = sortDataSource.map((item) => {
332
- if (item.title === record.title) {
333
- return {
334
- ...item,
335
- fixed: null,
336
- };
337
- }
338
- return item;
339
- });
340
- this.setState({
341
- sortDataSource: [
342
- ...newSortData.filter((item) => item.fixed === 'left'),
343
- ...newSortData.filter((item) => !item.fixed),
344
- ...newSortData.filter((item) => item.fixed === 'right'),
345
- ],
346
- isDefaultValue: false,
347
- dataSource: [
348
- ...this.state.dataSource.map((item) => {
349
- if (item.title === record.title) {
350
- return {
351
- ...item,
352
- fixed: null,
353
- };
354
- }
355
- return item;
356
- }),
357
- ],
358
- });
359
- }
360
- }}
361
- >
362
- <Tooltip
363
- placement="top"
364
- title={record?.fixed === 'right' ? '取消固定' : '固定列尾'}
365
- >
366
- <img
367
- src={record?.fixed === 'right' ? fixedRightActive : fixedRight}
368
- />
369
- </Tooltip>
370
- </span>
371
- );
372
- },
373
- },
374
- {
375
- title: '删除',
376
- dataIndex: 'title1',
377
- render: (text, record) => {
378
- return (
379
- <span
380
- onClick={() => {
381
- this.setState({
382
- sortDataSource: this.state.sortDataSource.filter((item) => {
383
- return item.title !== record.title;
384
- }),
385
- isDefaultValue: false,
386
- dataSource: [
387
- ...this.state.dataSource.map((item) => {
388
- if (item.title === record.title) {
389
- return {
390
- ...item,
391
- hidden: true,
392
- };
393
- }
394
-
395
- return item;
396
- }),
397
- ],
398
- });
399
- }}
400
- >
401
- <img src={close} />
402
- </span>
403
- );
404
- },
405
- },
406
- {
407
- title: 'Sort',
408
- dataIndex: 'sort',
409
- className: 'drag-visible',
410
- render: () => <DragHandle />,
411
- },
412
- ];
413
-
414
- showModal = () => {
415
- this.setState({
416
- visible: true,
417
- });
418
- this.setInitValue();
419
- };
420
-
421
- handleOk = (e?: React.MouseEvent<HTMLElement>) => {
422
- const { sortDataSource, isDefaultValue, defaultValue } = this.state;
423
- if (!sortDataSource.length) {
424
- message.warning('至少选择一列!');
425
- return;
426
- }
427
- // if (isDefaultValue) {
428
- // this.patchUserColumnConfig('');
429
- // return;
430
- // }
431
- this.patchUserColumnConfig(sortDataSource);
432
- };
433
-
434
- handleCancel = (e: React.MouseEvent<HTMLElement>) => {
435
- console.log(e);
436
- this.setState({
437
- visible: false,
438
- });
439
- };
440
-
441
- handleTableHeadHidden = (title: string) => {
442
- const { sortDataSource, dataSource } = this.state;
443
- this.setState(
444
- {
445
- sortDataSource: sortDataSource.filter((item) => {
446
- return item.title !== title;
447
- }),
448
- dataSource: [
449
- ...dataSource.map((item) => {
450
- if (item.title === title) {
451
- return {
452
- ...item,
453
- hidden: true,
454
- };
455
- }
456
-
457
- return item;
458
- }),
459
- ],
460
- },
461
- () => {
462
- this.handleOk();
463
- },
464
- );
465
- };
466
-
467
- onSortEnd = ({ oldIndex, newIndex }) => {
468
- const { sortDataSource } = this.state;
469
- if (oldIndex !== newIndex) {
470
- const newData = arrayMoveImmutable(
471
- [].concat(sortDataSource),
472
- oldIndex,
473
- newIndex,
474
- ).filter((el) => !!el);
475
- this.setState({
476
- sortDataSource: [
477
- ...newData.filter((item) => item.fixed === 'left'),
478
- ...newData.filter((item) => !item.fixed),
479
- ...newData.filter((item) => item.fixed === 'right'),
480
- ],
481
- isDefaultValue: false,
482
- });
483
- }
484
- };
485
-
486
- DraggableContainer = (props) => (
487
- <SortableBody
488
- useDragHandle
489
- disableAutoscroll
490
- helperClass="row-dragging"
491
- onSortEnd={this.onSortEnd}
492
- {...props}
493
- />
494
- );
495
-
496
- DraggableBodyRow = ({ className, style, ...restProps }) => {
497
- const { sortDataSource } = this.state;
498
- // function findIndex base on Table rowKey props and should always be a right array index
499
- const index = sortDataSource.findIndex(
500
- (x) => x.key === restProps['data-row-key'],
501
- );
502
- return <SortableItem index={index} {...restProps} />;
503
- };
504
-
505
- onChange = (e: CheckboxChangeEvent, title) => {
506
- const { sortDataSource, dataSource } = this.state;
507
- if (!e.target.checked) {
508
- this.setState({
509
- sortDataSource: sortDataSource.filter((item) => {
510
- return item.title !== title;
511
- }),
512
- isDefaultValue: false,
513
- dataSource: [
514
- ...dataSource.map((item) => {
515
- if (item.title === title) {
516
- return {
517
- ...item,
518
- hidden: true,
519
- };
520
- }
521
-
522
- return item;
523
- }),
524
- ],
525
- });
526
- } else {
527
- let fixedLeft: any[] = [];
528
- let fixedRight: any[] = [];
529
- let noFixedSortSource: any = [];
530
- let newSortData = [
531
- ...sortDataSource,
532
- ...dataSource
533
- .filter((item) => item.title === title)
534
- .map((source) => {
535
- return {
536
- ...source,
537
- hidden: false,
538
- };
539
- }),
540
- ];
541
- newSortData.forEach((item) => {
542
- if (item?.fixed === 'left') {
543
- fixedLeft.push(item);
544
- } else if (item?.fixed === 'right') {
545
- fixedRight.push(item);
546
- } else {
547
- noFixedSortSource.push(item);
548
- }
549
- });
550
- this.setState({
551
- sortDataSource: [...fixedLeft, ...noFixedSortSource, ...fixedRight],
552
- isDefaultValue: false,
553
- dataSource: [
554
- ...dataSource.map((item) => {
555
- if (item.title === title) {
556
- return {
557
- ...item,
558
- hidden: false,
559
- };
560
- }
561
-
562
- return item;
563
- }),
564
- ],
565
- });
566
- }
567
- };
568
-
569
- handleReset = () => {
570
- this.setInitValue(true);
571
- };
572
-
573
- onSearch = (e: any) => {
574
- this.setState({
575
- searchDataSource: e.target.value,
576
- });
577
- };
578
-
579
- onSearchSort = (e: any) => {
580
- this.setState({
581
- onSearchSort: e.target.value,
582
- });
583
- };
584
-
585
- render() {
586
- const {
587
- dataSource,
588
- searchDataSource,
589
- sortDataSource,
590
- visible,
591
- onSearchSort,
592
- } = this.state;
593
-
594
- let seatchDataSource = dataSource.filter(
595
- (item) => item?.title?.indexOf(searchDataSource || '') > -1,
596
- );
597
-
598
- return (
599
- <div className={'sort_table_wrapper'}>
600
- {visible && (
601
- <Modal
602
- title="设置表头内容"
603
- wrapClassName={'sort_table_wrapper'}
604
- width={820}
605
- visible={visible}
606
- onOk={this.handleOk}
607
- onCancel={this.handleCancel}
608
- footer={[
609
- <Button key="back" onClick={this.handleReset}>
610
- 恢复默认
611
- </Button>,
612
- <Button key="submit" onClick={this.handleCancel}>
613
- 取消
614
- </Button>,
615
- <Button key="submit" type="primary" onClick={this.handleOk}>
616
- 确认
617
- </Button>,
618
- ]}
619
- >
620
- <div className={'sort_table'}>
621
- <div className={'sort_table_column_wrapper'}>
622
- <span className={'sort_table_column_count'}>
623
- 可选字段 <span>(共{dataSource.length}个)</span>
624
- </span>
625
- <div className={'sort_table_column'}>
626
- <Input
627
- prefix={<SearchOutlined className="site-form-item-icon" />}
628
- placeholder="搜索"
629
- allowClear
630
- onChange={this.onSearch}
631
- style={{ width: 540 }}
632
- />
633
- <div>
634
- {!searchDataSource && (
635
- <Checkbox
636
- checked={
637
- !dataSource.some((item) => {
638
- if (item.hidden) return true;
639
-
640
- return false;
641
- })
642
- }
643
- onClick={(e) => {
644
- this.setState({
645
- isDefaultValue: false,
646
- dataSource: [
647
- ...dataSource.map((item) => {
648
- return {
649
- ...item,
650
- hidden: !e.target.checked,
651
- };
652
- }),
653
- ],
654
- sortDataSource: e.target.checked
655
- ? [
656
- ...dataSource
657
- .filter((item) => item.fixed === 'left')
658
- .map((item) => ({
659
- ...item,
660
- hidden: false,
661
- })),
662
- ...dataSource
663
- .filter((item) => !item.fixed)
664
- .map((item) => ({
665
- ...item,
666
- hidden: false,
667
- })),
668
- ...dataSource
669
- .filter((item) => item.fixed === 'right')
670
- .map((item) => ({
671
- ...item,
672
- hidden: false,
673
- })),
674
- ]
675
- : [],
676
- });
677
- }}
678
- >
679
- 全选
680
- </Checkbox>
681
- )}
682
- </div>
683
- <div className={'sort_table_column_all'}>
684
- {searchDataSource
685
- ? seatchDataSource.map((item) => {
686
- return (
687
- <Checkbox
688
- checked={!item.hidden}
689
- onChange={(e) => {
690
- this.onChange(e, item.title);
691
- }}
692
- >
693
- {item.title}
694
- </Checkbox>
695
- );
696
- })
697
- : dataSource
698
- .filter(
699
- (item) =>
700
- item?.title?.indexOf('人') === -1 &&
701
- item?.title?.indexOf('日期') === -1,
702
- )
703
- .map((item) => {
704
- return (
705
- <Checkbox
706
- checked={!item.hidden}
707
- onChange={(e) => {
708
- this.onChange(e, item.title);
709
- }}
710
- >
711
- {item.title}
712
- </Checkbox>
713
- );
714
- })}
715
- {!!seatchDataSource.length && (
716
- <span style={{ width: '144px' }}></span>
717
- )}
718
-
719
- {!seatchDataSource.length && (
720
- <div className={'sort_table_column_all_empty'}>
721
- 未查询到结果
722
- </div>
723
- )}
724
- </div>
725
- {!searchDataSource && (
726
- <div>
727
- <div className={'sort_table_column_special'}>
728
- <span>人员时间字段</span>
729
- </div>
730
- <div className={'sort_table_column_all'}>
731
- {[...dataSource]
732
- .filter(
733
- (item) =>
734
- item?.title?.indexOf('人') > -1 ||
735
- item?.title?.indexOf('日期') > -1,
736
- )
737
- .map((item) => {
738
- return (
739
- <Checkbox
740
- checked={!item.hidden}
741
- onChange={(e) => {
742
- this.onChange(e, item.title);
743
- }}
744
- >
745
- {item.title}
746
- </Checkbox>
747
- );
748
- })}
749
- <span style={{ width: '144px' }}></span>
750
- </div>
751
- </div>
752
- )}
753
- </div>
754
- </div>
755
- <div className={'sort_table_content_wrapper'}>
756
- <span className={'sort_table_content_count'}>
757
- 已选字段 <span>(共{sortDataSource.length}个)</span>
758
- </span>
759
- <div className={'sort_table_content'}>
760
- <span style={{ paddingLeft: '10px' }}>
761
- <Input
762
- prefix={
763
- <SearchOutlined className="site-form-item-icon" />
764
- }
765
- placeholder="搜索"
766
- allowClear
767
- onChange={this.onSearchSort}
768
- style={{ width: 190 }}
769
- />
770
- </span>
771
- <Table
772
- pagination={false}
773
- showHeader={false}
774
- dataSource={
775
- onSearchSort
776
- ? sortDataSource.filter(
777
- (item) => item?.title?.indexOf(onSearchSort) > -1,
778
- )
779
- : sortDataSource
780
- }
781
- columns={this.columns}
782
- rowKey="key"
783
- // rowSelection={rowSelection}
784
- components={{
785
- body: {
786
- wrapper: this.DraggableContainer,
787
- row: this.DraggableBodyRow,
788
- },
789
- }}
790
- />
791
- </div>
792
- </div>
793
- </div>
794
- </Modal>
795
- )}
796
- <div onClick={this.showModal} style={{fontSize:14}}>列设置</div>
797
- </div>
798
- );
799
- }
800
- }
801
-
802
- export default SortableTable;
1
+ // @ts-nocheck
2
+ import React from 'react';
3
+ import {
4
+ Table,
5
+ message,
6
+ Checkbox,
7
+ Modal,
8
+ Input,
9
+ Button,
10
+ Tooltip,
11
+ } from 'antd';
12
+ import {
13
+ SortableContainer,
14
+ SortableElement,
15
+ SortableHandle,
16
+ } from 'react-sortable-hoc';
17
+ import axios from 'axios';
18
+ import { SearchOutlined } from '@ant-design/icons';
19
+ import { arrayMoveImmutable } from 'array-move';
20
+ import shezhi from '../../../assets/icon-shezhi.svg';
21
+ import close from '../../../assets/close.svg';
22
+ import drag from '../../../assets/drag.svg';
23
+ import fixedLeft from '../../../assets/fixed-left.svg';
24
+ import fixedLeftActive from '../../../assets/fixed-left-active.svg';
25
+ import fixedRight from '../../../assets/fixed-right.svg';
26
+ import fixedRightActive from '../../../assets/fixed-right-active.svg';
27
+ import './index.less';
28
+ import ENUM from '@/utils/enumConfig';
29
+
30
+ const DragHandle = SortableHandle(() => <img src={drag} />);
31
+
32
+ const SortableItem = SortableElement((props) => <tr {...props} />);
33
+ const SortableBody = SortableContainer((props) => <tbody {...props} />);
34
+
35
+ class SortableTable extends React.Component {
36
+ state = {
37
+ dataSource: [],
38
+ columns: [],
39
+ sortDataSource: [],
40
+ setVisible: false,
41
+ searchDataSource: false,
42
+ onSearchSort: false,
43
+ isDefaultValue: false,
44
+ defaultValue: [],
45
+ bsTableCode: '', //设置table 列的标识
46
+ };
47
+
48
+ patchUserColumnConfig = (config) => {
49
+ let that = this;
50
+ let configvalue = config
51
+ ? config.map((item) => ({
52
+ key: item.key,
53
+ dataIndex: item.dataIndex,
54
+ width: item.width,
55
+ hidden: item.hidden,
56
+ fixed: item.fixed,
57
+ }))
58
+ : '';
59
+ axios({
60
+ url: '/user/appConfig/saveUserOrder',
61
+ method: 'POST',
62
+ data: {
63
+ code: that.state.bsTableCode,
64
+ detail: configvalue ? JSON.stringify(configvalue) : '',
65
+ },
66
+ }).then((res:any) => {
67
+ if (res?.data?.status === '0') {
68
+ this.patchConfigToLocalstorage(configvalue)
69
+ } else {
70
+ message.error('保存表头列自定义失败,请稍后尝试');
71
+ }
72
+ })
73
+ };
74
+
75
+ getConfigFromlocalstorage = () => {
76
+ let config = localStorage.getItem(ENUM.BROWSER_CACHE.COLUMN_CONDITION) || '[]';
77
+ let configArray = JSON.parse(config);
78
+ let configSetting = configArray.filter(
79
+ (item) => item.code === this.state.bsTableCode,
80
+ );
81
+
82
+ if (configSetting.length && configSetting[0].detail) {
83
+ return JSON.parse(configSetting[0].detail);
84
+ }
85
+ return [];
86
+ };
87
+
88
+ patchConfigToLocalstorage = (configvalue) => {
89
+ const { setShowColumns } = this.props;
90
+ const { sortDataSource, bsTableCode } = this.state;
91
+ let config = localStorage.getItem(ENUM.BROWSER_CACHE.COLUMN_CONDITION) || '[]'
92
+ let configArray = JSON.parse(config)
93
+ let currentSetting = configArray.filter(item => item.code === bsTableCode)
94
+ if (currentSetting.length) {
95
+ currentSetting[0].detail = JSON.stringify(configvalue)
96
+ } else {
97
+ configArray.push({
98
+ "code": bsTableCode,
99
+ "detail": JSON.stringify(configvalue)
100
+ })
101
+ }
102
+
103
+ localStorage.setItem(ENUM.BROWSER_CACHE.COLUMN_CONDITION, JSON.stringify(configArray));
104
+ this.setState({
105
+ visible: false,
106
+ });
107
+ setShowColumns([...sortDataSource]);
108
+ };
109
+
110
+ setInitValue = (isClick = false) => {
111
+ const { datasource, showColumn }: any =
112
+ this.props;
113
+ let config = this.getConfigFromlocalstorage();
114
+
115
+ this.setState({
116
+ isDefaultValue: true,
117
+ dataSource: datasource.map((item) => {
118
+ let innerItem = config.filter(
119
+ (inneritem) => {
120
+ let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
121
+ let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
122
+ return innerKey && innerKey === itemKey;
123
+ }
124
+ );
125
+ return {
126
+ ...item,
127
+ key: item.key || item.dataIndex,
128
+ width: innerItem[0]?.width || item.width,
129
+ hidden: config.length ? !innerItem.length : item.hidden,
130
+ };
131
+ }),
132
+ defaultValue: datasource.map((item) => {
133
+ let innerItem = config.filter(
134
+ (inneritem) => {
135
+ let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
136
+ let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
137
+ return innerKey && innerKey === itemKey;
138
+ }
139
+ );
140
+ return {
141
+ ...item,
142
+ key: item.key || item.dataIndex,
143
+ width: innerItem[0]?.width || item.width,
144
+ hidden: config.length ? !innerItem.length : item.hidden,
145
+ };
146
+ }),
147
+ sortDataSource: [...showColumn]
148
+ });
149
+ };
150
+
151
+ componentDidMount() {
152
+ const { datasource, showColumn, bsTableCode }: any =
153
+ this.props;
154
+ let config = this.getConfigFromlocalstorage();
155
+
156
+ this.setState({
157
+ dataSource: datasource.map((item) => {
158
+ let innerItem = config.filter(
159
+ (inneritem) => {
160
+ let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
161
+ let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
162
+ return innerKey && innerKey === itemKey;
163
+ }
164
+ );
165
+ return {
166
+ ...item,
167
+ key: item.key || item.dataIndex,
168
+ width: innerItem[0]?.width || item.width,
169
+ hidden: config.length ? !innerItem.length : item.hidden,
170
+ };
171
+ }),
172
+ defaultValue: datasource.map((item) => {
173
+ let innerItem = config.filter(
174
+ (inneritem) => {
175
+ let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
176
+ let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
177
+ return innerKey && innerKey === itemKey;
178
+ }
179
+ );
180
+ return {
181
+ ...item,
182
+ key: item.key || item.dataIndex,
183
+ width: innerItem[0]?.width || item.width,
184
+ hidden: config.length ? !innerItem.length : item.hidden,
185
+ };
186
+ }),
187
+ sortDataSource: datasource
188
+ .filter((item) => !item.hidden)
189
+ .map((item) => ({
190
+ ...item,
191
+ key: item.key || item.dataIndex,
192
+ width:
193
+ showColumn.filter(
194
+ (inneritem) => {
195
+ let innerKey = Array.isArray(inneritem.key || inneritem.dataIndex) ? JSON.stringify(inneritem.key || inneritem.dataIndex) : (inneritem.key || inneritem.dataIndex);
196
+ let itemKey = Array.isArray(item.key || item.dataIndex) ? JSON.stringify(item.key || item.dataIndex) : (item.key || item.dataIndex);
197
+ return innerKey && innerKey === itemKey;
198
+ }
199
+ )[0]?.width || item.width,
200
+ })),
201
+ bsTableCode
202
+ });
203
+ }
204
+
205
+ columns = [
206
+ {
207
+ title: '列名称',
208
+ dataIndex: 'title',
209
+ className: 'drag-visible',
210
+ width: 100,
211
+ },
212
+ {
213
+ title: '列首',
214
+ dataIndex: 'fixedLeft',
215
+ render: (text, record) => {
216
+ return (
217
+ <span
218
+ onClick={() => {
219
+ const { sortDataSource } = this.state;
220
+ if (record?.fixed !== 'left') {
221
+ let newSortData = sortDataSource.map((item) => {
222
+ if (item.title === record.title) {
223
+ return {
224
+ ...item,
225
+ fixed: 'left',
226
+ };
227
+ }
228
+ return item;
229
+ });
230
+ this.setState({
231
+ sortDataSource: [
232
+ ...newSortData.filter((item) => item.fixed === 'left'),
233
+ ...newSortData.filter((item) => !item.fixed),
234
+ ...newSortData.filter((item) => item.fixed === 'right'),
235
+ ],
236
+ isDefaultValue: false,
237
+ dataSource: [
238
+ ...this.state.dataSource.map((item) => {
239
+ if (item.title === record.title) {
240
+ return {
241
+ ...item,
242
+ fixed: 'left',
243
+ };
244
+ }
245
+ return item;
246
+ }),
247
+ ],
248
+ });
249
+ } else {
250
+ let newSortData = sortDataSource.map((item) => {
251
+ if (item.title === record.title) {
252
+ return {
253
+ ...item,
254
+ fixed: null,
255
+ };
256
+ }
257
+ return item;
258
+ });
259
+ this.setState({
260
+ sortDataSource: [
261
+ ...newSortData.filter((item) => item.fixed === 'left'),
262
+ ...newSortData.filter((item) => !item.fixed),
263
+ ...newSortData.filter((item) => item.fixed === 'right'),
264
+ ],
265
+ isDefaultValue: false,
266
+ dataSource: [
267
+ ...this.state.dataSource.map((item) => {
268
+ if (item.title === record.title) {
269
+ return {
270
+ ...item,
271
+ fixed: null,
272
+ };
273
+ }
274
+ return item;
275
+ }),
276
+ ],
277
+ });
278
+ }
279
+ }}
280
+ >
281
+ <Tooltip
282
+ placement="top"
283
+ title={record?.fixed === 'left' ? '取消固定' : '固定列首'}
284
+ >
285
+ <img
286
+ src={record?.fixed === 'left' ? fixedLeftActive : fixedLeft}
287
+ />
288
+ </Tooltip>
289
+ </span>
290
+ );
291
+ },
292
+ },
293
+ {
294
+ title: '列尾',
295
+ dataIndex: 'fixedRight',
296
+ render: (text, record) => {
297
+ return (
298
+ <span
299
+ onClick={() => {
300
+ const { sortDataSource } = this.state;
301
+ if (record?.fixed !== 'right') {
302
+ let newSortData = sortDataSource.map((item) => {
303
+ if (item.title === record.title) {
304
+ return {
305
+ ...item,
306
+ fixed: 'right',
307
+ };
308
+ }
309
+ return item;
310
+ });
311
+ this.setState({
312
+ sortDataSource: [
313
+ ...newSortData.filter((item) => item.fixed === 'left'),
314
+ ...newSortData.filter((item) => !item.fixed),
315
+ ...newSortData.filter((item) => item.fixed === 'right'),
316
+ ],
317
+ isDefaultValue: false,
318
+ dataSource: [
319
+ ...this.state.dataSource.map((item) => {
320
+ if (item.title === record.title) {
321
+ return {
322
+ ...item,
323
+ fixed: 'right',
324
+ };
325
+ }
326
+ return item;
327
+ }),
328
+ ],
329
+ });
330
+ } else {
331
+ let newSortData = sortDataSource.map((item) => {
332
+ if (item.title === record.title) {
333
+ return {
334
+ ...item,
335
+ fixed: null,
336
+ };
337
+ }
338
+ return item;
339
+ });
340
+ this.setState({
341
+ sortDataSource: [
342
+ ...newSortData.filter((item) => item.fixed === 'left'),
343
+ ...newSortData.filter((item) => !item.fixed),
344
+ ...newSortData.filter((item) => item.fixed === 'right'),
345
+ ],
346
+ isDefaultValue: false,
347
+ dataSource: [
348
+ ...this.state.dataSource.map((item) => {
349
+ if (item.title === record.title) {
350
+ return {
351
+ ...item,
352
+ fixed: null,
353
+ };
354
+ }
355
+ return item;
356
+ }),
357
+ ],
358
+ });
359
+ }
360
+ }}
361
+ >
362
+ <Tooltip
363
+ placement="top"
364
+ title={record?.fixed === 'right' ? '取消固定' : '固定列尾'}
365
+ >
366
+ <img
367
+ src={record?.fixed === 'right' ? fixedRightActive : fixedRight}
368
+ />
369
+ </Tooltip>
370
+ </span>
371
+ );
372
+ },
373
+ },
374
+ {
375
+ title: '删除',
376
+ dataIndex: 'title1',
377
+ render: (text, record) => {
378
+ return (
379
+ <span
380
+ onClick={() => {
381
+ this.setState({
382
+ sortDataSource: this.state.sortDataSource.filter((item) => {
383
+ return item.title !== record.title;
384
+ }),
385
+ isDefaultValue: false,
386
+ dataSource: [
387
+ ...this.state.dataSource.map((item) => {
388
+ if (item.title === record.title) {
389
+ return {
390
+ ...item,
391
+ hidden: true,
392
+ };
393
+ }
394
+
395
+ return item;
396
+ }),
397
+ ],
398
+ });
399
+ }}
400
+ >
401
+ <img src={close} />
402
+ </span>
403
+ );
404
+ },
405
+ },
406
+ {
407
+ title: 'Sort',
408
+ dataIndex: 'sort',
409
+ className: 'drag-visible',
410
+ render: () => <DragHandle />,
411
+ },
412
+ ];
413
+
414
+ showModal = () => {
415
+ this.setState({
416
+ visible: true,
417
+ });
418
+ this.setInitValue();
419
+ };
420
+
421
+ handleOk = (e?: React.MouseEvent<HTMLElement>) => {
422
+ const { sortDataSource, isDefaultValue, defaultValue } = this.state;
423
+ if (!sortDataSource.length) {
424
+ message.warning('至少选择一列!');
425
+ return;
426
+ }
427
+ // if (isDefaultValue) {
428
+ // this.patchUserColumnConfig('');
429
+ // return;
430
+ // }
431
+ this.patchUserColumnConfig(sortDataSource);
432
+ };
433
+
434
+ handleCancel = (e: React.MouseEvent<HTMLElement>) => {
435
+ console.log(e);
436
+ this.setState({
437
+ visible: false,
438
+ });
439
+ };
440
+
441
+ handleTableHeadHidden = (title: string) => {
442
+ const { sortDataSource, dataSource } = this.state;
443
+ this.setState(
444
+ {
445
+ sortDataSource: sortDataSource.filter((item) => {
446
+ return item.title !== title;
447
+ }),
448
+ dataSource: [
449
+ ...dataSource.map((item) => {
450
+ if (item.title === title) {
451
+ return {
452
+ ...item,
453
+ hidden: true,
454
+ };
455
+ }
456
+
457
+ return item;
458
+ }),
459
+ ],
460
+ },
461
+ () => {
462
+ this.handleOk();
463
+ },
464
+ );
465
+ };
466
+
467
+ onSortEnd = ({ oldIndex, newIndex }) => {
468
+ const { sortDataSource } = this.state;
469
+ if (oldIndex !== newIndex) {
470
+ const newData = arrayMoveImmutable(
471
+ [].concat(sortDataSource),
472
+ oldIndex,
473
+ newIndex,
474
+ ).filter((el) => !!el);
475
+ this.setState({
476
+ sortDataSource: [
477
+ ...newData.filter((item) => item.fixed === 'left'),
478
+ ...newData.filter((item) => !item.fixed),
479
+ ...newData.filter((item) => item.fixed === 'right'),
480
+ ],
481
+ isDefaultValue: false,
482
+ });
483
+ }
484
+ };
485
+
486
+ DraggableContainer = (props) => (
487
+ <SortableBody
488
+ useDragHandle
489
+ disableAutoscroll
490
+ helperClass="row-dragging"
491
+ onSortEnd={this.onSortEnd}
492
+ {...props}
493
+ />
494
+ );
495
+
496
+ DraggableBodyRow = ({ className, style, ...restProps }) => {
497
+ const { sortDataSource } = this.state;
498
+ // function findIndex base on Table rowKey props and should always be a right array index
499
+ const index = sortDataSource.findIndex(
500
+ (x) => x.key === restProps['data-row-key'],
501
+ );
502
+ return <SortableItem index={index} {...restProps} />;
503
+ };
504
+
505
+ onChange = (e: CheckboxChangeEvent, title) => {
506
+ const { sortDataSource, dataSource } = this.state;
507
+ if (!e.target.checked) {
508
+ this.setState({
509
+ sortDataSource: sortDataSource.filter((item) => {
510
+ return item.title !== title;
511
+ }),
512
+ isDefaultValue: false,
513
+ dataSource: [
514
+ ...dataSource.map((item) => {
515
+ if (item.title === title) {
516
+ return {
517
+ ...item,
518
+ hidden: true,
519
+ };
520
+ }
521
+
522
+ return item;
523
+ }),
524
+ ],
525
+ });
526
+ } else {
527
+ let fixedLeft: any[] = [];
528
+ let fixedRight: any[] = [];
529
+ let noFixedSortSource: any = [];
530
+ let newSortData = [
531
+ ...sortDataSource,
532
+ ...dataSource
533
+ .filter((item) => item.title === title)
534
+ .map((source) => {
535
+ return {
536
+ ...source,
537
+ hidden: false,
538
+ };
539
+ }),
540
+ ];
541
+ newSortData.forEach((item) => {
542
+ if (item?.fixed === 'left') {
543
+ fixedLeft.push(item);
544
+ } else if (item?.fixed === 'right') {
545
+ fixedRight.push(item);
546
+ } else {
547
+ noFixedSortSource.push(item);
548
+ }
549
+ });
550
+ this.setState({
551
+ sortDataSource: [...fixedLeft, ...noFixedSortSource, ...fixedRight],
552
+ isDefaultValue: false,
553
+ dataSource: [
554
+ ...dataSource.map((item) => {
555
+ if (item.title === title) {
556
+ return {
557
+ ...item,
558
+ hidden: false,
559
+ };
560
+ }
561
+
562
+ return item;
563
+ }),
564
+ ],
565
+ });
566
+ }
567
+ };
568
+
569
+ handleReset = () => {
570
+ this.setInitValue(true);
571
+ };
572
+
573
+ onSearch = (e: any) => {
574
+ this.setState({
575
+ searchDataSource: e.target.value,
576
+ });
577
+ };
578
+
579
+ onSearchSort = (e: any) => {
580
+ this.setState({
581
+ onSearchSort: e.target.value,
582
+ });
583
+ };
584
+
585
+ render() {
586
+ const {
587
+ dataSource,
588
+ searchDataSource,
589
+ sortDataSource,
590
+ visible,
591
+ onSearchSort,
592
+ } = this.state;
593
+
594
+ let seatchDataSource = dataSource.filter(
595
+ (item) => item?.title?.indexOf(searchDataSource || '') > -1,
596
+ );
597
+
598
+ return (
599
+ <div className={'sort_table_wrapper'}>
600
+ {visible && (
601
+ <Modal
602
+ title="设置表头内容"
603
+ wrapClassName={'sort_table_wrapper'}
604
+ width={820}
605
+ visible={visible}
606
+ onOk={this.handleOk}
607
+ onCancel={this.handleCancel}
608
+ footer={[
609
+ <Button key="back" onClick={this.handleReset}>
610
+ 恢复默认
611
+ </Button>,
612
+ <Button key="submit" onClick={this.handleCancel}>
613
+ 取消
614
+ </Button>,
615
+ <Button key="submit" type="primary" onClick={this.handleOk}>
616
+ 确认
617
+ </Button>,
618
+ ]}
619
+ >
620
+ <div className={'sort_table'}>
621
+ <div className={'sort_table_column_wrapper'}>
622
+ <span className={'sort_table_column_count'}>
623
+ 可选字段 <span>(共{dataSource.length}个)</span>
624
+ </span>
625
+ <div className={'sort_table_column'}>
626
+ <Input
627
+ prefix={<SearchOutlined className="site-form-item-icon" />}
628
+ placeholder="搜索"
629
+ allowClear
630
+ onChange={this.onSearch}
631
+ style={{ width: 540 }}
632
+ />
633
+ <div>
634
+ {!searchDataSource && (
635
+ <Checkbox
636
+ checked={
637
+ !dataSource.some((item) => {
638
+ if (item.hidden) return true;
639
+
640
+ return false;
641
+ })
642
+ }
643
+ onClick={(e) => {
644
+ this.setState({
645
+ isDefaultValue: false,
646
+ dataSource: [
647
+ ...dataSource.map((item) => {
648
+ return {
649
+ ...item,
650
+ hidden: !e.target.checked,
651
+ };
652
+ }),
653
+ ],
654
+ sortDataSource: e.target.checked
655
+ ? [
656
+ ...dataSource
657
+ .filter((item) => item.fixed === 'left')
658
+ .map((item) => ({
659
+ ...item,
660
+ hidden: false,
661
+ })),
662
+ ...dataSource
663
+ .filter((item) => !item.fixed)
664
+ .map((item) => ({
665
+ ...item,
666
+ hidden: false,
667
+ })),
668
+ ...dataSource
669
+ .filter((item) => item.fixed === 'right')
670
+ .map((item) => ({
671
+ ...item,
672
+ hidden: false,
673
+ })),
674
+ ]
675
+ : [],
676
+ });
677
+ }}
678
+ >
679
+ 全选
680
+ </Checkbox>
681
+ )}
682
+ </div>
683
+ <div className={'sort_table_column_all'}>
684
+ {searchDataSource
685
+ ? seatchDataSource.map((item) => {
686
+ return (
687
+ <Checkbox
688
+ checked={!item.hidden}
689
+ onChange={(e) => {
690
+ this.onChange(e, item.title);
691
+ }}
692
+ >
693
+ {item.title}
694
+ </Checkbox>
695
+ );
696
+ })
697
+ : dataSource
698
+ .filter(
699
+ (item) =>
700
+ item?.title?.indexOf('人') === -1 &&
701
+ item?.title?.indexOf('日期') === -1,
702
+ )
703
+ .map((item) => {
704
+ return (
705
+ <Checkbox
706
+ checked={!item.hidden}
707
+ onChange={(e) => {
708
+ this.onChange(e, item.title);
709
+ }}
710
+ >
711
+ {item.title}
712
+ </Checkbox>
713
+ );
714
+ })}
715
+ {!!seatchDataSource.length && (
716
+ <span style={{ width: '144px' }}></span>
717
+ )}
718
+
719
+ {!seatchDataSource.length && (
720
+ <div className={'sort_table_column_all_empty'}>
721
+ 未查询到结果
722
+ </div>
723
+ )}
724
+ </div>
725
+ {!searchDataSource && (
726
+ <div>
727
+ <div className={'sort_table_column_special'}>
728
+ <span>人员时间字段</span>
729
+ </div>
730
+ <div className={'sort_table_column_all'}>
731
+ {[...dataSource]
732
+ .filter(
733
+ (item) =>
734
+ item?.title?.indexOf('人') > -1 ||
735
+ item?.title?.indexOf('日期') > -1,
736
+ )
737
+ .map((item) => {
738
+ return (
739
+ <Checkbox
740
+ checked={!item.hidden}
741
+ onChange={(e) => {
742
+ this.onChange(e, item.title);
743
+ }}
744
+ >
745
+ {item.title}
746
+ </Checkbox>
747
+ );
748
+ })}
749
+ <span style={{ width: '144px' }}></span>
750
+ </div>
751
+ </div>
752
+ )}
753
+ </div>
754
+ </div>
755
+ <div className={'sort_table_content_wrapper'}>
756
+ <span className={'sort_table_content_count'}>
757
+ 已选字段 <span>(共{sortDataSource.length}个)</span>
758
+ </span>
759
+ <div className={'sort_table_content'}>
760
+ <span style={{ paddingLeft: '10px' }}>
761
+ <Input
762
+ prefix={
763
+ <SearchOutlined className="site-form-item-icon" />
764
+ }
765
+ placeholder="搜索"
766
+ allowClear
767
+ onChange={this.onSearchSort}
768
+ style={{ width: 190 }}
769
+ />
770
+ </span>
771
+ <Table
772
+ pagination={false}
773
+ showHeader={false}
774
+ dataSource={
775
+ onSearchSort
776
+ ? sortDataSource.filter(
777
+ (item) => item?.title?.indexOf(onSearchSort) > -1,
778
+ )
779
+ : sortDataSource
780
+ }
781
+ columns={this.columns}
782
+ rowKey="key"
783
+ // rowSelection={rowSelection}
784
+ components={{
785
+ body: {
786
+ wrapper: this.DraggableContainer,
787
+ row: this.DraggableBodyRow,
788
+ },
789
+ }}
790
+ />
791
+ </div>
792
+ </div>
793
+ </div>
794
+ </Modal>
795
+ )}
796
+ <div onClick={this.showModal} style={{fontSize:14}}>列设置</div>
797
+ </div>
798
+ );
799
+ }
800
+ }
801
+
802
+ export default SortableTable;