vxe-gantt 0.0.3 → 3.0.0-beta.0

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 (106) hide show
  1. package/README.md +14 -46
  2. package/es/components.js +3 -2
  3. package/es/gantt/src/gantt-body.js +83 -49
  4. package/es/gantt/src/gantt-chart.js +91 -43
  5. package/es/gantt/src/gantt-header.js +63 -36
  6. package/es/gantt/src/gantt-view.js +638 -586
  7. package/es/gantt/src/gantt.js +1347 -1178
  8. package/es/gantt/src/util.js +1 -4
  9. package/es/gantt/style.css +42 -17
  10. package/es/gantt/style.min.css +1 -1
  11. package/es/index.esm.js +5 -2
  12. package/es/style.css +1 -1
  13. package/es/style.min.css +1 -1
  14. package/es/ui/index.js +9 -3
  15. package/es/ui/src/comp.js +1 -2
  16. package/es/ui/src/log.js +3 -2
  17. package/es/ui/src/utils.js +17 -17
  18. package/es/vxe-gantt/style.css +42 -17
  19. package/es/vxe-gantt/style.min.css +1 -1
  20. package/helper/vetur/attributes.json +1 -1
  21. package/helper/vetur/tags.json +1 -1
  22. package/lib/components.js +20 -19
  23. package/lib/components.min.js +1 -1
  24. package/lib/gantt/index.js +3 -3
  25. package/lib/gantt/index.min.js +1 -1
  26. package/lib/gantt/src/gantt-body.js +109 -87
  27. package/lib/gantt/src/gantt-body.min.js +1 -1
  28. package/lib/gantt/src/gantt-chart.js +109 -69
  29. package/lib/gantt/src/gantt-chart.min.js +1 -1
  30. package/lib/gantt/src/gantt-header.js +75 -56
  31. package/lib/gantt/src/gantt-header.min.js +1 -1
  32. package/lib/gantt/src/gantt-view.js +684 -686
  33. package/lib/gantt/src/gantt-view.min.js +1 -1
  34. package/lib/gantt/src/gantt.js +1631 -1559
  35. package/lib/gantt/src/gantt.min.js +1 -1
  36. package/lib/gantt/src/util.js +1 -4
  37. package/lib/gantt/src/util.min.js +1 -1
  38. package/lib/gantt/style/style.css +42 -17
  39. package/lib/gantt/style/style.min.css +1 -1
  40. package/lib/index.common.js +12 -7
  41. package/lib/index.umd.js +10705 -5870
  42. package/lib/index.umd.min.js +1 -1
  43. package/lib/style.css +1 -1
  44. package/lib/style.min.css +1 -1
  45. package/lib/ui/index.js +12 -16
  46. package/lib/ui/index.min.js +1 -1
  47. package/lib/ui/src/comp.js +3 -2
  48. package/lib/ui/src/comp.min.js +1 -1
  49. package/lib/ui/src/dom.js +33 -33
  50. package/lib/ui/src/dom.min.js +1 -1
  51. package/lib/ui/src/log.js +4 -3
  52. package/lib/ui/src/log.min.js +1 -1
  53. package/lib/ui/src/utils.js +21 -24
  54. package/lib/ui/src/utils.min.js +1 -1
  55. package/lib/vxe-gantt/index.js +4 -2
  56. package/lib/vxe-gantt/index.min.js +1 -1
  57. package/lib/vxe-gantt/style/style.css +42 -17
  58. package/lib/vxe-gantt/style/style.min.css +1 -1
  59. package/lib/vxe-ui/index.js +4 -2
  60. package/lib/vxe-ui/index.min.js +1 -1
  61. package/package.json +13 -13
  62. package/packages/components.ts +8 -5
  63. package/packages/gantt/index.ts +2 -2
  64. package/packages/gantt/src/gantt-body.ts +89 -53
  65. package/packages/gantt/src/gantt-chart.ts +100 -49
  66. package/packages/gantt/src/gantt-header.ts +69 -39
  67. package/packages/gantt/src/gantt-view.ts +692 -624
  68. package/packages/gantt/src/gantt.ts +1460 -1240
  69. package/packages/gantt/src/util.ts +1 -4
  70. package/packages/index.ts +6 -2
  71. package/packages/ui/index.ts +9 -3
  72. package/packages/ui/src/comp.ts +2 -2
  73. package/packages/ui/src/log.ts +3 -1
  74. package/packages/ui/src/utils.ts +22 -21
  75. package/styles/components/gantt-module/gantt-chart.scss +28 -9
  76. package/styles/components/gantt.scss +12 -7
  77. package/styles/theme/base.scss +5 -1
  78. package/types/all.d.ts +3 -3
  79. package/types/index.d.ts +2 -2
  80. package/README.en.md +0 -72
  81. package/README.ja-JP.md +0 -72
  82. package/README.zh-TW.md +0 -73
  83. package/es/gantt/src/emits.js +0 -4
  84. package/es/gantt/src/grid-emits.js +0 -16
  85. package/es/gantt/src/grid-props.js +0 -7
  86. package/es/gantt/src/props.js +0 -2
  87. package/es/gantt/src/table-emits.js +0 -97
  88. package/es/gantt/src/table-props.js +0 -298
  89. package/lib/gantt/src/emits.js +0 -8
  90. package/lib/gantt/src/emits.min.js +0 -1
  91. package/lib/gantt/src/grid-emits.js +0 -8
  92. package/lib/gantt/src/grid-emits.min.js +0 -1
  93. package/lib/gantt/src/grid-props.js +0 -24
  94. package/lib/gantt/src/grid-props.min.js +0 -1
  95. package/lib/gantt/src/props.js +0 -13
  96. package/lib/gantt/src/props.min.js +0 -1
  97. package/lib/gantt/src/table-emits.js +0 -7
  98. package/lib/gantt/src/table-emits.min.js +0 -1
  99. package/lib/gantt/src/table-props.js +0 -306
  100. package/lib/gantt/src/table-props.min.js +0 -1
  101. package/packages/gantt/src/emits.ts +0 -7
  102. package/packages/gantt/src/grid-emits.ts +0 -19
  103. package/packages/gantt/src/grid-props.ts +0 -23
  104. package/packages/gantt/src/props.ts +0 -13
  105. package/packages/gantt/src/table-emits.ts +0 -109
  106. package/packages/gantt/src/table-props.ts +0 -304
@@ -1,7 +1,6 @@
1
- import { h, ref, reactive, nextTick, inject, watch, provide, onMounted, onUnmounted } from 'vue';
2
1
  import { defineVxeComponent } from '../../ui/src/comp';
2
+ import { VxeUI } from '@vxe-ui/core';
3
3
  import { setScrollTop, setScrollLeft } from '../../ui/src/dom';
4
- import { VxeUI } from '../../ui';
5
4
  import { getRefElem } from './util';
6
5
  import XEUtils from 'xe-utils';
7
6
  import GanttViewHeaderComponent from './gantt-header';
@@ -38,27 +37,437 @@ function createInternalData() {
38
37
  }
39
38
  const maxYHeight = 5e6;
40
39
  const maxXWidth = 5e6;
40
+ function handleParseColumn($xeGanttView) {
41
+ const $xeGantt = $xeGanttView.$xeGantt;
42
+ const reactData = $xeGanttView.reactData;
43
+ const internalData = $xeGanttView.internalData;
44
+ const { minViewDate, maxViewDate } = reactData;
45
+ const taskViewOpts = $xeGantt.computeTaskViewOpts;
46
+ const fullCols = [];
47
+ const groupCols = [];
48
+ switch (taskViewOpts.mode) {
49
+ case 'year':
50
+ break;
51
+ case 'quarter':
52
+ break;
53
+ case 'month':
54
+ break;
55
+ case 'week':
56
+ break;
57
+ default: {
58
+ if (minViewDate && maxViewDate) {
59
+ const currTime = minViewDate.getTime();
60
+ const diffDayNum = maxViewDate.getTime() - minViewDate.getTime();
61
+ const countDayNum = Math.max(6, Math.floor(diffDayNum / 86400000) + 1);
62
+ const groupList = [];
63
+ const colList = [];
64
+ const groupMaps = {};
65
+ for (let i = 0; i < countDayNum; i++) {
66
+ const itemDate = new Date(currTime + (i * 86400000));
67
+ const yyyyy = `${itemDate.getFullYear()}-${itemDate.getMonth() + 1}`;
68
+ const mmDd = `${itemDate.getDate()}`;
69
+ let groupCol = groupMaps[yyyyy];
70
+ const column = {
71
+ field: `${yyyyy}-${mmDd}`,
72
+ title: mmDd
73
+ };
74
+ if (groupCol) {
75
+ groupCol.children.push(column);
76
+ fullCols.push(groupCol);
77
+ }
78
+ else {
79
+ groupCol = {
80
+ field: yyyyy,
81
+ title: yyyyy,
82
+ children: [column]
83
+ };
84
+ groupList.push(groupCol);
85
+ fullCols.push(groupCol);
86
+ groupMaps[yyyyy] = groupCol;
87
+ }
88
+ colList.push(column);
89
+ }
90
+ groupCols.push(groupList, colList);
91
+ const $xeTable = internalData.xeTable;
92
+ if ($xeTable) {
93
+ const startField = $xeGantt.computeStartField;
94
+ const endField = $xeGantt.computeEndField;
95
+ const tableInternalData = $xeTable;
96
+ const { afterFullData } = tableInternalData;
97
+ const ctMaps = {};
98
+ afterFullData.forEach(row => {
99
+ const rowid = $xeTable.getRowid(row);
100
+ const startValue = XEUtils.get(row, startField);
101
+ const endValue = XEUtils.get(row, endField);
102
+ if (startValue && endValue) {
103
+ const startDate = XEUtils.toStringDate(startValue);
104
+ const endDate = XEUtils.toStringDate(endValue);
105
+ const oLeftSize = Math.floor((startDate.getTime() - minViewDate.getTime()) / 86400000);
106
+ const oWidthSize = Math.floor((endDate.getTime() - startDate.getTime()) / 86400000) + 1;
107
+ ctMaps[rowid] = {
108
+ row,
109
+ rowid,
110
+ oLeftSize,
111
+ oWidthSize
112
+ };
113
+ }
114
+ });
115
+ internalData.chartMaps = ctMaps;
116
+ }
117
+ }
118
+ break;
119
+ }
120
+ }
121
+ reactData.tableColumn = fullCols;
122
+ reactData.headerGroups = groupCols;
123
+ }
124
+ function handleUpdateData($xeGanttView) {
125
+ const $xeGantt = $xeGanttView.$xeGantt;
126
+ const reactData = $xeGanttView.reactData;
127
+ const internalData = $xeGanttView.internalData;
128
+ const $xeTable = internalData.xeTable;
129
+ const sdMaps = {};
130
+ const edMaps = {};
131
+ let minDate = null;
132
+ let maxDate = null;
133
+ if ($xeTable) {
134
+ const startField = $xeGantt.computeStartField;
135
+ const endField = $xeGantt.computeEndField;
136
+ const tableInternalData = $xeTable;
137
+ const { afterFullData } = tableInternalData;
138
+ afterFullData.forEach(row => {
139
+ const startValue = XEUtils.get(row, startField);
140
+ const endValue = XEUtils.get(row, endField);
141
+ if (startValue && endValue) {
142
+ const startDate = XEUtils.toStringDate(startValue);
143
+ if (!minDate || minDate.getTime() > startDate.getTime()) {
144
+ minDate = startDate;
145
+ }
146
+ const endDate = XEUtils.toStringDate(endValue);
147
+ if (!maxDate || maxDate.getTime() < endDate.getTime()) {
148
+ maxDate = endDate;
149
+ }
150
+ }
151
+ });
152
+ }
153
+ reactData.minViewDate = minDate;
154
+ reactData.maxViewDate = maxDate;
155
+ internalData.startMaps = sdMaps;
156
+ internalData.endMaps = edMaps;
157
+ handleParseColumn($xeGanttView);
158
+ }
159
+ function calcScrollbar($xeGanttView) {
160
+ const $xeGantt = $xeGanttView.$xeGantt;
161
+ const reactData = $xeGanttView.reactData;
162
+ const internalData = $xeGanttView.internalData;
163
+ const { scrollXWidth, scrollYHeight } = reactData;
164
+ const { elemStore } = internalData;
165
+ const scrollbarOpts = $xeGantt.computeScrollbarOpts;
166
+ const bodyWrapperElem = getRefElem(elemStore['main-body-wrapper']);
167
+ const xHandleEl = $xeGanttView.$refs.refScrollXHandleElem;
168
+ const yHandleEl = $xeGanttView.$refs.refScrollYHandleElem;
169
+ let overflowY = false;
170
+ let overflowX = false;
171
+ if (bodyWrapperElem) {
172
+ overflowY = scrollYHeight > bodyWrapperElem.clientHeight;
173
+ if (yHandleEl) {
174
+ reactData.scrollbarWidth = scrollbarOpts.width || (yHandleEl.offsetWidth - yHandleEl.clientWidth) || 14;
175
+ }
176
+ reactData.overflowY = overflowY;
177
+ overflowX = scrollXWidth > bodyWrapperElem.clientWidth;
178
+ if (xHandleEl) {
179
+ reactData.scrollbarHeight = scrollbarOpts.height || (xHandleEl.offsetHeight - xHandleEl.clientHeight) || 14;
180
+ }
181
+ reactData.overflowX = overflowX;
182
+ }
183
+ }
184
+ function updateChart($xeGanttView) {
185
+ const reactData = $xeGanttView.reactData;
186
+ const internalData = $xeGanttView.internalData;
187
+ const { viewCellWidth } = reactData;
188
+ const { elemStore, chartMaps } = internalData;
189
+ const chartWrapper = getRefElem(elemStore['main-chart-wrapper']);
190
+ if (chartWrapper) {
191
+ XEUtils.arrayEach(chartWrapper.children, (rowEl) => {
192
+ const barEl = rowEl.children[0];
193
+ if (!barEl) {
194
+ return;
195
+ }
196
+ const rowid = rowEl.getAttribute('rowid');
197
+ const rowRest = rowid ? chartMaps[rowid] : null;
198
+ if (rowRest) {
199
+ barEl.style.left = `${viewCellWidth * rowRest.oLeftSize}px`;
200
+ barEl.style.width = `${viewCellWidth * rowRest.oWidthSize}px`;
201
+ }
202
+ });
203
+ }
204
+ return $xeGanttView.$nextTick();
205
+ }
206
+ function updateStyle($xeGanttView) {
207
+ const $xeGantt = $xeGanttView.$xeGantt;
208
+ const reactData = $xeGanttView.reactData;
209
+ const internalData = $xeGanttView.internalData;
210
+ const { scrollbarWidth, scrollbarHeight, tableColumn } = reactData;
211
+ const { elemStore } = internalData;
212
+ const $xeTable = internalData.xeTable;
213
+ const el = $xeGanttView.$refs.refElem;
214
+ if (!el || !el.clientHeight) {
215
+ return;
216
+ }
217
+ const scrollbarXToTop = $xeGantt.computeScrollbarXToTop;
218
+ const xLeftCornerEl = $xeGanttView.$refs.refScrollXLeftCornerElem;
219
+ const xRightCornerEl = $xeGanttView.$refs.refScrollXRightCornerElem;
220
+ const scrollXVirtualEl = $xeGanttView.$refs.refScrollXVirtualElem;
221
+ const osbWidth = scrollbarWidth;
222
+ const osbHeight = scrollbarHeight;
223
+ let tbHeight = 0;
224
+ let tHeaderHeight = 0;
225
+ let tFooterHeight = 0;
226
+ if ($xeTable) {
227
+ const tableInternalData = $xeTable;
228
+ tbHeight = tableInternalData.tBodyHeight;
229
+ tHeaderHeight = tableInternalData.tHeaderHeight;
230
+ tFooterHeight = tableInternalData.tFooterHeight;
231
+ }
232
+ const headerScrollElem = getRefElem(elemStore['main-header-scroll']);
233
+ if (headerScrollElem) {
234
+ headerScrollElem.style.height = `${tHeaderHeight}px`;
235
+ }
236
+ const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
237
+ if (bodyScrollElem) {
238
+ bodyScrollElem.style.height = `${tbHeight}px`;
239
+ }
240
+ if (scrollXVirtualEl) {
241
+ scrollXVirtualEl.style.height = `${osbHeight}px`;
242
+ scrollXVirtualEl.style.visibility = 'visible';
243
+ }
244
+ const xWrapperEl = $xeGanttView.$refs.refScrollXWrapperElem;
245
+ if (xWrapperEl) {
246
+ xWrapperEl.style.left = scrollbarXToTop ? `${osbWidth}px` : '';
247
+ xWrapperEl.style.width = `${el.clientWidth - osbWidth}px`;
248
+ }
249
+ if (xLeftCornerEl) {
250
+ xLeftCornerEl.style.width = scrollbarXToTop ? `${osbWidth}px` : '';
251
+ xLeftCornerEl.style.display = scrollbarXToTop ? (osbHeight ? 'block' : '') : '';
252
+ }
253
+ if (xRightCornerEl) {
254
+ xRightCornerEl.style.width = scrollbarXToTop ? '' : `${osbWidth}px`;
255
+ xRightCornerEl.style.display = scrollbarXToTop ? '' : (osbHeight ? 'block' : '');
256
+ }
257
+ const scrollYVirtualEl = $xeGanttView.$refs.refScrollYVirtualElem;
258
+ if (scrollYVirtualEl) {
259
+ scrollYVirtualEl.style.width = `${osbWidth}px`;
260
+ scrollYVirtualEl.style.height = `${tbHeight + tHeaderHeight + tFooterHeight}px`;
261
+ scrollYVirtualEl.style.visibility = 'visible';
262
+ }
263
+ const yTopCornerEl = $xeGanttView.$refs.refScrollYTopCornerElem;
264
+ if (yTopCornerEl) {
265
+ yTopCornerEl.style.height = `${tHeaderHeight}px`;
266
+ yTopCornerEl.style.display = tHeaderHeight ? 'block' : '';
267
+ }
268
+ const yWrapperEl = $xeGanttView.$refs.refScrollYWrapperElem;
269
+ if (yWrapperEl) {
270
+ yWrapperEl.style.height = `${tbHeight}px`;
271
+ yWrapperEl.style.top = `${tHeaderHeight}px`;
272
+ }
273
+ const yBottomCornerEl = $xeGanttView.$refs.refScrollYBottomCornerElem;
274
+ if (yBottomCornerEl) {
275
+ yBottomCornerEl.style.height = `${tFooterHeight}px`;
276
+ yBottomCornerEl.style.top = `${tHeaderHeight + tbHeight}px`;
277
+ yBottomCornerEl.style.display = tFooterHeight ? 'block' : '';
278
+ }
279
+ const colInfoElem = $xeGanttView.$refs.refColInfoElem;
280
+ if (colInfoElem) {
281
+ reactData.viewCellWidth = colInfoElem.clientWidth || 40;
282
+ }
283
+ let viewTableWidth = reactData.viewCellWidth * tableColumn.length;
284
+ if (bodyScrollElem) {
285
+ const viewWidth = bodyScrollElem.clientWidth;
286
+ const remainWidth = viewWidth - viewTableWidth;
287
+ if (remainWidth > 0) {
288
+ reactData.viewCellWidth += Math.floor(remainWidth / tableColumn.length);
289
+ viewTableWidth = viewWidth;
290
+ }
291
+ }
292
+ const headerTableElem = getRefElem(elemStore['main-header-table']);
293
+ const bodyTableElem = getRefElem(elemStore['main-body-table']);
294
+ if (headerTableElem) {
295
+ headerTableElem.style.width = `${viewTableWidth}px`;
296
+ }
297
+ if (bodyTableElem) {
298
+ bodyTableElem.style.width = `${viewTableWidth}px`;
299
+ }
300
+ reactData.scrollXWidth = viewTableWidth;
301
+ return updateChart($xeGanttView);
302
+ }
303
+ function handleLazyRecalculate($xeGanttView) {
304
+ calcScrollbar($xeGanttView);
305
+ updateStyle($xeGanttView);
306
+ return $xeGanttView.$nextTick();
307
+ }
308
+ function updateScrollXSpace($xeGanttView) {
309
+ const reactData = $xeGanttView.reactData;
310
+ const internalData = $xeGanttView.internalData;
311
+ const { scrollXLoad, scrollXWidth } = reactData;
312
+ const { elemStore } = internalData;
313
+ const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
314
+ const bodyTableElem = getRefElem(elemStore['main-body-table']);
315
+ let xSpaceLeft = 0;
316
+ let clientWidth = 0;
317
+ if (bodyScrollElem) {
318
+ clientWidth = bodyScrollElem.clientWidth;
319
+ }
320
+ // 虚拟渲染
321
+ let isScrollXBig = false;
322
+ let ySpaceWidth = scrollXWidth;
323
+ if (scrollXWidth > maxXWidth) {
324
+ // 触右
325
+ if (bodyScrollElem && bodyTableElem && bodyScrollElem.scrollLeft + clientWidth >= maxXWidth) {
326
+ xSpaceLeft = maxXWidth - bodyTableElem.clientWidth;
327
+ }
328
+ else {
329
+ xSpaceLeft = (maxXWidth - clientWidth) * (xSpaceLeft / (scrollXWidth - clientWidth));
330
+ }
331
+ ySpaceWidth = maxXWidth;
332
+ isScrollXBig = true;
333
+ }
334
+ if (bodyTableElem) {
335
+ bodyTableElem.style.transform = `translate(${xSpaceLeft}px, ${reactData.scrollYTop || 0}px)`;
336
+ }
337
+ const layoutList = ['header', 'body', 'footer'];
338
+ layoutList.forEach(layout => {
339
+ const xSpaceElem = getRefElem(elemStore[`main-${layout}-xSpace`]);
340
+ if (xSpaceElem) {
341
+ xSpaceElem.style.width = scrollXLoad ? `${ySpaceWidth}px` : '';
342
+ }
343
+ });
344
+ reactData.scrollXLeft = xSpaceLeft;
345
+ reactData.scrollXWidth = ySpaceWidth;
346
+ reactData.isScrollXBig = isScrollXBig;
347
+ const scrollXSpaceEl = $xeGanttView.$refs.refScrollXSpaceElem;
348
+ if (scrollXSpaceEl) {
349
+ scrollXSpaceEl.style.width = `${ySpaceWidth}px`;
350
+ }
351
+ calcScrollbar($xeGanttView);
352
+ return $xeGanttView.$nextTick().then(() => {
353
+ updateStyle($xeGanttView);
354
+ });
355
+ }
356
+ function updateScrollYSpace($xeGanttView) {
357
+ const reactData = $xeGanttView.reactData;
358
+ const internalData = $xeGanttView.internalData;
359
+ const { scrollYLoad, overflowY } = reactData;
360
+ const { elemStore } = internalData;
361
+ const $xeTable = internalData.xeTable;
362
+ const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
363
+ const bodyTableElem = getRefElem(elemStore['main-body-table']);
364
+ let ySpaceTop = 0;
365
+ let scrollYHeight = 0;
366
+ let isScrollYBig = false;
367
+ if ($xeTable) {
368
+ const tableReactData = $xeTable;
369
+ ySpaceTop = tableReactData.scrollYTop;
370
+ scrollYHeight = tableReactData.scrollYHeight;
371
+ isScrollYBig = tableReactData.isScrollYBig;
372
+ }
373
+ let ySpaceHeight = scrollYHeight;
374
+ let scrollYTop = ySpaceTop;
375
+ let clientHeight = 0;
376
+ if (bodyScrollElem) {
377
+ clientHeight = bodyScrollElem.clientHeight;
378
+ }
379
+ if (isScrollYBig) {
380
+ // 触底
381
+ if (bodyScrollElem && bodyTableElem && bodyScrollElem.scrollTop + clientHeight >= maxYHeight) {
382
+ scrollYTop = maxYHeight - bodyTableElem.clientHeight;
383
+ }
384
+ else {
385
+ scrollYTop = (maxYHeight - clientHeight) * (ySpaceTop / (scrollYHeight - clientHeight));
386
+ }
387
+ ySpaceHeight = maxYHeight;
388
+ }
389
+ if (!(scrollYLoad && overflowY)) {
390
+ scrollYTop = 0;
391
+ }
392
+ if (bodyTableElem) {
393
+ bodyTableElem.style.transform = `translate(${reactData.scrollXLeft || 0}px, ${scrollYTop}px)`;
394
+ }
395
+ const layoutList = ['header', 'body', 'footer'];
396
+ layoutList.forEach(layout => {
397
+ const ySpaceElem = getRefElem(elemStore[`main-${layout}-ySpace`]);
398
+ if (ySpaceElem) {
399
+ ySpaceElem.style.height = ySpaceHeight ? `${ySpaceHeight}px` : '';
400
+ }
401
+ });
402
+ const scrollYSpaceEl = $xeGanttView.$refs.refScrollYSpaceElem;
403
+ if (scrollYSpaceEl) {
404
+ scrollYSpaceEl.style.height = ySpaceHeight ? `${ySpaceHeight}px` : '';
405
+ }
406
+ reactData.scrollYTop = scrollYTop;
407
+ reactData.scrollYHeight = scrollYHeight;
408
+ reactData.isScrollYBig = isScrollYBig;
409
+ calcScrollbar($xeGanttView);
410
+ return $xeGanttView.$nextTick().then(() => {
411
+ updateStyle($xeGanttView);
412
+ });
413
+ }
414
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
415
+ function checkLastSyncScroll($xeGanttView, isRollX, isRollY) {
416
+ const reactData = $xeGanttView.reactData;
417
+ const internalData = $xeGanttView.internalData;
418
+ const { lcsTimeout } = internalData;
419
+ reactData.lazScrollLoading = true;
420
+ if (lcsTimeout) {
421
+ clearTimeout(lcsTimeout);
422
+ }
423
+ internalData.lcsTimeout = setTimeout(() => {
424
+ internalData.lcsRunTime = Date.now();
425
+ internalData.lcsTimeout = undefined;
426
+ internalData.intoRunScroll = false;
427
+ internalData.inVirtualScroll = false;
428
+ internalData.inWheelScroll = false;
429
+ internalData.inHeaderScroll = false;
430
+ internalData.inBodyScroll = false;
431
+ internalData.inFooterScroll = false;
432
+ reactData.lazScrollLoading = false;
433
+ }, 200);
434
+ }
435
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
436
+ function handleScrollEvent($xeGanttView, evnt, isRollY, isRollX, scrollTop, scrollLeft) {
437
+ checkLastSyncScroll($xeGanttView, isRollX, isRollY);
438
+ }
439
+ /**
440
+ * 同步表格滚动
441
+ */
442
+ function syncTableScrollTop($xeGanttView, scrollTop) {
443
+ const internalData = $xeGanttView.internalData;
444
+ const $xeTable = internalData.xeTable;
445
+ if ($xeTable) {
446
+ const tableInternalData = $xeTable;
447
+ const { elemStore: tableElemStore } = tableInternalData;
448
+ const tableBodyScrollElem = getRefElem(tableElemStore['main-body-scroll']);
449
+ if (tableBodyScrollElem) {
450
+ tableBodyScrollElem.scrollTop = scrollTop;
451
+ }
452
+ }
453
+ }
41
454
  export default defineVxeComponent({
42
455
  name: 'VxeGanttView',
43
- setup(props, context) {
456
+ inject: {
457
+ $xeGantt: {
458
+ default: null
459
+ }
460
+ },
461
+ provide() {
462
+ const $xeGanttView = this;
463
+ return {
464
+ $xeGanttView
465
+ };
466
+ },
467
+ props: {},
468
+ data() {
44
469
  const xID = XEUtils.uniqueId();
45
- const $xeGantt = inject('$xeGantt', {});
46
- const { computeTaskViewOpts, computeStartField, computeEndField, computeScrollbarOpts, computeScrollbarXToTop, computeScrollbarYToLeft } = $xeGantt.getComputeMaps();
47
- const refElem = ref();
48
- const refScrollXVirtualElem = ref();
49
- const refScrollYVirtualElem = ref();
50
- const refScrollXHandleElem = ref();
51
- const refScrollXLeftCornerElem = ref();
52
- const refScrollXRightCornerElem = ref();
53
- const refScrollYHandleElem = ref();
54
- const refScrollYTopCornerElem = ref();
55
- const refScrollXWrapperElem = ref();
56
- const refScrollYWrapperElem = ref();
57
- const refScrollYBottomCornerElem = ref();
58
- const refScrollXSpaceElem = ref();
59
- const refScrollYSpaceElem = ref();
60
- const refColInfoElem = ref();
61
- const reactData = reactive({
470
+ const reactData = {
62
471
  // 是否启用了横向 X 可视渲染方式加载
63
472
  scrollXLoad: false,
64
473
  // 是否启用了纵向 Y 可视渲染方式加载
@@ -92,627 +501,274 @@ export default defineVxeComponent({
92
501
  small: 40,
93
502
  mini: 36
94
503
  }
95
- });
96
- const internalData = createInternalData();
97
- const refMaps = {
98
- refElem
99
504
  };
100
- const computeMaps = {};
101
- const $xeGanttView = {
505
+ const internalData = createInternalData();
506
+ return {
102
507
  xID,
103
- props,
104
- context,
105
508
  reactData,
106
- internalData,
107
- getRefMaps: () => refMaps,
108
- getComputeMaps: () => computeMaps
109
- };
110
- const handleParseColumn = () => {
111
- const { minViewDate, maxViewDate } = reactData;
112
- const taskViewOpts = computeTaskViewOpts.value;
113
- const fullCols = [];
114
- const groupCols = [];
115
- switch (taskViewOpts.mode) {
116
- case 'year':
117
- break;
118
- case 'quarter':
119
- break;
120
- case 'month':
121
- break;
122
- case 'week':
123
- break;
124
- default: {
125
- if (minViewDate && maxViewDate) {
126
- const currTime = minViewDate.getTime();
127
- const diffDayNum = maxViewDate.getTime() - minViewDate.getTime();
128
- const countDayNum = Math.max(6, Math.floor(diffDayNum / 86400000) + 1);
129
- const groupList = [];
130
- const colList = [];
131
- const groupMaps = {};
132
- for (let i = 0; i < countDayNum; i++) {
133
- const itemDate = new Date(currTime + (i * 86400000));
134
- const yyyyy = `${itemDate.getFullYear()}-${itemDate.getMonth() + 1}`;
135
- const mmDd = `${itemDate.getDate()}`;
136
- let groupCol = groupMaps[yyyyy];
137
- const column = {
138
- field: `${yyyyy}-${mmDd}`,
139
- title: mmDd
140
- };
141
- if (groupCol) {
142
- groupCol.children.push(column);
143
- fullCols.push(groupCol);
144
- }
145
- else {
146
- groupCol = {
147
- field: yyyyy,
148
- title: yyyyy,
149
- children: [column]
150
- };
151
- groupList.push(groupCol);
152
- fullCols.push(groupCol);
153
- groupMaps[yyyyy] = groupCol;
154
- }
155
- colList.push(column);
156
- }
157
- groupCols.push(groupList, colList);
158
- const $xeTable = internalData.xeTable;
159
- if ($xeTable) {
160
- const startField = computeStartField.value;
161
- const endField = computeEndField.value;
162
- const tableInternalData = $xeTable.internalData;
163
- const { afterFullData } = tableInternalData;
164
- const ctMaps = {};
165
- afterFullData.forEach(row => {
166
- const rowid = $xeTable.getRowid(row);
167
- const startValue = XEUtils.get(row, startField);
168
- const endValue = XEUtils.get(row, endField);
169
- if (startValue && endValue) {
170
- const startDate = XEUtils.toStringDate(startValue);
171
- const endDate = XEUtils.toStringDate(endValue);
172
- const oLeftSize = Math.floor((startDate.getTime() - minViewDate.getTime()) / 86400000);
173
- const oWidthSize = Math.floor((endDate.getTime() - startDate.getTime()) / 86400000) + 1;
174
- ctMaps[rowid] = {
175
- row,
176
- rowid,
177
- oLeftSize,
178
- oWidthSize
179
- };
180
- }
181
- });
182
- internalData.chartMaps = ctMaps;
183
- }
184
- }
185
- break;
186
- }
187
- }
188
- reactData.tableColumn = fullCols;
189
- reactData.headerGroups = groupCols;
509
+ internalData
190
510
  };
191
- const handleUpdateData = () => {
511
+ },
512
+ computed: Object.assign({}, {}),
513
+ methods: {
514
+ //
515
+ // Method
516
+ //
517
+ refreshData() {
518
+ const $xeGanttView = this;
519
+ handleUpdateData($xeGanttView);
520
+ return handleLazyRecalculate($xeGanttView);
521
+ },
522
+ updateViewData() {
523
+ const $xeGanttView = this;
524
+ const reactData = $xeGanttView.reactData;
525
+ const internalData = $xeGanttView.internalData;
192
526
  const $xeTable = internalData.xeTable;
193
- const sdMaps = {};
194
- const edMaps = {};
195
- let minDate = null;
196
- let maxDate = null;
197
527
  if ($xeTable) {
198
- const startField = computeStartField.value;
199
- const endField = computeEndField.value;
200
- const tableInternalData = $xeTable.internalData;
201
- const { afterFullData } = tableInternalData;
202
- afterFullData.forEach(row => {
203
- const startValue = XEUtils.get(row, startField);
204
- const endValue = XEUtils.get(row, endField);
205
- if (startValue && endValue) {
206
- const startDate = XEUtils.toStringDate(startValue);
207
- if (!minDate || minDate.getTime() > startDate.getTime()) {
208
- minDate = startDate;
209
- }
210
- const endDate = XEUtils.toStringDate(endValue);
211
- if (!maxDate || maxDate.getTime() < endDate.getTime()) {
212
- maxDate = endDate;
213
- }
214
- }
215
- });
216
- }
217
- reactData.minViewDate = minDate;
218
- reactData.maxViewDate = maxDate;
219
- internalData.startMaps = sdMaps;
220
- internalData.endMaps = edMaps;
221
- handleParseColumn();
222
- };
223
- const calcScrollbar = () => {
224
- const { scrollXWidth, scrollYHeight } = reactData;
225
- const { elemStore } = internalData;
226
- const scrollbarOpts = computeScrollbarOpts.value;
227
- const bodyWrapperElem = getRefElem(elemStore['main-body-wrapper']);
228
- const xHandleEl = refScrollXHandleElem.value;
229
- const yHandleEl = refScrollYHandleElem.value;
230
- let overflowY = false;
231
- let overflowX = false;
232
- if (bodyWrapperElem) {
233
- overflowY = scrollYHeight > bodyWrapperElem.clientHeight;
234
- if (yHandleEl) {
235
- reactData.scrollbarWidth = scrollbarOpts.width || (yHandleEl.offsetWidth - yHandleEl.clientWidth) || 14;
236
- }
237
- reactData.overflowY = overflowY;
238
- overflowX = scrollXWidth > bodyWrapperElem.clientWidth;
239
- if (xHandleEl) {
240
- reactData.scrollbarHeight = scrollbarOpts.height || (xHandleEl.offsetHeight - xHandleEl.clientHeight) || 14;
241
- }
242
- reactData.overflowX = overflowX;
528
+ const tableReactData = $xeTable;
529
+ const { tableData } = tableReactData;
530
+ reactData.tableData = tableData;
243
531
  }
244
- };
245
- const updateChart = () => {
246
- const { viewCellWidth } = reactData;
247
- const { elemStore, chartMaps } = internalData;
248
- const chartWrapper = getRefElem(elemStore['main-chart-wrapper']);
249
- if (chartWrapper) {
250
- XEUtils.arrayEach(chartWrapper.children, (rowEl) => {
251
- const barEl = rowEl.children[0];
252
- if (!barEl) {
253
- return;
254
- }
255
- const rowid = rowEl.getAttribute('rowid');
256
- const rowRest = rowid ? chartMaps[rowid] : null;
257
- if (rowRest) {
258
- barEl.style.left = `${viewCellWidth * rowRest.oLeftSize}px`;
259
- barEl.style.width = `${viewCellWidth * rowRest.oWidthSize}px`;
260
- }
261
- });
532
+ return $xeGanttView.$nextTick();
533
+ },
534
+ connectUpdate({ $table }) {
535
+ const $xeGanttView = this;
536
+ const internalData = $xeGanttView.internalData;
537
+ if ($table) {
538
+ internalData.xeTable = $table;
262
539
  }
263
- return nextTick();
264
- };
265
- const updateStyle = () => {
266
- const { scrollbarWidth, scrollbarHeight, tableColumn } = reactData;
267
- const { elemStore } = internalData;
268
- const $xeTable = internalData.xeTable;
269
- const el = refElem.value;
270
- if (!el || !el.clientHeight) {
540
+ return $xeGanttView.$nextTick();
541
+ },
542
+ handleUpdateStyle() {
543
+ const $xeGanttView = this;
544
+ return updateStyle($xeGanttView);
545
+ },
546
+ handleLazyRecalculate() {
547
+ const $xeGanttView = this;
548
+ return handleLazyRecalculate($xeGanttView);
549
+ },
550
+ triggerHeaderScrollEvent(evnt) {
551
+ const $xeGanttView = this;
552
+ const internalData = $xeGanttView.internalData;
553
+ const { elemStore, inVirtualScroll, inBodyScroll, inFooterScroll } = internalData;
554
+ if (inVirtualScroll) {
271
555
  return;
272
556
  }
273
- const scrollbarXToTop = computeScrollbarXToTop.value;
274
- const xLeftCornerEl = refScrollXLeftCornerElem.value;
275
- const xRightCornerEl = refScrollXRightCornerElem.value;
276
- const scrollXVirtualEl = refScrollXVirtualElem.value;
277
- const osbWidth = scrollbarWidth;
278
- const osbHeight = scrollbarHeight;
279
- let tbHeight = 0;
280
- let tHeaderHeight = 0;
281
- let tFooterHeight = 0;
282
- if ($xeTable) {
283
- const tableInternalData = $xeTable.internalData;
284
- tbHeight = tableInternalData.tBodyHeight;
285
- tHeaderHeight = tableInternalData.tHeaderHeight;
286
- tFooterHeight = tableInternalData.tFooterHeight;
287
- }
288
- const headerScrollElem = getRefElem(elemStore['main-header-scroll']);
289
- if (headerScrollElem) {
290
- headerScrollElem.style.height = `${tHeaderHeight}px`;
557
+ if (inBodyScroll || inFooterScroll) {
558
+ return;
291
559
  }
560
+ const wrapperEl = evnt.currentTarget;
292
561
  const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
293
- if (bodyScrollElem) {
294
- bodyScrollElem.style.height = `${tbHeight}px`;
295
- }
296
- if (scrollXVirtualEl) {
297
- scrollXVirtualEl.style.height = `${osbHeight}px`;
298
- scrollXVirtualEl.style.visibility = 'visible';
299
- }
300
- const xWrapperEl = refScrollXWrapperElem.value;
301
- if (xWrapperEl) {
302
- xWrapperEl.style.left = scrollbarXToTop ? `${osbWidth}px` : '';
303
- xWrapperEl.style.width = `${el.clientWidth - osbWidth}px`;
304
- }
305
- if (xLeftCornerEl) {
306
- xLeftCornerEl.style.width = scrollbarXToTop ? `${osbWidth}px` : '';
307
- xLeftCornerEl.style.display = scrollbarXToTop ? (osbHeight ? 'block' : '') : '';
308
- }
309
- if (xRightCornerEl) {
310
- xRightCornerEl.style.width = scrollbarXToTop ? '' : `${osbWidth}px`;
311
- xRightCornerEl.style.display = scrollbarXToTop ? '' : (osbHeight ? 'block' : '');
312
- }
313
- const scrollYVirtualEl = refScrollYVirtualElem.value;
314
- if (scrollYVirtualEl) {
315
- scrollYVirtualEl.style.width = `${osbWidth}px`;
316
- scrollYVirtualEl.style.height = `${tbHeight + tHeaderHeight + tFooterHeight}px`;
317
- scrollYVirtualEl.style.visibility = 'visible';
562
+ const xHandleEl = $xeGanttView.$refs.refScrollXHandleElem;
563
+ if (bodyScrollElem && wrapperEl) {
564
+ const isRollX = true;
565
+ const isRollY = false;
566
+ const currLeftNum = wrapperEl.scrollLeft;
567
+ internalData.inHeaderScroll = true;
568
+ setScrollLeft(xHandleEl, currLeftNum);
569
+ setScrollLeft(bodyScrollElem, currLeftNum);
570
+ handleScrollEvent($xeGanttView, evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
318
571
  }
319
- const yTopCornerEl = refScrollYTopCornerElem.value;
320
- if (yTopCornerEl) {
321
- yTopCornerEl.style.height = `${tHeaderHeight}px`;
322
- yTopCornerEl.style.display = tHeaderHeight ? 'block' : '';
572
+ },
573
+ triggerBodyScrollEvent(evnt) {
574
+ const $xeGanttView = this;
575
+ const internalData = $xeGanttView.internalData;
576
+ const { elemStore, inVirtualScroll, inHeaderScroll, inFooterScroll } = internalData;
577
+ if (inVirtualScroll) {
578
+ return;
323
579
  }
324
- const yWrapperEl = refScrollYWrapperElem.value;
325
- if (yWrapperEl) {
326
- yWrapperEl.style.height = `${tbHeight}px`;
327
- yWrapperEl.style.top = `${tHeaderHeight}px`;
580
+ if (inHeaderScroll || inFooterScroll) {
581
+ return;
328
582
  }
329
- const yBottomCornerEl = refScrollYBottomCornerElem.value;
330
- if (yBottomCornerEl) {
331
- yBottomCornerEl.style.height = `${tFooterHeight}px`;
332
- yBottomCornerEl.style.top = `${tHeaderHeight + tbHeight}px`;
333
- yBottomCornerEl.style.display = tFooterHeight ? 'block' : '';
583
+ const wrapperEl = evnt.currentTarget;
584
+ const headerScrollElem = getRefElem(elemStore['main-header-scroll']);
585
+ const xHandleEl = $xeGanttView.$refs.refScrollXHandleElem;
586
+ const yHandleEl = $xeGanttView.$refs.refScrollYHandleElem;
587
+ if (headerScrollElem && wrapperEl) {
588
+ const isRollX = true;
589
+ const isRollY = true;
590
+ const currLeftNum = wrapperEl.scrollLeft;
591
+ const currTopNum = wrapperEl.scrollTop;
592
+ internalData.inBodyScroll = true;
593
+ setScrollLeft(xHandleEl, currLeftNum);
594
+ setScrollLeft(headerScrollElem, currLeftNum);
595
+ setScrollTop(yHandleEl, currTopNum);
596
+ syncTableScrollTop($xeGanttView, currTopNum);
597
+ handleScrollEvent($xeGanttView, evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
334
598
  }
335
- const colInfoElem = refColInfoElem.value;
336
- if (colInfoElem) {
337
- reactData.viewCellWidth = colInfoElem.clientWidth || 40;
599
+ },
600
+ triggerFooterScrollEvent(evnt) {
601
+ const $xeGanttView = this;
602
+ const internalData = $xeGanttView.internalData;
603
+ const { inVirtualScroll, inHeaderScroll, inBodyScroll } = internalData;
604
+ if (inVirtualScroll) {
605
+ return;
338
606
  }
339
- let viewTableWidth = reactData.viewCellWidth * tableColumn.length;
340
- if (bodyScrollElem) {
341
- const viewWidth = bodyScrollElem.clientWidth;
342
- const remainWidth = viewWidth - viewTableWidth;
343
- if (remainWidth > 0) {
344
- reactData.viewCellWidth += Math.floor(remainWidth / tableColumn.length);
345
- viewTableWidth = viewWidth;
346
- }
607
+ if (inHeaderScroll || inBodyScroll) {
608
+ return;
347
609
  }
348
- const headerTableElem = getRefElem(elemStore['main-header-table']);
349
- const bodyTableElem = getRefElem(elemStore['main-body-table']);
350
- if (headerTableElem) {
351
- headerTableElem.style.width = `${viewTableWidth}px`;
610
+ const wrapperEl = evnt.currentTarget;
611
+ if (wrapperEl) {
612
+ const isRollX = true;
613
+ const isRollY = false;
614
+ const currLeftNum = wrapperEl.scrollLeft;
615
+ handleScrollEvent($xeGanttView, evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
352
616
  }
353
- if (bodyTableElem) {
354
- bodyTableElem.style.width = `${viewTableWidth}px`;
617
+ },
618
+ triggerVirtualScrollXEvent(evnt) {
619
+ const $xeGanttView = this;
620
+ const internalData = $xeGanttView.internalData;
621
+ const { elemStore, inHeaderScroll, inBodyScroll } = internalData;
622
+ if (inHeaderScroll || inBodyScroll) {
623
+ return;
355
624
  }
356
- reactData.scrollXWidth = viewTableWidth;
357
- return updateChart();
358
- };
359
- const handleLazyRecalculate = () => {
360
- calcScrollbar();
361
- updateStyle();
362
- return nextTick();
363
- };
364
- const updateScrollXSpace = () => {
365
- const { scrollXLoad, scrollXWidth } = reactData;
366
- const { elemStore } = internalData;
625
+ const wrapperEl = evnt.currentTarget;
626
+ const headerScrollElem = getRefElem(elemStore['main-header-scroll']);
367
627
  const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
368
- const bodyTableElem = getRefElem(elemStore['main-body-table']);
369
- let xSpaceLeft = 0;
370
- let clientWidth = 0;
371
- if (bodyScrollElem) {
372
- clientWidth = bodyScrollElem.clientWidth;
373
- }
374
- // 虚拟渲染
375
- let isScrollXBig = false;
376
- let ySpaceWidth = scrollXWidth;
377
- if (scrollXWidth > maxXWidth) {
378
- // 触右
379
- if (bodyScrollElem && bodyTableElem && bodyScrollElem.scrollLeft + clientWidth >= maxXWidth) {
380
- xSpaceLeft = maxXWidth - bodyTableElem.clientWidth;
381
- }
382
- else {
383
- xSpaceLeft = (maxXWidth - clientWidth) * (xSpaceLeft / (scrollXWidth - clientWidth));
384
- }
385
- ySpaceWidth = maxXWidth;
386
- isScrollXBig = true;
628
+ if (wrapperEl) {
629
+ const isRollY = false;
630
+ const isRollX = true;
631
+ const currLeftNum = wrapperEl.scrollLeft;
632
+ internalData.inVirtualScroll = true;
633
+ setScrollLeft(headerScrollElem, currLeftNum);
634
+ setScrollLeft(bodyScrollElem, currLeftNum);
635
+ handleScrollEvent($xeGanttView, evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
387
636
  }
388
- if (bodyTableElem) {
389
- bodyTableElem.style.transform = `translate(${xSpaceLeft}px, ${reactData.scrollYTop || 0}px)`;
390
- }
391
- const layoutList = ['header', 'body', 'footer'];
392
- layoutList.forEach(layout => {
393
- const xSpaceElem = getRefElem(elemStore[`main-${layout}-xSpace`]);
394
- if (xSpaceElem) {
395
- xSpaceElem.style.width = scrollXLoad ? `${ySpaceWidth}px` : '';
396
- }
397
- });
398
- reactData.scrollXLeft = xSpaceLeft;
399
- reactData.scrollXWidth = ySpaceWidth;
400
- reactData.isScrollXBig = isScrollXBig;
401
- const scrollXSpaceEl = refScrollXSpaceElem.value;
402
- if (scrollXSpaceEl) {
403
- scrollXSpaceEl.style.width = `${ySpaceWidth}px`;
637
+ },
638
+ triggerVirtualScrollYEvent(evnt) {
639
+ const $xeGanttView = this;
640
+ const internalData = $xeGanttView.internalData;
641
+ const { elemStore, inHeaderScroll, inBodyScroll } = internalData;
642
+ if (inHeaderScroll || inBodyScroll) {
643
+ return;
404
644
  }
405
- calcScrollbar();
406
- return nextTick().then(() => {
407
- updateStyle();
408
- });
409
- };
410
- const updateScrollYSpace = () => {
411
- const { scrollYLoad, overflowY } = reactData;
412
- const { elemStore } = internalData;
413
- const $xeTable = internalData.xeTable;
645
+ const wrapperEl = evnt.currentTarget;
414
646
  const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
415
- const bodyTableElem = getRefElem(elemStore['main-body-table']);
416
- let ySpaceTop = 0;
417
- let scrollYHeight = 0;
418
- let isScrollYBig = false;
419
- if ($xeTable) {
420
- const tableReactData = $xeTable.reactData;
421
- ySpaceTop = tableReactData.scrollYTop;
422
- scrollYHeight = tableReactData.scrollYHeight;
423
- isScrollYBig = tableReactData.isScrollYBig;
424
- }
425
- let ySpaceHeight = scrollYHeight;
426
- let scrollYTop = ySpaceTop;
427
- let clientHeight = 0;
428
- if (bodyScrollElem) {
429
- clientHeight = bodyScrollElem.clientHeight;
647
+ if (wrapperEl) {
648
+ const isRollY = true;
649
+ const isRollX = false;
650
+ const currTopNum = wrapperEl.scrollTop;
651
+ internalData.inVirtualScroll = true;
652
+ setScrollTop(bodyScrollElem, currTopNum);
653
+ syncTableScrollTop($xeGanttView, currTopNum);
654
+ handleScrollEvent($xeGanttView, evnt, isRollY, isRollX, currTopNum, wrapperEl.scrollLeft);
430
655
  }
431
- if (isScrollYBig) {
432
- // 触底
433
- if (bodyScrollElem && bodyTableElem && bodyScrollElem.scrollTop + clientHeight >= maxYHeight) {
434
- scrollYTop = maxYHeight - bodyTableElem.clientHeight;
435
- }
436
- else {
437
- scrollYTop = (maxYHeight - clientHeight) * (ySpaceTop / (scrollYHeight - clientHeight));
438
- }
439
- ySpaceHeight = maxYHeight;
440
- }
441
- if (!(scrollYLoad && overflowY)) {
442
- scrollYTop = 0;
443
- }
444
- if (bodyTableElem) {
445
- bodyTableElem.style.transform = `translate(${reactData.scrollXLeft || 0}px, ${scrollYTop}px)`;
446
- }
447
- const layoutList = ['header', 'body', 'footer'];
448
- layoutList.forEach(layout => {
449
- const ySpaceElem = getRefElem(elemStore[`main-${layout}-ySpace`]);
450
- if (ySpaceElem) {
451
- ySpaceElem.style.height = ySpaceHeight ? `${ySpaceHeight}px` : '';
452
- }
453
- });
454
- const scrollYSpaceEl = refScrollYSpaceElem.value;
455
- if (scrollYSpaceEl) {
456
- scrollYSpaceEl.style.height = ySpaceHeight ? `${ySpaceHeight}px` : '';
457
- }
458
- reactData.scrollYTop = scrollYTop;
459
- reactData.scrollYHeight = scrollYHeight;
460
- reactData.isScrollYBig = isScrollYBig;
461
- calcScrollbar();
462
- return nextTick().then(() => {
463
- updateStyle();
464
- });
465
- };
466
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
467
- const checkLastSyncScroll = (isRollX, isRollY) => {
468
- const { lcsTimeout } = internalData;
469
- reactData.lazScrollLoading = true;
470
- if (lcsTimeout) {
471
- clearTimeout(lcsTimeout);
472
- }
473
- internalData.lcsTimeout = setTimeout(() => {
474
- internalData.lcsRunTime = Date.now();
475
- internalData.lcsTimeout = undefined;
476
- internalData.intoRunScroll = false;
477
- internalData.inVirtualScroll = false;
478
- internalData.inWheelScroll = false;
479
- internalData.inHeaderScroll = false;
480
- internalData.inBodyScroll = false;
481
- internalData.inFooterScroll = false;
482
- reactData.lazScrollLoading = false;
483
- }, 200);
484
- };
485
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
486
- const handleScrollEvent = (evnt, isRollY, isRollX, scrollTop, scrollLeft) => {
487
- checkLastSyncScroll(isRollX, isRollY);
488
- };
489
- const ganttViewMethods = {
490
- updateViewData() {
491
- const $xeTable = internalData.xeTable;
492
- if ($xeTable) {
493
- const tableReactData = $xeTable.reactData;
494
- const { tableData } = tableReactData;
495
- reactData.tableData = tableData;
496
- }
497
- return nextTick();
498
- },
499
- connectUpdate({ $table }) {
500
- if ($table) {
501
- internalData.xeTable = $table;
502
- }
503
- return nextTick();
504
- }
505
- };
506
- /**
507
- * 同步表格滚动
508
- */
509
- const syncTableScrollTop = (scrollTop) => {
510
- const $xeTable = internalData.xeTable;
511
- if ($xeTable) {
512
- const tableInternalData = $xeTable.internalData;
513
- const { elemStore: tableElemStore } = tableInternalData;
514
- const tableBodyScrollElem = getRefElem(tableElemStore['main-body-scroll']);
515
- if (tableBodyScrollElem) {
516
- tableBodyScrollElem.scrollTop = scrollTop;
517
- }
518
- }
519
- };
520
- const ganttViewPrivateMethods = {
521
- handleUpdateStyle: updateStyle,
522
- handleLazyRecalculate,
523
- triggerHeaderScrollEvent(evnt) {
524
- const { elemStore, inVirtualScroll, inBodyScroll, inFooterScroll } = internalData;
525
- if (inVirtualScroll) {
526
- return;
527
- }
528
- if (inBodyScroll || inFooterScroll) {
529
- return;
530
- }
531
- const wrapperEl = evnt.currentTarget;
532
- const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
533
- const xHandleEl = refScrollXHandleElem.value;
534
- if (bodyScrollElem && wrapperEl) {
535
- const isRollX = true;
536
- const isRollY = false;
537
- const currLeftNum = wrapperEl.scrollLeft;
538
- internalData.inHeaderScroll = true;
539
- setScrollLeft(xHandleEl, currLeftNum);
540
- setScrollLeft(bodyScrollElem, currLeftNum);
541
- handleScrollEvent(evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
542
- }
543
- },
544
- triggerBodyScrollEvent(evnt) {
545
- const { elemStore, inVirtualScroll, inHeaderScroll, inFooterScroll } = internalData;
546
- if (inVirtualScroll) {
547
- return;
548
- }
549
- if (inHeaderScroll || inFooterScroll) {
550
- return;
551
- }
552
- const wrapperEl = evnt.currentTarget;
553
- const headerScrollElem = getRefElem(elemStore['main-header-scroll']);
554
- const xHandleEl = refScrollXHandleElem.value;
555
- const yHandleEl = refScrollYHandleElem.value;
556
- if (headerScrollElem && wrapperEl) {
557
- const isRollX = true;
558
- const isRollY = true;
559
- const currLeftNum = wrapperEl.scrollLeft;
560
- const currTopNum = wrapperEl.scrollTop;
561
- internalData.inBodyScroll = true;
562
- setScrollLeft(xHandleEl, currLeftNum);
563
- setScrollLeft(headerScrollElem, currLeftNum);
564
- setScrollTop(yHandleEl, currTopNum);
565
- syncTableScrollTop(currTopNum);
566
- handleScrollEvent(evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
567
- }
568
- },
569
- triggerFooterScrollEvent(evnt) {
570
- const { inVirtualScroll, inHeaderScroll, inBodyScroll } = internalData;
571
- if (inVirtualScroll) {
572
- return;
573
- }
574
- if (inHeaderScroll || inBodyScroll) {
575
- return;
576
- }
577
- const wrapperEl = evnt.currentTarget;
578
- if (wrapperEl) {
579
- const isRollX = true;
580
- const isRollY = false;
581
- const currLeftNum = wrapperEl.scrollLeft;
582
- handleScrollEvent(evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
583
- }
584
- },
585
- triggerVirtualScrollXEvent(evnt) {
586
- const { elemStore, inHeaderScroll, inBodyScroll } = internalData;
587
- if (inHeaderScroll || inBodyScroll) {
588
- return;
589
- }
590
- const wrapperEl = evnt.currentTarget;
591
- const headerScrollElem = getRefElem(elemStore['main-header-scroll']);
592
- const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
593
- if (wrapperEl) {
594
- const isRollY = false;
595
- const isRollX = true;
596
- const currLeftNum = wrapperEl.scrollLeft;
597
- internalData.inVirtualScroll = true;
598
- setScrollLeft(headerScrollElem, currLeftNum);
599
- setScrollLeft(bodyScrollElem, currLeftNum);
600
- handleScrollEvent(evnt, isRollY, isRollX, wrapperEl.scrollTop, currLeftNum);
601
- }
602
- },
603
- triggerVirtualScrollYEvent(evnt) {
604
- const { elemStore, inHeaderScroll, inBodyScroll } = internalData;
605
- if (inHeaderScroll || inBodyScroll) {
606
- return;
607
- }
608
- const wrapperEl = evnt.currentTarget;
609
- const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
610
- if (wrapperEl) {
611
- const isRollY = true;
612
- const isRollX = false;
613
- const currTopNum = wrapperEl.scrollTop;
614
- internalData.inVirtualScroll = true;
615
- setScrollTop(bodyScrollElem, currTopNum);
616
- syncTableScrollTop(currTopNum);
617
- handleScrollEvent(evnt, isRollY, isRollX, currTopNum, wrapperEl.scrollLeft);
618
- }
619
- },
620
- updateScrollXSpace,
621
- updateScrollYSpace
622
- };
623
- const handleGlobalResizeEvent = () => {
624
- handleLazyRecalculate();
625
- };
626
- Object.assign($xeGanttView, ganttViewMethods, ganttViewPrivateMethods);
627
- const renderScrollX = () => {
656
+ },
657
+ updateScrollXSpace() {
658
+ const $xeGanttView = this;
659
+ return updateScrollXSpace($xeGanttView);
660
+ },
661
+ updateScrollYSpace() {
662
+ const $xeGanttView = this;
663
+ return updateScrollYSpace($xeGanttView);
664
+ },
665
+ handleGlobalResizeEvent() {
666
+ const $xeGanttView = this;
667
+ handleLazyRecalculate($xeGanttView);
668
+ },
669
+ //
670
+ // Render
671
+ //
672
+ renderScrollX(h) {
673
+ const $xeGanttView = this;
628
674
  return h('div', {
629
675
  key: 'vsx',
630
- ref: refScrollXVirtualElem,
676
+ ref: 'refScrollXVirtualElem',
631
677
  class: 'vxe-gantt-view--scroll-x-virtual'
632
678
  }, [
633
679
  h('div', {
634
- ref: refScrollXLeftCornerElem,
680
+ ref: 'refScrollXLeftCornerElem',
635
681
  class: 'vxe-gantt-view--scroll-x-left-corner'
636
682
  }),
637
683
  h('div', {
638
- ref: refScrollXWrapperElem,
684
+ ref: 'refScrollXWrapperElem',
639
685
  class: 'vxe-gantt-view--scroll-x-wrapper'
640
686
  }, [
641
687
  h('div', {
642
- ref: refScrollXHandleElem,
688
+ ref: 'refScrollXHandleElem',
643
689
  class: 'vxe-gantt-view--scroll-x-handle',
644
- onScroll: $xeGanttView.triggerVirtualScrollXEvent
690
+ on: {
691
+ scroll: $xeGanttView.triggerVirtualScrollXEvent
692
+ }
645
693
  }, [
646
694
  h('div', {
647
- ref: refScrollXSpaceElem,
695
+ ref: 'refScrollXSpaceElem',
648
696
  class: 'vxe-gantt-view--scroll-x-space'
649
697
  })
650
698
  ])
651
699
  ]),
652
700
  h('div', {
653
- ref: refScrollXRightCornerElem,
701
+ ref: 'refScrollXRightCornerElem',
654
702
  class: 'vxe-gantt-view--scroll-x-right-corner'
655
703
  })
656
704
  ]);
657
- };
658
- const renderScrollY = () => {
705
+ },
706
+ renderScrollY(h) {
707
+ const $xeGanttView = this;
659
708
  return h('div', {
660
- ref: refScrollYVirtualElem,
709
+ ref: 'refScrollYVirtualElem',
661
710
  class: 'vxe-gantt-view--scroll-y-virtual'
662
711
  }, [
663
712
  h('div', {
664
- ref: refScrollYTopCornerElem,
713
+ ref: 'refScrollYTopCornerElem',
665
714
  class: 'vxe-gantt-view--scroll-y-top-corner'
666
715
  }),
667
716
  h('div', {
668
- ref: refScrollYWrapperElem,
717
+ ref: 'refScrollYWrapperElem',
669
718
  class: 'vxe-gantt-view--scroll-y-wrapper'
670
719
  }, [
671
720
  h('div', {
672
- ref: refScrollYHandleElem,
721
+ ref: 'refScrollYHandleElem',
673
722
  class: 'vxe-gantt-view--scroll-y-handle',
674
- onScroll: $xeGanttView.triggerVirtualScrollYEvent
723
+ on: {
724
+ scroll: $xeGanttView.triggerVirtualScrollYEvent
725
+ }
675
726
  }, [
676
727
  h('div', {
677
- ref: refScrollYSpaceElem,
728
+ ref: 'refScrollYSpaceElem',
678
729
  class: 'vxe-gantt-view--scroll-y-space'
679
730
  })
680
731
  ])
681
732
  ]),
682
733
  h('div', {
683
- ref: refScrollYBottomCornerElem,
734
+ ref: 'refScrollYBottomCornerElem',
684
735
  class: 'vxe-gantt-view--scroll-y-bottom-corner'
685
736
  })
686
737
  ]);
687
- };
688
- const renderViewport = () => {
738
+ },
739
+ renderViewport(h) {
689
740
  return h('div', {
690
741
  class: 'vxe-gantt-view--viewport-wrapper'
691
742
  }, [
692
743
  h(GanttViewHeaderComponent),
693
744
  h(GanttViewBodyComponent)
694
745
  ]);
695
- };
696
- const renderBody = () => {
697
- const scrollbarYToLeft = computeScrollbarYToLeft.value;
746
+ },
747
+ renderBody(h) {
748
+ const $xeGanttView = this;
749
+ const $xeGantt = $xeGanttView.$xeGantt;
750
+ const scrollbarYToLeft = $xeGantt.computeScrollbarYToLeft;
698
751
  return h('div', {
699
752
  class: 'vxe-gantt-view--layout-wrapper'
700
753
  }, scrollbarYToLeft
701
754
  ? [
702
- renderScrollY(),
703
- renderViewport()
755
+ $xeGanttView.renderScrollY(h),
756
+ $xeGanttView.renderViewport(h)
704
757
  ]
705
758
  : [
706
- renderViewport(),
707
- renderScrollY()
759
+ $xeGanttView.renderViewport(h),
760
+ $xeGanttView.renderScrollY(h)
708
761
  ]);
709
- };
710
- const renderVN = () => {
762
+ },
763
+ renderVN(h) {
764
+ const $xeGanttView = this;
765
+ const $xeGantt = $xeGanttView.$xeGantt;
766
+ const reactData = $xeGanttView.reactData;
711
767
  const { overflowX, overflowY, scrollXLoad, scrollYLoad } = reactData;
712
- const taskViewOpts = computeTaskViewOpts.value;
713
- const scrollbarXToTop = computeScrollbarXToTop.value;
768
+ const taskViewOpts = $xeGantt.computeTaskViewOpts;
769
+ const scrollbarXToTop = $xeGantt.computeScrollbarXToTop;
714
770
  return h('div', {
715
- ref: refElem,
771
+ ref: 'refElem',
716
772
  class: ['vxe-gantt-view', `mode--${taskViewOpts.mode || 'day'}`, {
717
773
  'is--scroll-y': overflowY,
718
774
  'is--scroll-x': overflowX,
@@ -724,45 +780,41 @@ export default defineVxeComponent({
724
780
  class: 'vxe-gantt-view--render-wrapper'
725
781
  }, scrollbarXToTop
726
782
  ? [
727
- renderScrollX(),
728
- renderBody()
783
+ $xeGanttView.renderScrollX(h),
784
+ $xeGanttView.renderBody(h)
729
785
  ]
730
786
  : [
731
- renderBody(),
732
- renderScrollX()
787
+ $xeGanttView.renderBody(h),
788
+ $xeGanttView.renderScrollX(h)
733
789
  ]),
734
790
  h('div', {
735
791
  class: 'vxe-gantt-view--render-vars'
736
792
  }, [
737
793
  h('div', {
738
- ref: refColInfoElem,
794
+ ref: 'refColInfoElem',
739
795
  class: 'vxe-gantt-view--column-info'
740
796
  })
741
797
  ])
742
798
  ]);
743
- };
744
- const tdFlag = ref(0);
745
- watch(() => reactData.tableData, () => {
746
- tdFlag.value++;
747
- });
748
- watch(() => reactData.tableData.length, () => {
749
- tdFlag.value++;
750
- });
751
- watch(tdFlag, () => {
752
- handleUpdateData();
753
- });
754
- onMounted(() => {
755
- globalEvents.on($xeGanttView, 'resize', handleGlobalResizeEvent);
756
- });
757
- onUnmounted(() => {
758
- globalEvents.off($xeGanttView, 'keydown');
759
- XEUtils.assign(internalData, createInternalData());
760
- });
761
- $xeGanttView.renderVN = renderVN;
762
- provide('$xeGanttView', $xeGanttView);
763
- return $xeGanttView;
799
+ }
800
+ },
801
+ watch: {
802
+ 'reactData.tableData'() {
803
+ const $xeGanttView = this;
804
+ handleUpdateData($xeGanttView);
805
+ }
806
+ },
807
+ mounted() {
808
+ const $xeGanttView = this;
809
+ globalEvents.on($xeGanttView, 'resize', $xeGanttView.handleGlobalResizeEvent);
810
+ },
811
+ beforeDestroy() {
812
+ const $xeGanttView = this;
813
+ const internalData = $xeGanttView.internalData;
814
+ globalEvents.off($xeGanttView, 'keydown');
815
+ XEUtils.assign(internalData, createInternalData());
764
816
  },
765
- render() {
766
- return this.renderVN();
817
+ render(h) {
818
+ return this.renderVN(h);
767
819
  }
768
820
  });