@bit-sun/business-component 3.1.10-alpha.1 → 3.1.10-alpha.10

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 (223) 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/Functional/AddSelect/index.d.ts +1 -1
  9. package/dist/index.esm.js +476 -202
  10. package/dist/index.js +477 -203
  11. package/docs/index.md +21 -21
  12. package/lib/assets/drag.svg +17 -17
  13. package/lib/assets/exportFail.svg +37 -37
  14. package/lib/assets/exportProcessing.svg +28 -28
  15. package/lib/assets/exportSuccess.svg +34 -34
  16. package/lib/assets/label_icon_bottom.svg +25 -25
  17. package/lib/assets/upExport.svg +22 -22
  18. package/package.json +88 -88
  19. package/src/assets/32.svg +27 -27
  20. package/src/assets/addIcon.svg +17 -17
  21. package/src/assets/allfunc.svg +27 -27
  22. package/src/assets/arrowRight.svg +24 -24
  23. package/src/assets/arrow_top.svg +17 -17
  24. package/src/assets/btn-delete.svg +29 -29
  25. package/src/assets/btn-edit.svg +19 -19
  26. package/src/assets/btn-more.svg +17 -17
  27. package/src/assets/btn-submit.svg +19 -19
  28. package/src/assets/caidan.svg +11 -11
  29. package/src/assets/close.svg +26 -26
  30. package/src/assets/drag.svg +17 -17
  31. package/src/assets/exportFail.svg +37 -37
  32. package/src/assets/exportProcessing.svg +28 -28
  33. package/src/assets/exportSuccess.svg +34 -34
  34. package/src/assets/fixed-left-active.svg +11 -11
  35. package/src/assets/fixed-left.svg +15 -15
  36. package/src/assets/fixed-right-active.svg +11 -11
  37. package/src/assets/fixed-right.svg +15 -15
  38. package/src/assets/guanbi.svg +15 -15
  39. package/src/assets/icon-quanping.svg +15 -15
  40. package/src/assets/icon-shezhi.svg +17 -17
  41. package/src/assets/label_icon_bottom.svg +25 -25
  42. package/src/assets/list-no-img.svg +21 -21
  43. package/src/assets/morentouxiang-32.svg +23 -23
  44. package/src/assets/scanning.svg +24 -24
  45. package/src/assets/upExport.svg +22 -22
  46. package/src/common/ENUM.ts +41 -41
  47. package/src/components/Business/AddSelectBusiness/index.md +398 -398
  48. package/src/components/Business/AddSelectBusiness/index.tsx +1116 -1116
  49. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +112 -112
  50. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  51. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  52. package/src/components/Business/BsLayouts/Components/ChooseStore/index.tsx +193 -193
  53. package/src/components/Business/BsLayouts/Components/ChooseStore/services.ts +10 -10
  54. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  55. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  56. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  57. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  58. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  59. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  60. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  61. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  62. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  63. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  64. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +163 -163
  65. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  66. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  67. package/src/components/Business/BsLayouts/Components/RightContent/i18n.ts +8 -8
  68. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +172 -172
  69. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  70. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  71. package/src/components/Business/BsLayouts/index.less +79 -79
  72. package/src/components/Business/BsLayouts/index.tsx +1606 -1606
  73. package/src/components/Business/BsLayouts/service.ts +10 -10
  74. package/src/components/Business/BsLayouts/utils.tsx +205 -205
  75. package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +568 -566
  76. package/src/components/Business/BsSulaQueryTable/bssulaquerytable.less +5 -5
  77. package/src/components/Business/BsSulaQueryTable/index.less +227 -227
  78. package/src/components/Business/BsSulaQueryTable/index.tsx +767 -767
  79. package/src/components/Business/BsSulaQueryTable/setting.tsx +890 -888
  80. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  81. package/src/components/Business/BsSulaQueryTable/utils.tsx +709 -709
  82. package/src/components/Business/CommodityEntry/index.md +84 -84
  83. package/src/components/Business/CommodityEntry/index.tsx +82 -82
  84. package/src/components/Business/CommonAlert/index.tsx +23 -23
  85. package/src/components/Business/CommonGuideWrapper/index.less +121 -121
  86. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  87. package/src/components/Business/CommonGuideWrapper/index.tsx +94 -94
  88. package/src/components/Business/DetailPageWrapper/index.less +87 -87
  89. package/src/components/Business/DetailPageWrapper/index.tsx +327 -327
  90. package/src/components/Business/DetailPageWrapper/utils.tsx +166 -166
  91. package/src/components/Business/HomePageWrapper/index.less +33 -33
  92. package/src/components/Business/HomePageWrapper/index.md +45 -45
  93. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  94. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +823 -823
  95. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +205 -205
  96. package/src/components/Business/JsonQueryTable/components/Formula.tsx +205 -205
  97. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  98. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  99. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  100. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  101. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  102. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  103. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  104. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  105. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  106. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  107. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  108. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  109. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  110. package/src/components/Business/JsonQueryTable/index.less +16 -16
  111. package/src/components/Business/JsonQueryTable/index.md +328 -328
  112. package/src/components/Business/JsonQueryTable/index.tsx +534 -534
  113. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  114. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  115. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  116. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  117. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  118. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  119. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  120. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  121. package/src/components/Business/JsonQueryTable/static.ts +450 -450
  122. package/src/components/Business/SearchSelect/BusinessUtils.tsx +2326 -2318
  123. package/src/components/Business/SearchSelect/common.ts +134 -134
  124. package/src/components/Business/SearchSelect/index.md +1570 -1570
  125. package/src/components/Business/SearchSelect/index.tsx +55 -55
  126. package/src/components/Business/SearchSelect/utils.ts +125 -125
  127. package/src/components/Business/StateFlow/index.less +130 -130
  128. package/src/components/Business/StateFlow/index.md +60 -60
  129. package/src/components/Business/StateFlow/index.tsx +29 -29
  130. package/src/components/Business/TreeSearchSelect/index.md +239 -239
  131. package/src/components/Business/TreeSearchSelect/index.tsx +33 -33
  132. package/src/components/Business/TreeSearchSelect/utils.ts +115 -115
  133. package/src/components/Business/columnSettingTable/columnSetting.tsx +818 -816
  134. package/src/components/Business/columnSettingTable/index.less +253 -253
  135. package/src/components/Business/columnSettingTable/index.md +372 -372
  136. package/src/components/Business/columnSettingTable/index.tsx +225 -225
  137. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +232 -232
  138. package/src/components/Business/columnSettingTable/utils.tsx +87 -87
  139. package/src/components/Business/moreTreeTable/FixedScrollBar.tsx +87 -87
  140. package/src/components/Business/moreTreeTable/hooks/useSticky.ts +21 -21
  141. package/src/components/Business/moreTreeTable/index.less +99 -99
  142. package/src/components/Business/moreTreeTable/index.md +448 -448
  143. package/src/components/Business/moreTreeTable/index.tsx +387 -387
  144. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  145. package/src/components/Functional/AccessWrapper/index.tsx +33 -33
  146. package/src/components/Functional/AddSelect/helps.ts +81 -81
  147. package/src/components/Functional/AddSelect/index.less +367 -367
  148. package/src/components/Functional/AddSelect/index.md +155 -155
  149. package/src/components/Functional/AddSelect/index.tsx +1088 -1072
  150. package/src/components/Functional/AuthButton/index.tsx +15 -15
  151. package/src/components/Functional/BillEntry/index.less +371 -371
  152. package/src/components/Functional/BillEntry/index.md +39 -39
  153. package/src/components/Functional/BillEntry/index.tsx +771 -771
  154. package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -62
  155. package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -178
  156. package/src/components/Functional/BsAntdSula/index.ts +2 -2
  157. package/src/components/Functional/DataImport/index.less +63 -63
  158. package/src/components/Functional/DataImport/index.md +44 -44
  159. package/src/components/Functional/DataImport/index.tsx +782 -782
  160. package/src/components/Functional/DataValidation/index.less +63 -63
  161. package/src/components/Functional/DataValidation/index.md +52 -52
  162. package/src/components/Functional/DataValidation/index.tsx +788 -788
  163. package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -5
  164. package/src/components/Functional/EllipsisTooltip/index.js +36 -36
  165. package/src/components/Functional/EllipsisTooltip/index.md +30 -30
  166. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  167. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +65 -65
  168. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  169. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  170. package/src/components/Functional/QueryMutipleInput/index.tsx +129 -129
  171. package/src/components/Functional/SearchSelect/index.less +121 -121
  172. package/src/components/Functional/SearchSelect/index.md +141 -141
  173. package/src/components/Functional/SearchSelect/index.tsx +1046 -1046
  174. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  175. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  176. package/src/components/Functional/TreeSearchSelect/index.tsx +224 -224
  177. package/src/components/Solution/RuleComponent/CustomPlugin/CustomSelector/CustomSelectorModal.tsx +358 -358
  178. package/src/components/Solution/RuleComponent/CustomPlugin/CustomSelector/function.js +255 -255
  179. package/src/components/Solution/RuleComponent/CustomPlugin/CustomSelector/helps.tsx +57 -57
  180. package/src/components/Solution/RuleComponent/CustomPlugin/CustomSelector/index.tsx +129 -129
  181. package/src/components/Solution/RuleComponent/Formula.tsx +335 -335
  182. package/src/components/Solution/RuleComponent/InnerSelect.tsx +62 -62
  183. package/src/components/Solution/RuleComponent/RenderCompItem.tsx +774 -774
  184. package/src/components/Solution/RuleComponent/index.d.ts +34 -29
  185. package/src/components/Solution/RuleComponent/index.js +1680 -1663
  186. package/src/components/Solution/RuleComponent/index.less +247 -247
  187. package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -99
  188. package/src/components/Solution/RuleComponent/ruleFiled.js +2695 -2695
  189. package/src/components/Solution/RuleComponent/services.ts +13 -13
  190. package/src/components/Solution/RuleComponent/util.js +143 -143
  191. package/src/components/Solution/RuleSetter/RuleInstance.tsx +6 -6
  192. package/src/components/Solution/RuleSetter/baseRule.tsx +414 -414
  193. package/src/components/Solution/RuleSetter/function.ts +467 -467
  194. package/src/components/Solution/RuleSetter/index.less +221 -221
  195. package/src/components/Solution/RuleSetter/index.tsx +210 -210
  196. package/src/components/Solution/RuleSetter/service.js +276 -276
  197. package/src/index.ts +42 -42
  198. package/src/plugin/TableColumnSetting/index.less +247 -247
  199. package/src/plugin/TableColumnSetting/index.md +50 -50
  200. package/src/plugin/TableColumnSetting/index.tsx +725 -725
  201. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  202. package/src/styles/bsDefault.less +1933 -1933
  203. package/src/utils/CheckOneUser/index.md +39 -39
  204. package/src/utils/CheckOneUser/index.ts +51 -51
  205. package/src/utils/CustomLoginInfo.ts +55 -55
  206. package/src/utils/LocalstorageUtils.ts +134 -134
  207. package/src/utils/TableUtils.less +51 -51
  208. package/src/utils/TableUtils.tsx +691 -691
  209. package/src/utils/TreeUtils.ts +12 -12
  210. package/src/utils/auth.ts +38 -38
  211. package/src/utils/businessUtils.ts +434 -434
  212. package/src/utils/checkUtils.ts +39 -39
  213. package/src/utils/constant.ts +38 -38
  214. package/src/utils/enumConfig.ts +17 -17
  215. package/src/utils/getFormMode.js +12 -12
  216. package/src/utils/index.ts +21 -21
  217. package/src/utils/request.ts +53 -53
  218. package/src/utils/requestUtils.ts +197 -197
  219. package/src/utils/serialize.js +7 -7
  220. package/src/utils/utils.ts +266 -266
  221. package/src/utils/xlsxUtil.tsx +145 -145
  222. package/tsconfig.json +29 -29
  223. package/typings.d.ts +4 -4
@@ -1,888 +1,890 @@
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
+ onSearchSort: false,
476
+ searchDataSource: false,
477
+ });
478
+ this.setInitValue();
479
+ };
480
+
481
+ handleOk = (e?: React.MouseEvent<HTMLElement>) => {
482
+ const { sortDataSource, isDefaultValue, defaultValue } = this.state;
483
+ if (!sortDataSource.length) {
484
+ message.warning('至少选择一列!');
485
+ return;
486
+ }
487
+ // if (isDefaultValue) {
488
+ // this.patchUserColumnConfig('');
489
+ // return;
490
+ // }
491
+ this.patchUserColumnConfig(sortDataSource);
492
+ };
493
+
494
+ handleCancel = (e: React.MouseEvent<HTMLElement>) => {
495
+ this.setState({
496
+ visible: false,
497
+ });
498
+ };
499
+
500
+ handleTableHeadHidden = (title: string) => {
501
+ const { sortDataSource, dataSource } = this.state;
502
+ this.setState(
503
+ {
504
+ sortDataSource: sortDataSource.filter((item) => {
505
+ return item.title !== title;
506
+ }),
507
+ dataSource: [
508
+ ...dataSource.map((item) => {
509
+ if (item.title === title) {
510
+ return {
511
+ ...item,
512
+ hidden: true,
513
+ };
514
+ }
515
+
516
+ return item;
517
+ }),
518
+ ],
519
+ },
520
+ () => {
521
+ this.handleOk();
522
+ },
523
+ );
524
+ };
525
+
526
+ onSortEnd = ({ oldIndex, newIndex }) => {
527
+ const { sortDataSource } = this.state;
528
+ if (oldIndex !== newIndex) {
529
+ const newData = arrayMoveImmutable(
530
+ [].concat(sortDataSource),
531
+ oldIndex,
532
+ newIndex,
533
+ ).filter((el) => !!el);
534
+ this.setState({
535
+ sortDataSource: [
536
+ ...newData.filter((item) => item.fixed === 'left'),
537
+ ...newData.filter((item) => !item.fixed),
538
+ ...newData.filter((item) => item.fixed === 'right'),
539
+ ],
540
+ isDefaultValue: false,
541
+ });
542
+ }
543
+ };
544
+
545
+ DraggableContainer = (props) => (
546
+ <SortableBody
547
+ useDragHandle
548
+ disableAutoscroll
549
+ helperClass="row-dragging"
550
+ onSortEnd={this.onSortEnd}
551
+ {...props}
552
+ />
553
+ );
554
+
555
+ DraggableBodyRow = ({ className, style, ...restProps }) => {
556
+ const { sortDataSource } = this.state;
557
+ // function findIndex base on Table rowKey props and should always be a right array index
558
+ const index = sortDataSource.findIndex(
559
+ (x) => x.key === restProps['data-row-key'],
560
+ );
561
+ return <SortableItem index={index} {...restProps} />;
562
+ };
563
+
564
+
565
+
566
+ onChange = (e: CheckboxChangeEvent, title) => {
567
+ const { sortDataSource, dataSource } = this.state;
568
+
569
+ if (!e.target.checked) {
570
+ this.setState({
571
+ sortDataSource: sortDataSource.filter((item) => {
572
+ return renderToString(item.title) !== renderToString(title);
573
+ }),
574
+ isDefaultValue: false,
575
+ dataSource: [
576
+ ...dataSource.map((item) => {
577
+ if (renderToString(item.title) === renderToString(title)) {
578
+ return {
579
+ ...item,
580
+ hidden: true,
581
+ };
582
+ }
583
+ return item;
584
+ }),
585
+ ],
586
+ });
587
+ } else {
588
+ let fixedLeft: any[] = [];
589
+ let fixedRight: any[] = [];
590
+ let noFixedSortSource: any = [];
591
+ let newSortData = [
592
+ ...sortDataSource,
593
+ ...dataSource
594
+ .filter((item) => renderToString(item.title) === renderToString(title))
595
+ .map((source) => {
596
+ return {
597
+ ...source,
598
+ hidden: false,
599
+ };
600
+ }),
601
+ ];
602
+ newSortData.forEach((item) => {
603
+ if (item?.fixed === 'left') {
604
+ fixedLeft.push(item);
605
+ } else if (item?.fixed === 'right') {
606
+ fixedRight.push(item);
607
+ } else {
608
+ noFixedSortSource.push(item);
609
+ }
610
+ });
611
+ this.setState({
612
+ sortDataSource: [...fixedLeft, ...noFixedSortSource, ...fixedRight],
613
+ isDefaultValue: false,
614
+ dataSource: [
615
+ ...dataSource.map((item) => {
616
+ if (renderToString(item.title) === renderToString(title)) {
617
+ return {
618
+ ...item,
619
+ hidden: false,
620
+ };
621
+ }
622
+
623
+ return item;
624
+ }),
625
+ ],
626
+ });
627
+ }
628
+ };
629
+
630
+ handleReset = () => {
631
+ this.setInitValue(true);
632
+ };
633
+
634
+ handleResetSetting = () => {
635
+ this.patchUserColumnConfig('');
636
+ };
637
+
638
+ onSearch = (e: any) => {
639
+ this.setState({
640
+ searchDataSource: e.target.value,
641
+ });
642
+ };
643
+
644
+ onSearchSort = (e: any) => {
645
+ this.setState({
646
+ onSearchSort: e.target.value,
647
+ });
648
+ };
649
+
650
+
651
+ render() {
652
+ const { onlyModal } = this.props;
653
+ const {
654
+ dataSource,
655
+ searchDataSource,
656
+ sortDataSource,
657
+ visible,
658
+ onSearchSort,
659
+ } = this.state;
660
+
661
+ let seatchDataSource = dataSource.filter(
662
+ (item) =>
663
+ renderToString(item?.title)?.indexOf?.(searchDataSource || '') > -1,
664
+ );
665
+
666
+ return (
667
+ <div className={'sort_table_wrapper'}>
668
+ {visible && (
669
+ <Modal
670
+ title="设置表头内容"
671
+ wrapClassName={'sort_table_wrapper'}
672
+ width={820}
673
+ visible={visible}
674
+ onOk={this.handleOk}
675
+ onCancel={this.handleCancel}
676
+ footer={[
677
+ <div>
678
+ <Button
679
+ key="back"
680
+ onClick={this.handleReset}
681
+ style={{ marginRight: 0 }}
682
+ >
683
+ 恢复默认
684
+ </Button>
685
+ <Button key="back" onClick={this.handleResetSetting}>
686
+ 重置设置
687
+ </Button>
688
+ <span style={{fontSize: '12px', color: '8A8F8D'}}>(列表字段变更会影响列设置功能,变更后请点击重置然后重新设置)</span>
689
+ </div>,
690
+ <div>
691
+ <Button
692
+ key="submit"
693
+ onClick={this.handleCancel}
694
+ style={{ marginRight: 0 }}
695
+ >
696
+ 取消
697
+ </Button>
698
+ <Button key="submit" type="primary" onClick={this.handleOk}>
699
+ 确认
700
+ </Button>
701
+ </div>,
702
+ ]}
703
+ >
704
+ <div className={'sort_table'}>
705
+ <div className={'sort_table_column_wrapper'}>
706
+ <span className={'sort_table_column_count'}>
707
+ 可选字段 <span>(共{dataSource.length}个)</span>
708
+ </span>
709
+ <div className={'sort_table_column'}>
710
+ <Input
711
+ prefix={<SearchOutlined className="site-form-item-icon" />}
712
+ placeholder="搜索"
713
+ allowClear
714
+ onChange={this.onSearch}
715
+ style={{ width: 540 }}
716
+ />
717
+ <div>
718
+ {!searchDataSource && (
719
+ <Checkbox
720
+ checked={
721
+ !dataSource.some((item) => {
722
+ if (item.hidden) return true;
723
+
724
+ return false;
725
+ })
726
+ }
727
+ onClick={(e) => {
728
+ this.setState({
729
+ isDefaultValue: false,
730
+ dataSource: [
731
+ ...dataSource.map((item) => {
732
+ return {
733
+ ...item,
734
+ hidden: !e.target.checked,
735
+ };
736
+ }),
737
+ ],
738
+ sortDataSource: e.target.checked
739
+ ? [
740
+ ...dataSource
741
+ .filter((item) => item.fixed === 'left')
742
+ .map((item) => ({
743
+ ...item,
744
+ hidden: false,
745
+ })),
746
+ ...dataSource
747
+ .filter((item) => !item.fixed)
748
+ .map((item) => ({
749
+ ...item,
750
+ hidden: false,
751
+ })),
752
+ ...dataSource
753
+ .filter((item) => item.fixed === 'right')
754
+ .map((item) => ({
755
+ ...item,
756
+ hidden: false,
757
+ })),
758
+ ]
759
+ : [],
760
+ });
761
+ }}
762
+ >
763
+ 全选
764
+ </Checkbox>
765
+ )}
766
+ </div>
767
+ <div className={'sort_table_column_all'}>
768
+ {searchDataSource
769
+ ? seatchDataSource.map((item) => {
770
+ return (
771
+ <Checkbox
772
+ checked={!item.hidden}
773
+ onChange={(e) => {
774
+ this.onChange(e, item.title);
775
+ }}
776
+ >
777
+ {item.title}
778
+ </Checkbox>
779
+ );
780
+ })
781
+ : dataSource
782
+ .filter(
783
+ (item) =>
784
+ {const title = renderToString(item.title)
785
+ return (title?.indexOf?.('人') === -1 &&
786
+ title?.indexOf?.('日期') === -1)})
787
+ .map((item) => {
788
+ return (
789
+ <Checkbox
790
+ checked={!item.hidden}
791
+ onChange={(e) => {
792
+ this.onChange(e, item.title);
793
+ }}
794
+ >
795
+ {item.title}
796
+ </Checkbox>
797
+ );
798
+ })}
799
+ {!!seatchDataSource.length && (
800
+ <span style={{ width: '144px' }}></span>
801
+ )}
802
+
803
+ {!seatchDataSource.length && (
804
+ <div className={'sort_table_column_all_empty'}>
805
+ 未查询到结果
806
+ </div>
807
+ )}
808
+ </div>
809
+ {!searchDataSource && (
810
+ <div>
811
+ <div className={'sort_table_column_special'}>
812
+ <span>人员时间字段</span>
813
+ </div>
814
+ <div className={'sort_table_column_all'}>
815
+ {[...dataSource]
816
+ .filter(
817
+ (item) =>
818
+ item?.title?.indexOf?.('人') > -1 ||
819
+ item?.title?.indexOf?.('日期') > -1,
820
+ )
821
+ .map((item) => {
822
+ return (
823
+ <Checkbox
824
+ checked={!item.hidden}
825
+ onChange={(e) => {
826
+ this.onChange(e, item.title);
827
+ }}
828
+ >
829
+ {item.title}
830
+ </Checkbox>
831
+ );
832
+ })}
833
+ <span style={{ width: '144px' }}></span>
834
+ </div>
835
+ </div>
836
+ )}
837
+ </div>
838
+ </div>
839
+ <div className={'sort_table_content_wrapper'}>
840
+ <span className={'sort_table_content_count'}>
841
+ 已选字段 <span>(共{sortDataSource.length}个)</span>
842
+ </span>
843
+ <div className={'sort_table_content'}>
844
+ <span style={{ paddingLeft: '10px' }}>
845
+ <Input
846
+ prefix={
847
+ <SearchOutlined className="site-form-item-icon" />
848
+ }
849
+ placeholder="搜索"
850
+ allowClear
851
+ onChange={this.onSearchSort}
852
+ style={{ width: 190 }}
853
+ />
854
+ </span>
855
+ <Table
856
+ pagination={false}
857
+ showHeader={false}
858
+ dataSource={
859
+ onSearchSort
860
+ ? sortDataSource.filter(
861
+ (item) => renderToString(item?.title)?.indexOf(onSearchSort) > -1,
862
+ )
863
+ : sortDataSource
864
+ }
865
+ columns={this.columns}
866
+ rowKey="key"
867
+ // rowSelection={rowSelection}
868
+ components={{
869
+ body: {
870
+ wrapper: this.DraggableContainer,
871
+ row: this.DraggableBodyRow,
872
+ },
873
+ }}
874
+ />
875
+ </div>
876
+ </div>
877
+ </div>
878
+ </Modal>
879
+ )}
880
+ {
881
+ !onlyModal
882
+ ? <div onClick={this.showModal} style={{fontSize:14}}>列设置</div>
883
+ : ''
884
+ }
885
+ </div>
886
+ );
887
+ }
888
+ }
889
+
890
+ export default SortableTable;