fix(日历组件): 修复任务切换时状态未重置的问题
重置日历组件状态时清除筛选条件和恢复标记 在任务切换时强制刷新页面数据并滚动到顶部
Showing
2 changed files
with
52 additions
and
7 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-01-25 15:34:17 | 2 | * @Date: 2025-01-25 15:34:17 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-12-18 23:45:18 | 4 | + * @LastEditTime: 2025-12-19 01:22:52 |
| 5 | * @FilePath: /mlaj/src/components/ui/CollapsibleCalendar.vue | 5 | * @FilePath: /mlaj/src/components/ui/CollapsibleCalendar.vue |
| 6 | * @Description: 可折叠日历组件 | 6 | * @Description: 可折叠日历组件 |
| 7 | --> | 7 | --> |
| ... | @@ -381,6 +381,14 @@ defineExpose({ | ... | @@ -381,6 +381,14 @@ defineExpose({ |
| 381 | if (calendarRef.value && calendarRef.value.reset) { | 381 | if (calendarRef.value && calendarRef.value.reset) { |
| 382 | calendarRef.value.reset(date || new Date()) | 382 | calendarRef.value.reset(date || new Date()) |
| 383 | } | 383 | } |
| 384 | + // 重置筛选状态 | ||
| 385 | + selectedCourseId.value = '' | ||
| 386 | + selectedCourseText.value = '全部作业' | ||
| 387 | + // 重置恢复状态标记,防止后续 subtaskList 监听器误判为恢复模式 | ||
| 388 | + isRestored.value = false | ||
| 389 | + // 重置头部隐藏状态 | ||
| 390 | + isHeaderHidden.value = false | ||
| 391 | + sessionStorage.removeItem(STORAGE_KEY) | ||
| 384 | } | 392 | } |
| 385 | }) | 393 | }) |
| 386 | </script> | 394 | </script> | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-05-29 15:34:17 | 2 | * @Date: 2025-05-29 15:34:17 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-12-19 00:12:31 | 4 | + * @LastEditTime: 2025-12-19 01:21:14 |
| 5 | * @FilePath: /mlaj/src/views/checkin/IndexCheckInPage.vue | 5 | * @FilePath: /mlaj/src/views/checkin/IndexCheckInPage.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -616,18 +616,39 @@ const onLoad = async (date) => { | ... | @@ -616,18 +616,39 @@ const onLoad = async (date) => { |
| 616 | loading.value = false; | 616 | loading.value = false; |
| 617 | }; | 617 | }; |
| 618 | 618 | ||
| 619 | -onMounted(async () => { | 619 | +const initPage = async (date) => { |
| 620 | - const current_date = route.query.date; | 620 | + // 重置数据 |
| 621 | + checkinDataList.value = []; | ||
| 622 | + page.value = 0; | ||
| 623 | + finished.value = false; | ||
| 624 | + loading.value = false; | ||
| 625 | + taskDetail.value = {}; | ||
| 626 | + selectedSubtaskId.value = ''; | ||
| 627 | + | ||
| 628 | + const current_date = date || route.query.date; | ||
| 621 | if (current_date) { | 629 | if (current_date) { |
| 622 | selectedDate.value = new Date(current_date); | 630 | selectedDate.value = new Date(current_date); |
| 623 | - getTaskDetail(dayjs(current_date).format('YYYY-MM')); | 631 | + await getTaskDetail(dayjs(current_date).format('YYYY-MM')); |
| 624 | - myRefCalendar.value?.reset(new Date(current_date)); | 632 | + // 确保日历组件已挂载再调用 reset |
| 633 | + nextTick(() => { | ||
| 634 | + calendarRef.value?.reset(new Date(current_date)); | ||
| 635 | + }) | ||
| 625 | onLoad(current_date); | 636 | onLoad(current_date); |
| 626 | } else { | 637 | } else { |
| 627 | selectedDate.value = new Date(); | 638 | selectedDate.value = new Date(); |
| 628 | - getTaskDetail(dayjs().format('YYYY-MM')); | 639 | + await getTaskDetail(dayjs().format('YYYY-MM')); |
| 640 | + // 确保日历组件已挂载再调用 reset | ||
| 641 | + nextTick(() => { | ||
| 642 | + calendarRef.value?.reset(new Date()); | ||
| 643 | + }) | ||
| 629 | onLoad(dayjs().format('YYYY-MM-DD')); | 644 | onLoad(dayjs().format('YYYY-MM-DD')); |
| 630 | } | 645 | } |
| 646 | +} | ||
| 647 | + | ||
| 648 | +onMounted(async () => { | ||
| 649 | + // 记录当前的taskId | ||
| 650 | + lastTaskId.value = route.query.id; | ||
| 651 | + await initPage(route.query.date); | ||
| 631 | 652 | ||
| 632 | // 获取作品类型数据 | 653 | // 获取作品类型数据 |
| 633 | try { | 654 | try { |
| ... | @@ -713,12 +734,28 @@ const formatData = (data) => { | ... | @@ -713,12 +734,28 @@ const formatData = (data) => { |
| 713 | 734 | ||
| 714 | // 保存滚动位置 | 735 | // 保存滚动位置 |
| 715 | const savedScrollTop = ref(0) | 736 | const savedScrollTop = ref(0) |
| 737 | +// 记录上次的taskId,用于判断是否切换了任务 | ||
| 738 | +const lastTaskId = ref('') | ||
| 716 | 739 | ||
| 717 | onDeactivated(() => { | 740 | onDeactivated(() => { |
| 718 | savedScrollTop.value = window.scrollY | 741 | savedScrollTop.value = window.scrollY |
| 719 | }) | 742 | }) |
| 720 | 743 | ||
| 721 | onActivated(async () => { | 744 | onActivated(async () => { |
| 745 | + // 检查任务ID是否变化 | ||
| 746 | + // 注意:route.query.id 可能是数字或字符串,统一转为字符串比较 | ||
| 747 | + const currentId = String(route.query.id || '') | ||
| 748 | + const lastId = String(lastTaskId.value || '') | ||
| 749 | + | ||
| 750 | + if (currentId && currentId !== lastId) { | ||
| 751 | + lastTaskId.value = currentId; | ||
| 752 | + // 如果任务ID变化,强制刷新整个页面数据 | ||
| 753 | + await initPage(route.query.date); | ||
| 754 | + // 滚动到顶部 | ||
| 755 | + window.scrollTo(0, 0); | ||
| 756 | + return; | ||
| 757 | + } | ||
| 758 | + | ||
| 722 | // 恢复滚动位置 | 759 | // 恢复滚动位置 |
| 723 | if (savedScrollTop.value > 0) { | 760 | if (savedScrollTop.value > 0) { |
| 724 | setTimeout(() => { | 761 | setTimeout(() => { | ... | ... |
-
Please register or login to post a comment