vxe-gantt 4.1.16 → 4.1.18

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.
@@ -119,6 +119,7 @@ export default defineVxeComponent({
119
119
  const taskViewOpts = computeTaskViewOpts.value
120
120
  const minScale = computeMinScale.value
121
121
  const { gridding } = taskViewOpts
122
+ const { type, startDay } = minScale
122
123
  const dateList: Date[] = []
123
124
  if (!minViewDate || !maxViewDate) {
124
125
  return dateList
@@ -126,14 +127,15 @@ export default defineVxeComponent({
126
127
 
127
128
  const leftSize = -XEUtils.toNumber(gridding ? gridding.leftSpacing || 0 : 0)
128
129
  const rightSize = XEUtils.toNumber(gridding ? gridding.rightSpacing || 0 : 0)
129
- switch (minScale.type) {
130
+ const currStep = 1// XEUtils.toNumber(step || 1) || 1
131
+ switch (type) {
130
132
  case 'year': {
131
133
  let currDate = XEUtils.getWhatYear(minViewDate, leftSize, 'first')
132
134
  const endDate = XEUtils.getWhatYear(maxViewDate, rightSize, 'first')
133
135
  while (currDate <= endDate) {
134
136
  const itemDate = currDate
135
137
  dateList.push(itemDate)
136
- currDate = XEUtils.getWhatYear(currDate, 1)
138
+ currDate = XEUtils.getWhatYear(currDate, currStep)
137
139
  }
138
140
  break
139
141
  }
@@ -143,7 +145,7 @@ export default defineVxeComponent({
143
145
  while (currDate <= endDate) {
144
146
  const itemDate = currDate
145
147
  dateList.push(itemDate)
146
- currDate = XEUtils.getWhatQuarter(currDate, 1)
148
+ currDate = XEUtils.getWhatQuarter(currDate, currStep)
147
149
  }
148
150
  break
149
151
  }
@@ -153,17 +155,17 @@ export default defineVxeComponent({
153
155
  while (currDate <= endDate) {
154
156
  const itemDate = currDate
155
157
  dateList.push(itemDate)
156
- currDate = XEUtils.getWhatMonth(currDate, 1)
158
+ currDate = XEUtils.getWhatMonth(currDate, currStep)
157
159
  }
158
160
  break
159
161
  }
160
162
  case 'week': {
161
- let currDate = XEUtils.getWhatWeek(minViewDate, leftSize, minScale.startDay, minScale.startDay)
162
- const endDate = XEUtils.getWhatWeek(maxViewDate, rightSize, minScale.startDay, minScale.startDay)
163
+ let currDate = XEUtils.getWhatWeek(minViewDate, leftSize, startDay, startDay)
164
+ const endDate = XEUtils.getWhatWeek(maxViewDate, rightSize, startDay, startDay)
163
165
  while (currDate <= endDate) {
164
166
  const itemDate = currDate
165
167
  dateList.push(itemDate)
166
- currDate = XEUtils.getWhatWeek(currDate, 1)
168
+ currDate = XEUtils.getWhatWeek(currDate, currStep)
167
169
  }
168
170
  break
169
171
  }
@@ -174,14 +176,14 @@ export default defineVxeComponent({
174
176
  while (currDate <= endDate) {
175
177
  const itemDate = currDate
176
178
  dateList.push(itemDate)
177
- currDate = XEUtils.getWhatDay(currDate, 1)
179
+ currDate = XEUtils.getWhatDay(currDate, currStep)
178
180
  }
179
181
  break
180
182
  }
181
183
  case 'hour':
182
184
  case 'minute':
183
185
  case 'second': {
184
- const gapTime = getStandardGapTime(minScale.type)
186
+ const gapTime = getStandardGapTime(minScale.type) * currStep
185
187
  let currTime = minViewDate.getTime() + (leftSize * gapTime)
186
188
  const endTime = maxViewDate.getTime() + (rightSize * gapTime)
187
189
  while (currTime <= endTime) {
@@ -261,7 +263,6 @@ export default defineVxeComponent({
261
263
  minute: [],
262
264
  second: []
263
265
  }
264
-
265
266
  const tempTypeMaps: Record<VxeGanttDefines.ColumnScaleType, Record<string, VxeGanttDefines.ViewColumn>> = {
266
267
  year: {},
267
268
  quarter: {},
@@ -273,6 +274,7 @@ export default defineVxeComponent({
273
274
  minute: {},
274
275
  second: {}
275
276
  }
277
+ const isMinWeek = minScale.type === 'week'
276
278
 
277
279
  const handleData = (type: VxeGanttDefines.ColumnScaleType, colMaps: Record<VxeGanttDefines.ColumnScaleType, VxeGanttDefines.ViewColumn>, minCol: VxeGanttDefines.ViewColumn) => {
278
280
  if (minScale.type === type) {
@@ -293,15 +295,17 @@ export default defineVxeComponent({
293
295
  currGpCol.children.push(minCol)
294
296
  }
295
297
  }
296
-
297
298
  for (let i = 0; i < scaleDateList.length; i++) {
298
299
  const itemDate = scaleDateList[i]
299
- const [yy, yyyy, M, MM, d, dd, H, HH, m, mm, s, ss] = XEUtils.toDateString(itemDate, 'yy-yyyy-M-MM-d-dd-H-HH-m-mm-s-ss').split('-')
300
+ let [yy, yyyy, M, MM, d, dd, H, HH, m, mm, s, ss] = XEUtils.toDateString(itemDate, 'yy-yyyy-M-MM-d-dd-H-HH-m-mm-s-ss').split('-')
300
301
  const e = itemDate.getDay()
301
302
  const E = e + 1
302
303
  const q = Math.ceil((itemDate.getMonth() + 1) / 3)
303
304
  const W = `${XEUtils.getYearWeek(itemDate, weekScale ? weekScale.startDay : undefined)}`
304
305
  const WW = XEUtils.padStart(W, 2, '0')
306
+ if (isMinWeek && checkWeekOfsetYear(W, M)) {
307
+ yyyy = `${Number(yyyy) + 1}`
308
+ }
305
309
  const dateObj: VxeGanttDefines.ScaleDateObj = { date: itemDate, yy, yyyy, M, MM, d, dd, H, HH, m, mm, s, ss, q, W, WW, E, e }
306
310
  const colMaps: Record<VxeGanttDefines.ColumnScaleType, VxeGanttDefines.ViewColumn> = {
307
311
  year: {
@@ -410,6 +414,32 @@ export default defineVxeComponent({
410
414
  }
411
415
  }
412
416
 
417
+ /**
418
+ * 判断周的年份是否跨年
419
+ */
420
+ const checkWeekOfsetYear = (W: number | string, M: number | string) => {
421
+ return `${W}` === '1' && `${M}` === '12'
422
+ }
423
+
424
+ /**
425
+ * 周维度,由于年份和第几周是冲突的行为,所以需要特殊处理,判断是否跨年,例如
426
+ * '2024-12-31' 'yyyy-MM-dd W' >> '2024-12-31 1'
427
+ * '2025-01-01' 'yyyy-MM-dd W' >> '2025-01-01 1'
428
+ */
429
+ const parseWeekObj = (date: any, firstDay?: 0 | 5 | 1 | 2 | 3 | 4 | 6) => {
430
+ const currDate = XEUtils.toStringDate(date)
431
+ let yyyy = currDate.getFullYear()
432
+ const month = currDate.getMonth()
433
+ const weekNum = XEUtils.getYearWeek(currDate, firstDay)
434
+ if (checkWeekOfsetYear(weekNum, month + 1)) {
435
+ yyyy++
436
+ }
437
+ return {
438
+ yyyy,
439
+ W: weekNum
440
+ }
441
+ }
442
+
413
443
  const createChartRender = (fullCols: VxeGanttDefines.ViewColumn[]) => {
414
444
  const { minViewDate } = reactData
415
445
  const minScale = computeMinScale.value
@@ -488,15 +518,17 @@ export default defineVxeComponent({
488
518
  case 'week': {
489
519
  const indexMaps: Record<string, number> = {}
490
520
  fullCols.forEach(({ dateObj }, i) => {
491
- const yyyyW = XEUtils.toDateString(dateObj.date, 'yyyy-W', { firstDay: weekScale ? weekScale.startDay : undefined })
521
+ const yyyyW = `${dateObj.yyyy}-${dateObj.W}`
492
522
  indexMaps[yyyyW] = i
493
523
  })
494
524
  return (startValue: any, endValue: any) => {
495
525
  const startDate = parseStringDate(startValue)
496
526
  const endDate = parseStringDate(endValue)
497
- const startStr = XEUtils.toDateString(startDate, 'yyyy-W', { firstDay: weekScale ? weekScale.startDay : undefined })
527
+ const startWeekObj = parseWeekObj(startDate, weekScale ? weekScale.startDay : undefined)
528
+ const startStr = `${startWeekObj.yyyy}-${startWeekObj.W}`
498
529
  const startFirstDate = XEUtils.getWhatWeek(startDate, 0, weekScale ? weekScale.startDay : undefined, weekScale ? weekScale.startDay : undefined)
499
- const endStr = XEUtils.toDateString(endDate, 'yyyy-W', { firstDay: weekScale ? weekScale.startDay : undefined })
530
+ const endWeekObj = parseWeekObj(endDate, weekScale ? weekScale.startDay : undefined)
531
+ const endStr = `${endWeekObj.yyyy}-${endWeekObj.W}`
500
532
  const endFirstDate = XEUtils.getWhatWeek(endDate, 0, weekScale ? weekScale.startDay : undefined, weekScale ? weekScale.startDay : undefined)
501
533
  const dateSize = Math.floor((XEUtils.getWhatWeek(endDate, 1, weekScale ? weekScale.startDay : undefined, weekScale ? weekScale.startDay : undefined).getTime() - endFirstDate.getTime()) / dayMs)
502
534
  const subtract = (startDate.getTime() - startFirstDate.getTime()) / dayMs / dateSize
@@ -560,7 +560,10 @@ export default defineVxeComponent({
560
560
  const scaleList = (taskScaleConfs && taskScaleConfs.length ? taskScaleConfs : ['month', 'date'] as VxeGanttDefines.ColumnScaleType[])
561
561
  scaleList.forEach(conf => {
562
562
  const sConf = !conf || XEUtils.isString(conf) ? { type: conf } : conf
563
- const { type } = sConf
563
+ const { type, step } = sConf
564
+ if (step) {
565
+ errLog('vxe.error.errProp', [`step=${step}`, 'step=1'])
566
+ }
564
567
  if (!type || !viewTypeLevelMaps[type]) {
565
568
  errLog('vxe.error.errProp', [`type=${type}`, XEUtils.keys(viewTypeLevelMaps).join(',')])
566
569
  return