vxe-gantt 4.0.0-beta.3 → 4.0.0-beta.5

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 (45) hide show
  1. package/README.md +2 -2
  2. package/es/gantt/src/gantt-body.js +70 -36
  3. package/es/gantt/src/gantt-chart.js +80 -56
  4. package/es/gantt/src/gantt-view.js +62 -7
  5. package/es/gantt/src/gantt.js +25 -6
  6. package/es/gantt/style.css +17 -0
  7. package/es/gantt/style.min.css +1 -1
  8. package/es/style.css +1 -1
  9. package/es/style.min.css +1 -1
  10. package/es/ui/index.js +7 -2
  11. package/es/ui/src/log.js +1 -1
  12. package/es/ui/src/vn.js +7 -1
  13. package/es/vxe-gantt/style.css +17 -0
  14. package/es/vxe-gantt/style.min.css +1 -1
  15. package/lib/gantt/src/gantt-body.js +104 -44
  16. package/lib/gantt/src/gantt-body.min.js +1 -1
  17. package/lib/gantt/src/gantt-chart.js +100 -60
  18. package/lib/gantt/src/gantt-chart.min.js +1 -1
  19. package/lib/gantt/src/gantt-view.js +79 -6
  20. package/lib/gantt/src/gantt-view.min.js +1 -1
  21. package/lib/gantt/src/gantt.js +33 -9
  22. package/lib/gantt/src/gantt.min.js +1 -1
  23. package/lib/gantt/style/style.css +17 -0
  24. package/lib/gantt/style/style.min.css +1 -1
  25. package/lib/index.umd.js +377 -160
  26. package/lib/index.umd.min.js +1 -1
  27. package/lib/style.css +1 -1
  28. package/lib/style.min.css +1 -1
  29. package/lib/ui/index.js +13 -2
  30. package/lib/ui/index.min.js +1 -1
  31. package/lib/ui/src/log.js +1 -1
  32. package/lib/ui/src/log.min.js +1 -1
  33. package/lib/ui/src/vn.js +14 -1
  34. package/lib/ui/src/vn.min.js +1 -0
  35. package/lib/vxe-gantt/style/style.css +17 -0
  36. package/lib/vxe-gantt/style/style.min.css +1 -1
  37. package/package.json +3 -3
  38. package/packages/gantt/src/gantt-body.ts +79 -37
  39. package/packages/gantt/src/gantt-chart.ts +90 -61
  40. package/packages/gantt/src/gantt-view.ts +62 -7
  41. package/packages/gantt/src/gantt.ts +24 -5
  42. package/packages/ui/index.ts +9 -1
  43. package/packages/ui/src/vn.ts +9 -0
  44. package/styles/components/gantt-module/gantt-chart.scss +1 -0
  45. package/styles/components/gantt.scss +19 -0
@@ -5,7 +5,7 @@ import XEUtils from 'xe-utils'
5
5
  import { getCellRestHeight } from './util'
6
6
  import { getStringValue } from '../../ui/src/utils'
7
7
 
8
- import type { VxeTablePropTypes, TableInternalData } from 'vxe-table'
8
+ import type { VxeTableConstructor, VxeTableMethods, VxeTablePrivateMethods } from 'vxe-table'
9
9
  import type { VxeGanttViewConstructor, VxeGanttViewPrivateMethods, VxeGanttConstructor, VxeGanttPrivateMethods } from '../../../types'
10
10
 
11
11
  const { renderEmptyElement } = VxeUI
@@ -21,80 +21,109 @@ export default defineVxeComponent({
21
21
 
22
22
  const refElem = ref() as Ref<HTMLDivElement>
23
23
 
24
- const renderVN = () => {
25
- const $xeTable = $xeGanttView.internalData.xeTable
26
-
27
- const tableInternalData = $xeTable ? $xeTable.internalData : {} as TableInternalData
28
- const fullAllDataRowIdData = tableInternalData.fullAllDataRowIdData || {}
29
- let cellOpts: VxeTablePropTypes.CellConfig = {}
30
- let rowOpts : VxeTablePropTypes.RowConfig = {}
31
- let defaultRowHeight = 0
32
- if ($xeTable) {
33
- const { computeCellOpts, computeRowOpts, computeDefaultRowHeight } = $xeTable.getComputeMaps()
34
- cellOpts = computeCellOpts.value
35
- rowOpts = computeRowOpts.value
36
- defaultRowHeight = computeDefaultRowHeight.value
37
- }
24
+ const renderTaskBar = ($xeTable: VxeTableConstructor & VxeTableMethods & VxeTablePrivateMethods, row: any, rowid: string, $rowIndex: number) => {
25
+ const tableProps = $xeTable.props
26
+ const { treeConfig } = tableProps
27
+ const tableInternalData = $xeTable.internalData
28
+ const { fullAllDataRowIdData } = tableInternalData
29
+ const { computeCellOpts, computeRowOpts, computeDefaultRowHeight } = $xeTable.getComputeMaps()
30
+ const cellOpts = computeCellOpts.value
31
+ const rowOpts = computeRowOpts.value
32
+ const defaultRowHeight = computeDefaultRowHeight.value
38
33
 
39
- const { tableData } = reactData
40
34
  const titleField = computeTitleField.value
41
35
  const progressField = computeProgressField.value
42
36
  const taskBarOpts = computeTaskBarOpts.value
43
37
  const { showProgress, showContent, contentMethod, barStyle } = taskBarOpts
44
38
  const { round } = barStyle || {}
45
39
 
40
+ const rowRest = fullAllDataRowIdData[rowid] || {}
41
+ const cellHeight = getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight)
42
+ let title = getStringValue(XEUtils.get(row, titleField))
43
+ const progressValue = showProgress ? Math.min(100, Math.max(0, XEUtils.toNumber(XEUtils.get(row, progressField)))) : 0
44
+
45
+ if (contentMethod) {
46
+ title = getStringValue(contentMethod({ row, title }))
47
+ }
48
+ return h('div', {
49
+ key: treeConfig ? rowid : $rowIndex,
50
+ rowid,
51
+ class: ['vxe-gantt-view--chart-row', {
52
+ 'is--round': round
53
+ }],
54
+ style: {
55
+ height: `${cellHeight}px`
56
+ }
57
+ }, [
58
+ h('div', {
59
+ class: 'vxe-gantt-view--chart-bar',
60
+ rowid,
61
+ onClick (evnt) {
62
+ $xeGantt.handleTaskBarClickEvent(evnt, { row })
63
+ },
64
+ onDblclick (evnt) {
65
+ $xeGantt.handleTaskBarDblclickEvent(evnt, { row })
66
+ }
67
+ }, [
68
+ showProgress
69
+ ? h('div', {
70
+ class: 'vxe-gantt-view--chart-progress',
71
+ style: {
72
+ width: `${progressValue || 0}%`
73
+ }
74
+ })
75
+ : renderEmptyElement($xeGantt),
76
+ showContent
77
+ ? h('div', {
78
+ class: 'vxe-gantt-view--chart-content'
79
+ }, title)
80
+ : renderEmptyElement($xeGantt)
81
+ ])
82
+ ])
83
+ }
84
+
85
+ const renderRows = ($xeTable: VxeTableConstructor & VxeTableMethods & VxeTablePrivateMethods, tableData: any[]) => {
86
+ const tableProps = $xeTable.props
87
+ const { treeConfig } = tableProps
88
+ const tableReactData = $xeTable.reactData
89
+ const { treeExpandedFlag } = tableReactData
90
+ const tableInternalData = $xeTable.internalData
91
+ const { treeExpandedMaps } = tableInternalData
92
+ const { computeTreeOpts } = $xeTable.getComputeMaps()
93
+ const treeOpts = computeTreeOpts.value
94
+ const { transform } = treeOpts
95
+ const childrenField = treeOpts.children || treeOpts.childrenField
96
+
97
+ const { scrollYLoad } = reactData
98
+
46
99
  const trVNs: VNode[] = []
47
- tableData.forEach((row, rIndex) => {
100
+ tableData.forEach((row, $rowIndex) => {
48
101
  const rowid = $xeTable ? $xeTable.getRowid(row) : ''
49
- const rowRest = fullAllDataRowIdData[rowid] || {}
50
- const cellHeight = getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight)
51
- let title = getStringValue(XEUtils.get(row, titleField))
52
- const progressValue = showProgress ? Math.min(100, Math.max(0, XEUtils.toNumber(XEUtils.get(row, progressField)))) : 0
53
- if (contentMethod) {
54
- title = getStringValue(contentMethod({ row, title }))
102
+ trVNs.push(renderTaskBar($xeTable, row, rowid, $rowIndex))
103
+ let isExpandTree = false
104
+ let rowChildren: any[] = []
105
+
106
+ if (treeConfig && !scrollYLoad && !transform) {
107
+ rowChildren = row[childrenField]
108
+ isExpandTree = !!treeExpandedFlag && rowChildren && rowChildren.length > 0 && !!treeExpandedMaps[rowid]
109
+ }
110
+ // 如果是树形表格
111
+ if (isExpandTree) {
112
+ trVNs.push(...renderRows($xeTable, rowChildren))
55
113
  }
56
- trVNs.push(
57
- h('div', {
58
- key: rIndex,
59
- rowid,
60
- class: ['vxe-gantt-view--chart-row', {
61
- 'is--round': round
62
- }],
63
- style: {
64
- height: `${cellHeight}px`
65
- }
66
- }, [
67
- h('div', {
68
- class: 'vxe-gantt-view--chart-bar',
69
- rowid,
70
- onClick (evnt) {
71
- $xeGantt.handleTaskBarClickEvent(evnt, { row })
72
- },
73
- onDblclick (evnt) {
74
- $xeGantt.handleTaskBarDblclickEvent(evnt, { row })
75
- }
76
- }, [
77
- showProgress
78
- ? h('div', {
79
- class: 'vxe-gantt-view--chart-progress',
80
- style: {
81
- width: `${progressValue || 0}%`
82
- }
83
- })
84
- : renderEmptyElement($xeGantt),
85
- showContent
86
- ? h('div', {
87
- class: 'vxe-gantt-view--chart-content'
88
- }, title)
89
- : renderEmptyElement($xeGantt)
90
- ])
91
- ])
92
- )
93
114
  })
115
+ return trVNs
116
+ }
117
+
118
+ const renderVN = () => {
119
+ const $xeTable = $xeGanttView.internalData.xeTable
120
+
121
+ const { tableData } = reactData
122
+
94
123
  return h('div', {
95
124
  ref: refElem,
96
125
  class: 'vxe-gantt-view--chart-wrapper'
97
- }, trVNs)
126
+ }, $xeTable ? renderRows($xeTable, tableData) : [])
98
127
  }
99
128
 
100
129
  onMounted(() => {
@@ -1,6 +1,6 @@
1
1
  import { h, ref, reactive, nextTick, inject, watch, provide, onMounted, onUnmounted } from 'vue'
2
2
  import { defineVxeComponent } from '../../ui/src/comp'
3
- import { setScrollTop, setScrollLeft } from '../../ui/src/dom'
3
+ import { setScrollTop, setScrollLeft, removeClass, addClass } from '../../ui/src/dom'
4
4
  import { VxeUI } from '@vxe-ui/core'
5
5
  import { getRefElem } from './util'
6
6
  import XEUtils from 'xe-utils'
@@ -131,6 +131,8 @@ export default defineVxeComponent({
131
131
  } as unknown as VxeGanttViewConstructor & VxeGanttViewPrivateMethods
132
132
 
133
133
  const handleParseColumn = () => {
134
+ const ganttProps = $xeGantt.props
135
+ const { treeConfig } = ganttProps
134
136
  const { minViewDate, maxViewDate } = reactData
135
137
  const taskViewOpts = computeTaskViewOpts.value
136
138
  const fullCols: VxeGanttPropTypes.Column[] = []
@@ -182,10 +184,15 @@ export default defineVxeComponent({
182
184
  if ($xeTable) {
183
185
  const startField = computeStartField.value
184
186
  const endField = computeEndField.value
187
+ const { computeTreeOpts } = $xeTable.getComputeMaps()
185
188
  const tableInternalData = $xeTable.internalData
186
- const { afterFullData } = tableInternalData
189
+ const { afterFullData, afterTreeFullData } = tableInternalData
190
+ const treeOpts = computeTreeOpts.value
191
+ const { transform } = treeOpts
192
+ const childrenField = treeOpts.children || treeOpts.childrenField
193
+
187
194
  const ctMaps: Record<string, VxeGanttDefines.RowCacheItem> = {}
188
- afterFullData.forEach(row => {
195
+ const handleParseRender = (row: any) => {
189
196
  const rowid = $xeTable.getRowid(row)
190
197
  const startValue = XEUtils.get(row, startField)
191
198
  const endValue = XEUtils.get(row, endField)
@@ -201,7 +208,13 @@ export default defineVxeComponent({
201
208
  oWidthSize
202
209
  }
203
210
  }
204
- })
211
+ }
212
+
213
+ if (treeConfig) {
214
+ XEUtils.eachTree(afterTreeFullData, handleParseRender, { children: transform ? treeOpts.mapChildrenField : childrenField })
215
+ } else {
216
+ afterFullData.forEach(handleParseRender)
217
+ }
205
218
  internalData.chartMaps = ctMaps
206
219
  }
207
220
  }
@@ -213,6 +226,8 @@ export default defineVxeComponent({
213
226
  }
214
227
 
215
228
  const handleUpdateData = () => {
229
+ const ganttProps = $xeGantt.props
230
+ const { treeConfig } = ganttProps
216
231
  const $xeTable = internalData.xeTable
217
232
  const sdMaps: Record<string, any> = {}
218
233
  const edMaps: Record<string, any> = {}
@@ -221,9 +236,14 @@ export default defineVxeComponent({
221
236
  if ($xeTable) {
222
237
  const startField = computeStartField.value
223
238
  const endField = computeEndField.value
239
+ const { computeTreeOpts } = $xeTable.getComputeMaps()
224
240
  const tableInternalData = $xeTable.internalData
225
- const { afterFullData } = tableInternalData
226
- afterFullData.forEach(row => {
241
+ const { afterFullData, afterTreeFullData } = tableInternalData
242
+ const treeOpts = computeTreeOpts.value
243
+ const { transform } = treeOpts
244
+ const childrenField = treeOpts.children || treeOpts.childrenField
245
+
246
+ const handleMinMaxData = (row: any) => {
227
247
  const startValue = XEUtils.get(row, startField)
228
248
  const endValue = XEUtils.get(row, endField)
229
249
  if (startValue && endValue) {
@@ -236,7 +256,13 @@ export default defineVxeComponent({
236
256
  maxDate = endDate
237
257
  }
238
258
  }
239
- })
259
+ }
260
+
261
+ if (treeConfig) {
262
+ XEUtils.eachTree(afterTreeFullData, handleMinMaxData, { children: transform ? treeOpts.mapChildrenField : childrenField })
263
+ } else {
264
+ afterFullData.forEach(handleMinMaxData)
265
+ }
240
266
  }
241
267
  reactData.minViewDate = minDate
242
268
  reactData.maxViewDate = maxDate
@@ -400,6 +426,7 @@ export default defineVxeComponent({
400
426
  const handleLazyRecalculate = () => {
401
427
  calcScrollbar()
402
428
  updateStyle()
429
+ updateChart()
403
430
  return nextTick()
404
431
  }
405
432
 
@@ -584,6 +611,34 @@ export default defineVxeComponent({
584
611
  const ganttViewPrivateMethods: VxeGanttViewPrivateMethods = {
585
612
  handleUpdateStyle: updateStyle,
586
613
  handleLazyRecalculate,
614
+ handleUpdateCurrentRow (row) {
615
+ const $xeTable = internalData.xeTable
616
+ const el = refElem.value
617
+ if ($xeTable && el) {
618
+ if (row) {
619
+ const tableProps = $xeTable.props
620
+ const { highlightCurrentRow } = tableProps
621
+ const { computeRowOpts } = $xeTable.getComputeMaps()
622
+ const rowOpts = computeRowOpts.value
623
+ if (rowOpts.isCurrent || highlightCurrentRow) {
624
+ XEUtils.arrayEach(el.querySelectorAll(`.vxe-gantt-view--body-row[rowid="${$xeTable.getRowid(row)}"]`), elem => addClass(elem, 'row--current'))
625
+ }
626
+ } else {
627
+ XEUtils.arrayEach(el.querySelectorAll('.vxe-gantt-view--body-row.row--current'), elem => removeClass(elem, 'row--current'))
628
+ }
629
+ }
630
+ },
631
+ handleUpdateHoverRow (row) {
632
+ const $xeTable = internalData.xeTable
633
+ const el = refElem.value
634
+ if ($xeTable && el) {
635
+ if (row) {
636
+ XEUtils.arrayEach(el.querySelectorAll(`.vxe-gantt-view--body-row[rowid="${$xeTable.getRowid(row)}"]`), elem => addClass(elem, 'row--hover'))
637
+ } else {
638
+ XEUtils.arrayEach(el.querySelectorAll('.vxe-gantt-view--body-row.row--hover'), elem => removeClass(elem, 'row--hover'))
639
+ }
640
+ }
641
+ },
587
642
  triggerHeaderScrollEvent (evnt) {
588
643
  const { elemStore, inVirtualScroll, inBodyScroll, inFooterScroll } = internalData
589
644
  if (inVirtualScroll) {
@@ -3,6 +3,7 @@ import { defineVxeComponent } from '../../ui/src/comp'
3
3
  import XEUtils from 'xe-utils'
4
4
  import { getLastZIndex, nextZIndex, isEnableConf } from '../../ui/src/utils'
5
5
  import { getOffsetHeight, getPaddingTopBottomSize, getDomNode, toCssUnit, addClass, removeClass } from '../../ui/src/dom'
6
+ import { getSlotVNs } from '../../ui/src/vn'
6
7
  import { VxeUI } from '@vxe-ui/core'
7
8
  import { ganttEmits } from './emits'
8
9
  import { tableEmits } from './table-emits'
@@ -14,7 +15,7 @@ import type { VxeGanttConstructor, VxeGanttEmits, GanttReactData, GanttInternalD
14
15
  import type { ValueOf, VxeFormEvents, VxeFormInstance, VxePagerEvents, VxeFormItemProps, VxePagerInstance, VxeComponentStyleType } from 'vxe-pc-ui'
15
16
  import type { VxeTableMethods, VxeToolbarPropTypes, VxeTableProps, VxeTablePropTypes, VxeTableConstructor, VxeTablePrivateMethods, VxeTableEvents, VxeTableDefines, VxeTableEventProps, VxeToolbarInstance, VxeGridPropTypes } from 'vxe-table'
16
17
 
17
- const { getConfig, getIcon, getI18n, commands, hooks, useFns, createEvent, globalEvents, GLOBAL_EVENT_KEYS, renderEmptyElement, getSlotVNs } = VxeUI
18
+ const { getConfig, getIcon, getI18n, commands, hooks, useFns, createEvent, globalEvents, GLOBAL_EVENT_KEYS, renderEmptyElement } = VxeUI
18
19
 
19
20
  const tableProps = (VxeTableComponent as any).props
20
21
 
@@ -1397,6 +1398,22 @@ export default defineVxeComponent({
1397
1398
  $xeGantt.dispatchEvent('zoom', { type: reactData.isZMax ? 'max' : 'revert' }, evnt)
1398
1399
  },
1399
1400
  handleTaskCellClickEvent (evnt, params) {
1401
+ const $xeTable = refTable.value
1402
+ if ($xeTable) {
1403
+ const tableProps = $xeTable.props
1404
+ const { highlightCurrentRow } = tableProps
1405
+ const { computeRowOpts } = $xeTable.getComputeMaps()
1406
+ const rowOpts = computeRowOpts.value
1407
+ const { row } = params
1408
+ // 如果是当前行
1409
+ if (rowOpts.isCurrent || highlightCurrentRow) {
1410
+ $xeTable.triggerCurrentRowEvent(evnt, Object.assign({
1411
+ $table: $xeTable,
1412
+ rowIndex: $xeTable.getRowIndex(row),
1413
+ $rowIndex: $xeTable.getVMRowIndex(row)
1414
+ }, params))
1415
+ }
1416
+ }
1400
1417
  $xeGantt.dispatchEvent('task-cell-click', params, evnt)
1401
1418
  },
1402
1419
  handleTaskCellDblclickEvent (evnt, params) {
@@ -1710,20 +1727,21 @@ export default defineVxeComponent({
1710
1727
  if (!enabled) {
1711
1728
  return renderEmptyElement($xeGantt)
1712
1729
  }
1730
+ const isResize = resize && showLeftView && showRightView
1713
1731
  const ons: {
1714
1732
  onMousedown?: typeof dragSplitEvent
1715
1733
  } = {}
1716
- if (resize) {
1734
+ if (isResize) {
1717
1735
  ons.onMousedown = dragSplitEvent
1718
1736
  }
1719
1737
  return h('div', {
1720
1738
  class: ['vxe-gantt--view-split-bar', {
1721
- 'is--resize': resize,
1722
- ...ons
1739
+ 'is--resize': isResize
1723
1740
  }]
1724
1741
  }, [
1725
1742
  h('div', {
1726
- class: 'vxe-gantt--view-split-bar-handle'
1743
+ class: 'vxe-gantt--view-split-bar-handle',
1744
+ ...ons
1727
1745
  }),
1728
1746
  showCollapseTableButton || showCollapseTaskButton
1729
1747
  ? h('div', {
@@ -1954,6 +1972,7 @@ export default defineVxeComponent({
1954
1972
 
1955
1973
  $xeGantt.renderVN = renderVN
1956
1974
 
1975
+ provide('$xeGrid', null)
1957
1976
  provide('$xeGantt', $xeGantt)
1958
1977
 
1959
1978
  return $xeGantt
@@ -1,6 +1,7 @@
1
1
  import { VxeUI } from '@vxe-ui/core'
2
+ import { errLog } from './src/log'
2
3
 
3
- const { setConfig, setIcon } = VxeUI
4
+ const { setConfig, setIcon, checkVersion } = VxeUI
4
5
 
5
6
  VxeUI.ganttVersion = process.env.VUE_APP_VXE_VERSION as string
6
7
 
@@ -61,4 +62,11 @@ setIcon({
61
62
  GANTT_VIEW_RIGHT_CLOSE: iconPrefix + 'arrow-left'
62
63
  })
63
64
 
65
+ if (!checkVersion(VxeUI.tableVersion, 4, 16)) {
66
+ errLog('vxe.error.errorVersion', [`vxe-table@${VxeUI.tableVersion || '?'}`, 'vxe-table v4.16+'])
67
+ }
68
+
69
+ export {
70
+ VxeUI
71
+ }
64
72
  export default VxeUI
@@ -0,0 +1,9 @@
1
+ import XEUtils from 'xe-utils'
2
+ import { VxeComponentSlotType } from '@vxe-ui/core'
3
+
4
+ export function getSlotVNs (vns: VxeComponentSlotType | VxeComponentSlotType[] | undefined) {
5
+ if (XEUtils.isArray(vns)) {
6
+ return vns
7
+ }
8
+ return vns ? [vns] : []
9
+ }
@@ -41,6 +41,7 @@
41
41
  width: 100%;
42
42
  height: 100%;
43
43
  background-color: rgba(0, 0, 0, 0.1);
44
+ pointer-events: none;
44
45
  }
45
46
  }
46
47
  }
@@ -578,6 +578,25 @@
578
578
  white-space: nowrap;
579
579
  }
580
580
 
581
+ // 行高亮
582
+ .vxe-gantt-view--body-row {
583
+ &.row--stripe {
584
+ background-color: var(--vxe-ui-table-row-striped-background-color);
585
+ }
586
+ &.row--current {
587
+ background-color: var(--vxe-ui-table-row-current-background-color);
588
+ }
589
+ &.row--hover {
590
+ background-color: var(--vxe-ui-table-row-hover-background-color);
591
+ &.row--stripe {
592
+ background-color: var(--vxe-ui-table-row-hover-striped-background-color);
593
+ }
594
+ &.row--current {
595
+ background-color: var(--vxe-ui-table-row-hover-current-background-color);
596
+ }
597
+ }
598
+ }
599
+
581
600
  .vxe-gantt-view {
582
601
  &.mode--day {
583
602
  .vxe-gantt-view--header-column {