From 4f339d7d025c624234a89782e68900739022d5d7 Mon Sep 17 00:00:00 2001 From: zhangwen <1062680993@qq.com> Date: Mon, 22 Aug 2022 18:29:48 +0800 Subject: [PATCH] fix: fix demo and support GanttDate in scrollToDate #INFR-4334 --- example/src/app/gantt/gantt.component.html | 3 --- example/src/app/gantt/gantt.component.ts | 15 ++++++--------- example/src/styles.scss | 3 --- packages/gantt/src/gantt.component.ts | 3 ++- packages/gantt/src/root.component.ts | 12 +++++++++--- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/example/src/app/gantt/gantt.component.html b/example/src/app/gantt/gantt.component.html index bd3157b8..c1901e4b 100644 --- a/example/src/app/gantt/gantt.component.html +++ b/example/src/app/gantt/gantt.component.html @@ -11,9 +11,6 @@       ↓ 导出为图片       - 滚动到: - -       基线对比: 基线对比 diff --git a/example/src/app/gantt/gantt.component.ts b/example/src/app/gantt/gantt.component.ts index 1705d8e9..12cbfe21 100644 --- a/example/src/app/gantt/gantt.component.ts +++ b/example/src/app/gantt/gantt.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, HostBinding, ViewChild } from '@angular/core'; +import { Component, OnInit, HostBinding, ViewChild, AfterViewInit } from '@angular/core'; import { GanttBarClickEvent, GanttViewType, @@ -21,7 +21,7 @@ import { randomItems, random } from '../helper'; templateUrl: './gantt.component.html', providers: [GanttPrintService] }) -export class AppGanttExampleComponent implements OnInit { +export class AppGanttExampleComponent implements OnInit, AfterViewInit { views = [ { name: '日', @@ -94,8 +94,6 @@ export class AppGanttExampleComponent implements OnInit { } }; - date = new Date(); - @HostBinding('class.gantt-example-component') class = true; @ViewChild('gantt') ganttComponent: NgxGanttComponent; @@ -109,6 +107,10 @@ export class AppGanttExampleComponent implements OnInit { ngOnInit(): void {} + ngAfterViewInit() { + setTimeout(() => this.ganttComponent.scrollToDate(1627729997), 200); + } + barClick(event: GanttBarClickEvent) { this.thyNotify.info('Event: barClick', `你点击了 [${event.item.title}]`); } @@ -141,14 +143,9 @@ export class AppGanttExampleComponent implements OnInit { } scrollToToday() { - this.date = new Date(); this.ganttComponent.scrollToToday(); } - dateChange(event: number) { - this.ganttComponent.scrollToDate(event); - } - switchChange() { if (this.isBaselineChecked) { this.baselineItems = [ diff --git a/example/src/styles.scss b/example/src/styles.scss index ce04ed36..145338b4 100644 --- a/example/src/styles.scss +++ b/example/src/styles.scss @@ -61,8 +61,5 @@ $primary: #348fe4; .baseline-switch { display: flex; } - .thy-calendar-picker { - width: 120px; - } } } diff --git a/packages/gantt/src/gantt.component.ts b/packages/gantt/src/gantt.component.ts index 2d307f6d..71606411 100644 --- a/packages/gantt/src/gantt.component.ts +++ b/packages/gantt/src/gantt.component.ts @@ -29,6 +29,7 @@ import { GANTT_ABSTRACT_TOKEN } from './gantt-abstract'; import { defaultColumnWidth } from './components/table/gantt-table.component'; import { GanttGlobalConfig, GANTT_GLOBAL_CONFIG } from './gantt.config'; import { NgxGanttRootComponent } from './root.component'; +import { GanttDate } from './utils/date'; @Component({ selector: 'ngx-gantt', templateUrl: './gantt.component.html', @@ -161,7 +162,7 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, AfterViewIn this.ganttRoot.scrollToToday(); } - scrollToDate(date: number) { + scrollToDate(date: number | GanttDate) { this.ganttRoot.scrollToDate(date); } } diff --git a/packages/gantt/src/root.component.ts b/packages/gantt/src/root.component.ts index d0950bde..b8c26ae6 100644 --- a/packages/gantt/src/root.component.ts +++ b/packages/gantt/src/root.component.ts @@ -19,7 +19,7 @@ import { GanttUpper, GANTT_UPPER_TOKEN } from './gantt-upper'; import { GanttPrintService } from './gantt-print.service'; import { passiveListenerOptions } from './utils/passive-listeners'; import { GanttDragBackdropComponent } from './components/drag-backdrop/drag-backdrop.component'; -import { GanttDate } from './public-api'; +import { GanttDate } from './utils/date'; @Component({ selector: 'ngx-gantt-root', @@ -139,8 +139,14 @@ export class NgxGanttRootComponent implements OnInit, OnDestroy { this.dom.scrollMainContainer(x); } - public scrollToDate(date: number) { - const x = this.view.getXPointByDate(new GanttDate(date)); + public scrollToDate(date: number | GanttDate) { + let x: number; + if (typeof date === 'number') { + x = this.view.getXPointByDate(new GanttDate(date)); + } else { + x = this.view.getXPointByDate(date); + } + this.dom.scrollMainContainer(x); } }