@bit-sun/business-component 2.3.21 → 2.3.23

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