mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(components): basicLayout布局组件重构完成:根据NavMode拆分为多个布局组件
This commit is contained in:
@ -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
27
src/router/guide/index.ts
Normal 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();
|
||||
});
|
||||
}
|
@ -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);
|
@ -1,4 +1,3 @@
|
||||
export * from './const';
|
||||
export * from './routes';
|
||||
export * from './setup';
|
||||
export * from './export';
|
||||
|
@ -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: [
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user