vxe-gantt 3.0.4 → 3.0.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.
@@ -9,7 +9,7 @@ import GanttViewBodyComponent from './gantt-body'
9
9
  import GanttViewFooterComponent from './gantt-footer'
10
10
 
11
11
  import type { TableReactData, TableInternalData, VxeTableConstructor, VxeTableMethods, VxeTablePrivateMethods } from 'vxe-table'
12
- import type { VxeGanttViewConstructor, GanttViewReactData, VxeGanttPropTypes, VxeGanttDefines, VxeGanttViewPrivateMethods, GanttViewInternalData, VxeGanttConstructor, VxeGanttPrivateMethods } from '../../../types'
12
+ import type { VxeGanttViewConstructor, GanttViewReactData, VxeGanttDefines, VxeGanttViewPrivateMethods, GanttViewInternalData, VxeGanttConstructor, VxeGanttPrivateMethods } from '../../../types'
13
13
 
14
14
  const { globalEvents } = VxeUI
15
15
 
@@ -59,92 +59,251 @@ function handleParseColumn ($xeGanttView: VxeGanttViewConstructor & VxeGanttView
59
59
  const internalData = $xeGanttView.internalData
60
60
 
61
61
  const ganttProps = $xeGantt
62
+ const ganttReactData = $xeGantt.reactData
62
63
  const { treeConfig } = ganttProps
64
+ const { taskScaleList } = ganttReactData
63
65
  const { minViewDate, maxViewDate } = reactData
64
- const taskViewOpts = $xeGantt.computeTaskViewOpts
65
- const fullCols: VxeGanttPropTypes.Column[] = []
66
- const groupCols: VxeGanttPropTypes.Column[][] = []
67
- switch (taskViewOpts.mode) {
68
- case 'year':
69
- break
70
- case 'quarter':
71
- break
72
- case 'month':
73
- break
74
- case 'week':
75
- break
76
- default: {
77
- if (minViewDate && maxViewDate) {
78
- const currTime = minViewDate.getTime()
79
- const diffDayNum = maxViewDate.getTime() - minViewDate.getTime()
80
- const countDayNum = Math.max(6, Math.floor(diffDayNum / 86400000) + 1)
81
- const groupList: VxeGanttDefines.GroupHeaderColumn[] = []
82
- const colList: VxeGanttPropTypes.Column[] = []
83
- const groupMaps: Record<string, VxeGanttDefines.GroupHeaderColumn> = {}
84
- for (let i = 0; i < countDayNum; i++) {
85
- const itemDate = new Date(currTime + (i * 86400000))
86
- const yyyyy = `${itemDate.getFullYear()}-${itemDate.getMonth() + 1}`
87
- const mmDd = `${itemDate.getDate()}`
88
- let groupCol = groupMaps[yyyyy]
89
- const column = {
90
- field: `${yyyyy}-${mmDd}`,
91
- title: mmDd
92
- }
93
- if (groupCol) {
94
- groupCol.children.push(column)
95
- fullCols.push(groupCol)
96
- } else {
97
- groupCol = {
98
- field: yyyyy,
99
- title: yyyyy,
100
- children: [column]
101
- }
102
- groupList.push(groupCol)
103
- fullCols.push(groupCol)
104
- groupMaps[yyyyy] = groupCol
105
- }
106
- colList.push(column)
66
+ const minScale = XEUtils.last(taskScaleList)
67
+ const fullCols: VxeGanttDefines.ViewColumn[] = []
68
+ const groupCols: VxeGanttDefines.HeaderColumn[] = []
69
+ if (minScale && minViewDate && maxViewDate) {
70
+ const minSType = minScale.type
71
+ const weekScale = taskScaleList.find(item => item.type === 'week')
72
+ let gapTime = 1000 * 60 * 60 * 24
73
+ switch (minScale.type) {
74
+ case 'hour':
75
+ gapTime = 1000 * 60 * 60
76
+ break
77
+ case 'minute':
78
+ gapTime = 1000 * 60
79
+ break
80
+ case 'second':
81
+ gapTime = 1000
82
+ break
83
+ default: {
84
+ break
85
+ }
86
+ }
87
+ const currTime = minViewDate.getTime()
88
+ const diffDayNum = maxViewDate.getTime() - minViewDate.getTime()
89
+ const countSize = Math.max(5, Math.floor(diffDayNum / gapTime) + 1)
90
+
91
+ switch (minScale.type) {
92
+ case 'day':
93
+ case 'date':
94
+ if (diffDayNum > (1000 * 60 * 60 * 24 * 366 * 3)) {
95
+ reactData.tableColumn = []
96
+ reactData.headerGroups = []
97
+ return
107
98
  }
108
- groupCols.push(groupList, colList)
109
-
110
- const $xeTable = internalData.xeTable
111
- if ($xeTable) {
112
- const startField = $xeGantt.computeStartField
113
- const endField = $xeGantt.computeEndField
114
- const tableInternalData = $xeTable as unknown as TableInternalData
115
- const { afterFullData, afterTreeFullData } = tableInternalData
116
- const treeOpts = $xeTable.computeTreeOpts
117
- const { transform } = treeOpts
118
- const childrenField = treeOpts.children || treeOpts.childrenField
119
-
120
- const ctMaps: Record<string, VxeGanttDefines.RowCacheItem> = {}
121
- const handleParseRender = (row: any) => {
122
- const rowid = $xeTable.getRowid(row)
123
- const startValue = XEUtils.get(row, startField)
124
- const endValue = XEUtils.get(row, endField)
125
- if (startValue && endValue) {
126
- const startDate = parseStringDate($xeGanttView, startValue)
127
- const endDate = parseStringDate($xeGanttView, endValue)
128
- const oLeftSize = Math.floor((startDate.getTime() - minViewDate.getTime()) / 86400000)
129
- const oWidthSize = Math.floor((endDate.getTime() - startDate.getTime()) / 86400000) + 1
130
- ctMaps[rowid] = {
131
- row,
132
- rowid,
133
- oLeftSize,
134
- oWidthSize
135
- }
136
- }
137
- }
99
+ break
100
+ case 'hour':
101
+ if (diffDayNum > (1000 * 60 * 60 * 24 * 31 * 3)) {
102
+ reactData.tableColumn = []
103
+ reactData.headerGroups = []
104
+ return
105
+ }
106
+ break
107
+ case 'minute':
108
+ if (diffDayNum > (1000 * 60 * 60 * 24 * 3)) {
109
+ reactData.tableColumn = []
110
+ reactData.headerGroups = []
111
+ return
112
+ }
113
+ break
114
+ case 'second':
115
+ if (diffDayNum > (1000 * 60 * 60 * 3)) {
116
+ reactData.tableColumn = []
117
+ reactData.headerGroups = []
118
+ return
119
+ }
120
+ break
121
+ }
122
+
123
+ const renderListMaps: Record<VxeGanttDefines.ColumnScaleType, VxeGanttDefines.ViewColumn[]> = {
124
+ year: [],
125
+ quarter: [],
126
+ month: [],
127
+ week: [],
128
+ day: [],
129
+ date: [],
130
+ hour: [],
131
+ minute: [],
132
+ second: []
133
+ }
134
+
135
+ const tempTypeMaps: Record<VxeGanttDefines.ColumnScaleType, Record<string, VxeGanttDefines.ViewColumn>> = {
136
+ year: {},
137
+ quarter: {},
138
+ month: {},
139
+ week: {},
140
+ day: {},
141
+ date: {},
142
+ hour: {},
143
+ minute: {},
144
+ second: {}
145
+ }
146
+
147
+ const handleData = (type: VxeGanttDefines.ColumnScaleType, colMaps: Record<VxeGanttDefines.ColumnScaleType, VxeGanttDefines.ViewColumn>, minCol: VxeGanttDefines.ViewColumn) => {
148
+ if (minSType === type) {
149
+ return
150
+ }
151
+ const currCol = colMaps[type]
152
+ const currKey = `${currCol.field}`
153
+ let currGpCol = tempTypeMaps[type][currKey]
154
+ if (!currGpCol) {
155
+ currGpCol = currCol
156
+ tempTypeMaps[type][currKey] = currGpCol
157
+ renderListMaps[type].push(currGpCol)
158
+ }
159
+ if (currGpCol) {
160
+ if (!currGpCol.children) {
161
+ currGpCol.children = []
162
+ }
163
+ currGpCol.children.push(minCol)
164
+ }
165
+ }
138
166
 
139
- if (treeConfig) {
140
- XEUtils.eachTree(afterTreeFullData, handleParseRender, { children: transform ? treeOpts.mapChildrenField : childrenField })
141
- } else {
142
- afterFullData.forEach(handleParseRender)
167
+ for (let i = 0; i < countSize; i++) {
168
+ const itemDate = new Date(currTime + (i * gapTime))
169
+ const [yyyy, MM, dd, HH, mm, ss] = XEUtils.toDateString(itemDate, 'yyyy-M-d-H-m-s').split('-')
170
+ const e = itemDate.getDay()
171
+ const E = e + 1
172
+ const q = Math.ceil((itemDate.getMonth() + 1) / 3)
173
+ const W = XEUtils.getYearWeek(itemDate, weekScale ? weekScale.startDay : undefined)
174
+ const dateObj: VxeGanttDefines.ScaleDateObj = { yy: yyyy, M: MM, d: dd, H: HH, m: mm, s: ss, q, W, E, e }
175
+ const colMaps: Record<VxeGanttDefines.ColumnScaleType, VxeGanttDefines.ViewColumn> = {
176
+ year: {
177
+ field: yyyy,
178
+ title: yyyy,
179
+ params: dateObj
180
+ },
181
+ quarter: {
182
+ field: `${yyyy}_q${q}`,
183
+ title: q,
184
+ params: dateObj
185
+ },
186
+ month: {
187
+ field: `${yyyy}_${MM}`,
188
+ title: MM,
189
+ params: dateObj
190
+ },
191
+ week: {
192
+ field: `${yyyy}_W${W}`,
193
+ title: W,
194
+ params: dateObj
195
+ },
196
+ day: {
197
+ field: `${yyyy}_${MM}_${dd}_E${E}`,
198
+ title: E,
199
+ params: dateObj
200
+ },
201
+ date: {
202
+ field: `${yyyy}_${MM}_${dd}`,
203
+ title: dd,
204
+ params: dateObj
205
+ },
206
+ hour: {
207
+ field: `${yyyy}_${MM}_${dd}_${HH}`,
208
+ title: HH,
209
+ params: dateObj
210
+ },
211
+ minute: {
212
+ field: `${yyyy}_${MM}_${dd}_${HH}_${mm}`,
213
+ title: mm,
214
+ params: dateObj
215
+ },
216
+ second: {
217
+ field: `${yyyy}_${MM}_${dd}_${HH}_${mm}_${ss}`,
218
+ title: ss,
219
+ params: dateObj
220
+ }
221
+ }
222
+ const minCol = colMaps[minSType]
223
+ if (minScale.level < 19) {
224
+ handleData('year', colMaps, minCol)
225
+ }
226
+ if (minScale.level < 17) {
227
+ handleData('quarter', colMaps, minCol)
228
+ }
229
+ if (minScale.level < 14) {
230
+ handleData('month', colMaps, minCol)
231
+ }
232
+ if (minScale.level < 13) {
233
+ handleData('week', colMaps, minCol)
234
+ }
235
+ if (minScale.level < 11) {
236
+ handleData('day', colMaps, minCol)
237
+ }
238
+ if (minScale.level < 12) {
239
+ handleData('date', colMaps, minCol)
240
+ }
241
+ if (minScale.level < 7) {
242
+ handleData('hour', colMaps, minCol)
243
+ }
244
+ if (minScale.level < 5) {
245
+ handleData('minute', colMaps, minCol)
246
+ }
247
+
248
+ fullCols.push(minCol)
249
+ }
250
+
251
+ taskScaleList.forEach(scaleItem => {
252
+ if (scaleItem.type === minSType) {
253
+ groupCols.push({
254
+ scaleItem,
255
+ columns: fullCols
256
+ })
257
+ return
258
+ }
259
+ const list = renderListMaps[scaleItem.type] || []
260
+ if (list) {
261
+ list.forEach(item => {
262
+ item.childCount = item.children ? item.children.length : 0
263
+ item.children = undefined
264
+ })
265
+ }
266
+ groupCols.push({
267
+ scaleItem,
268
+ columns: list
269
+ })
270
+ })
271
+
272
+ const $xeTable = internalData.xeTable
273
+ if ($xeTable) {
274
+ const startField = $xeGantt.computeStartField
275
+ const endField = $xeGantt.computeEndField
276
+ const tableInternalData = $xeTable as unknown as TableInternalData
277
+ const { afterFullData, afterTreeFullData } = tableInternalData
278
+ const treeOpts = $xeTable.computeTreeOpts
279
+ const { transform } = treeOpts
280
+ const childrenField = treeOpts.children || treeOpts.childrenField
281
+
282
+ const ctMaps: Record<string, VxeGanttDefines.RowCacheItem> = {}
283
+ const handleParseRender = (row: any) => {
284
+ const rowid = $xeTable.getRowid(row)
285
+ const startValue = XEUtils.get(row, startField)
286
+ const endValue = XEUtils.get(row, endField)
287
+ if (startValue && endValue) {
288
+ const startDate = parseStringDate($xeGanttView, startValue)
289
+ const endDate = parseStringDate($xeGanttView, endValue)
290
+ const oLeftSize = Math.floor((startDate.getTime() - minViewDate.getTime()) / gapTime)
291
+ const oWidthSize = Math.floor((endDate.getTime() - startDate.getTime()) / gapTime) + 1
292
+ ctMaps[rowid] = {
293
+ row,
294
+ rowid,
295
+ oLeftSize,
296
+ oWidthSize
143
297
  }
144
- internalData.chartMaps = ctMaps
145
298
  }
146
299
  }
147
- break
300
+
301
+ if (treeConfig) {
302
+ XEUtils.eachTree(afterTreeFullData, handleParseRender, { children: transform ? treeOpts.mapChildrenField : childrenField })
303
+ } else {
304
+ afterFullData.forEach(handleParseRender)
305
+ }
306
+ internalData.chartMaps = ctMaps
148
307
  }
149
308
  }
150
309
  reactData.tableColumn = fullCols
@@ -599,15 +758,7 @@ export default defineVxeComponent({
599
758
  tableColumn: [],
600
759
  headerGroups: [],
601
760
 
602
- viewCellWidth: 40,
603
-
604
- rowHeightStore: {
605
- large: 52,
606
- default: 48,
607
- medium: 44,
608
- small: 40,
609
- mini: 36
610
- }
761
+ viewCellWidth: 20
611
762
  }
612
763
 
613
764
  const internalData = createInternalData()
@@ -957,11 +1108,10 @@ export default defineVxeComponent({
957
1108
  const reactData = $xeGanttView.reactData
958
1109
 
959
1110
  const { overflowX, overflowY, scrollXLoad, scrollYLoad } = reactData
960
- const taskViewOpts = $xeGantt.computeTaskViewOpts
961
1111
  const scrollbarXToTop = $xeGantt.computeScrollbarXToTop
962
1112
  return h('div', {
963
1113
  ref: 'refElem',
964
- class: ['vxe-gantt-view', `mode--${taskViewOpts.mode || 'day'}`, {
1114
+ class: ['vxe-gantt-view', {
965
1115
  'is--scroll-y': overflowY,
966
1116
  'is--scroll-x': overflowX,
967
1117
  'is--virtual-x': scrollXLoad,
@@ -22,6 +22,22 @@ const propKeys = Object.keys(tableProps) as (keyof VxeTableProps)[]
22
22
 
23
23
  const defaultLayouts: VxeGanttPropTypes.Layouts = [['Form'], ['Toolbar', 'Top', 'Gantt', 'Bottom', 'Pager']]
24
24
 
25
+ const viewTypeLevelMaps = {
26
+ year: 19,
27
+ quarter: 17,
28
+ month: 15,
29
+ week: 13,
30
+ day: 11,
31
+ date: 9,
32
+ hour: 7,
33
+ minute: 5,
34
+ second: 3
35
+ }
36
+
37
+ function getViewTypeLevel (type: VxeGanttDefines.ColumnScaleType) {
38
+ return viewTypeLevelMaps[type || 'date'] || viewTypeLevelMaps.date
39
+ }
40
+
25
41
  function getTableOns ($xeGantt: VxeGanttConstructor) {
26
42
  const _vm = $xeGantt as any
27
43
  const $listeners = _vm.$listeners
@@ -99,6 +115,7 @@ export default /* define-vxe-component start */ defineVxeComponent({
99
115
 
100
116
  layouts: Array as PropType<VxeGanttPropTypes.Layouts>,
101
117
  taskConfig: Object as PropType<VxeGanttPropTypes.TaskConfig>,
118
+ taskViewScaleConfs: Object as PropType<VxeGanttPropTypes.TaskViewScaleConfs>,
102
119
  taskViewConfig: Object as PropType<VxeGanttPropTypes.TaskViewConfig>,
103
120
  taskBarConfig: Object as PropType<VxeGanttPropTypes.TaskBarConfig>,
104
121
  taskSplitConfig: Object as PropType<VxeGanttPropTypes.TaskSplitConfig>,
@@ -134,7 +151,8 @@ export default /* define-vxe-component start */ defineVxeComponent({
134
151
  currentPage: 1
135
152
  },
136
153
  showLeftView: true,
137
- showRightView: true
154
+ showRightView: true,
155
+ taskScaleList: []
138
156
  }
139
157
 
140
158
  const internalData = createInternalData()
@@ -197,6 +215,12 @@ export default /* define-vxe-component start */ defineVxeComponent({
197
215
 
198
216
  return Object.assign({}, getConfig().gantt.taskConfig, props.taskConfig)
199
217
  },
218
+ computeTaskViewScaleMapsOpts () {
219
+ const $xeGantt = this
220
+ const props = $xeGantt
221
+
222
+ return XEUtils.merge({}, getConfig().gantt.taskViewScaleConfs, props.taskViewScaleConfs)
223
+ },
200
224
  computeTaskViewOpts () {
201
225
  const $xeGantt = this
202
226
  const props = $xeGantt
@@ -215,6 +239,13 @@ export default /* define-vxe-component start */ defineVxeComponent({
215
239
 
216
240
  return Object.assign({}, getConfig().gantt.taskSplitConfig, props.taskSplitConfig)
217
241
  },
242
+ computeTaskScaleConfs () {
243
+ const $xeGantt = this
244
+
245
+ const taskViewOpts = $xeGantt.computeTaskViewOpts as VxeGanttPropTypes.TaskViewConfig
246
+ const { scales } = taskViewOpts
247
+ return scales
248
+ },
218
249
  computeTitleField () {
219
250
  const $xeGantt = this
220
251
 
@@ -472,6 +503,11 @@ export default /* define-vxe-component start */ defineVxeComponent({
472
503
  const $xeGantt = this
473
504
 
474
505
  $xeGantt.initProxy()
506
+ },
507
+ computeTaskScaleConfs () {
508
+ const $xeGantt = this
509
+
510
+ $xeGantt.handleTaskScaleConfig()
475
511
  }
476
512
  },
477
513
  methods: {
@@ -481,6 +517,40 @@ export default /* define-vxe-component start */ defineVxeComponent({
481
517
 
482
518
  $xeGantt.$emit(type, createEvent(evnt, { $grid: null, $gantt: $xeGantt }, params))
483
519
  },
520
+ handleTaskScaleConfig () {
521
+ const $xeGantt = this
522
+ const reactData = $xeGantt.reactData
523
+
524
+ const taskScaleConfs = $xeGantt.computeTaskScaleConfs
525
+ const taskViewScaleMapsOpts = $xeGantt.computeTaskViewScaleMapsOpts
526
+ const scaleConfs: VxeGanttDefines.ColumnScaleObj[] = []
527
+ if (taskScaleConfs) {
528
+ const keyMaps: Record<string, boolean> = {}
529
+ taskScaleConfs.forEach(conf => {
530
+ const sConf = !conf || XEUtils.isString(conf) ? { type: conf } : conf
531
+ const { type } = sConf
532
+ if (!type || !viewTypeLevelMaps[type]) {
533
+ errLog('vxe.error.errProp', [`type=${type}`, XEUtils.keys(viewTypeLevelMaps).join(',')])
534
+ return
535
+ }
536
+ if (keyMaps[type]) {
537
+ errLog('vxe.error.repeatProp', ['type', type])
538
+ return
539
+ }
540
+ keyMaps[type] = true
541
+ scaleConfs.push(Object.assign({}, type ? taskViewScaleMapsOpts[type] || {} : {}, sConf, {
542
+ level: getViewTypeLevel(type)
543
+ }))
544
+ })
545
+ }
546
+ if (!scaleConfs.length) {
547
+ scaleConfs.push(
548
+ { type: 'month', level: viewTypeLevelMaps.month },
549
+ { type: 'day', level: viewTypeLevelMaps.day }
550
+ )
551
+ }
552
+ reactData.taskScaleList = XEUtils.orderBy(scaleConfs, { field: 'level', order: 'desc' })
553
+ },
484
554
  initToolbar () {
485
555
  const $xeGantt = this
486
556
 
@@ -2173,6 +2243,7 @@ export default /* define-vxe-component start */ defineVxeComponent({
2173
2243
  }
2174
2244
  })
2175
2245
 
2246
+ $xeGantt.handleTaskScaleConfig()
2176
2247
  $xeGantt.initPages()
2177
2248
  },
2178
2249
  mounted () {
@@ -43,6 +43,11 @@ setConfig({
43
43
  // beforeSave: null,
44
44
  // afterSave: null
45
45
  },
46
+ taskViewScaleConfs: {
47
+ week: {
48
+ startDay: 1
49
+ }
50
+ },
46
51
  taskSplitConfig: {
47
52
  enabled: true,
48
53
  resize: true,
@@ -1,6 +1,6 @@
1
1
  :root {
2
2
  /*gantt*/
3
- --vxe-ui-gantt-view-default-cell-width: 40px;
3
+ --vxe-ui-gantt-view-default-cell-width: 2.2em;
4
4
  --vxe-ui-gantt-view-chart-bar-height: 1.6em;
5
5
  --vxe-ui-gantt-view-split-bar-width: 10px;
6
6
  --vxe-ui-gantt-view-split-bar-height: 6.8em;