From cde6fa415513c604fa89da7b6a91d0a8824440d3 Mon Sep 17 00:00:00 2001 From: leiboT Date: Fri, 7 Jul 2023 17:39:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=9D=A2=E5=8C=85=E5=B1=91?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E7=AE=80=E5=8C=96=EF=BC=8C=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 66 ++------------------------------------- src/views/index/Index.vue | 49 ++++++++++++++--------------- 2 files changed, 26 insertions(+), 89 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 49e081025..684d8cb1f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,13 +1,5 @@ -import { - createRouter, - createWebHistory, - createWebHashHistory, - type RouteLocationRaw, - type RouteLocationNamedRaw -} from 'vue-router' +import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router' import routes from './routes' -import { useBreadcrumb } from '@/pinia/stores/breadcrumb' -import { useRouteOperateState, RouteOperateState } from '@/pinia/stores/routeOperateState' import isAuthenticated from './isAuthenticated' const createHistory = @@ -18,39 +10,7 @@ const router = createRouter({ routes }) -router.beforeEach((to, from) => { - const { setRouteOperateState } = useRouteOperateState() - const { setBreadcrumb } = useBreadcrumb() - const toHistory = to.query.history as string - const fromHistory = from.query.history as string - // 路由操作状态 - if (toHistory && toHistory.split(',').includes(from.name as string)) { - setRouteOperateState(RouteOperateState.forward) - } else if (fromHistory && fromHistory.split(',').includes(to.name as string)) { - setRouteOperateState(RouteOperateState.back) - } else { - setRouteOperateState(RouteOperateState.replace) - } - // 面包屑 - let breadcrumb = to.meta.menuName - ? [{ routeName: to.name as string, menuName: to.meta.menuName as string }] - : [] - if (toHistory) { - breadcrumb = toHistory - .split(',') - .map((history) => { - const route = router.getRoutes().find((route) => route.name === history) - return { - routeName: history, - menuName: route?.meta.menuName as string - } - }) - .concat(breadcrumb) - } - setBreadcrumb(breadcrumb) -}) - -router.beforeEach(async (to, from) => { +router.beforeEach(async (to) => { // 是否已登录 跳转控制 try { await isAuthenticated.value @@ -60,26 +20,6 @@ router.beforeEach(async (to, from) => { } }) -router.afterEach((to, from) => {}) - -// 重写push -const { push } = router -router.push = (to: RouteLocationRaw) => { - const locationNamedRaw = to as RouteLocationNamedRaw - const name = locationNamedRaw.name - // 命名路由 都应该用路由名称跳转 - if (name) { - const routes = router.getRoutes() - const route = routes.find((route) => route.name === locationNamedRaw.name) - const currentRoute = router.currentRoute.value - if (route?.meta.hidden) { - if (!locationNamedRaw.query) locationNamedRaw.query = {} - locationNamedRaw.query.history = currentRoute.query.history - ? `${currentRoute.query.history},${currentRoute.name as string}` - : (currentRoute.name as string) - } - } - return push(to) -} +// router.afterEach((to, from) => {}) export default router diff --git a/src/views/index/Index.vue b/src/views/index/Index.vue index 867cefe4f..c47272422 100644 --- a/src/views/index/Index.vue +++ b/src/views/index/Index.vue @@ -66,18 +66,15 @@ - - + + {{ t(item.menuName) }} - - - - - + + + + + @@ -99,9 +96,9 @@