Merge pull request #40 from cikezhu/main

去除多余的代码/修改记录位置的方式/修复IOS14登录页显示bug
This commit is contained in:
jxxghp
2023-09-19 12:07:54 +08:00
committed by GitHub
4 changed files with 6 additions and 22 deletions
-3
View File
@@ -7,9 +7,6 @@ import store from './store'
const { global: globalTheme } = useTheme() const { global: globalTheme } = useTheme()
globalTheme.name.value = localStorage.getItem('theme') || 'light' globalTheme.name.value = localStorage.getItem('theme') || 'light'
// 路由
const route = useRoute()
// 提示框 // 提示框
const $toast = useToast() const $toast = useToast()
-16
View File
@@ -30,9 +30,6 @@ app.use(vuetify)
}) })
.use(VuetifyUseDialog).mount('#app') .use(VuetifyUseDialog).mount('#app')
// 记录和恢复滚动位置
const scrollPositions: { [key: string]: number } = {} // 用于存储每个路由的滚动位置
// 路由导航守卫 // 路由导航守卫
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const isAuthenticated = store.state.auth.token !== null const isAuthenticated = store.state.auth.token !== null
@@ -41,24 +38,11 @@ router.beforeEach((to, from, next) => {
next('/login') next('/login')
} }
else { else {
// 只有 meta 中 keepAlive 为 true 的情况下才记录滚动位置
if (from.meta.keepAlive)
scrollPositions[from.fullPath] = window.scrollY
startNProgress() startNProgress()
next() next()
} }
}) })
router.afterEach((to) => { router.afterEach((to) => {
// 只有 meta 中 keepAlive 为 true 的情况下才恢复滚动位置
if (to.meta.keepAlive) {
const savedPosition = scrollPositions[to.fullPath]
if (savedPosition !== undefined) {
setTimeout(() => {
window.scrollTo(0, savedPosition)
}, 0)
}
}
doneNProgress() doneNProgress()
}) })
+1 -1
View File
@@ -130,7 +130,7 @@ onMounted(() => {
<VCardItem class="justify-center mb-7"> <VCardItem class="justify-center mb-7">
<template #prepend> <template #prepend>
<div class="d-flex pe-0"> <div class="d-flex pe-0">
<VImg :src="logo" width="64" /> <VImg :src="logo" width="64" height="64" />
</div> </div>
</template> </template>
+5 -2
View File
@@ -2,8 +2,11 @@ import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
scrollBehavior() { scrollBehavior(to, from, savedPosition) {
// 始终滚动到顶部 // 如果页面有缓存那么恢复其位置, 否则始终滚动到顶部
if (to.meta.keepAlive && savedPosition)
return savedPosition
// console.log('top: 0')
return { top: 0 } return { top: 0 }
}, },
routes: [ routes: [