Skip to content

Commit

Permalink
fix: 修复侧滑返回黑屏
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 19, 2024
1 parent 4f0ff12 commit 2fd9b99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.81",
"version": "2.14.82",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
16 changes: 11 additions & 5 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,23 @@ const router = createRouter({

// 全局前置守卫
router.afterEach(async (to, from) => {
console.log(`afterEach ${from.path} => ${to.path}`)
document.querySelector('html').style['overflow-y'] = '';
document.querySelector('html').style.height = '';
document.body.style.height = '';
document.body.style['overflow-y'] = '';
(document.querySelector('#app') as HTMLElement).style['overflow-y'] = '';
(document.querySelector('#app') as HTMLElement).style.height = '';
// console.log(`afterEach ${from.path} => ${to.path}`)
if (to?.path && from?.path !== to?.path) {
let scrollTop = 0;
if (to?.meta?.needTabBar && globalStore !== null) {
const savedPositions = toRaw(globalStore.savedPositions);
if (savedPositions[to.path]?.top) {
scrollTop = savedPositions[to.path]?.top
console.log(`读取到 ${to.path} 保存的滚动位置:${scrollTop}`)
// console.log(`读取到 ${to.path} 保存的滚动位置:${scrollTop}`)
}
}
console.log(`${to.path} 滚动到:${scrollTop}`)
// console.log(`${to.path} 滚动到:${scrollTop}`)
await nextTick()
window.scrollTo({
top: scrollTop,
Expand All @@ -209,15 +215,15 @@ router.afterEach(async (to, from) => {
}
});
router.beforeEach((to, from) => {
console.log(`beforeEach ${from.path} => ${to.path}`)
// console.log(`beforeEach ${from.path} => ${to.path}`)
if (!globalStore) {
globalStore = useGlobalStore();
}
if (globalStore) {
if (from?.meta?.needTabBar && from?.path !== to?.path) {
// if (from?.meta?.needTabBar) {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
console.log(`保存 ${from.path} 滚动位置:${scrollTop}`)
// console.log(`保存 ${from.path} 滚动位置:${scrollTop}`)
globalStore.setSavedPositions(from.path, { left: 0, top: scrollTop })
}
}
Expand Down

0 comments on commit 2fd9b99

Please sign in to comment.