From e687fa8ebd3a118c606f7fa52fff0366d0aada3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=BC=A0?= <2091066548@qq.com> Date: Fri, 19 Sep 2025 18:48:17 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=AE=A8=E8=AE=BA=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E9=A1=B5=E9=9D=A2=E5=85=A8=E9=83=A8=E5=AE=8C=E6=88=90?= =?UTF-8?q?=EF=BC=8Cbug=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=90=B4=E8=80=81?= =?UTF-8?q?=E5=B8=88=E8=AF=B4=E7=9A=84bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 65 ++- src/views/CourseExchanged.vue | 554 ++++++++++++++++++++---- src/views/Home.vue | 5 +- src/views/teacher/ExamPages/AddExam.vue | 13 +- 4 files changed, 546 insertions(+), 91 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index e60814c..483145e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -762,12 +762,28 @@ const routes: RouteRecordRaw[] = [ const router = createRouter({ history: createWebHistory(), routes, - scrollBehavior(_to, _from, savedPosition) { + scrollBehavior(to, from, savedPosition) { + console.log('🔍 scrollBehavior 触发:', { + to: to.path, + from: from.path, + savedPosition, + currentScrollY: window.scrollY + }) + + // 如果是浏览器前进/后退,使用保存的位置 if (savedPosition) { + console.log('📍 使用保存的位置:', savedPosition) return savedPosition - } else { - return { top: 0 } } + + // 对于所有新的路由跳转,都滚动到顶部 + console.log('⬆️ 准备滚动到顶部') + return new Promise((resolve) => { + setTimeout(() => { + console.log('⬆️ 执行滚动到顶部') + resolve({ top: 0, behavior: 'smooth' }) + }, 100) // 延迟确保页面已渲染 + }) } }) @@ -801,4 +817,47 @@ router.beforeEach((to, from, next) => { }) }) +// 路由跳转完成后的处理 +router.afterEach((to, from) => { + console.log('🔍 router.afterEach 触发:', { + to: to.path, + from: from.path, + windowScrollY: window.scrollY, + documentScrollTop: document.documentElement.scrollTop, + bodyScrollTop: document.body.scrollTop + }) + + // 检查所有可能的滚动容器 + setTimeout(() => { + console.log('🔍 检查滚动容器:') + console.log('- window.scrollY:', window.scrollY) + console.log('- document.documentElement.scrollTop:', document.documentElement.scrollTop) + console.log('- document.body.scrollTop:', document.body.scrollTop) + + // 查找所有可能的滚动容器 + const scrollableElements = document.querySelectorAll('.n-layout, .n-layout-content, .content, .app-layout') + scrollableElements.forEach((el, index) => { + console.log(`- 滚动容器 ${index}:`, el.className, 'scrollTop:', el.scrollTop) + }) + + // 强制滚动所有容器到顶部 + console.log('⬆️ 强制滚动所有容器到顶部') + window.scrollTo(0, 0) + document.documentElement.scrollTop = 0 + document.body.scrollTop = 0 + + scrollableElements.forEach((el) => { + el.scrollTop = 0 + }) + + // 最后检查 + setTimeout(() => { + console.log('⬆️ 最终检查所有滚动位置:') + console.log('- window.scrollY:', window.scrollY) + console.log('- document.documentElement.scrollTop:', document.documentElement.scrollTop) + console.log('- document.body.scrollTop:', document.body.scrollTop) + }, 100) + }, 100) +}) + export default router \ No newline at end of file diff --git a/src/views/CourseExchanged.vue b/src/views/CourseExchanged.vue index ff8ad59..69417c2 100644 --- a/src/views/CourseExchanged.vue +++ b/src/views/CourseExchanged.vue @@ -64,7 +64,7 @@