refactor(projects): 精简版+动态路由权限初步

This commit is contained in:
Soybean
2022-01-03 22:20:10 +08:00
parent 7a0648dba5
commit de2057f141
354 changed files with 2053 additions and 22117 deletions

View File

@ -1,85 +0,0 @@
import type { RouteRecordRaw } from 'vue-router';
import { BlankLayout } from '@/layouts';
import type { LoginModuleType } from '@/interface';
import { Login, NoPermission, NotFound, ServiceError } from '@/views';
import { getLoginModuleRegExp } from '@/utils';
import { routeName, routePath, routeTitle } from '../constant';
import { ROUTE_HOME_NAME } from './route-home';
/**
* 固定不变的路由
* @description !最后一项重定向未找到的路由须放置路由的最后一项
*/
const constantRoutes: RouteRecordRaw[] = [
{
name: routeName('root'),
path: routePath('root'),
redirect: { name: ROUTE_HOME_NAME }
},
{
// 名称、路径随意不在路由声明里面只是为各个子路由充当应用BlankLayout布局的桥梁因此访问该路由时重定向到404
name: 'constant-single_',
path: '/constant-single_',
component: BlankLayout,
redirect: { name: routeName('not-found') },
meta: {
title: 'constant-single_',
keepAlive: true
},
children: [
// 登录
{
name: routeName('login'),
path: `${routePath('login')}/:module(${getLoginModuleRegExp()})?`,
component: Login,
props: route => {
const moduleType = (route.params.module as LoginModuleType) || 'pwd-login';
return {
module: moduleType
};
},
meta: {
title: routeTitle('login'),
fullPage: true
}
},
// 403
{
name: routeName('no-permission'),
path: routePath('no-permission'),
component: NoPermission,
meta: {
title: routeTitle('no-permission'),
fullPage: true
}
},
// 404
{
name: routeName('not-found'),
path: routePath('not-found'),
component: NotFound,
meta: {
title: routeTitle('not-found'),
fullPage: true
}
},
// 500
{
name: routeName('service-error'),
path: routePath('service-error'),
component: ServiceError,
meta: {
title: routeTitle('service-error'),
fullPage: true
}
}
]
},
// 匹配无效的路径重定向404
{
path: '/:pathMatch(.*)*',
redirect: { name: routeName('not-found') }
}
];
export default constantRoutes;

View File

@ -0,0 +1,59 @@
/** 固定的路由 */
const constantRoutes: AuthRoute.Route[] = [
{
name: 'root',
path: '/',
redirect: '/dashboard/analysis',
meta: {
title: 'Root'
}
},
{
name: 'login',
path: '/login',
component: 'blank',
meta: {
title: '登录',
single: true
}
},
{
name: 'no-permission',
path: '/no-permission',
component: 'blank',
meta: {
title: '无权限',
single: true
}
},
{
name: 'not-found',
path: '/not-found',
component: 'blank',
meta: {
title: '未找到',
single: true
}
},
{
name: 'service-error',
path: '/service-error',
component: 'blank',
meta: {
title: '服务器错误',
single: true
}
},
// 匹配无效的路径重定向not-found的页面
{
name: 'redirect-not-found',
path: '/:pathMatch(.*)*',
component: 'blank',
meta: {
title: '未找到',
single: true
}
}
];
export default constantRoutes;

View File

@ -1,11 +1,8 @@
import type { RouteRecordRaw } from 'vue-router';
import { transformMultiDegreeRoutes } from '@/utils';
import customRoutes from '../modules';
import constantRoutes from './constant-routes';
const transformRoutes = transformMultiDegreeRoutes(customRoutes);
import { transformAuthRouteToVueRoute } from '@/utils';
import constantRoutes from './constant';
/** 所有路由 */
export const routes: RouteRecordRaw[] = [...transformRoutes, ...constantRoutes];
export const routes: RouteRecordRaw[] = constantRoutes.map(item => transformAuthRouteToVueRoute(item));
export { ROUTE_HOME } from './route-home';
export { constantRoutes };

View File

@ -1,9 +0,0 @@
import { getRouteHome } from '@/utils';
import { routeName } from '../constant';
import customRoutes from '../modules';
/** 路由首页的名字 */
export const ROUTE_HOME_NAME = routeName('dashboard_analysis');
/** 路由首页 */
export const ROUTE_HOME = getRouteHome(customRoutes, ROUTE_HOME_NAME);