@bit-sun/business-component 2.3.0 → 2.3.2

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 (201) 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/CustomerMenu/MenuSetting/index.d.ts +1 -1
  9. package/dist/components/Business/BsLayouts/Components/CustomerMenu/index.d.ts +1 -1
  10. package/dist/components/Business/SearchSelect/index.d.ts +1 -1
  11. package/dist/components/Business/moreTreeTable/FixedScrollBar.d.ts +1 -1
  12. package/dist/components/Functional/SearchSelect/index.d.ts +1 -1
  13. package/dist/index.esm.js +1212 -906
  14. package/dist/index.js +1218 -912
  15. package/dist/utils/utils.d.ts +1 -1
  16. package/docs/index.md +21 -21
  17. package/lib/assets/drag.svg +17 -17
  18. package/lib/assets/exportFail.svg +37 -37
  19. package/lib/assets/exportProcessing.svg +28 -28
  20. package/lib/assets/exportSuccess.svg +34 -34
  21. package/lib/assets/label_icon_bottom.svg +25 -25
  22. package/lib/assets/upExport.svg +22 -22
  23. package/package.json +78 -78
  24. package/src/assets/32.svg +27 -27
  25. package/src/assets/addIcon.svg +17 -17
  26. package/src/assets/allfunc.svg +27 -27
  27. package/src/assets/arrowRight.svg +24 -24
  28. package/src/assets/btn-delete.svg +29 -29
  29. package/src/assets/btn-edit.svg +19 -19
  30. package/src/assets/btn-more.svg +17 -17
  31. package/src/assets/btn-submit.svg +19 -19
  32. package/src/assets/caidan.svg +11 -11
  33. package/src/assets/close.svg +26 -26
  34. package/src/assets/drag.svg +17 -17
  35. package/src/assets/exportFail.svg +37 -37
  36. package/src/assets/exportProcessing.svg +28 -28
  37. package/src/assets/exportSuccess.svg +34 -34
  38. package/src/assets/fixed-left-active.svg +11 -11
  39. package/src/assets/fixed-left.svg +15 -15
  40. package/src/assets/fixed-right-active.svg +11 -11
  41. package/src/assets/fixed-right.svg +15 -15
  42. package/src/assets/guanbi.svg +15 -15
  43. package/src/assets/icon-quanping.svg +15 -15
  44. package/src/assets/icon-shezhi.svg +17 -17
  45. package/src/assets/label_icon_bottom.svg +25 -25
  46. package/src/assets/list-no-img.svg +21 -21
  47. package/src/assets/morentouxiang-32.svg +23 -23
  48. package/src/assets/scanning.svg +24 -24
  49. package/src/assets/upExport.svg +22 -22
  50. package/src/common/ENUM.ts +41 -41
  51. package/src/components/Business/AddSelectBusiness/index.md +161 -161
  52. package/src/components/Business/AddSelectBusiness/index.tsx +861 -861
  53. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +111 -111
  54. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  55. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  56. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  57. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  58. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  59. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  60. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  61. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  62. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  63. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  64. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  65. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  66. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +157 -157
  67. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  68. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  69. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +155 -155
  70. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  71. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  72. package/src/components/Business/BsLayouts/index.less +79 -79
  73. package/src/components/Business/BsLayouts/index.tsx +1484 -1484
  74. package/src/components/Business/BsLayouts/service.ts +10 -10
  75. package/src/components/Business/BsLayouts/utils.tsx +203 -203
  76. package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +564 -564
  77. package/src/components/Business/BsSulaQueryTable/index.less +221 -221
  78. package/src/components/Business/BsSulaQueryTable/index.tsx +527 -527
  79. package/src/components/Business/BsSulaQueryTable/setting.tsx +832 -832
  80. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  81. package/src/components/Business/BsSulaQueryTable/utils.tsx +688 -688
  82. package/src/components/Business/CommodityEntry/index.md +70 -70
  83. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  84. package/src/components/Business/CommonAlert/index.tsx +23 -23
  85. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  86. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  87. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  88. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  89. package/src/components/Business/DetailPageWrapper/index.tsx +313 -313
  90. package/src/components/Business/DetailPageWrapper/utils.tsx +100 -100
  91. package/src/components/Business/HomePageWrapper/index.less +33 -33
  92. package/src/components/Business/HomePageWrapper/index.md +45 -45
  93. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  94. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +824 -824
  95. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +205 -201
  96. package/src/components/Business/JsonQueryTable/components/Formula.tsx +205 -205
  97. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  98. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  99. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  100. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  101. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  102. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  103. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  104. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  105. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  106. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  107. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  108. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  109. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  110. package/src/components/Business/JsonQueryTable/index.less +16 -16
  111. package/src/components/Business/JsonQueryTable/index.md +328 -328
  112. package/src/components/Business/JsonQueryTable/index.tsx +535 -320
  113. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  114. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  115. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  116. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  117. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  118. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  119. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  120. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  121. package/src/components/Business/JsonQueryTable/static.ts +390 -390
  122. package/src/components/Business/SearchSelect/BusinessUtils.ts +1732 -1732
  123. package/src/components/Business/SearchSelect/common.ts +53 -53
  124. package/src/components/Business/SearchSelect/index.md +1319 -1319
  125. package/src/components/Business/SearchSelect/index.tsx +51 -51
  126. package/src/components/Business/SearchSelect/utils.ts +100 -100
  127. package/src/components/Business/StateFlow/index.less +130 -130
  128. package/src/components/Business/StateFlow/index.md +60 -60
  129. package/src/components/Business/StateFlow/index.tsx +29 -29
  130. package/src/components/Business/TreeSearchSelect/index.md +154 -154
  131. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  132. package/src/components/Business/TreeSearchSelect/utils.ts +69 -69
  133. package/src/components/Business/columnSettingTable/columnSetting.tsx +764 -764
  134. package/src/components/Business/columnSettingTable/index.less +247 -247
  135. package/src/components/Business/columnSettingTable/index.md +357 -357
  136. package/src/components/Business/columnSettingTable/index.tsx +232 -232
  137. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +240 -240
  138. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  139. package/src/components/Business/moreTreeTable/FixedScrollBar.tsx +86 -86
  140. package/src/components/Business/moreTreeTable/hooks/useSticky.ts +21 -21
  141. package/src/components/Business/moreTreeTable/index.less +99 -99
  142. package/src/components/Business/moreTreeTable/index.md +448 -448
  143. package/src/components/Business/moreTreeTable/index.tsx +380 -380
  144. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  145. package/src/components/Functional/AddSelect/helps.ts +14 -14
  146. package/src/components/Functional/AddSelect/index.less +367 -367
  147. package/src/components/Functional/AddSelect/index.md +155 -155
  148. package/src/components/Functional/AddSelect/index.tsx +1279 -1279
  149. package/src/components/Functional/BillEntry/index.less +371 -371
  150. package/src/components/Functional/BillEntry/index.md +39 -39
  151. package/src/components/Functional/BillEntry/index.tsx +772 -772
  152. package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -62
  153. package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -178
  154. package/src/components/Functional/BsAntdSula/index.ts +2 -2
  155. package/src/components/Functional/DataImport/index.less +63 -63
  156. package/src/components/Functional/DataImport/index.md +44 -44
  157. package/src/components/Functional/DataImport/index.tsx +695 -695
  158. package/src/components/Functional/DataValidation/index.less +63 -63
  159. package/src/components/Functional/DataValidation/index.md +39 -39
  160. package/src/components/Functional/DataValidation/index.tsx +687 -687
  161. package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -5
  162. package/src/components/Functional/EllipsisTooltip/index.js +36 -36
  163. package/src/components/Functional/EllipsisTooltip/index.md +30 -30
  164. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  165. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  166. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  167. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  168. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  169. package/src/components/Functional/SearchSelect/index.less +115 -115
  170. package/src/components/Functional/SearchSelect/index.md +141 -141
  171. package/src/components/Functional/SearchSelect/index.tsx +859 -849
  172. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  173. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  174. package/src/components/Functional/TreeSearchSelect/index.tsx +162 -162
  175. package/src/components/Solution/RuleComponent/Formula.tsx +335 -335
  176. package/src/components/Solution/RuleComponent/index.d.ts +29 -29
  177. package/src/components/Solution/RuleComponent/index.js +2028 -2028
  178. package/src/components/Solution/RuleComponent/index.less +230 -230
  179. package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -99
  180. package/src/components/Solution/RuleComponent/ruleFiled.js +2074 -2074
  181. package/src/components/Solution/RuleComponent/services.ts +13 -13
  182. package/src/components/Solution/RuleComponent/util.js +139 -139
  183. package/src/index.ts +38 -38
  184. package/src/plugin/TableColumnSetting/index.less +247 -247
  185. package/src/plugin/TableColumnSetting/index.md +50 -50
  186. package/src/plugin/TableColumnSetting/index.tsx +724 -724
  187. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  188. package/src/styles/bsDefault.less +1912 -1912
  189. package/src/utils/CheckOneUser/index.md +39 -39
  190. package/src/utils/CheckOneUser/index.ts +51 -51
  191. package/src/utils/LocalstorageUtils.ts +90 -90
  192. package/src/utils/TableUtils.tsx +18 -18
  193. package/src/utils/checkUtils.ts +39 -39
  194. package/src/utils/enumConfig.ts +11 -11
  195. package/src/utils/getFormMode.js +12 -12
  196. package/src/utils/index.ts +4 -4
  197. package/src/utils/requestUtils.ts +34 -34
  198. package/src/utils/serialize.js +7 -7
  199. package/src/utils/utils.ts +212 -212
  200. package/tsconfig.json +29 -29
  201. package/typings.d.ts +4 -4
@@ -1,832 +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 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;
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;