Fix: 修正重定向逻辑 & 使用Pinia管理状态

This commit is contained in:
2025-07-16 15:51:34 +08:00
parent bdb02fd147
commit 9720bf05c6
6 changed files with 110 additions and 10 deletions

31
src/stores/navigation.ts Normal file
View File

@ -0,0 +1,31 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { useRoute } from 'vue-router'
import { navigationConfig } from '@/config/navigation'
export const useNavigationStore = defineStore('navigation', () => {
// Status
const route = useRoute()
const drawer = ref(false)
// 当前选中的菜单项
const selectedIndex = computed(() => {
return navigationConfig.findIndex(item => item.to === route.path)
})
// Actions
function toggleDrawer () {
drawer.value = !drawer.value
}
function setDrawerOpen (open: boolean) {
drawer.value = open
}
return {
selectedIndex,
drawer,
toggleDrawer,
setDrawerOpen,
}
})