|
@@ -1,19 +1,18 @@
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
|
-import { IonicModule } from '@ionic/angular'; // 导入 IonicModule
|
|
|
+import { IonicModule } from '@ionic/angular';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-discount-banner',
|
|
|
templateUrl: './discount-banner.component.html',
|
|
|
styleUrls: ['./discount-banner.component.scss'],
|
|
|
- standalone: true, // 确保组件是独立组件
|
|
|
- imports: [IonicModule], // 引入 Ionic 模块
|
|
|
+ standalone: true,
|
|
|
+ imports: [IonicModule],
|
|
|
})
|
|
|
export class DiscountBannerComponent implements OnInit, OnDestroy {
|
|
|
- countdown: string = ''; // 倒计时字符串
|
|
|
- private countdownInterval: any; // 保存计时器引用
|
|
|
-
|
|
|
+ countdown: string = '';
|
|
|
+ private countdownInterval: any;
|
|
|
ngOnInit() {
|
|
|
- const endTime = new Date('2024-12-01T00:00:00'); // 活动结束时间
|
|
|
+ const endTime = new Date('2025-01-01T00:00:00');
|
|
|
this.countdownInterval = setInterval(() => {
|
|
|
const now = new Date();
|
|
|
const diff = endTime.getTime() - now.getTime();
|
|
@@ -21,14 +20,11 @@ export class DiscountBannerComponent implements OnInit, OnDestroy {
|
|
|
const hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
|
|
|
const minutes = Math.floor((diff / (1000 * 60)) % 60);
|
|
|
const seconds = Math.floor((diff / 1000) % 60);
|
|
|
-
|
|
|
- // 更新倒计时字符串
|
|
|
this.countdown = `${days}天 ${hours}小时 ${minutes}分 ${seconds}秒`;
|
|
|
}, 1000);
|
|
|
}
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
- // 清除计时器
|
|
|
if (this.countdownInterval) {
|
|
|
clearInterval(this.countdownInterval);
|
|
|
}
|