|
@@ -1,12 +1,211 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
-import { RouterModule } from '@angular/router';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+
|
|
|
+interface CalendarDay {
|
|
|
+ date: number;
|
|
|
+ isCurrentMonth: boolean;
|
|
|
+ isToday: boolean;
|
|
|
+ events: any[];
|
|
|
+}
|
|
|
+
|
|
|
+interface Event {
|
|
|
+ id: number;
|
|
|
+ date: Date;
|
|
|
+ title: string;
|
|
|
+ type: string;
|
|
|
+ time: string;
|
|
|
+ venue: string;
|
|
|
+}
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-page-mine',
|
|
|
- imports: [RouterModule],
|
|
|
templateUrl: './page-mine.html',
|
|
|
- styleUrl: './page-mine.scss'
|
|
|
+ styleUrls: ['./page-mine.scss'],
|
|
|
+ standalone:true,
|
|
|
+ imports:[
|
|
|
+ CommonModule
|
|
|
+ ]
|
|
|
})
|
|
|
-export class PageMine {
|
|
|
+export class PageMine implements OnInit {
|
|
|
+ weekDays = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
|
|
+ hours = Array.from({length: 24}, (_, i) => i); // 0-23小时
|
|
|
+ currentDate: Date = new Date(); // 初始化当前日期
|
|
|
+ currentMonth: number = this.currentDate.getMonth(); // 初始化当前月份
|
|
|
+ currentYear: number = this.currentDate.getFullYear(); // 初始化当前年份
|
|
|
+ viewMode: 'month' | 'week' = 'month';
|
|
|
+ activeFilter: string = 'all';
|
|
|
+
|
|
|
+ monthDays: CalendarDay[] = [];
|
|
|
+ events: Event[] = [];
|
|
|
+
|
|
|
+ stats = {
|
|
|
+ totalEvents: 0,
|
|
|
+ weddings: 0,
|
|
|
+ banquets: 0,
|
|
|
+ meetings: 0
|
|
|
+ };
|
|
|
|
|
|
-}
|
|
|
+ ngOnInit() {
|
|
|
+ // 不需要再次初始化,因为已经在声明时初始化
|
|
|
+ this.initializeEvents();
|
|
|
+ this.generateCalendar();
|
|
|
+ this.calculateStats();
|
|
|
+ }
|
|
|
+
|
|
|
+ initializeEvents() {
|
|
|
+ this.events = [
|
|
|
+ { id: 1, date: new Date(this.currentYear, this.currentMonth, 5), title: '张先生 & 李女士婚礼', type: 'wedding', time: '10:00-14:00', venue: '玫瑰厅' },
|
|
|
+ { id: 2, date: new Date(this.currentYear, this.currentMonth, 8), title: '公司年度晚宴', type: 'banquet', time: '18:00-21:00', venue: '宴会A厅' },
|
|
|
+ { id: 3, date: new Date(this.currentYear, this.currentMonth, 12), title: '王先生 & 赵女士婚礼', type: 'wedding', time: '11:00-15:00', venue: '百合厅' },
|
|
|
+ { id: 4, date: new Date(this.currentYear, this.currentMonth, 15), title: '产品发布会', type: 'meeting', time: '14:00-16:00', venue: '会议中心' },
|
|
|
+ { id: 5, date: new Date(this.currentYear, this.currentMonth, 18), title: '陈先生 & 刘女士婚礼', type: 'wedding', time: '09:30-13:30', venue: '牡丹厅' },
|
|
|
+ { id: 6, date: new Date(this.currentYear, this.currentMonth, 20), title: '生日宴会', type: 'banquet', time: '19:00-22:00', venue: '宴会B厅' },
|
|
|
+ { id: 7, date: new Date(this.currentYear, this.currentMonth, 25), title: '婚庆行业交流会', type: 'meeting', time: '10:00-12:00', venue: '会议中心' },
|
|
|
+ { id: 8, date: new Date(this.currentYear, this.currentMonth, 28), title: '周先生 & 吴女士婚礼', type: 'wedding', time: '10:30-14:30', venue: '玫瑰厅' },
|
|
|
+ { id: 9, date: new Date(this.currentYear, this.currentMonth, 30), title: '公司团建活动', type: 'other', time: '全天', venue: '户外场地' }
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ generateCalendar() {
|
|
|
+ this.monthDays = [];
|
|
|
+
|
|
|
+ // 获取当月第一天
|
|
|
+ const firstDay = new Date(this.currentYear, this.currentMonth, 1);
|
|
|
+ // 获取当月最后一天
|
|
|
+ const lastDay = new Date(this.currentYear, this.currentMonth + 1, 0);
|
|
|
+ // 获取当月第一天是星期几(0为周日,6为周六)
|
|
|
+ const firstDayIndex = firstDay.getDay() === 0 ? 6 : firstDay.getDay() - 1;
|
|
|
+ // 获取当月最后一天是星期几
|
|
|
+ const lastDayIndex = lastDay.getDay();
|
|
|
+
|
|
|
+ // 上个月最后一天
|
|
|
+ const prevLastDay = new Date(this.currentYear, this.currentMonth, 0).getDate();
|
|
|
+ const today = new Date();
|
|
|
+
|
|
|
+ // 添加上个月日期
|
|
|
+ for (let i = firstDayIndex; i > 0; i--) {
|
|
|
+ const day = prevLastDay - i + 1;
|
|
|
+ this.monthDays.push({
|
|
|
+ date: day,
|
|
|
+ isCurrentMonth: false,
|
|
|
+ isToday: false,
|
|
|
+ events: []
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加当月日期
|
|
|
+ for (let i = 1; i <= lastDay.getDate(); i++) {
|
|
|
+ const dayDate = new Date(this.currentYear, this.currentMonth, i);
|
|
|
+ const isToday = dayDate.toDateString() === today.toDateString();
|
|
|
+
|
|
|
+ // 获取当天的活动(根据筛选条件)
|
|
|
+ const dayEvents = this.events.filter(event =>
|
|
|
+ event.date.getDate() === i &&
|
|
|
+ event.date.getMonth() === this.currentMonth &&
|
|
|
+ event.date.getFullYear() === this.currentYear &&
|
|
|
+ (this.activeFilter === 'all' || event.type === this.activeFilter)
|
|
|
+ );
|
|
|
+
|
|
|
+ this.monthDays.push({
|
|
|
+ date: i,
|
|
|
+ isCurrentMonth: true,
|
|
|
+ isToday: isToday,
|
|
|
+ events: dayEvents
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加下个月日期
|
|
|
+ const daysNeeded = 42 - (firstDayIndex + lastDay.getDate()); // 42是6行7列的格子总数
|
|
|
+ for (let i = 1; i <= daysNeeded; i++) {
|
|
|
+ this.monthDays.push({
|
|
|
+ date: i,
|
|
|
+ isCurrentMonth: false,
|
|
|
+ isToday: false,
|
|
|
+ events: []
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ getEventsForDayAndHour(dayIndex: number, hour: number): Event[] {
|
|
|
+ const dayOfWeek = dayIndex; // 0-6对应周一到周日
|
|
|
+ const currentDate = new Date(this.currentYear, this.currentMonth, 1);
|
|
|
+
|
|
|
+ // 计算当前月份第一天是星期几
|
|
|
+ const firstDayOfWeek = currentDate.getDay() === 0 ? 7 : currentDate.getDay();
|
|
|
+
|
|
|
+ // 计算目标日期
|
|
|
+ const targetDate = new Date(
|
|
|
+ this.currentYear,
|
|
|
+ this.currentMonth,
|
|
|
+ 1 + (dayOfWeek - firstDayOfWeek + 7) % 7
|
|
|
+ );
|
|
|
+
|
|
|
+ // 过滤事件
|
|
|
+ return this.events.filter(event => {
|
|
|
+ const eventDate = event.date;
|
|
|
+
|
|
|
+ // 检查日期是否匹配
|
|
|
+ const sameDate =
|
|
|
+ eventDate.getDate() === targetDate.getDate() &&
|
|
|
+ eventDate.getMonth() === targetDate.getMonth() &&
|
|
|
+ eventDate.getFullYear() === targetDate.getFullYear();
|
|
|
+
|
|
|
+ if (!sameDate) return false;
|
|
|
+
|
|
|
+ // 检查时间是否匹配
|
|
|
+ if (event.time === '全天') return true;
|
|
|
+
|
|
|
+ const [startTime] = event.time.split('-');
|
|
|
+ const eventHour = parseInt(startTime.split(':')[0]);
|
|
|
+
|
|
|
+ return eventHour === hour;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ changeMonth(offset: number) {
|
|
|
+ this.currentMonth += offset;
|
|
|
+
|
|
|
+ if (this.currentMonth < 0) {
|
|
|
+ this.currentMonth = 11;
|
|
|
+ this.currentYear--;
|
|
|
+ } else if (this.currentMonth > 11) {
|
|
|
+ this.currentMonth = 0;
|
|
|
+ this.currentYear++;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.initializeEvents();
|
|
|
+ this.generateCalendar();
|
|
|
+ this.calculateStats();
|
|
|
+ }
|
|
|
+
|
|
|
+ goToToday() {
|
|
|
+ const today = new Date();
|
|
|
+ this.currentDate = today;
|
|
|
+ this.currentMonth = today.getMonth();
|
|
|
+ this.currentYear = today.getFullYear();
|
|
|
+
|
|
|
+ this.initializeEvents();
|
|
|
+ this.generateCalendar();
|
|
|
+ this.calculateStats();
|
|
|
+ }
|
|
|
+
|
|
|
+ setFilter(filter: string) {
|
|
|
+ this.activeFilter = filter;
|
|
|
+ this.generateCalendar();
|
|
|
+ this.calculateStats();
|
|
|
+ }
|
|
|
+
|
|
|
+ calculateStats() {
|
|
|
+ const currentMonthEvents = this.events.filter(event =>
|
|
|
+ event.date.getMonth() === this.currentMonth &&
|
|
|
+ event.date.getFullYear() === this.currentYear
|
|
|
+ );
|
|
|
+
|
|
|
+ this.stats = {
|
|
|
+ totalEvents: currentMonthEvents.length,
|
|
|
+ weddings: currentMonthEvents.filter(e => e.type === 'wedding').length,
|
|
|
+ banquets: currentMonthEvents.filter(e => e.type === 'banquet').length,
|
|
|
+ meetings: currentMonthEvents.filter(e => e.type === 'meeting').length
|
|
|
+ };
|
|
|
+ }
|
|
|
+}
|