// middleware/auth.ts import { verifyBlankRoute } from '@/constants/index'; // import { useRouter } from 'vue-router' // const router = useRouter() /** * 全局认证中间件 * 用于处理需要登录才能访问的路由 * 如果用户未登录,将显示登录框并重定向到模型广场 * * @param to - 目标路由对象 * @returns void | NavigationResult - 如果需要重定向则返回导航结果 */ export default defineNuxtRouteMiddleware((to, from) => { const userStore = useUserStore() const modalStore = useModalStore() const menuStore = useMenuStore() if(to.path !== '/search'){ modalStore.searchQuery = '' } if (verifyBlankRoute.includes(to.path) && !verifyBlankRoute.includes(from.path)) { return abortNavigation() } // if(to.path === "/personal-center" && !userStore.isLoggedIn){ // return abortNavigation() // } menuStore.setActiveMenu(from.path) })