refactor(components): basicLayout布局组件重构完成:根据NavMode拆分为多个布局组件

This commit is contained in:
Soybean
2021-11-20 20:14:02 +08:00
parent 0e0d559d2f
commit ffe987832f
110 changed files with 743 additions and 1713 deletions

View File

@ -1,5 +0,0 @@
import { getCacheRoutes, transformRouteToMenu } from '@/utils';
import { customRoutes, routes } from '../routes';
export const cacheRoutes = getCacheRoutes(routes);
export const menus = transformRouteToMenu(customRoutes);

27
src/router/guide/index.ts Normal file
View File

@ -0,0 +1,27 @@
import type { Router } from 'vue-router';
import { useTitle } from '@vueuse/core';
import { useAppStore } from '@/store';
import { handlePagePermission } from './permission';
/**
* 路由守卫函数
* @param router - 路由实例
*/
export function createRouterGuide(router: Router) {
const { resetScrollBehavior } = useAppStore();
router.beforeEach((to, from, next) => {
// 开始 loadingBar
window.$loadingBar?.start();
// 页面跳转逻辑
handlePagePermission(to, from, next);
});
router.afterEach(to => {
// 设置document title
useTitle(to.meta.title as string);
// 结束 loadingBar
window.$loadingBar?.finish();
// 重置滚动条行为
resetScrollBehavior();
});
}

View File

@ -1,30 +1,15 @@
import type { Router, RouteLocationNormalized, NavigationGuardNext } from 'vue-router';
import { useTitle } from '@vueuse/core';
import type { RouteLocationNormalized, NavigationGuardNext } from 'vue-router';
import { routeName } from '@/router';
import { getToken, getLoginRedirectUrl } from '@/utils';
/**
*
* @param router -
*/
export default function createRouterGuide(router: Router) {
router.beforeEach((to, from, next) => {
// 开始 loadingBar
window.$loadingBar?.start();
// 页面跳转逻辑
handleRouterAction(to, from, next);
});
router.afterEach(to => {
// 设置document title
useTitle(to.meta.title as string);
// 结束 loadingBar
window.$loadingBar?.finish();
});
}
type RouterAction = [boolean, () => void];
function handleRouterAction(to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) {
/** 处理页面的权限 */
export function handlePagePermission(
to: RouteLocationNormalized,
from: RouteLocationNormalized,
next: NavigationGuardNext
) {
const token = getToken();
const isLogin = Boolean(token);
const needLogin = Boolean(to.meta?.requiresAuth);

View File

@ -1,4 +1,3 @@
export * from './const';
export * from './routes';
export * from './setup';
export * from './export';

View File

@ -13,7 +13,7 @@ const DASHBOARD: CustomRoute = {
component: BasicLayout,
redirect: { name: routeName('dashboard_analysis') },
meta: {
title: routeTitle('dashboard_analysis'),
title: routeTitle('dashboard'),
icon: 'carbon:dashboard'
},
children: [

View File

@ -1,7 +1,8 @@
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import type { App } from 'vue';
import { routes } from '../routes';
import createRouterGuide from '../permission';
import { getCacheRoutes, transformRouteToMenu } from '@/utils';
import { routes, customRoutes } from '../routes';
import { createRouterGuide } from '../guide';
/** 用于部署vercel托管服务 */
const isStaging = import.meta.env.VITE_HTTP_ENV === 'STAGING';
@ -16,3 +17,9 @@ export async function setupRouter(app: App) {
createRouterGuide(router);
await router.isReady();
}
/** 缓存的路由对应vue页面的名称 */
export const cacheRoutes = getCacheRoutes(routes);
/** 菜单 */
export const menus = transformRouteToMenu(customRoutes);