@bit-sun/business-component 2.1.17 → 2.1.18

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