mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-15 02:32:27 +08:00
fix Bug or esLink formatting
This commit is contained in:
@@ -3,43 +3,43 @@ import { ErrorPage, RedirectName, Layout } from '@/router/constant';
|
||||
|
||||
// 404 on a page
|
||||
export const ErrorPageRoute: AppRouteRecordRaw = {
|
||||
path: '/:path(.*)*',
|
||||
name: 'ErrorPage',
|
||||
component: Layout,
|
||||
meta: {
|
||||
path: '/:path(.*)*',
|
||||
name: 'ErrorPage',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'ErrorPage',
|
||||
hideBreadcrumb: true,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/:path(.*)*',
|
||||
name: 'ErrorPage',
|
||||
component: ErrorPage,
|
||||
meta: {
|
||||
title: 'ErrorPage',
|
||||
hideBreadcrumb: true,
|
||||
},
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/:path(.*)*',
|
||||
name: 'ErrorPage',
|
||||
component: ErrorPage,
|
||||
meta: {
|
||||
title: 'ErrorPage',
|
||||
hideBreadcrumb: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
export const RedirectRoute: AppRouteRecordRaw = {
|
||||
path: '/redirect',
|
||||
name: RedirectName,
|
||||
component: Layout,
|
||||
meta: {
|
||||
path: '/redirect',
|
||||
name: RedirectName,
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: RedirectName,
|
||||
hideBreadcrumb: true,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/redirect/:path(.*)',
|
||||
name: RedirectName,
|
||||
component: () => import('@/views/redirect/index.vue'),
|
||||
meta: {
|
||||
title: RedirectName,
|
||||
hideBreadcrumb: true,
|
||||
},
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/redirect/:path(.*)',
|
||||
name: RedirectName,
|
||||
component: () => import('@/views/redirect/index.vue'),
|
||||
meta: {
|
||||
title: RedirectName,
|
||||
hideBreadcrumb: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
@@ -3,4 +3,3 @@ export const RedirectName = 'Redirect';
|
||||
export const ErrorPage = () => import('@/views/exception/404.vue');
|
||||
|
||||
export const Layout = () => import('@/layout/index.vue');
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { RouterView } from 'vue-router'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { DashboardOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index';
|
||||
import { DashboardOutlined } from '@vicons/antd';
|
||||
// import { RouterTransition } from '@/components/transition'
|
||||
|
||||
//前端路由映射表
|
||||
export const constantRouterComponents = {
|
||||
'Layout': () => import('@/layout/index.vue'), //布局
|
||||
'DashboardConsole': () => import('@/views/dashboard/console/console.vue'), // 主控台
|
||||
'DashboardMonitor': () => import('@/views/dashboard/monitor/monitor.vue'), // 监控页
|
||||
'DashboardWorkplace': () => import('@/views/dashboard/workplace/workplace.vue'), // 工作台
|
||||
}
|
||||
Layout: () => import('@/layout/index.vue'), //布局
|
||||
DashboardConsole: () => import('@/views/dashboard/console/console.vue'), // 主控台
|
||||
DashboardMonitor: () => import('@/views/dashboard/monitor/monitor.vue'), // 监控页
|
||||
DashboardWorkplace: () => import('@/views/dashboard/workplace/workplace.vue'), // 工作台
|
||||
};
|
||||
|
||||
//前端路由图标映射表
|
||||
export const constantRouterIcon = {
|
||||
'DashboardOutlined': renderIcon(DashboardOutlined)
|
||||
}
|
||||
DashboardOutlined: renderIcon(DashboardOutlined),
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { adminMenus } from '@/api/system/menu'
|
||||
import { constantRouterComponents, constantRouterIcon } from './constantRouterComponents'
|
||||
import router from '@/router/index'
|
||||
import { constantRouter } from '@/router/index'
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { adminMenus } from '@/api/system/menu';
|
||||
import { constantRouterComponents, constantRouterIcon } from './constantRouterComponents';
|
||||
import router from '@/router/index';
|
||||
import { constantRouter } from '@/router/index';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
/**
|
||||
* 格式化 后端 结构信息并递归生成层级路由表
|
||||
@@ -12,35 +12,34 @@ import { RouteRecordRaw } from 'vue-router'
|
||||
* @returns {*}
|
||||
*/
|
||||
export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
return routerMap.map(item => {
|
||||
const currentRouter: any = {
|
||||
// 路由地址 动态拼接生成如 /dashboard/workplace
|
||||
path: `${ parent && parent.path || '' }/${ item.path }`,
|
||||
// 路由名称,建议唯一
|
||||
name: item.name || '',
|
||||
// 该路由对应页面的 组件
|
||||
component: constantRouterComponents[item.component],
|
||||
// meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
|
||||
meta: {
|
||||
...item.meta,
|
||||
label: item.meta.title,
|
||||
icon: constantRouterIcon[item.meta.icon] || null,
|
||||
permission: item.meta.permission || null
|
||||
}
|
||||
}
|
||||
// 为了防止出现后端返回结果不规范,处理有可能出现拼接出两个 反斜杠
|
||||
currentRouter.path = currentRouter.path.replace('//', '/')
|
||||
// 重定向
|
||||
item.redirect && (currentRouter.redirect = item.redirect)
|
||||
// 是否有子菜单,并递归处理
|
||||
if (item.children && item.children.length > 0) {
|
||||
// Recursion
|
||||
currentRouter.children = routerGenerator(item.children, currentRouter)
|
||||
}
|
||||
return currentRouter
|
||||
})
|
||||
}
|
||||
|
||||
return routerMap.map((item) => {
|
||||
const currentRouter: any = {
|
||||
// 路由地址 动态拼接生成如 /dashboard/workplace
|
||||
path: `${(parent && parent.path) || ''}/${item.path}`,
|
||||
// 路由名称,建议唯一
|
||||
name: item.name || '',
|
||||
// 该路由对应页面的 组件
|
||||
component: constantRouterComponents[item.component],
|
||||
// meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
|
||||
meta: {
|
||||
...item.meta,
|
||||
label: item.meta.title,
|
||||
icon: constantRouterIcon[item.meta.icon] || null,
|
||||
permission: item.meta.permission || null,
|
||||
},
|
||||
};
|
||||
// 为了防止出现后端返回结果不规范,处理有可能出现拼接出两个 反斜杠
|
||||
currentRouter.path = currentRouter.path.replace('//', '/');
|
||||
// 重定向
|
||||
item.redirect && (currentRouter.redirect = item.redirect);
|
||||
// 是否有子菜单,并递归处理
|
||||
if (item.children && item.children.length > 0) {
|
||||
// Recursion
|
||||
currentRouter.children = routerGenerator(item.children, currentRouter);
|
||||
}
|
||||
return currentRouter;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 动态生成菜单
|
||||
@@ -48,18 +47,18 @@ export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
* @returns {Promise<Router>}
|
||||
*/
|
||||
export const generatorDynamicRouter = (): Promise<RouteRecordRaw[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
adminMenus()
|
||||
.then((result) => {
|
||||
const routeList = routerGenerator(result)
|
||||
const asyncRoutesList = [...constantRouter, ...routeList]
|
||||
asyncRoutesList.forEach(item => {
|
||||
router.addRoute(item)
|
||||
})
|
||||
resolve(asyncRoutesList)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
adminMenus()
|
||||
.then((result) => {
|
||||
const routeList = routerGenerator(result);
|
||||
const asyncRoutesList = [...constantRouter, ...routeList];
|
||||
asyncRoutesList.forEach((item) => {
|
||||
router.addRoute(item);
|
||||
});
|
||||
resolve(asyncRoutesList);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { App } from 'vue'
|
||||
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
|
||||
import { App } from 'vue';
|
||||
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
||||
import { ErrorPageRoute, RedirectRoute } from '@/router/base';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import { createRouterGuards } from './router-guards'
|
||||
import 'nprogress/css/nprogress.css' // 进度条样式
|
||||
import { createRouterGuards } from './router-guards';
|
||||
import 'nprogress/css/nprogress.css'; // 进度条样式
|
||||
|
||||
// @ts-ignore
|
||||
const modules = import.meta.globEager('./modules/**/*.ts');
|
||||
@@ -11,53 +11,52 @@ const modules = import.meta.globEager('./modules/**/*.ts');
|
||||
const routeModuleList: RouteRecordRaw[] = [];
|
||||
|
||||
Object.keys(modules).forEach((key) => {
|
||||
const mod = modules[key].default || {};
|
||||
const modList = Array.isArray(mod) ? [...mod] : [mod];
|
||||
routeModuleList.push(...modList);
|
||||
const mod = modules[key].default || {};
|
||||
const modList = Array.isArray(mod) ? [...mod] : [mod];
|
||||
routeModuleList.push(...modList);
|
||||
});
|
||||
|
||||
function sortRoute(a, b) {
|
||||
return (a.meta.sort || 0) - (b.meta.sort || 0)
|
||||
return (a.meta.sort || 0) - (b.meta.sort || 0);
|
||||
}
|
||||
|
||||
routeModuleList.sort(sortRoute)
|
||||
routeModuleList.sort(sortRoute);
|
||||
|
||||
export const RootRoute: RouteRecordRaw = {
|
||||
path: '/',
|
||||
name: 'Root',
|
||||
redirect: PageEnum.BASE_HOME,
|
||||
meta: {
|
||||
title: 'Root',
|
||||
},
|
||||
path: '/',
|
||||
name: 'Root',
|
||||
redirect: PageEnum.BASE_HOME,
|
||||
meta: {
|
||||
title: 'Root',
|
||||
},
|
||||
};
|
||||
|
||||
export const LoginRoute: RouteRecordRaw = {
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/views/login/index.vue'),
|
||||
meta: {
|
||||
title: '登录',
|
||||
},
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/views/login/index.vue'),
|
||||
meta: {
|
||||
title: '登录',
|
||||
},
|
||||
};
|
||||
|
||||
//需要验证权限
|
||||
export const asyncRoutes = [ErrorPageRoute, ...routeModuleList];
|
||||
|
||||
|
||||
//普通路由 无需验证权限
|
||||
export const constantRouter:any[] = [LoginRoute, RootRoute, RedirectRoute]
|
||||
export const constantRouter: any[] = [LoginRoute, RootRoute, RedirectRoute];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(''),
|
||||
routes: constantRouter,
|
||||
strict: true,
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
})
|
||||
history: createWebHashHistory(''),
|
||||
routes: constantRouter,
|
||||
strict: true,
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
});
|
||||
|
||||
export function setupRouter(app: App) {
|
||||
app.use(router)
|
||||
// 创建路由守卫
|
||||
createRouterGuards(router)
|
||||
app.use(router);
|
||||
// 创建路由守卫
|
||||
createRouterGuards(router);
|
||||
}
|
||||
|
||||
export default router
|
||||
export default router;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { WalletOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { WalletOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
|
||||
const routeName = 'comp'
|
||||
const routeName = 'comp';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -18,36 +17,35 @@ const routeName = 'comp'
|
||||
*
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/comp',
|
||||
name: routeName,
|
||||
redirect: '/comp/console',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/comp',
|
||||
name: routeName,
|
||||
redirect: '/comp/console',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '组件示例',
|
||||
icon: renderIcon(WalletOutlined),
|
||||
sort: 8,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'table',
|
||||
name: `${routeName}_table`,
|
||||
meta: {
|
||||
title: '组件示例',
|
||||
icon: renderIcon(WalletOutlined),
|
||||
sort: 8
|
||||
title: '表格',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'table',
|
||||
name: `${ routeName }_table`,
|
||||
meta: {
|
||||
title: '表格',
|
||||
},
|
||||
component: () => import('@/views/comp/table/list.vue')
|
||||
},
|
||||
{
|
||||
component: () => import('@/views/comp/table/list.vue'),
|
||||
},
|
||||
{
|
||||
path: 'upload',
|
||||
name: `${routeName}_upload`,
|
||||
meta: {
|
||||
title: '上传',
|
||||
},
|
||||
component: () => import('@/views/comp/upload/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
path: 'upload',
|
||||
name: `${ routeName }_upload`,
|
||||
meta: {
|
||||
title: '上传',
|
||||
},
|
||||
component: () => import('@/views/comp/upload/index.vue')
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { DashboardOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { DashboardOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
const routeName = 'dashboard'
|
||||
const routeName = 'dashboard';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -16,48 +16,48 @@ const routeName = 'dashboard'
|
||||
* @param meta.sort 排序越小越排前
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/dashboard',
|
||||
name: routeName,
|
||||
redirect: '/dashboard/console',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/dashboard',
|
||||
name: routeName,
|
||||
redirect: '/dashboard/console',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Dashboard',
|
||||
icon: renderIcon(DashboardOutlined),
|
||||
permission: ['dashboard_console', 'dashboard_console', 'dashboard_workplace'],
|
||||
sort: 0,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'console',
|
||||
name: `${routeName}_console`,
|
||||
meta: {
|
||||
title: 'Dashboard',
|
||||
icon: renderIcon(DashboardOutlined),
|
||||
permission: ['dashboard_console', 'dashboard_console', 'dashboard_workplace'],
|
||||
sort: 0
|
||||
title: '主控台',
|
||||
permission: ['dashboard_console'],
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'console',
|
||||
name: `${ routeName }_console`,
|
||||
meta: {
|
||||
title: '主控台',
|
||||
permission: ['dashboard_console']
|
||||
},
|
||||
component: () => import('@/views/dashboard/console/console.vue')
|
||||
},
|
||||
// {
|
||||
// path: 'monitor',
|
||||
// name: `${ routeName }_monitor`,
|
||||
// meta: {
|
||||
// title: '监控页',
|
||||
// permission: ['dashboard_monitor']
|
||||
// },
|
||||
// component: () => import('@/views/dashboard/monitor/monitor.vue')
|
||||
// },
|
||||
{
|
||||
path: 'workplace',
|
||||
name: `${ routeName }_workplace`,
|
||||
meta: {
|
||||
title: '工作台',
|
||||
keepAlive: true,
|
||||
permission: ['dashboard_workplace']
|
||||
},
|
||||
component: () => import('@/views/dashboard/workplace/workplace.vue')
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
component: () => import('@/views/dashboard/console/console.vue'),
|
||||
},
|
||||
// {
|
||||
// path: 'monitor',
|
||||
// name: `${ routeName }_monitor`,
|
||||
// meta: {
|
||||
// title: '监控页',
|
||||
// permission: ['dashboard_monitor']
|
||||
// },
|
||||
// component: () => import('@/views/dashboard/monitor/monitor.vue')
|
||||
// },
|
||||
{
|
||||
path: 'workplace',
|
||||
name: `${routeName}_workplace`,
|
||||
meta: {
|
||||
title: '工作台',
|
||||
keepAlive: true,
|
||||
permission: ['dashboard_workplace'],
|
||||
},
|
||||
component: () => import('@/views/dashboard/workplace/workplace.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { ExclamationCircleOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { ExclamationCircleOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -15,43 +15,43 @@ import { renderIcon } from '@/utils/index'
|
||||
*
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/exception',
|
||||
name: 'Exception',
|
||||
redirect: '/exception/403',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/exception',
|
||||
name: 'Exception',
|
||||
redirect: '/exception/403',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '异常页面',
|
||||
icon: renderIcon(ExclamationCircleOutlined),
|
||||
sort: 3,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '403',
|
||||
name: 'exception-403',
|
||||
meta: {
|
||||
title: '异常页面',
|
||||
icon: renderIcon(ExclamationCircleOutlined),
|
||||
sort: 3
|
||||
title: '403',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '403',
|
||||
name: 'exception-403',
|
||||
meta: {
|
||||
title: '403',
|
||||
},
|
||||
component: () => import('@/views/exception/403.vue')
|
||||
},
|
||||
{
|
||||
path: '404',
|
||||
name: 'exception-404',
|
||||
meta: {
|
||||
title: '404',
|
||||
},
|
||||
component: () => import('@/views/exception/404.vue')
|
||||
},
|
||||
{
|
||||
path: '500',
|
||||
name: 'exception-500',
|
||||
meta: {
|
||||
title: '500',
|
||||
},
|
||||
component: () => import('@/views/exception/500.vue')
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
component: () => import('@/views/exception/403.vue'),
|
||||
},
|
||||
{
|
||||
path: '404',
|
||||
name: 'exception-404',
|
||||
meta: {
|
||||
title: '404',
|
||||
},
|
||||
component: () => import('@/views/exception/404.vue'),
|
||||
},
|
||||
{
|
||||
path: '500',
|
||||
name: 'exception-500',
|
||||
meta: {
|
||||
title: '500',
|
||||
},
|
||||
component: () => import('@/views/exception/500.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { ProfileOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { ProfileOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -15,44 +15,43 @@ import { renderIcon } from '@/utils/index'
|
||||
*
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/form',
|
||||
name: 'Form',
|
||||
redirect: '/form/basic-form',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/form',
|
||||
name: 'Form',
|
||||
redirect: '/form/basic-form',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '表单页面',
|
||||
icon: renderIcon(ProfileOutlined),
|
||||
sort: 3,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'basic-form',
|
||||
name: 'form-basic-form',
|
||||
meta: {
|
||||
title: '表单页面',
|
||||
icon: renderIcon(ProfileOutlined),
|
||||
sort: 1
|
||||
title: '基础表单',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'basic-form',
|
||||
name: 'form-basic-form',
|
||||
meta: {
|
||||
title: '基础表单',
|
||||
},
|
||||
component: () => import('@/views/form/basicForm/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'step-form',
|
||||
name: 'form-step-form',
|
||||
meta: {
|
||||
title: '分步表单',
|
||||
},
|
||||
component: () => import('@/views/form/stepForm/stepForm.vue')
|
||||
},
|
||||
{
|
||||
path: 'detail',
|
||||
name: 'form-detail',
|
||||
meta: {
|
||||
title: '表单详情',
|
||||
},
|
||||
component: () => import('@/views/form/detail/index.vue')
|
||||
},
|
||||
component: () => import('@/views/form/basicForm/index.vue'),
|
||||
},
|
||||
{
|
||||
path: 'step-form',
|
||||
name: 'form-step-form',
|
||||
meta: {
|
||||
title: '分步表单',
|
||||
},
|
||||
component: () => import('@/views/form/stepForm/stepForm.vue'),
|
||||
},
|
||||
{
|
||||
path: 'detail',
|
||||
name: 'form-detail',
|
||||
meta: {
|
||||
title: '表单详情',
|
||||
},
|
||||
component: () => import('@/views/form/detail/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
],
|
||||
}
|
||||
]
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { TableOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { TableOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -15,36 +15,36 @@ import { renderIcon } from '@/utils/index'
|
||||
*
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/list',
|
||||
name: 'List',
|
||||
redirect: '/list/basic-list',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/list',
|
||||
name: 'List',
|
||||
redirect: '/list/basic-list',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '列表页面',
|
||||
icon: renderIcon(TableOutlined),
|
||||
sort: 2,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'basic-list',
|
||||
name: 'basic-list',
|
||||
meta: {
|
||||
title: '列表页面',
|
||||
icon: renderIcon(TableOutlined),
|
||||
sort: 1
|
||||
title: '基础列表',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'basic-list',
|
||||
name: 'basic-list',
|
||||
meta: {
|
||||
title: '基础列表',
|
||||
},
|
||||
component: () => import('@/views/list/basicList/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'basic-info/:id?',
|
||||
name: 'basic-info',
|
||||
meta: {
|
||||
title: '基础详情',
|
||||
hidden:true
|
||||
},
|
||||
component: () => import('@/views/list/basicList/info.vue')
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
component: () => import('@/views/list/basicList/index.vue'),
|
||||
},
|
||||
{
|
||||
path: 'basic-info/:id?',
|
||||
name: 'basic-info',
|
||||
meta: {
|
||||
title: '基础详情',
|
||||
hidden: true,
|
||||
},
|
||||
component: () => import('@/views/list/basicList/info.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { CheckCircleOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { CheckCircleOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -15,43 +15,43 @@ import { renderIcon } from '@/utils/index'
|
||||
*
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/result',
|
||||
name: 'Result',
|
||||
redirect: '/result/success',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/result',
|
||||
name: 'Result',
|
||||
redirect: '/result/success',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '结果页面',
|
||||
icon: renderIcon(CheckCircleOutlined),
|
||||
sort: 4,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'success',
|
||||
name: 'result-success',
|
||||
meta: {
|
||||
title: '结果页面',
|
||||
icon: renderIcon(CheckCircleOutlined),
|
||||
sort: 4
|
||||
title: '成功页',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'success',
|
||||
name: 'result-success',
|
||||
meta: {
|
||||
title: '成功页',
|
||||
},
|
||||
component: () => import('@/views/result/success.vue')
|
||||
},
|
||||
{
|
||||
path: 'fail',
|
||||
name: 'result-fail',
|
||||
meta: {
|
||||
title: '失败页',
|
||||
},
|
||||
component: () => import('@/views/result/fail.vue')
|
||||
},
|
||||
{
|
||||
path: 'info',
|
||||
name: 'result-info',
|
||||
meta: {
|
||||
title: '信息页',
|
||||
},
|
||||
component: () => import('@/views/result/info.vue')
|
||||
},
|
||||
],
|
||||
}
|
||||
]
|
||||
component: () => import('@/views/result/success.vue'),
|
||||
},
|
||||
{
|
||||
path: 'fail',
|
||||
name: 'result-fail',
|
||||
meta: {
|
||||
title: '失败页',
|
||||
},
|
||||
component: () => import('@/views/result/fail.vue'),
|
||||
},
|
||||
{
|
||||
path: 'info',
|
||||
name: 'result-info',
|
||||
meta: {
|
||||
title: '信息页',
|
||||
},
|
||||
component: () => import('@/views/result/info.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { SettingOutlined } from '@vicons/antd'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { SettingOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -15,35 +15,35 @@ import { renderIcon } from '@/utils/index'
|
||||
*
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/setting',
|
||||
name: 'Setting',
|
||||
redirect: '/setting/account',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/setting',
|
||||
name: 'Setting',
|
||||
redirect: '/setting/account',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '设置页面',
|
||||
icon: renderIcon(SettingOutlined),
|
||||
sort: 5,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'account',
|
||||
name: 'setting-account',
|
||||
meta: {
|
||||
title: '设置页面',
|
||||
icon: renderIcon(SettingOutlined),
|
||||
sort: 5
|
||||
title: '个人设置',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'account',
|
||||
name: 'setting-account',
|
||||
meta: {
|
||||
title: '个人设置',
|
||||
},
|
||||
component: () => import('@/views/setting/account/account.vue')
|
||||
},
|
||||
{
|
||||
path: 'system',
|
||||
name: 'setting-system',
|
||||
meta: {
|
||||
title: '系统设置',
|
||||
},
|
||||
component: () => import('@/views/setting/system/system.vue')
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
component: () => import('@/views/setting/account/account.vue'),
|
||||
},
|
||||
{
|
||||
path: 'system',
|
||||
name: 'setting-system',
|
||||
meta: {
|
||||
title: '系统设置',
|
||||
},
|
||||
component: () => import('@/views/setting/system/system.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { ToolOutlined } from '@vicons/antd'
|
||||
import { OptionsSharp } from '@vicons/ionicons5'
|
||||
import { renderIcon } from '@/utils/index'
|
||||
import { OptionsSharp } from '@vicons/ionicons5';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -16,35 +15,35 @@ import { renderIcon } from '@/utils/index'
|
||||
*
|
||||
* */
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/system',
|
||||
name: 'System',
|
||||
redirect: '/system/menu',
|
||||
component: Layout,
|
||||
{
|
||||
path: '/system',
|
||||
name: 'System',
|
||||
redirect: '/system/menu',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '系统设置',
|
||||
icon: renderIcon(OptionsSharp),
|
||||
sort: 1,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'menu',
|
||||
name: 'system_menu',
|
||||
meta: {
|
||||
title: '系统设置',
|
||||
icon: renderIcon(OptionsSharp),
|
||||
sort: 1
|
||||
title: '菜单权限管理',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'menu',
|
||||
name: 'system_menu',
|
||||
meta: {
|
||||
title: '菜单权限管理',
|
||||
},
|
||||
component: () => import('@/views/system/menu/menu.vue')
|
||||
},
|
||||
{
|
||||
path: 'role',
|
||||
name: 'system_role',
|
||||
meta: {
|
||||
title: '角色权限管理',
|
||||
},
|
||||
component: () => import('@/views/system/role/role.vue')
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
component: () => import('@/views/system/menu/menu.vue'),
|
||||
},
|
||||
{
|
||||
path: 'role',
|
||||
name: 'system_role',
|
||||
meta: {
|
||||
title: '角色权限管理',
|
||||
},
|
||||
component: () => import('@/views/system/role/role.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes
|
||||
export default routes;
|
||||
|
||||
@@ -1,106 +1,102 @@
|
||||
import { isNavigationFailure, Router } from 'vue-router'
|
||||
import { useUserStoreWidthOut } from '@/store/modules/user'
|
||||
import { useAsyncRouteStoreWidthOut } from '@/store/modules/asyncRoute'
|
||||
import NProgress from 'nprogress' // progress bar
|
||||
import { ACCESS_TOKEN } from '@/store/mutation-types'
|
||||
import { storage } from '@/utils/Storage'
|
||||
import { PageEnum } from '@/enums/pageEnum'
|
||||
import { isNavigationFailure, Router } from 'vue-router';
|
||||
import { useUserStoreWidthOut } from '@/store/modules/user';
|
||||
import { useAsyncRouteStoreWidthOut } from '@/store/modules/asyncRoute';
|
||||
import NProgress from 'nprogress'; // progress bar
|
||||
import { ACCESS_TOKEN } from '@/store/mutation-types';
|
||||
import { storage } from '@/utils/Storage';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
|
||||
NProgress.configure({ showSpinner: false }); // NProgress Configuration
|
||||
|
||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||
const LOGIN_PATH = PageEnum.BASE_LOGIN;
|
||||
|
||||
const LOGIN_PATH = PageEnum.BASE_LOGIN
|
||||
|
||||
const whitePathList = [LOGIN_PATH] // no redirect whitelist
|
||||
const whitePathList = [LOGIN_PATH]; // no redirect whitelist
|
||||
|
||||
export function createRouterGuards(router: Router) {
|
||||
const userStore = useUserStoreWidthOut();
|
||||
const userStore = useUserStoreWidthOut();
|
||||
const asyncRouteStore = useAsyncRouteStoreWidthOut();
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start();
|
||||
if (from.path === LOGIN_PATH && to.name === 'errorPage') {
|
||||
next(PageEnum.BASE_HOME);
|
||||
return;
|
||||
}
|
||||
|
||||
// Whitelist can be directly entered
|
||||
if (whitePathList.includes(to.path as PageEnum)) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const token = storage.get(ACCESS_TOKEN);
|
||||
|
||||
if (!token) {
|
||||
// You can access without permission. You need to set the routing meta.ignoreAuth to true
|
||||
if (to.meta.ignoreAuth) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
// redirect login page
|
||||
const redirectData: { path: string; replace: boolean; query?: Recordable<string> } = {
|
||||
path: LOGIN_PATH,
|
||||
replace: true,
|
||||
};
|
||||
if (to.path) {
|
||||
redirectData.query = {
|
||||
...redirectData.query,
|
||||
redirect: to.path,
|
||||
};
|
||||
}
|
||||
next(redirectData);
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncRouteStore.getIsDynamicAddedRoute) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const userInfo = await userStore.GetInfo();
|
||||
|
||||
const routes = await asyncRouteStore.generateRoutes(userInfo);
|
||||
|
||||
// 动态添加可访问路由表
|
||||
routes.forEach((item) => {
|
||||
router.addRoute(item);
|
||||
});
|
||||
|
||||
const redirectPath = (from.query.redirect || to.path) as string;
|
||||
const redirect = decodeURIComponent(redirectPath);
|
||||
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
||||
asyncRouteStore.setDynamicAddedRoute(true);
|
||||
next(nextData);
|
||||
NProgress.done();
|
||||
});
|
||||
|
||||
router.afterEach((to, _, failure) => {
|
||||
document.title = (to?.meta?.title as string) || document.title;
|
||||
if (isNavigationFailure(failure)) {
|
||||
//console.log('failed navigation', failure)
|
||||
}
|
||||
const asyncRouteStore = useAsyncRouteStoreWidthOut();
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start()
|
||||
if (from.path === LOGIN_PATH && to.name === 'errorPage') {
|
||||
next(PageEnum.BASE_HOME);
|
||||
return;
|
||||
}
|
||||
// 在这里设置需要缓存的组件名称
|
||||
const keepAliveComponents = asyncRouteStore.keepAliveComponents;
|
||||
const currentComName: any = to.matched.find((item) => item.name == to.name)?.name;
|
||||
if (currentComName && !keepAliveComponents.includes(currentComName) && to.meta?.keepAlive) {
|
||||
// 需要缓存的组件
|
||||
keepAliveComponents.push(currentComName);
|
||||
} else if (!to.meta?.keepAlive || to.name == 'Redirect') {
|
||||
// 不需要缓存的组件
|
||||
const index = asyncRouteStore.keepAliveComponents.findIndex((name) => name == currentComName);
|
||||
if (index != -1) {
|
||||
keepAliveComponents.splice(index, 1);
|
||||
}
|
||||
}
|
||||
asyncRouteStore.setKeepAliveComponents(keepAliveComponents);
|
||||
NProgress.done(); // finish progress bar
|
||||
});
|
||||
|
||||
// Whitelist can be directly entered
|
||||
if (whitePathList.includes(to.path as PageEnum)) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const token = storage.get(ACCESS_TOKEN)
|
||||
|
||||
if (!token) {
|
||||
|
||||
// You can access without permission. You need to set the routing meta.ignoreAuth to true
|
||||
if (to.meta.ignoreAuth) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
// redirect login page
|
||||
const redirectData: { path: string; replace: boolean; query?: Recordable<string> } = {
|
||||
path: LOGIN_PATH,
|
||||
replace: true,
|
||||
};
|
||||
if (to.path) {
|
||||
redirectData.query = {
|
||||
...redirectData.query,
|
||||
redirect: to.path,
|
||||
};
|
||||
}
|
||||
next(redirectData);
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncRouteStore.getIsDynamicAddedRoute) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const userInfo = await userStore.GetInfo()
|
||||
|
||||
const routes = await asyncRouteStore.generateRoutes(userInfo)
|
||||
|
||||
// 动态添加可访问路由表
|
||||
routes.forEach((item) => {
|
||||
router.addRoute(item)
|
||||
});
|
||||
|
||||
const redirectPath = (from.query.redirect || to.path) as string;
|
||||
const redirect = decodeURIComponent(redirectPath);
|
||||
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
||||
asyncRouteStore.setDynamicAddedRoute(true);
|
||||
next(nextData);
|
||||
NProgress.done()
|
||||
})
|
||||
|
||||
router.afterEach((to, _, failure) => {
|
||||
document.title = (to?.meta?.title as string) || document.title
|
||||
if (isNavigationFailure(failure)) {
|
||||
//console.log('failed navigation', failure)
|
||||
}
|
||||
const asyncRouteStore = useAsyncRouteStoreWidthOut();
|
||||
// 在这里设置需要缓存的组件名称
|
||||
const keepAliveComponents = asyncRouteStore.keepAliveComponents
|
||||
const currentComName: any = to.matched.find((item) => item.name == to.name)?.name
|
||||
if (currentComName && !keepAliveComponents.includes(currentComName) && to.meta?.keepAlive) {
|
||||
// 需要缓存的组件
|
||||
keepAliveComponents.push(currentComName)
|
||||
} else if (!to.meta?.keepAlive || to.name == 'Redirect') {
|
||||
// 不需要缓存的组件
|
||||
const index = asyncRouteStore.keepAliveComponents.findIndex(
|
||||
(name) => name == currentComName
|
||||
)
|
||||
if (index != -1) {
|
||||
keepAliveComponents.splice(index, 1)
|
||||
}
|
||||
}
|
||||
asyncRouteStore.setKeepAliveComponents(keepAliveComponents)
|
||||
NProgress.done() // finish progress bar
|
||||
})
|
||||
|
||||
router.onError((error) => {
|
||||
console.log(error, '路由错误')
|
||||
})
|
||||
router.onError((error) => {
|
||||
console.log(error, '路由错误');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
import type { RouteRecordRaw, RouteMeta } from 'vue-router';
|
||||
import { defineComponent } from 'vue';
|
||||
import { RoleEnum } from '@/enums/roleEnum'
|
||||
import { RoleEnum } from '@/enums/roleEnum';
|
||||
|
||||
export type Component<T extends any = any> =
|
||||
| ReturnType<typeof defineComponent>
|
||||
| (() => Promise<typeof import('*.vue')>)
|
||||
| (() => Promise<T>);
|
||||
| ReturnType<typeof defineComponent>
|
||||
| (() => Promise<typeof import('*.vue')>)
|
||||
| (() => Promise<T>);
|
||||
|
||||
// @ts-ignore
|
||||
export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
|
||||
name: string;
|
||||
meta: RouteMeta;
|
||||
component?: Component | string;
|
||||
components?: Component;
|
||||
children?: AppRouteRecordRaw[];
|
||||
props?: Recordable;
|
||||
fullPath?: string;
|
||||
name: string;
|
||||
meta: RouteMeta;
|
||||
component?: Component | string;
|
||||
components?: Component;
|
||||
children?: AppRouteRecordRaw[];
|
||||
props?: Recordable;
|
||||
fullPath?: string;
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
// 名称
|
||||
title: string
|
||||
// 是否忽略权限
|
||||
ignoreAuth?: boolean
|
||||
roles?: RoleEnum[]
|
||||
// 是否不缓存
|
||||
noKeepAlive?: boolean
|
||||
// 是否固定在tab上
|
||||
affix?: boolean
|
||||
// tab上的图标
|
||||
icon?: string
|
||||
// 跳转地址
|
||||
frameSrc?: string
|
||||
// 外链跳转地址
|
||||
externalLink?: string
|
||||
// 名称
|
||||
title: string;
|
||||
// 是否忽略权限
|
||||
ignoreAuth?: boolean;
|
||||
roles?: RoleEnum[];
|
||||
// 是否不缓存
|
||||
noKeepAlive?: boolean;
|
||||
// 是否固定在tab上
|
||||
affix?: boolean;
|
||||
// tab上的图标
|
||||
icon?: string;
|
||||
// 跳转地址
|
||||
frameSrc?: string;
|
||||
// 外链跳转地址
|
||||
externalLink?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user