@bit-sun/business-component 2.4.19 → 2.4.21

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