@bit-sun/business-component 3.1.4 → 3.1.6

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