@bit-sun/business-component 2.3.0 → 2.3.2

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 (201) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -5
  3. package/.gitlab-ci.yml +179 -179
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.d.ts +1 -1
  9. package/dist/components/Business/BsLayouts/Components/CustomerMenu/index.d.ts +1 -1
  10. package/dist/components/Business/SearchSelect/index.d.ts +1 -1
  11. package/dist/components/Business/moreTreeTable/FixedScrollBar.d.ts +1 -1
  12. package/dist/components/Functional/SearchSelect/index.d.ts +1 -1
  13. package/dist/index.esm.js +1212 -906
  14. package/dist/index.js +1218 -912
  15. package/dist/utils/utils.d.ts +1 -1
  16. package/docs/index.md +21 -21
  17. package/lib/assets/drag.svg +17 -17
  18. package/lib/assets/exportFail.svg +37 -37
  19. package/lib/assets/exportProcessing.svg +28 -28
  20. package/lib/assets/exportSuccess.svg +34 -34
  21. package/lib/assets/label_icon_bottom.svg +25 -25
  22. package/lib/assets/upExport.svg +22 -22
  23. package/package.json +78 -78
  24. package/src/assets/32.svg +27 -27
  25. package/src/assets/addIcon.svg +17 -17
  26. package/src/assets/allfunc.svg +27 -27
  27. package/src/assets/arrowRight.svg +24 -24
  28. package/src/assets/btn-delete.svg +29 -29
  29. package/src/assets/btn-edit.svg +19 -19
  30. package/src/assets/btn-more.svg +17 -17
  31. package/src/assets/btn-submit.svg +19 -19
  32. package/src/assets/caidan.svg +11 -11
  33. package/src/assets/close.svg +26 -26
  34. package/src/assets/drag.svg +17 -17
  35. package/src/assets/exportFail.svg +37 -37
  36. package/src/assets/exportProcessing.svg +28 -28
  37. package/src/assets/exportSuccess.svg +34 -34
  38. package/src/assets/fixed-left-active.svg +11 -11
  39. package/src/assets/fixed-left.svg +15 -15
  40. package/src/assets/fixed-right-active.svg +11 -11
  41. package/src/assets/fixed-right.svg +15 -15
  42. package/src/assets/guanbi.svg +15 -15
  43. package/src/assets/icon-quanping.svg +15 -15
  44. package/src/assets/icon-shezhi.svg +17 -17
  45. package/src/assets/label_icon_bottom.svg +25 -25
  46. package/src/assets/list-no-img.svg +21 -21
  47. package/src/assets/morentouxiang-32.svg +23 -23
  48. package/src/assets/scanning.svg +24 -24
  49. package/src/assets/upExport.svg +22 -22
  50. package/src/common/ENUM.ts +41 -41
  51. package/src/components/Business/AddSelectBusiness/index.md +161 -161
  52. package/src/components/Business/AddSelectBusiness/index.tsx +861 -861
  53. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +111 -111
  54. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  55. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  56. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  57. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  58. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  59. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  60. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  61. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  62. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  63. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  64. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  65. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  66. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +157 -157
  67. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  68. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  69. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +155 -155
  70. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  71. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  72. package/src/components/Business/BsLayouts/index.less +79 -79
  73. package/src/components/Business/BsLayouts/index.tsx +1484 -1484
  74. package/src/components/Business/BsLayouts/service.ts +10 -10
  75. package/src/components/Business/BsLayouts/utils.tsx +203 -203
  76. package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +564 -564
  77. package/src/components/Business/BsSulaQueryTable/index.less +221 -221
  78. package/src/components/Business/BsSulaQueryTable/index.tsx +527 -527
  79. package/src/components/Business/BsSulaQueryTable/setting.tsx +832 -832
  80. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  81. package/src/components/Business/BsSulaQueryTable/utils.tsx +688 -688
  82. package/src/components/Business/CommodityEntry/index.md +70 -70
  83. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  84. package/src/components/Business/CommonAlert/index.tsx +23 -23
  85. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  86. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  87. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  88. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  89. package/src/components/Business/DetailPageWrapper/index.tsx +313 -313
  90. package/src/components/Business/DetailPageWrapper/utils.tsx +100 -100
  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 +824 -824
  95. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +205 -201
  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 +535 -320
  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 +390 -390
  122. package/src/components/Business/SearchSelect/BusinessUtils.ts +1732 -1732
  123. package/src/components/Business/SearchSelect/common.ts +53 -53
  124. package/src/components/Business/SearchSelect/index.md +1319 -1319
  125. package/src/components/Business/SearchSelect/index.tsx +51 -51
  126. package/src/components/Business/SearchSelect/utils.ts +100 -100
  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 +154 -154
  131. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  132. package/src/components/Business/TreeSearchSelect/utils.ts +69 -69
  133. package/src/components/Business/columnSettingTable/columnSetting.tsx +764 -764
  134. package/src/components/Business/columnSettingTable/index.less +247 -247
  135. package/src/components/Business/columnSettingTable/index.md +357 -357
  136. package/src/components/Business/columnSettingTable/index.tsx +232 -232
  137. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +240 -240
  138. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  139. package/src/components/Business/moreTreeTable/FixedScrollBar.tsx +86 -86
  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 +380 -380
  144. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  145. package/src/components/Functional/AddSelect/helps.ts +14 -14
  146. package/src/components/Functional/AddSelect/index.less +367 -367
  147. package/src/components/Functional/AddSelect/index.md +155 -155
  148. package/src/components/Functional/AddSelect/index.tsx +1279 -1279
  149. package/src/components/Functional/BillEntry/index.less +371 -371
  150. package/src/components/Functional/BillEntry/index.md +39 -39
  151. package/src/components/Functional/BillEntry/index.tsx +772 -772
  152. package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -62
  153. package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -178
  154. package/src/components/Functional/BsAntdSula/index.ts +2 -2
  155. package/src/components/Functional/DataImport/index.less +63 -63
  156. package/src/components/Functional/DataImport/index.md +44 -44
  157. package/src/components/Functional/DataImport/index.tsx +695 -695
  158. package/src/components/Functional/DataValidation/index.less +63 -63
  159. package/src/components/Functional/DataValidation/index.md +39 -39
  160. package/src/components/Functional/DataValidation/index.tsx +687 -687
  161. package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -5
  162. package/src/components/Functional/EllipsisTooltip/index.js +36 -36
  163. package/src/components/Functional/EllipsisTooltip/index.md +30 -30
  164. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  165. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  166. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  167. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  168. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  169. package/src/components/Functional/SearchSelect/index.less +115 -115
  170. package/src/components/Functional/SearchSelect/index.md +141 -141
  171. package/src/components/Functional/SearchSelect/index.tsx +859 -849
  172. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  173. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  174. package/src/components/Functional/TreeSearchSelect/index.tsx +162 -162
  175. package/src/components/Solution/RuleComponent/Formula.tsx +335 -335
  176. package/src/components/Solution/RuleComponent/index.d.ts +29 -29
  177. package/src/components/Solution/RuleComponent/index.js +2028 -2028
  178. package/src/components/Solution/RuleComponent/index.less +230 -230
  179. package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -99
  180. package/src/components/Solution/RuleComponent/ruleFiled.js +2074 -2074
  181. package/src/components/Solution/RuleComponent/services.ts +13 -13
  182. package/src/components/Solution/RuleComponent/util.js +139 -139
  183. package/src/index.ts +38 -38
  184. package/src/plugin/TableColumnSetting/index.less +247 -247
  185. package/src/plugin/TableColumnSetting/index.md +50 -50
  186. package/src/plugin/TableColumnSetting/index.tsx +724 -724
  187. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  188. package/src/styles/bsDefault.less +1912 -1912
  189. package/src/utils/CheckOneUser/index.md +39 -39
  190. package/src/utils/CheckOneUser/index.ts +51 -51
  191. package/src/utils/LocalstorageUtils.ts +90 -90
  192. package/src/utils/TableUtils.tsx +18 -18
  193. package/src/utils/checkUtils.ts +39 -39
  194. package/src/utils/enumConfig.ts +11 -11
  195. package/src/utils/getFormMode.js +12 -12
  196. package/src/utils/index.ts +4 -4
  197. package/src/utils/requestUtils.ts +34 -34
  198. package/src/utils/serialize.js +7 -7
  199. package/src/utils/utils.ts +212 -212
  200. package/tsconfig.json +29 -29
  201. package/typings.d.ts +4 -4
@@ -1,380 +1,380 @@
1
- // @ts-nocheck
2
- import React, { useState, useEffect, useImperativeHandle, forwardRef, useMemo, useRef } from 'react';
3
- import { getAllColumns, convertToRows, headersToRows } from './utils';
4
- import './index.less';
5
- import FixedScrollBar from "./FixedScrollBar";
6
-
7
-
8
- export default forwardRef((props, ref) => {
9
- const [show, setShow] = useState(false);
10
- const [config, setConfig] = useState({
11
- tableType: 'col-header-table',
12
- colHeader: [],
13
- colLastData: [],
14
- rowHeader: [],
15
- rowLastData: [],
16
- colHeaderWidth: 400,
17
- colHeaderToTop: 0,
18
- });
19
- const [colTableData, setColTableData] = useState([]); //纵向表头数据
20
- const [multiTableData, setMmultiTableData] = useState({}); //多表头数据
21
- const [viewCount, setViewCount] = useState(10); //虚拟表格每次渲染数量
22
- const itemWidth = 100; // 表格每一项宽度
23
-
24
- const viewPort = useRef(null);
25
- const topScrollBar = useRef(null)
26
-
27
- //起始渲染item
28
- const [startIndex, setStartIndex] = useState(0);
29
-
30
- //结束渲染item
31
- const endIndex = useMemo(() => {
32
- return startIndex + viewCount;
33
- }, [startIndex, viewCount])
34
-
35
- //表格偏移量
36
- const [offsetWidth, setOffset] = useState(0);
37
-
38
- useEffect(() => { //根据容器宽度计算每次渲染个数
39
- let viewPortWidth = viewPort.current.clientWidth;
40
- let defaultTableWidth = viewPortWidth - (props.colHeaderWidth || 400);
41
- let viewCount = Math.floor(defaultTableWidth/itemWidth) + 2 <= 10 ? 10 : Math.floor(defaultTableWidth/itemWidth) + 2;
42
- setViewCount(viewCount)
43
- }, [])
44
-
45
- const onScroll = () => {
46
- if(topScrollBar.current){
47
- topScrollBar.current.scrollTo(viewPort.current.scrollLeft, 0)
48
- }
49
- const scrollWidth = viewPort.current.scrollLeft;
50
- const startIndex = Math.floor(scrollWidth/itemWidth);
51
- const offsetWidth = startIndex * itemWidth;
52
- setStartIndex(startIndex);
53
- setOffset(offsetWidth);
54
- }
55
-
56
- // 占位符,表格列总宽度
57
- const placeholderWidth = useMemo(() => {
58
- return colTableData.length*100
59
- }, [colTableData])
60
-
61
-
62
- useImperativeHandle(ref, () => ({
63
- // 暴露子组件刷新表格方法出去,父组件可以调用该方法刷新表格数据
64
- getDataSource: getDataSource,
65
- }));
66
-
67
- // 设置表头相关信息
68
- useEffect(() => {
69
- const { colData, rowData, colHeaderWidth=400 } = props;
70
- let tableType;
71
- if (colData && colData.length && rowData && rowData.length) {
72
- tableType = 'multi-header-table';
73
- const colHeaderData = convertToRows(colData);
74
- const rowHeaderData = headersToRows(rowData);
75
- const { rowHeader } = rowHeaderData;
76
- setConfig({
77
- colHeader: [],
78
- colLastData: [],
79
- rowHeader: [],
80
- rowLastData: [],
81
- ...colHeaderData,
82
- ...rowHeaderData,
83
- colHeaderWidth: colHeaderWidth,
84
- colHeaderToTop: (rowHeader?.length || 0)*40,
85
- tableType: tableType
86
- })
87
- } else if (colData && colData.length) {
88
- tableType = 'col-header-table';
89
- const colHeaderData = convertToRows(colData);
90
- setConfig({
91
- colHeader: [],
92
- colLastData: [],
93
- rowHeader: [],
94
- rowLastData: [],
95
- ...colHeaderData,
96
- colHeaderWidth: colHeaderWidth || 400,
97
- colHeaderToTop: 0,
98
- tableType: tableType
99
- })
100
- }
101
- }, [props.colData, props.rowData]);
102
-
103
- // 设置多表头表格数据
104
- useEffect(() => {
105
- if (!config.colLastData.length || !config.rowLastData.length || !props.multiTableData) return;
106
- let tableData = {};
107
- let [row, col] = [config.rowLastData, config.colLastData];
108
- col.forEach(x => {
109
- row.forEach(y => {
110
- let key = x.id + "__" + y.id;
111
- tableData[key] = "";
112
- });
113
- });
114
- Object.assign(tableData, props.multiTableData);
115
- setMmultiTableData({
116
- ...tableData
117
- });
118
- }, [config.colLastData, config.rowLastData, props.multiTableData])
119
-
120
- // 设置纵向表格数据
121
- useEffect(() => {
122
- if (props?.colTableData && props?.colTableData.length) {
123
- setColTableData([
124
- ...props.colTableData
125
- ])
126
- }
127
- }, [props.colTableData])
128
-
129
- const getDataSource = () => {
130
- return colTableData;
131
- }
132
-
133
- const tableInsFn = {
134
- getDataSource: getDataSource,
135
- }
136
-
137
-
138
-
139
- // if (!show) {
140
- // return <div>loading</div>;
141
- // }
142
-
143
- const {width, height, tableProps } = props;
144
- let tableWidth = width ? `${width}px` : '100%';
145
- let tableHeight = `${height || 400}px`;
146
- const rightAreaWidth = 'calc(100% - ' + `${config.colHeaderWidth}px` + ')';
147
- return (
148
- <div
149
- style={{width: tableWidth, height: tableHeight}}
150
- key='moreTreeTable'
151
- className={'editTableWrapper'}
152
- onScroll={onScroll}
153
- ref={viewPort}
154
- >
155
- <FixedScrollBar
156
- stickyProps={tableProps?.sticky}
157
- viewPort={viewPort}
158
- ref={topScrollBar}
159
- />
160
- <div style={{
161
- width: `${config.colHeaderWidth + 1 + placeholderWidth}px`,
162
- position: 'absolute',
163
- top: 0,
164
- left: 0,
165
- height: '100%',
166
- }}
167
- ></div>
168
- {/* -------------------------------------左上角区域--------------------------------------- */}
169
- <table
170
- style={{
171
- width: `${config.colHeaderWidth+1}px`,
172
- height: `${config.colHeaderToTop}px`,
173
- display: config.tableType === 'col-header-table' ? 'none' : '',
174
- }}
175
- className={`${'north__west'}`}
176
- >
177
- </table>
178
-
179
- {/* --------------------------------------纵向表头---------------------------------------- */}
180
- <table
181
- style={{
182
- tableLayout:'auto',
183
- minWidth: '100px',
184
- width: `${config.colHeaderWidth+1}px`,
185
- top: `${config.colHeaderToTop}px`,
186
- left: '0px',
187
- position: 'sticky',
188
- }}
189
- className={`${'south__west'} ${'editTable__block'} ${'table_border_style'}`}
190
- >
191
- <tbody>
192
- {config.colHeader.map((item, index) => {
193
- return (
194
- <tr>
195
- {item.map((innerItem) => {
196
- if (!innerItem) return null;
197
- let fixedTop = innerItem.fixed ? `${index*40 + config.colHeaderToTop}px` : 0;
198
- return (
199
- <td
200
- style={{
201
- // width: '200px',
202
- height: '40px',
203
- background: '#f7f8fb',
204
- lineHeight: '28px',
205
- color: '#000000',
206
- fontWeight: 500,
207
- position: innerItem.fixed ? 'sticky' : '',
208
- top: fixedTop,
209
- }}
210
- rowSpan={innerItem && innerItem.colSpan}
211
- colSpan={innerItem && innerItem.rowSpan}
212
- >
213
- {innerItem && innerItem.title}
214
- </td>
215
- );
216
- })}
217
- {/* <td></td> */}
218
- </tr>
219
- );
220
- })}
221
- </tbody>
222
- </table>
223
- <table
224
- className={` ${'editTable__block'} ${'table_border_style'}`}
225
- style={{
226
- width: '100%',
227
- top: 0,
228
- left: `${config.colHeaderWidth}px`,
229
- position: 'absolute',
230
- display: config.tableType === 'col-header-table' ? 'none' : ''
231
- }}
232
- >
233
- <colgroup>
234
- {
235
- config.rowLastData.map(row => {
236
- return (<col width={row.width ? `${row.width}px` : '100px'} />)
237
- })
238
- }
239
- </colgroup>
240
- <tbody>
241
- {
242
- config.rowHeader.map((item) => {
243
- return (
244
- <tr>
245
- {
246
- item.map((innerItem) => {
247
- if (!innerItem) return null;
248
- return (
249
- <td
250
- style={{
251
- height: '40px',
252
- background: '#f7f8fb',
253
- color: '#000000',
254
- fontWeight: 500,
255
- width: innerItem.width ? `${innerItem.width}px` : '100px',
256
- }}
257
- rowSpan={innerItem && innerItem.rowSpan}
258
- colSpan={innerItem && innerItem.colSpan}
259
- >
260
- {innerItem && innerItem.title}
261
- </td>
262
- )
263
- })
264
- }
265
- </tr>
266
- )
267
- })
268
- }
269
- </tbody>
270
- </table>
271
- <div
272
- style={{
273
- position: 'absolute',
274
- left: `${config.colHeaderWidth}px`,
275
- top: `${config.colHeaderToTop}px`,
276
- minWidth: rightAreaWidth,
277
- zIndex: 0,
278
- }}
279
- >
280
- {/* --------------------------------------横向表头---------------------------------------- */}
281
- {/* <div style={{position: 'relative'}}>
282
-
283
- </div> */}
284
- <div
285
- style={{
286
- width: '100%',
287
- position: 'relative'
288
- }}
289
- className={`${'value_table'} ${'table_border_style'}`}
290
- >
291
- {/* ------------------------------------纵向表头数据-------------------------------------- */}
292
- <table
293
- style={{
294
- tableLayout:'auto',
295
- width: '800px',
296
- display: config.tableType === 'col-header-table' ? '' : 'none',
297
- transform: `translateX(${offsetWidth}px)`
298
- }}
299
- className={`${'editTable__block'} ${'table_border_style'}`}
300
- >
301
- <tbody>
302
- {config.colLastData.map((item, index) => {
303
- let fixedTop = item.fixed ? `${index*40 + config.colHeaderToTop}px` : 0;
304
- return (
305
- <tr>
306
- {colTableData.map((record, index) => {
307
- let tdHidden = record?.['_rowConfig']?.hidden ? 'none' : 'table-cell'
308
- let onCellResult = item.onCell?.(record, index) || {}
309
- let {addStyle={}} = onCellResult
310
- return (
311
- <td
312
- style={{
313
- ...addStyle,
314
- display: tdHidden,
315
- background: (index % 2 === 1) || item.fixed ? '#f7f8fb' : '#fff',
316
- minWidth: '100px',
317
- width: `${itemWidth}px`,
318
- height: '40px',
319
- position: item.fixed ? 'sticky' : '',
320
- top: fixedTop,
321
- color: item.fixed ? '#000000' : 'inherit',
322
- zIndex: item.fixed ? 10 : '',
323
- }}
324
- >
325
- {
326
- item.render ? item.render({text:record[item.key || item.dataIndex], record, index, table: tableInsFn}) : record[item.key || item.dataIndex]
327
- }
328
- {/* {record[item.key || item.dataIndex]?.value} */}
329
- </td>
330
- );
331
- }).slice(startIndex, endIndex+1)}
332
- {/* <td></td> */}
333
- </tr>
334
- );
335
- })}
336
- </tbody>
337
- </table>
338
- {/* -------------------------------------多表头数据-------------------------------------- */}
339
- <table
340
- style={{
341
- width: '100%',
342
- display: config.tableType === 'col-header-table' ? 'none' : '',
343
- }}
344
- className={`${'editTable__block'} ${'table_border_style'}`}
345
- >
346
- <colgroup>
347
- {
348
- config.rowLastData.map(row => {
349
- return (<col width={row.width ? `${row.width}px` : '100px'} />)
350
- })
351
- }
352
- </colgroup>
353
- <tbody>
354
- {config.colLastData.map((col) => {
355
- return (
356
- <tr>
357
- {config.rowLastData.map((row, index) => {
358
- return (
359
- <td
360
- style={{
361
- background: (index % 2 === 0) ? '#fff' : '#f7f8fb',
362
- width: row.width ? `${row.width}px` : '100px',
363
- height: '40px',
364
- }}
365
- >
366
- {multiTableData[(row.key || row.dataIndex)+'__'+(col.key || col.dataIndex)]}
367
- </td>
368
- );
369
- })}
370
- {/* <td></td> */}
371
- </tr>
372
- );
373
- })}
374
- </tbody>
375
- </table>
376
- </div>
377
- </div>
378
- </div>
379
- );
380
- });
1
+ // @ts-nocheck
2
+ import React, { useState, useEffect, useImperativeHandle, forwardRef, useMemo, useRef } from 'react';
3
+ import { getAllColumns, convertToRows, headersToRows } from './utils';
4
+ import './index.less';
5
+ import FixedScrollBar from "./FixedScrollBar";
6
+
7
+
8
+ export default forwardRef((props, ref) => {
9
+ const [show, setShow] = useState(false);
10
+ const [config, setConfig] = useState({
11
+ tableType: 'col-header-table',
12
+ colHeader: [],
13
+ colLastData: [],
14
+ rowHeader: [],
15
+ rowLastData: [],
16
+ colHeaderWidth: 400,
17
+ colHeaderToTop: 0,
18
+ });
19
+ const [colTableData, setColTableData] = useState([]); //纵向表头数据
20
+ const [multiTableData, setMmultiTableData] = useState({}); //多表头数据
21
+ const [viewCount, setViewCount] = useState(10); //虚拟表格每次渲染数量
22
+ const itemWidth = 100; // 表格每一项宽度
23
+
24
+ const viewPort = useRef(null);
25
+ const topScrollBar = useRef(null)
26
+
27
+ //起始渲染item
28
+ const [startIndex, setStartIndex] = useState(0);
29
+
30
+ //结束渲染item
31
+ const endIndex = useMemo(() => {
32
+ return startIndex + viewCount;
33
+ }, [startIndex, viewCount])
34
+
35
+ //表格偏移量
36
+ const [offsetWidth, setOffset] = useState(0);
37
+
38
+ useEffect(() => { //根据容器宽度计算每次渲染个数
39
+ let viewPortWidth = viewPort.current.clientWidth;
40
+ let defaultTableWidth = viewPortWidth - (props.colHeaderWidth || 400);
41
+ let viewCount = Math.floor(defaultTableWidth/itemWidth) + 2 <= 10 ? 10 : Math.floor(defaultTableWidth/itemWidth) + 2;
42
+ setViewCount(viewCount)
43
+ }, [])
44
+
45
+ const onScroll = () => {
46
+ if(topScrollBar.current){
47
+ topScrollBar.current.scrollTo(viewPort.current.scrollLeft, 0)
48
+ }
49
+ const scrollWidth = viewPort.current.scrollLeft;
50
+ const startIndex = Math.floor(scrollWidth/itemWidth);
51
+ const offsetWidth = startIndex * itemWidth;
52
+ setStartIndex(startIndex);
53
+ setOffset(offsetWidth);
54
+ }
55
+
56
+ // 占位符,表格列总宽度
57
+ const placeholderWidth = useMemo(() => {
58
+ return colTableData.length*100
59
+ }, [colTableData])
60
+
61
+
62
+ useImperativeHandle(ref, () => ({
63
+ // 暴露子组件刷新表格方法出去,父组件可以调用该方法刷新表格数据
64
+ getDataSource: getDataSource,
65
+ }));
66
+
67
+ // 设置表头相关信息
68
+ useEffect(() => {
69
+ const { colData, rowData, colHeaderWidth=400 } = props;
70
+ let tableType;
71
+ if (colData && colData.length && rowData && rowData.length) {
72
+ tableType = 'multi-header-table';
73
+ const colHeaderData = convertToRows(colData);
74
+ const rowHeaderData = headersToRows(rowData);
75
+ const { rowHeader } = rowHeaderData;
76
+ setConfig({
77
+ colHeader: [],
78
+ colLastData: [],
79
+ rowHeader: [],
80
+ rowLastData: [],
81
+ ...colHeaderData,
82
+ ...rowHeaderData,
83
+ colHeaderWidth: colHeaderWidth,
84
+ colHeaderToTop: (rowHeader?.length || 0)*40,
85
+ tableType: tableType
86
+ })
87
+ } else if (colData && colData.length) {
88
+ tableType = 'col-header-table';
89
+ const colHeaderData = convertToRows(colData);
90
+ setConfig({
91
+ colHeader: [],
92
+ colLastData: [],
93
+ rowHeader: [],
94
+ rowLastData: [],
95
+ ...colHeaderData,
96
+ colHeaderWidth: colHeaderWidth || 400,
97
+ colHeaderToTop: 0,
98
+ tableType: tableType
99
+ })
100
+ }
101
+ }, [props.colData, props.rowData]);
102
+
103
+ // 设置多表头表格数据
104
+ useEffect(() => {
105
+ if (!config.colLastData.length || !config.rowLastData.length || !props.multiTableData) return;
106
+ let tableData = {};
107
+ let [row, col] = [config.rowLastData, config.colLastData];
108
+ col.forEach(x => {
109
+ row.forEach(y => {
110
+ let key = x.id + "__" + y.id;
111
+ tableData[key] = "";
112
+ });
113
+ });
114
+ Object.assign(tableData, props.multiTableData);
115
+ setMmultiTableData({
116
+ ...tableData
117
+ });
118
+ }, [config.colLastData, config.rowLastData, props.multiTableData])
119
+
120
+ // 设置纵向表格数据
121
+ useEffect(() => {
122
+ if (props?.colTableData && props?.colTableData.length) {
123
+ setColTableData([
124
+ ...props.colTableData
125
+ ])
126
+ }
127
+ }, [props.colTableData])
128
+
129
+ const getDataSource = () => {
130
+ return colTableData;
131
+ }
132
+
133
+ const tableInsFn = {
134
+ getDataSource: getDataSource,
135
+ }
136
+
137
+
138
+
139
+ // if (!show) {
140
+ // return <div>loading</div>;
141
+ // }
142
+
143
+ const {width, height, tableProps } = props;
144
+ let tableWidth = width ? `${width}px` : '100%';
145
+ let tableHeight = `${height || 400}px`;
146
+ const rightAreaWidth = 'calc(100% - ' + `${config.colHeaderWidth}px` + ')';
147
+ return (
148
+ <div
149
+ style={{width: tableWidth, height: tableHeight}}
150
+ key='moreTreeTable'
151
+ className={'editTableWrapper'}
152
+ onScroll={onScroll}
153
+ ref={viewPort}
154
+ >
155
+ <FixedScrollBar
156
+ stickyProps={tableProps?.sticky}
157
+ viewPort={viewPort}
158
+ ref={topScrollBar}
159
+ />
160
+ <div style={{
161
+ width: `${config.colHeaderWidth + 1 + placeholderWidth}px`,
162
+ position: 'absolute',
163
+ top: 0,
164
+ left: 0,
165
+ height: '100%',
166
+ }}
167
+ ></div>
168
+ {/* -------------------------------------左上角区域--------------------------------------- */}
169
+ <table
170
+ style={{
171
+ width: `${config.colHeaderWidth+1}px`,
172
+ height: `${config.colHeaderToTop}px`,
173
+ display: config.tableType === 'col-header-table' ? 'none' : '',
174
+ }}
175
+ className={`${'north__west'}`}
176
+ >
177
+ </table>
178
+
179
+ {/* --------------------------------------纵向表头---------------------------------------- */}
180
+ <table
181
+ style={{
182
+ tableLayout:'auto',
183
+ minWidth: '100px',
184
+ width: `${config.colHeaderWidth+1}px`,
185
+ top: `${config.colHeaderToTop}px`,
186
+ left: '0px',
187
+ position: 'sticky',
188
+ }}
189
+ className={`${'south__west'} ${'editTable__block'} ${'table_border_style'}`}
190
+ >
191
+ <tbody>
192
+ {config.colHeader.map((item, index) => {
193
+ return (
194
+ <tr>
195
+ {item.map((innerItem) => {
196
+ if (!innerItem) return null;
197
+ let fixedTop = innerItem.fixed ? `${index*40 + config.colHeaderToTop}px` : 0;
198
+ return (
199
+ <td
200
+ style={{
201
+ // width: '200px',
202
+ height: '40px',
203
+ background: '#f7f8fb',
204
+ lineHeight: '28px',
205
+ color: '#000000',
206
+ fontWeight: 500,
207
+ position: innerItem.fixed ? 'sticky' : '',
208
+ top: fixedTop,
209
+ }}
210
+ rowSpan={innerItem && innerItem.colSpan}
211
+ colSpan={innerItem && innerItem.rowSpan}
212
+ >
213
+ {innerItem && innerItem.title}
214
+ </td>
215
+ );
216
+ })}
217
+ {/* <td></td> */}
218
+ </tr>
219
+ );
220
+ })}
221
+ </tbody>
222
+ </table>
223
+ <table
224
+ className={` ${'editTable__block'} ${'table_border_style'}`}
225
+ style={{
226
+ width: '100%',
227
+ top: 0,
228
+ left: `${config.colHeaderWidth}px`,
229
+ position: 'absolute',
230
+ display: config.tableType === 'col-header-table' ? 'none' : ''
231
+ }}
232
+ >
233
+ <colgroup>
234
+ {
235
+ config.rowLastData.map(row => {
236
+ return (<col width={row.width ? `${row.width}px` : '100px'} />)
237
+ })
238
+ }
239
+ </colgroup>
240
+ <tbody>
241
+ {
242
+ config.rowHeader.map((item) => {
243
+ return (
244
+ <tr>
245
+ {
246
+ item.map((innerItem) => {
247
+ if (!innerItem) return null;
248
+ return (
249
+ <td
250
+ style={{
251
+ height: '40px',
252
+ background: '#f7f8fb',
253
+ color: '#000000',
254
+ fontWeight: 500,
255
+ width: innerItem.width ? `${innerItem.width}px` : '100px',
256
+ }}
257
+ rowSpan={innerItem && innerItem.rowSpan}
258
+ colSpan={innerItem && innerItem.colSpan}
259
+ >
260
+ {innerItem && innerItem.title}
261
+ </td>
262
+ )
263
+ })
264
+ }
265
+ </tr>
266
+ )
267
+ })
268
+ }
269
+ </tbody>
270
+ </table>
271
+ <div
272
+ style={{
273
+ position: 'absolute',
274
+ left: `${config.colHeaderWidth}px`,
275
+ top: `${config.colHeaderToTop}px`,
276
+ minWidth: rightAreaWidth,
277
+ zIndex: 0,
278
+ }}
279
+ >
280
+ {/* --------------------------------------横向表头---------------------------------------- */}
281
+ {/* <div style={{position: 'relative'}}>
282
+
283
+ </div> */}
284
+ <div
285
+ style={{
286
+ width: '100%',
287
+ position: 'relative'
288
+ }}
289
+ className={`${'value_table'} ${'table_border_style'}`}
290
+ >
291
+ {/* ------------------------------------纵向表头数据-------------------------------------- */}
292
+ <table
293
+ style={{
294
+ tableLayout:'auto',
295
+ width: '800px',
296
+ display: config.tableType === 'col-header-table' ? '' : 'none',
297
+ transform: `translateX(${offsetWidth}px)`
298
+ }}
299
+ className={`${'editTable__block'} ${'table_border_style'}`}
300
+ >
301
+ <tbody>
302
+ {config.colLastData.map((item, index) => {
303
+ let fixedTop = item.fixed ? `${index*40 + config.colHeaderToTop}px` : 0;
304
+ return (
305
+ <tr>
306
+ {colTableData.map((record, index) => {
307
+ let tdHidden = record?.['_rowConfig']?.hidden ? 'none' : 'table-cell'
308
+ let onCellResult = item.onCell?.(record, index) || {}
309
+ let {addStyle={}} = onCellResult
310
+ return (
311
+ <td
312
+ style={{
313
+ ...addStyle,
314
+ display: tdHidden,
315
+ background: (index % 2 === 1) || item.fixed ? '#f7f8fb' : '#fff',
316
+ minWidth: '100px',
317
+ width: `${itemWidth}px`,
318
+ height: '40px',
319
+ position: item.fixed ? 'sticky' : '',
320
+ top: fixedTop,
321
+ color: item.fixed ? '#000000' : 'inherit',
322
+ zIndex: item.fixed ? 10 : '',
323
+ }}
324
+ >
325
+ {
326
+ item.render ? item.render({text:record[item.key || item.dataIndex], record, index, table: tableInsFn}) : record[item.key || item.dataIndex]
327
+ }
328
+ {/* {record[item.key || item.dataIndex]?.value} */}
329
+ </td>
330
+ );
331
+ }).slice(startIndex, endIndex+1)}
332
+ {/* <td></td> */}
333
+ </tr>
334
+ );
335
+ })}
336
+ </tbody>
337
+ </table>
338
+ {/* -------------------------------------多表头数据-------------------------------------- */}
339
+ <table
340
+ style={{
341
+ width: '100%',
342
+ display: config.tableType === 'col-header-table' ? 'none' : '',
343
+ }}
344
+ className={`${'editTable__block'} ${'table_border_style'}`}
345
+ >
346
+ <colgroup>
347
+ {
348
+ config.rowLastData.map(row => {
349
+ return (<col width={row.width ? `${row.width}px` : '100px'} />)
350
+ })
351
+ }
352
+ </colgroup>
353
+ <tbody>
354
+ {config.colLastData.map((col) => {
355
+ return (
356
+ <tr>
357
+ {config.rowLastData.map((row, index) => {
358
+ return (
359
+ <td
360
+ style={{
361
+ background: (index % 2 === 0) ? '#fff' : '#f7f8fb',
362
+ width: row.width ? `${row.width}px` : '100px',
363
+ height: '40px',
364
+ }}
365
+ >
366
+ {multiTableData[(row.key || row.dataIndex)+'__'+(col.key || col.dataIndex)]}
367
+ </td>
368
+ );
369
+ })}
370
+ {/* <td></td> */}
371
+ </tr>
372
+ );
373
+ })}
374
+ </tbody>
375
+ </table>
376
+ </div>
377
+ </div>
378
+ </div>
379
+ );
380
+ });