@bit-sun/business-component 2.1.4 → 2.1.5

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