@worktile/gantt 19.0.8-next.3 → 19.0.8-next.4

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.
@@ -1005,6 +1005,18 @@ class GanttView {
1005
1005
  return this.getDayOccupancyWidth(date);
1006
1006
  }
1007
1007
  }
1008
+ /**
1009
+ * 根据起始日期和宽度计算结束日期
1010
+ * @param start 起始日期
1011
+ * @param width 视觉宽度
1012
+ * @returns 结束日期
1013
+ */
1014
+ getEndDateByWidth(start, width) {
1015
+ const startX = this.getXPointByDate(start);
1016
+ // 减去偏移量避免因为 getDateRangeWidth 加了 1 秒而多算一天
1017
+ const endX = startX + width - 0.1;
1018
+ return this.getDateByXPoint(endX);
1019
+ }
1008
1020
  }
1009
1021
 
1010
1022
  const viewOptions$5 = {
@@ -1065,6 +1077,30 @@ class GanttViewDay extends GanttView {
1065
1077
  }
1066
1078
  return points;
1067
1079
  }
1080
+ getEndDateByWidth(start, width) {
1081
+ if (!this.options.hoilday?.hideHoliday) {
1082
+ return super.getEndDateByWidth(start, width);
1083
+ }
1084
+ // 通过宽度计算包含多少个工作日(每个工作日的宽度是 cellWidth)
1085
+ const workingDaysCount = Math.round(width / this.getCellWidth());
1086
+ let end = start;
1087
+ let addedWorkingDays = 0;
1088
+ let attempts = 0;
1089
+ const maxAttempts = 365;
1090
+ while (addedWorkingDays < workingDaysCount && attempts < maxAttempts) {
1091
+ if (this.getDayOccupancyWidth(end) > 0) {
1092
+ addedWorkingDays++;
1093
+ if (addedWorkingDays < workingDaysCount) {
1094
+ end = end.addDays(1);
1095
+ }
1096
+ }
1097
+ else {
1098
+ end = end.addDays(1);
1099
+ }
1100
+ attempts++;
1101
+ }
1102
+ return end;
1103
+ }
1068
1104
  }
1069
1105
 
1070
1106
  const viewOptions$4 = {
@@ -2398,25 +2434,13 @@ class GanttBarDrag {
2398
2434
  }
2399
2435
  barDragMove() {
2400
2436
  const currentX = this.item().refs.x + this.barDragMoveDistance + this.dragScrollDistance;
2401
- const currentDate = this.ganttUpper.view.getDateByXPoint(currentX);
2402
- const currentStartX = this.ganttUpper.view.getXPointByDate(currentDate);
2403
- const currentEndDate = this.ganttUpper.view.getDateByXPoint(currentX + this.item().refs.width);
2404
- const diffs = this.ganttUpper.view.differenceByPrecisionUnit(currentEndDate, currentDate);
2405
- let start = currentDate;
2406
- let end = currentDate.add(diffs, this.ganttUpper.view?.options?.datePrecisionUnit);
2407
- // 日视图特殊逻辑处理
2408
- if (this.ganttUpper.view.viewType === GanttViewType.day) {
2409
- const dayWidth = this.ganttUpper.view.getDayOccupancyWidth(currentDate);
2410
- if (currentX > currentStartX + dayWidth / 2) {
2411
- start = start.addDays(1);
2412
- end = end.addDays(1);
2413
- }
2414
- }
2437
+ const start = this.ganttUpper.view.getDateByXPoint(currentX);
2438
+ const end = this.ganttUpper.view.getEndDateByWidth(start, this.item().refs.width);
2415
2439
  if (this.dragScrolling) {
2416
2440
  const left = currentX - this.barDragMoveDistance;
2417
2441
  this.barElement.style.left = left + 'px';
2418
2442
  }
2419
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(currentX), this.ganttUpper.view.getDateByXPoint(currentX + this.item().refs.width));
2443
+ this.openDragBackdrop(this.barElement, start, end);
2420
2444
  if (!this.isStartOrEndInsideView(start, end)) {
2421
2445
  return;
2422
2446
  }