|
|
@@ -17,6 +17,7 @@ export interface PracticeStatistics {
|
|
|
|
|
|
export function useCalendar() {
|
|
|
const calendarUtil = new CalendarUtil();
|
|
|
+ const globalStudentId = ref(0);
|
|
|
const selected = ref<PracticeData[]>([]);
|
|
|
const statistics = ref<PracticeStatistics>({
|
|
|
totalQuestions: 0,
|
|
|
@@ -29,6 +30,9 @@ export function useCalendar() {
|
|
|
const currentDate = ref(new Date());
|
|
|
const displayMode = ref<'year' | 'month' | 'week'>('year');
|
|
|
const loading = ref(false);
|
|
|
+
|
|
|
+ // 配置变量:最早可访问的年份
|
|
|
+ const EARLIEST_YEAR = 2020;
|
|
|
|
|
|
// 计算当前周范围
|
|
|
const currentWeekRange = computed(() => {
|
|
|
@@ -46,12 +50,13 @@ export function useCalendar() {
|
|
|
const current = currentDate.value;
|
|
|
|
|
|
if (displayMode.value === 'year') {
|
|
|
- return current.getFullYear() > 2020; // 假设最早年份是2020年
|
|
|
+ return current.getFullYear() > EARLIEST_YEAR;
|
|
|
} else if (displayMode.value === 'week') {
|
|
|
- return currentWeekNumber.value > 1 || current.getMonth() > 0;
|
|
|
+ // 周模式:支持跨年
|
|
|
+ return currentWeekNumber.value > 1 || !(current.getFullYear() === EARLIEST_YEAR && current.getMonth() === 0);
|
|
|
} else {
|
|
|
- // 月份模式:支持跨年,只要不是2020年1月就可以往前切换
|
|
|
- return !(current.getFullYear() === 2020 && current.getMonth() === 0);
|
|
|
+ // 月份模式:支持跨年,只要不是最早年份1月就可以往前切换
|
|
|
+ return !(current.getFullYear() === EARLIEST_YEAR && current.getMonth() === 0);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -96,7 +101,7 @@ export function useCalendar() {
|
|
|
// 4. 统计数据会从返回的练习数据中自动计算,无需额外处理
|
|
|
// ========================================================
|
|
|
const fetchPracticeData = async (startDate: string, endDate: string): Promise<PracticeData[]> => {
|
|
|
- console.log('请求数据', startDate, endDate)
|
|
|
+ console.log('请求数据', startDate, endDate, globalStudentId.value)
|
|
|
// ========== 模拟网络延迟 - 真实接口时删除此部分 ==========
|
|
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
|
|
|
|
@@ -235,8 +240,14 @@ export function useCalendar() {
|
|
|
await updateCalendarData(undefined, 'week', currentWeekNumber.value - 1);
|
|
|
} else {
|
|
|
// 切换到上个月的最后一周
|
|
|
- const preDate = new Date(currentDate.value);
|
|
|
- preDate.setMonth(preDate.getMonth() - 1);
|
|
|
+ const currentMonth = currentDate.value.getMonth();
|
|
|
+ const currentYear = currentDate.value.getFullYear();
|
|
|
+
|
|
|
+ // 计算上个月的年月
|
|
|
+ const prevYear = currentMonth === 0 ? currentYear - 1 : currentYear;
|
|
|
+ const prevMonth = currentMonth === 0 ? 11 : currentMonth - 1;
|
|
|
+
|
|
|
+ const preDate = new Date(prevYear, prevMonth, 1);
|
|
|
calendarUtil.setDate(preDate);
|
|
|
const range = calendarUtil.getCurrentWeekRange(preDate);
|
|
|
await updateCalendarData(preDate, 'week', range.totalWeeks);
|
|
|
@@ -326,8 +337,9 @@ export function useCalendar() {
|
|
|
};
|
|
|
|
|
|
// 初始化数据 - 默认按年份模式初始化
|
|
|
- const init = async () => {
|
|
|
+ const init = async (studentId: number) => {
|
|
|
const today = new Date();
|
|
|
+ globalStudentId.value = studentId;
|
|
|
await updateCalendarData(today, 'year', today.getFullYear());
|
|
|
};
|
|
|
|
|
|
@@ -352,6 +364,9 @@ export function useCalendar() {
|
|
|
currentYear,
|
|
|
currentMonth,
|
|
|
|
|
|
+ // 配置
|
|
|
+ EARLIEST_YEAR,
|
|
|
+
|
|
|
// 方法
|
|
|
updateCalendarData,
|
|
|
goToPrevWeek,
|