mirror of https://github.com/halo-dev/halo
fix: menu scrollbar position cannot be restored after switching routes (#3634)
#### What type of PR is this? /kind bug /area console /milestone 2.4.0 #### What this PR does / why we need it: 修复跳转页面之后无法固定菜单滚动位置的问题。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3633 #### Does this PR introduce a user-facing change? ```release-note None ```pull/3625/head^2
parent
29f3c25a44
commit
0b3343f219
|
@ -18,7 +18,7 @@ import {
|
||||||
useRouter,
|
useRouter,
|
||||||
type RouteRecordRaw,
|
type RouteRecordRaw,
|
||||||
} from "vue-router";
|
} from "vue-router";
|
||||||
import { nextTick, onMounted, onUnmounted, reactive, ref, watch } from "vue";
|
import { onMounted, onUnmounted, reactive, ref } from "vue";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import GlobalSearchModal from "@/components/global-search/GlobalSearchModal.vue";
|
import GlobalSearchModal from "@/components/global-search/GlobalSearchModal.vue";
|
||||||
import LoginModal from "@/components/login/LoginModal.vue";
|
import LoginModal from "@/components/login/LoginModal.vue";
|
||||||
|
@ -28,7 +28,6 @@ import { useRoleStore } from "@/stores/role";
|
||||||
import { hasPermission } from "@/utils/permission";
|
import { hasPermission } from "@/utils/permission";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import { rbacAnnotations } from "@/constants/annotations";
|
import { rbacAnnotations } from "@/constants/annotations";
|
||||||
import { useScroll } from "@vueuse/core";
|
|
||||||
import { defineStore, storeToRefs } from "pinia";
|
import { defineStore, storeToRefs } from "pinia";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import {
|
import {
|
||||||
|
@ -189,9 +188,8 @@ const generateMenus = () => {
|
||||||
|
|
||||||
onMounted(generateMenus);
|
onMounted(generateMenus);
|
||||||
|
|
||||||
// store scroll position
|
// aside scroll
|
||||||
const navbarScroller = ref();
|
const navbarScroller = ref();
|
||||||
const { y } = useScroll(navbarScroller);
|
|
||||||
|
|
||||||
const useNavbarScrollStore = defineStore("navbar", {
|
const useNavbarScrollStore = defineStore("navbar", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
@ -201,20 +199,6 @@ const useNavbarScrollStore = defineStore("navbar", {
|
||||||
|
|
||||||
const navbarScrollStore = useNavbarScrollStore();
|
const navbarScrollStore = useNavbarScrollStore();
|
||||||
|
|
||||||
watch(
|
|
||||||
() => y.value,
|
|
||||||
() => {
|
|
||||||
navbarScrollStore.y = y.value;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
nextTick(() => {
|
|
||||||
y.value = navbarScrollStore.y;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// aside scroll
|
|
||||||
const reactiveParams = reactive<UseOverlayScrollbarsParams>({
|
const reactiveParams = reactive<UseOverlayScrollbarsParams>({
|
||||||
options: {
|
options: {
|
||||||
scrollbars: {
|
scrollbars: {
|
||||||
|
@ -222,7 +206,17 @@ const reactiveParams = reactive<UseOverlayScrollbarsParams>({
|
||||||
autoHideDelay: 600,
|
autoHideDelay: 600,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defer: true,
|
events: {
|
||||||
|
scroll: (_, onScrollArgs) => {
|
||||||
|
const target = onScrollArgs.target as HTMLElement;
|
||||||
|
navbarScrollStore.y = target.scrollTop;
|
||||||
|
},
|
||||||
|
updated: (instance) => {
|
||||||
|
const { viewport } = instance.elements();
|
||||||
|
if (!viewport) return;
|
||||||
|
viewport.scrollTo({ top: navbarScrollStore.y });
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const [initialize] = useOverlayScrollbars(reactiveParams);
|
const [initialize] = useOverlayScrollbars(reactiveParams);
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|
Loading…
Reference in New Issue