Skip to content

Commit

Permalink
refactor: 重构路由移除扩展菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
oljc committed Jan 24, 2024
1 parent 26f6db2 commit dff44cb
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 73 deletions.
18 changes: 11 additions & 7 deletions src/components/menu/use-menu-tree.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { computed } from 'vue';
import type { RouteRecordRaw, RouteRecordNormalized } from 'vue-router';
import { appRoutes } from '@/router/routes';
import usePermission from '@/hooks/permission';
import { useAppStore } from '@/store';
import appClientMenus from '@/router/app-menus';
import { cloneDeep } from 'lodash';

export default function useMenuTree() {
const permission = usePermission();
const appStore = useAppStore();
const appRoute = computed(() => {
if (appStore.menuFromServer) {
return appStore.appAsyncMenus;
}
return appClientMenus;
return appRoutes.map(el => {
const { name, path, meta, redirect, children } = el;
return {
name,
path,
meta,
redirect,
children
};
});
});
const menuTree = computed(() => {
const copyRouter = cloneDeep(appRoute.value) as RouteRecordNormalized[];
Expand Down
16 changes: 0 additions & 16 deletions src/router/app-menus/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createRouter, createWebHistory } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

import { appRoutes } from './routes';
import { REDIRECT_MAIN, NOT_FOUND_ROUTE } from './routes/base';
import createRouteGuard from './guard';

NProgress.configure({ showSpinner: false }); // NProgress Configuration
NProgress.configure({ showSpinner: false });

const router = createRouter({
history: createWebHistory(),
Expand Down
10 changes: 0 additions & 10 deletions src/router/routes/externalModules/arco.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/router/routes/externalModules/faq.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/router/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { RouteRecordNormalized } from 'vue-router';

const modules = import.meta.glob('./modules/*.ts', { eager: true });
const externalModules = import.meta.glob('./externalModules/*.ts', {
eager: true
});

function formatModules(_modules: any, result: RouteRecordNormalized[]) {
Object.keys(_modules).forEach(key => {
Expand All @@ -18,8 +15,3 @@ function formatModules(_modules: any, result: RouteRecordNormalized[]) {
}

export const appRoutes: RouteRecordNormalized[] = formatModules(modules, []);

export const appExternalRoutes: RouteRecordNormalized[] = formatModules(
externalModules,
[]
);
20 changes: 10 additions & 10 deletions src/router/routes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export type Component<T = any> =
| (() => Promise<T>);

export interface AppRouteRecordRaw {
path: string;
name?: string | symbol;
meta?: RouteMeta;
redirect?: string;
component: Component | string;
children?: AppRouteRecordRaw[];
alias?: string | string[];
props?: Record<string, any>;
beforeEnter?: NavigationGuard | NavigationGuard[];
fullPath?: string;
path: string; // 路径
name?: string | symbol; // 名字
meta?: RouteMeta; // 路由元信息
redirect?: string; // 重定向地址
component: Component | string; // 组件
children?: AppRouteRecordRaw[]; // 子路由
alias?: string | string[]; // 别名
props?: Record<string, any>; // 传递给路由的参数
beforeEnter?: NavigationGuard | NavigationGuard[]; // 路由独享的守卫
fullPath?: string; // 完整路径
}
30 changes: 20 additions & 10 deletions src/router/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ import 'vue-router';

declare module 'vue-router' {
interface RouteMeta {
roles?: string[]; // Controls roles that have access to the page
requiresAuth: boolean; // Whether login is required to access the current page (every route must declare)
icon?: string; // The icon show in the side menu
locale?: string; // The locale name show in side menu and breadcrumb
hideInMenu?: boolean; // If true, it is not displayed in the side menu
hideChildrenInMenu?: boolean; // if set true, the children are not displayed in the side menu
activeMenu?: string; // if set name, the menu will be highlighted according to the name you set
order?: number; // Sort routing menu items. If set key, the higher the value, the more forward it is
noAffix?: boolean; // if set true, the tag will not affix in the tab-bar
ignoreCache?: boolean; // if set true, the page will not be cached
/** 页面角色权限 */
roles?: string[];
/** 是否需要登录(必填) */
requiresAuth: boolean;
/** 菜单图标 */
icon?: string;
/** 国际化 */
locale?: string;
/** 隐藏菜单 */
hideInMenu?: boolean;
/** 隐藏子菜单 */
hideChildrenInMenu?: boolean;
/** 高亮菜单名字 */
activeMenu?: string;
/** 排序 */
order?: number;
/** 是否出现在 tabBar 标签栏 */
noAffix?: boolean;
/** 是否忽略缓存 */
ignoreCache?: boolean;
}
}

0 comments on commit dff44cb

Please sign in to comment.