Skip to content

Commit

Permalink
fixbug: 修改打开默认添加标签逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jul 7, 2022
1 parent c4299ee commit b1fc36a
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/layouts/pageLayouts/components/AppTabs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -79,6 +80,8 @@
const { setTabPaneKey, addRouteTabs, onFresh, removeTab } = useTabsChange(multiTabs);
const { selectMenu } = useSelectMenu();
const { visible, rightClickTags, rightViewStyle, contextmenu, rightViewChange } =
useTabsView(multiTabs);
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/pageLayouts/components/Sidebar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { usePermissionStoreHook } from '@/store/modules/permission';

const { whiteRouteModulesList, routeModulesList } = configRouteList();

// 在导航栏上的路由
export const sidebarRouteList = routeModulesList;

export const router = createRouter({
Expand Down
5 changes: 3 additions & 2 deletions src/router/modules/error/index.ts
Original file line number Diff line number Diff line change
@@ -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: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/router/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []; // 不参与菜单处理的路由
Expand Down
8 changes: 3 additions & 5 deletions src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down Expand Up @@ -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[]);
Expand All @@ -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);
}
});
Expand Down
7 changes: 4 additions & 3 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -220,6 +220,7 @@
.input-group > div {
position: relative;
height: 45px;
flex: 1;
}
.input-group > div > h5 {
Expand Down

0 comments on commit b1fc36a

Please sign in to comment.