@bit-sun/business-component 2.0.38 → 2.0.39-alpha.1

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