|
@@ -10,19 +10,47 @@ class CalendarController extends GetxController {
|
|
|
int currentMonth = 12; // 当前月份
|
|
|
int selectedDayIndex = 0; // 当前选择的日期的下标,从0开始,范围是0-34 有时是 0-41
|
|
|
int maxDaysLength = 35; // 最大的日期数组长度,有时是42
|
|
|
- List<DayStructure> daysList = []; // 当前维护的日期列表
|
|
|
- ///TODO: 维护一个日程列表
|
|
|
+ List<Schedule> scheduleList = []; // 当前维护的日程列表
|
|
|
+ List<ScheduleType> scheduleTypeList = []; // 当前维护的一个日程类型列表
|
|
|
+ List<MiniViewDayStructure> miniViewDaysList = []; // 当前维护的迷你日历列表
|
|
|
+ /// 日程列表与日期列表拼装,即可变成月视图大列表,将日程塞入每一天
|
|
|
+ List<MonthViewDayStructure> get monthViewDaysList {
|
|
|
+ final List<MonthViewDayStructure> monthViewDaysList = [];
|
|
|
+ for (int i = 0; i < maxDaysLength; i++) {
|
|
|
+ final MiniViewDayStructure miniViewDayStructure = miniViewDaysList[i];
|
|
|
+ final MonthViewDayStructure monthViewDayStructure = MonthViewDayStructure(
|
|
|
+ index: miniViewDayStructure.index,
|
|
|
+ date: miniViewDayStructure.date,
|
|
|
+ isToday: miniViewDayStructure.isToday,
|
|
|
+ isCurrentMonth: miniViewDayStructure.isCurrentMonth,
|
|
|
+ isSelected: miniViewDayStructure.isSelected,
|
|
|
+ scheduleList: [],
|
|
|
+ );
|
|
|
+ monthViewDaysList.add(monthViewDayStructure);
|
|
|
+ }
|
|
|
+ for (final Schedule schedule in scheduleList) {
|
|
|
+ final DateTime scheduleDate = schedule.day;
|
|
|
+ final int scheduleDay = scheduleDate.day;
|
|
|
+ for (int i = 0; i < maxDaysLength; i++) {
|
|
|
+ final MiniViewDayStructure miniViewDayStructure = miniViewDaysList[i];
|
|
|
+ final MonthViewDayStructure monthViewDayStructure =
|
|
|
+ monthViewDaysList[i];
|
|
|
+ if (miniViewDayStructure.isCurrentMonth &&
|
|
|
+ miniViewDayStructure.date.day == scheduleDay) {
|
|
|
+ monthViewDayStructure.scheduleList.add(schedule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return monthViewDaysList;
|
|
|
+ }
|
|
|
|
|
|
/// TODO[Gavin]: i18n
|
|
|
String get currentYearMonth => '$currentYear年$currentMonth月';
|
|
|
- bool get isToday => daysList[selectedDayIndex].isToday;
|
|
|
+ bool get isToday => miniViewDaysList[selectedDayIndex].isToday;
|
|
|
int get calendarLines => maxDaysLength ~/ 7;
|
|
|
- // _initData() {
|
|
|
- // update(["calendar"]);
|
|
|
- // }
|
|
|
- FEventHandler<void> onDaysListChange = FEventHandler<void>();
|
|
|
|
|
|
- void onTap() {}
|
|
|
+ /// 数据变更事件通知
|
|
|
+ FEventHandler<void> onDaysListChange = FEventHandler<void>();
|
|
|
|
|
|
@override
|
|
|
void onInit() {
|
|
@@ -32,7 +60,7 @@ class CalendarController extends GetxController {
|
|
|
final DateTime now = DateTime.now();
|
|
|
currentYear = now.year;
|
|
|
currentMonth = now.month;
|
|
|
- daysList = _countDaysList(currentYear, currentMonth);
|
|
|
+ miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
selectToday();
|
|
|
|
|
|
/// 虚拟的日程数据
|
|
@@ -57,24 +85,26 @@ class CalendarController extends GetxController {
|
|
|
DateTime(2022, 12, 30),
|
|
|
DateTime(2022, 12, 31),
|
|
|
];
|
|
|
+
|
|
|
+ _initMockScheduleType();
|
|
|
+ _initMockSchedule(mockSchedule);
|
|
|
_setSchedule(mockSchedule);
|
|
|
print("CalendarController 全局临时控制器初始化");
|
|
|
}
|
|
|
|
|
|
- @override
|
|
|
- void onReady() {
|
|
|
- super.onReady();
|
|
|
- // _initData();
|
|
|
+ void _initMockScheduleType() {
|
|
|
+ /// 创建5个假日程类型,填充到scheduleTypeList
|
|
|
+ }
|
|
|
+
|
|
|
+ /// TODO:[Gavin] 改为真实数据接口
|
|
|
+ void _initMockSchedule(List<DateTime> scheduleList) {
|
|
|
+ /// 创建30个假日程数据,填充到scheduleList
|
|
|
}
|
|
|
|
|
|
- // @override
|
|
|
- // void onClose() {
|
|
|
- // super.onClose();
|
|
|
- // }
|
|
|
/// 传入起始年月,返回35个日期结构体
|
|
|
- List<DayStructure> _countDaysList(int year, int month) {
|
|
|
+ List<MiniViewDayStructure> _countDaysList(int year, int month) {
|
|
|
maxDaysLength = _isNeedExtraRow(year, month) ? 42 : 35;
|
|
|
- final daysList = <DayStructure>[];
|
|
|
+ final miniViewDaysList = <MiniViewDayStructure>[];
|
|
|
final firstDay = DateTime(year, month, 1);
|
|
|
final firstDayWeek = firstDay.weekday;
|
|
|
final lastDay = DateTime(year, month + 1, 0);
|
|
@@ -88,8 +118,8 @@ class CalendarController extends GetxController {
|
|
|
|
|
|
// 上个月的日期
|
|
|
for (var i = 0; i < firstDayWeekIndex; i++) {
|
|
|
- daysList.add(
|
|
|
- DayStructure(
|
|
|
+ miniViewDaysList.add(
|
|
|
+ MiniViewDayStructure(
|
|
|
index: i,
|
|
|
date: DateTime(
|
|
|
year, month - 1, lastDayOfLastMonth - firstDayWeekIndex + i + 1),
|
|
@@ -100,10 +130,10 @@ class CalendarController extends GetxController {
|
|
|
|
|
|
// 当月的日期
|
|
|
for (var i = 0;
|
|
|
- (i < lastDayOfMonth) && daysList.length < maxDaysLength;
|
|
|
+ (i < lastDayOfMonth) && miniViewDaysList.length < maxDaysLength;
|
|
|
i++) {
|
|
|
- daysList.add(
|
|
|
- DayStructure(
|
|
|
+ miniViewDaysList.add(
|
|
|
+ MiniViewDayStructure(
|
|
|
index: i + firstDayWeek,
|
|
|
date: DateTime(year, month, i + 1),
|
|
|
isToday:
|
|
@@ -112,16 +142,16 @@ class CalendarController extends GetxController {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- while (daysList.length < maxDaysLength) {
|
|
|
- daysList.add(DayStructure(
|
|
|
- index: daysList.length,
|
|
|
+ while (miniViewDaysList.length < maxDaysLength) {
|
|
|
+ miniViewDaysList.add(MiniViewDayStructure(
|
|
|
+ index: miniViewDaysList.length,
|
|
|
date: DateTime(month == 12 ? year + 1 : year,
|
|
|
month == 12 ? 1 : month + 1, nextMonthDay),
|
|
|
isCurrentMonth: false,
|
|
|
));
|
|
|
nextMonthDay++;
|
|
|
}
|
|
|
- return daysList;
|
|
|
+ return miniViewDaysList;
|
|
|
}
|
|
|
|
|
|
/// 计算是否需要显示六行日期,一般为5行,但是有时候会有6行
|
|
@@ -140,9 +170,9 @@ class CalendarController extends GetxController {
|
|
|
void handleSelectedDayByIndex(int index) {
|
|
|
assert(index >= 0 && index < maxDaysLength,
|
|
|
'index must be in 0-$maxDaysLength');
|
|
|
- assert(daysList.length == maxDaysLength,
|
|
|
- 'daysList length must be maxDaysLength');
|
|
|
- for (var element in daysList) {
|
|
|
+ assert(miniViewDaysList.length == maxDaysLength,
|
|
|
+ 'miniViewDaysList length must be maxDaysLength');
|
|
|
+ for (var element in miniViewDaysList) {
|
|
|
if (element.index == index) {
|
|
|
element.isSelected = true;
|
|
|
} else {
|
|
@@ -155,7 +185,7 @@ class CalendarController extends GetxController {
|
|
|
|
|
|
/// 选中当月第一天
|
|
|
void _selectFirstDay() {
|
|
|
- for (var element in daysList) {
|
|
|
+ for (var element in miniViewDaysList) {
|
|
|
if (element.isCurrentMonth) {
|
|
|
handleSelectedDayByIndex(element.index);
|
|
|
break;
|
|
@@ -170,9 +200,9 @@ class CalendarController extends GetxController {
|
|
|
if (currentYear != now.year || currentMonth != now.month) {
|
|
|
currentYear = now.year;
|
|
|
currentMonth = now.month;
|
|
|
- daysList = _countDaysList(currentYear, currentMonth);
|
|
|
+ miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
}
|
|
|
- for (var element in daysList) {
|
|
|
+ for (var element in miniViewDaysList) {
|
|
|
if (element.isToday) {
|
|
|
handleSelectedDayByIndex(element.index);
|
|
|
break;
|
|
@@ -184,7 +214,7 @@ class CalendarController extends GetxController {
|
|
|
void _setSchedule(List<DateTime> scheduleList) {
|
|
|
/// 如果scheduleList中存在daysList中的日期,则设置hasSchedule为true
|
|
|
for (var element in scheduleList) {
|
|
|
- for (var day in daysList) {
|
|
|
+ for (var day in miniViewDaysList) {
|
|
|
if (element.year == day.date.year &&
|
|
|
element.month == day.date.month &&
|
|
|
element.day == day.date.day) {
|
|
@@ -202,7 +232,7 @@ class CalendarController extends GetxController {
|
|
|
} else {
|
|
|
currentMonth--;
|
|
|
}
|
|
|
- daysList = _countDaysList(currentYear, currentMonth);
|
|
|
+ miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
_selectFirstDay();
|
|
|
|
|
|
onDaysListChange.emit(this, null);
|
|
@@ -216,7 +246,7 @@ class CalendarController extends GetxController {
|
|
|
} else {
|
|
|
currentMonth++;
|
|
|
}
|
|
|
- daysList = _countDaysList(currentYear, currentMonth);
|
|
|
+ miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
_selectFirstDay();
|
|
|
|
|
|
onDaysListChange.emit(this, null);
|