@bit-sun/business-component 2.3.7 → 2.3.9

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