From 5e0392443ead59b4503178ddd565de4c550e2979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BB=E8=B0=B1?= <144224541+xixiIBN5100@users.noreply.github.com> Date: Sun, 29 Sep 2024 22:20:18 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BA=86=E8=AF=BE?= =?UTF-8?q?=E8=A1=A8=E5=8D=A1=E7=89=87=E7=9A=84=E6=98=BE=E7=A4=BA=20(#109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 优化了课表卡片的显示 --- .../LessonsTableQuickView/index.vue | 44 +++++++++---------- src/services/services/zfService.ts | 7 +-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/components/LessonsTableQuickView/index.vue b/src/components/LessonsTableQuickView/index.vue index 5a3f5ed3..20cf910e 100644 --- a/src/components/LessonsTableQuickView/index.vue +++ b/src/components/LessonsTableQuickView/index.vue @@ -1,9 +1,11 @@ @@ -52,15 +58,20 @@ import { dayScheduleStartTime } from "@/constants/dayScheduleStartTime"; import { useTimeInstance } from "@/hooks"; import { Lesson } from "@/types/Lesson"; +const tenPM = dayjs().set('hour', 22).set('minute', 0).set('second', 0); const emit = defineEmits(["showHelp"]); const timer: Ref | null> = ref(null); -const todayLessonTable = computed(() => { +const showTomorrow = computed(() => { + return dayjs().isAfter(tenPM); +}); + +const lessonTable = computed(() => { const year = systemStore.generalInfo.termYear; const term = systemStore.generalInfo.term; let tmp: Lesson[] | undefined; try { - tmp = ZFService.getTodayLessonTable(); + tmp = showTomorrow.value ? ZFService.getDayLessonTable('tomorrow') : ZFService.getDayLessonTable('today'); serviceStore.zf.lessonsTableInfo[year][term].data.lessonsTable; } catch (error) { tmp = undefined; @@ -72,14 +83,12 @@ const updateRestTimeCounter = ref(0); // TODO: 计时器控制渲染 onMounted(() => { - ZFService.getTodayLessonTable(); + lessonTable.value; // 触发计算属性 timer.value = setInterval(() => { updateRestTimeCounter.value++; }, 5000); }); -// FIXME: 等有课了来观察 - onUnmounted(() => { if (timer.value) clearInterval(timer.value); }); @@ -95,7 +104,7 @@ const updateTime = computed(() => { updateTime = serviceStore.zf.lessonsTableInfo[systemStore.generalInfo.termYear][ systemStore.generalInfo.term - ]?.updateTime; + ]?.updateTime; if (updateTime) return updateTime; else return undefined; } catch (e) { @@ -109,9 +118,7 @@ function nav2Lesson() { function sectionsTimeString(sections: string) { const arr = sections.split("-"); - return `${getLessonTimeInstance(parseInt(arr[0])).format( - "HH:mm" - )}-${getLessonTimeInstance(parseInt(arr[1]), 45).format("HH:mm")}`; + return `${getLessonTimeInstance(parseInt(arr[0])).format("HH:mm")}-${getLessonTimeInstance(parseInt(arr[1]), 45).format("HH:mm")}`; } function getLessonTimeInstance(jc: number, offset = 0) { @@ -121,14 +128,7 @@ function getLessonTimeInstance(jc: number, offset = 0) { ); } -/** - * 从节次字符串提取这节课的开始时间 - * - * @param sections 节次字符串: "10-12" - * @return 距离这节课开始的剩余时间 - */ function getRestTimeString(sections: string) { - // FIXME: 使用 timeUitls const begin = parseInt(sections.split("-")[0]); const time = dayScheduleStartTime[begin - 1]; const minutesCount = time.hour * 60 + time.min; diff --git a/src/services/services/zfService.ts b/src/services/services/zfService.ts index 6c95daf1..69024393 100644 --- a/src/services/services/zfService.ts +++ b/src/services/services/zfService.ts @@ -134,10 +134,11 @@ export default class ZFService { return updateDateStateWithSession(api.zf.freeroom, data, "setRoomInfo"); } - static getTodayLessonTable() { + static getDayLessonTable( day: string ) { const lessonsTable = this.getLessonTable(); - const lessons = lessonsTable?.filter((item: Lesson) => { - const currentDay = new Date().getDay() || 7; + const lessons = lessonsTable?.filter((item: Lesson) => { + const currentDay = day === 'today' ? (new Date().getDay() || 7) : (new Date().getDay() + 1 || 7); + console.log(currentDay) if (currentDay !== parseInt(item.weekday)) return false; const currentWeek = systemStore.generalInfo.week;