@bit-sun/business-component 2.2.44 → 2.2.46

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