@bit-sun/business-component 2.3.22-beta1 → 2.3.22-beta10

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