From b1fc36a0e9dcd4e24e5fbd9de34e04622a47ce9b Mon Sep 17 00:00:00 2001 From: SuperCuteXiaoSi <1531733886@qq.com> Date: Thu, 7 Jul 2022 21:53:55 +0800 Subject: [PATCH] =?UTF-8?q?fixbug:=20=E4=BF=AE=E6=94=B9=E6=89=93=E5=BC=80?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=B7=BB=E5=8A=A0=E6=A0=87=E7=AD=BE=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/pageLayouts/components/AppTabs/index.vue | 8 ++++++-- src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue | 2 +- src/layouts/pageLayouts/components/Sidebar/index.vue | 2 +- .../{components/Sidebar => }/hooks/useSelectMenu.ts | 7 +++++-- src/router/index.ts | 1 + src/router/modules/error/index.ts | 5 +++-- src/router/modules/index.ts | 2 +- src/router/utils.ts | 8 +++----- src/views/login/index.vue | 7 ++++--- 9 files changed, 25 insertions(+), 17 deletions(-) rename src/layouts/pageLayouts/{components/Sidebar => }/hooks/useSelectMenu.ts (70%) diff --git a/src/layouts/pageLayouts/components/AppTabs/index.vue b/src/layouts/pageLayouts/components/AppTabs/index.vue index 5adb73f6..238157e8 100644 --- a/src/layouts/pageLayouts/components/AppTabs/index.vue +++ b/src/layouts/pageLayouts/components/AppTabs/index.vue @@ -71,6 +71,7 @@ import { useTabsView } from './hooks/useTabsView'; import { useTabsChange } from './hooks/useTabsChange'; import { emitter } from '@/utils/mitt'; + import { useSelectMenu } from '../../hooks/useSelectMenu'; const route = useRoute(); const router = useRouter(); @@ -79,6 +80,8 @@ const { setTabPaneKey, addRouteTabs, onFresh, removeTab } = useTabsChange(multiTabs); + const { selectMenu } = useSelectMenu(); + const { visible, rightClickTags, rightViewStyle, contextmenu, rightViewChange } = useTabsView(multiTabs); @@ -92,12 +95,13 @@ ); onBeforeMount(() => { - addRouteTabs(route); - contextmenu(route.path); emitter.on('siteBarChange', ({ routeRaw }) => { addRouteTabs(routeRaw as unknown as MultiTabsType); contextmenu(routeRaw.path); }); + + selectMenu(route.path); + contextmenu(route.path); }); const tabRemoveChange = (e: string) => { diff --git a/src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue b/src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue index c0569cc4..b53a6fe9 100644 --- a/src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue +++ b/src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue @@ -27,7 +27,7 @@ import { usePermissionStoreHook } from '@/store/modules/permission'; import { computed } from 'vue'; import { useRoute } from 'vue-router'; - import { useSelectMenu } from './hooks/useSelectMenu'; + import { useSelectMenu } from '../../hooks/useSelectMenu'; import { AppRouteRecordRaw } from '#/route'; import { getParentPaths, findRouteByPath } from '@/router/utils'; diff --git a/src/layouts/pageLayouts/components/Sidebar/index.vue b/src/layouts/pageLayouts/components/Sidebar/index.vue index 048691bc..542f53c3 100644 --- a/src/layouts/pageLayouts/components/Sidebar/index.vue +++ b/src/layouts/pageLayouts/components/Sidebar/index.vue @@ -26,7 +26,7 @@ import { usePermissionStoreHook } from '@/store/modules/permission'; import { AppRouteRecordRaw } from '#/route'; import { getParentPaths, findRouteByPath } from '@/router/utils'; - import { useSelectMenu } from './hooks/useSelectMenu'; + import { useSelectMenu } from '../../hooks/useSelectMenu'; const { selectMenu } = useSelectMenu(); diff --git a/src/layouts/pageLayouts/components/Sidebar/hooks/useSelectMenu.ts b/src/layouts/pageLayouts/hooks/useSelectMenu.ts similarity index 70% rename from src/layouts/pageLayouts/components/Sidebar/hooks/useSelectMenu.ts rename to src/layouts/pageLayouts/hooks/useSelectMenu.ts index 618dd389..d9cab245 100644 --- a/src/layouts/pageLayouts/components/Sidebar/hooks/useSelectMenu.ts +++ b/src/layouts/pageLayouts/hooks/useSelectMenu.ts @@ -4,9 +4,12 @@ import { emitter } from '@/utils/mitt'; import { useRouter } from 'vue-router'; export const useSelectMenu = () => { - const router = useRouter().options.routes as AppRouteRecordRaw[]; + const router = (useRouter().options.routes.find((i) => i.path === '/') || + []) as AppRouteRecordRaw; const selectMenu = (path: string) => { - const findRoute = findRouteByPath(path, router[0]?.children || []); + console.log(router); + const findRoute = findRouteByPath(path, router.children || []); + console.log(findRoute); if (findRoute) { if (findRoute.redirect && findRoute.children && findRoute.children.length) { selectMenu(findRoute.children[0].path); diff --git a/src/router/index.ts b/src/router/index.ts index 861ea36a..edf73c29 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -6,6 +6,7 @@ import { usePermissionStoreHook } from '@/store/modules/permission'; const { whiteRouteModulesList, routeModulesList } = configRouteList(); +// 在导航栏上的路由 export const sidebarRouteList = routeModulesList; export const router = createRouter({ diff --git a/src/router/modules/error/index.ts b/src/router/modules/error/index.ts index fbf62088..b4c61b72 100644 --- a/src/router/modules/error/index.ts +++ b/src/router/modules/error/index.ts @@ -1,16 +1,17 @@ import { AppRouteRecordRaw } from '#/route'; import { t } from '@/hooks/web/useI18n'; +const Layout = () => import('@/layouts/pageLayouts/index.vue'); + const error: AppRouteRecordRaw[] = [ { path: '/error', redirect: '/error/404', name: 'error', + component: Layout, meta: { title: 'route.pathName.error', icon: 'iEL-remove-filled', - whiteList: true, - position: 9, }, children: [ { diff --git a/src/router/modules/index.ts b/src/router/modules/index.ts index c94f259b..218a82d8 100644 --- a/src/router/modules/index.ts +++ b/src/router/modules/index.ts @@ -3,7 +3,7 @@ import { pathNamekeyCheck, setUpRoutePath } from '../utils'; export function configRouteList() { // 白名单目录/文件 - const whiteCatalogue = ['root', 'whiteList']; + const whiteCatalogue = ['root', 'whiteList', 'error']; let routeModulesList: AppRouteRecordRaw[] = []; //菜单路由 const whiteRouteModulesList: AppRouteRecordRaw[] = []; // 不参与菜单处理的路由 diff --git a/src/router/utils.ts b/src/router/utils.ts index 2673a738..50964030 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -58,7 +58,6 @@ function privilegeRouting(routeList: RouteRecordRaw[], dataRouter: AppRouteRecor dataRouter.forEach((i) => { routeList[homeIndex].children?.push(i as RouteRecordRaw); }); - console.log('routeList[homeIndex]', routeList[homeIndex]); router.addRoute(routeList[homeIndex]); } } @@ -188,11 +187,9 @@ function getParentPaths(routePath: string, routes: AppRouteRecordRaw[]) { // 查找对应path的路由信息 function findRouteByPath(path: string, routes: AppRouteRecordRaw[]): AppRouteRecordRaw | null { const res = routes.find((item: { path: string }) => item.path == path) || null; - console.log(res); if (res) { return res; } else { - console.log('什么情况下才走这里?'); for (let i = 0; i < routes.length; i++) { if (routes[i].children instanceof Array && routes[i].children?.length) { const miRes = findRouteByPath(path, routes[i].children as AppRouteRecordRaw[]); @@ -210,8 +207,9 @@ function findRouteByPath(path: string, routes: AppRouteRecordRaw[]): AppRouteRec // 重置路由 不重置白名单 function resetRouter() { sidebarRouteList.forEach((route) => { - const { name, meta } = route; - if (name && !meta?.whiteList) { + const { name } = route; + console.log(name); + if (name) { router.hasRoute(name) && router.removeRoute(name); } }); diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 2916050d..cf9d5603 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -79,7 +79,7 @@ }, { errorMessageMode: 'modal', withToken: false }, ); - console.log(res); + if (res.code === 1) { localStorage.setItem('userInfo', JSON.stringify(res.data)); await initAsyncRoute(res.data.power); @@ -178,8 +178,8 @@ .input-group { position: relative; - display: grid; - grid-template-columns: 7% 93%; + display: flex; + align-items: center; margin: 25px 0; padding: 5px 0; border-bottom: 2px solid #d9d9d9; @@ -220,6 +220,7 @@ .input-group > div { position: relative; height: 45px; + flex: 1; } .input-group > div > h5 {