以下是一个使用Angular编写的简单日历组件示例,其中包含了一个默认的滚动视图,从早上8点到晚上11点,并在日/周视图中带有固定的标题栏。
calendar.component.html:
{{ time }}
{{ event }}
calendar.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-calendar',
templateUrl: './calendar.component.html',
styleUrls: ['./calendar.component.css']
})
export class CalendarComponent {
viewMode: string = 'day'; // 默认为日视图
timeSlots: string[] = ['8:00 AM', '9:00 AM', '10:00 AM', '11:00 AM', '12:00 PM', '1:00 PM', '2:00 PM', '3:00 PM', '4:00 PM', '5:00 PM', '6:00 PM', '7:00 PM', '8:00 PM', '9:00 PM', '10:00 PM', '11:00 PM'];
events: string[] = ['Event 1', 'Event 2', 'Event 3']; // 示例事件
constructor() { }
}
calendar.component.css:
.calendar {
width: 100%;
height: 100%;
}
.title-bar {
background-color: #333;
color: #fff;
padding: 10px;
}
.view {
height: calc(100% - 40px);
overflow-y: scroll;
}
.day-view,
.week-view {
width: 100%;
padding: 10px;
}
.time-slots {
display: flex;
flex-direction: column;
width: 100px;
}
.time-slot {
border-bottom: 1px solid #ccc;
padding: 10px;
}
.events {
flex-grow: 1;
}
.event {
margin-bottom: 10px;
padding: 10px;
background-color: #eee;
}
这只是一个简单的示例,你可以根据自己的需求进行修改和扩展。