@bit-sun/business-component 3.1.6 → 3.1.8

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