123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import {
- AppstoreOutlined,
- ContainerOutlined,
- DesktopOutlined,
- MailOutlined,
- MenuFoldOutlined,
- MenuUnfoldOutlined,
- PieChartOutlined,
- } from '@ant-design/icons';
- import AuthLayout from "@/layouts/AuthLayout";
- import PageContainer from "@/layouts/PageContainer";
- import Login from '@/pages/login';
- import Page404 from '@/pages/404';
- import Index from '@/pages/index';
- import Home from "@/pages/sample/home";
- import BasicForm from '@/pages/sample/form';
- import BasicTable from '@/pages/sample/table';
-
- /**
- * meta 用来扩展自定义数据数据
- * {
- * title: 用于页面或者菜单的标题, 没有此字段, 菜单不会显示
- * hideInMenu: 布尔值, 如果为 false, 菜单不会显示
- * noLayout: 布尔值, 如果为 true, 将不会使用默认布局
- * noSiderBar: 布尔值, 如果为 true, 将没有左侧菜单栏
- * noFooter: 布尔值, 如果为 true, 将没有底部 footer
- * target: 字符串, 如果为 _blank, 将在新窗口打开
- * permission: 对应服务器端权限名称
- * }
- */
-
- export const authRoutes = [
- {
- path: 'index',
- element: <Index />,
- },
- {
- path: "system",
- element: <PageContainer />,
- meta: {
- title: '系统管理',
- // icon: <AppstoreOutlined />,
- // permission: 'form',
- },
- children: [
- {
- path: "user",
- element: <Index />,
- meta: {
- title: '人员管理',
- // icon: <AppstoreOutlined />,
- // permission: 'form',
- },
- },
- {
- path: "role",
- element: <Index />,
- meta: {
- title: '角色管理',
- // icon: <AppstoreOutlined />,
- // permission: 'form',
- },
- },
- ]
- },
-
- // {
- // path: "form",
- // element: <BasicForm />,
- // meta: {
- // title: '表单',
- // icon: <AppstoreOutlined />,
- // permission: 'form',
- // },
- // },
- // {
- // path: "table",
- // element: <BasicTable />,
- // meta: {
- // title: '表格',
- // icon: <ContainerOutlined />,
- // permission: 'table',
- // },
- // },
- ];
-
- export const defaultRoutes = [
- {
- path: "/",
- element: <AuthLayout />,
- children: [
- {
- index: true,
- element: <Home />,
- },
- {
- path: "home",
- element: <Home />,
- meta: {
- title: '首页',
- icon: <DesktopOutlined />,
- },
- },
- {
- path: '*',
- element: <Page404 />
- }
- ],
- },
- {
- path: '/login',
- element: <Login />,
- },
- {
- path: '*',
- element: <Page404 />
- }
- ]
-
- export function mergeAuthRoutes (r1, r2) {
- const r = r1.slice();
- const children = r1[0].children.slice();
- r[0].children = children.concat(r2);
- return r;
- }
-
- // 全部路由
- export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
- function getPath (parent = "/", current = "") {
- if (current.indexOf("/") === 0 || current.indexOf("http") === 0)
- return current;
- return `${parent}/${current}`.replace(/\/\//g, "/");
- }
-
- // 路由数组, 一维数组
- export const routeArr = (() => {
- const flatten = (routes, parentPath = "/") => {
- return routes.reduce((acc, route) => {
- const path = getPath(parentPath, route.path);
- const children = route.children ? flatten(route.children, path) : [];
-
- return acc.concat([{ ...route, path }].concat(children));
- }, []);
- };
-
- return flatten(routes);
- })();
|