Commit 7e972199 authored by trumansdo's avatar trumansdo
Browse files

添加hibernate-validator逻辑,并对service层进行验证

parent e24b97ee
import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title'
/*
* @Author: 一日看尽长安花
* @since: 2019-09-04 20:55:14
* @LastEditTime: 2019-10-29 21:31:55
* @LastEditors: 一日看尽长安花
* @Description:
*/
import router from './router';
import store from './store';
import { Message } from 'element-ui';
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css'; // progress bar style
import { getToken } from '@/utils/auth'; // get token from cookie
import getPageTitle from '@/utils/get-page-title';
NProgress.configure({ showSpinner: false }) // NProgress Configuration
NProgress.configure({ showSpinner: false }); // NProgress Configuration
const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist
const whiteList = ['/login', '/auth-redirect']; // no redirect whitelist
router.beforeEach(async(to, from, next) => {
router.beforeEach(async (to, from, next) => {
// start progress bar
NProgress.start()
NProgress.start();
// set page title
document.title = getPageTitle(to.meta.title)
document.title = getPageTitle(to.meta.title);
// determine whether the user has logged in
const hasToken = getToken()
const hasToken = getToken();
if (hasToken) {
if (to.path === '/login') {
// if is logged in, redirect to the home page
next({ path: '/' })
NProgress.done()
next({ path: '/' });
NProgress.done();
} else {
// determine whether the user has obtained his permission roles through getInfo
const hasRoles = store.getters.roles && store.getters.roles.length > 0
const hasRoles = store.getters.roles && store.getters.roles.length > 0;
if (hasRoles) {
next()
next();
} else {
try {
// get user info
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
const { roles } = await store.dispatch('user/getInfo')
const { roles } = await store.dispatch('user/getInfo');
// generate accessible routes map based on roles
const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
debugger
const accessRoutes = await store.dispatch(
'permission/generateRoutes',
roles
);
// dynamically add accessible routes
router.addRoutes(accessRoutes)
router.addRoutes(accessRoutes);
// hack method to ensure that addRoutes is complete
// set the replace: true, so the navigation will not leave a history record
next({ ...to, replace: true })
next({ ...to, replace: true });
} catch (error) {
// remove token and go to login page to re-login
await store.dispatch('user/resetToken')
Message.error(error || 'Has Error')
next(`/login?redirect=${to.path}`)
NProgress.done()
await store.dispatch('user/resetToken');
Message.error(error || 'Has Error');
next(`/login?redirect=${to.path}`);
NProgress.done();
}
}
}
......@@ -59,16 +69,16 @@ router.beforeEach(async(to, from, next) => {
if (whiteList.indexOf(to.path) !== -1) {
// in the free login whitelist, go directly
next()
next();
} else {
// other pages that do not have permission to access are redirected to the login page.
next(`/login?redirect=${to.path}`)
NProgress.done()
next(`/login?redirect=${to.path}`);
NProgress.done();
}
}
})
});
router.afterEach(() => {
// finish progress bar
NProgress.done()
})
NProgress.done();
});
/*
* @Author: 一日看尽长安花
* @since: 2019-09-15 15:22:58
* @LastEditTime: 2019-10-27 22:44:09
* @LastEditTime: 2019-10-29 22:25:59
* @LastEditors: 一日看尽长安花
* @Description:
*/
......
/*
* @Author: 一日看尽长安花
* @since: 2019-09-04 20:55:14
* @LastEditTime: 2019-10-30 19:54:00
* @LastEditors: 一日看尽长安花
* @Description:
*/
/*
路由映射表,由路由名映射确定。
格式见最下方的注释
......@@ -80,19 +87,19 @@ let asyncRoutes = [
{
path: 'page',
component: () => import('@/views/permission/page'),
name: 'PagePermission',
name: 'PagePermission'
},
{
path: 'directive',
component: () => import('@/views/permission/directive'),
name: 'DirectivePermission',
name: 'DirectivePermission'
},
{
path: 'role',
component: () => import('@/views/permission/role'),
name: 'RolePermission',
},
],
name: 'RolePermission'
}
]
},
{
......@@ -104,9 +111,9 @@ let asyncRoutes = [
path: 'index',
component: () => import('@/views/icons/index'),
name: 'Icons',
meta: { noCache: true },
},
],
meta: { noCache: true }
}
]
},
/** when your routing map is too long, you can split it into small modules **/
......@@ -123,21 +130,21 @@ let asyncRoutes = [
{
path: 'create',
component: () => import('@/views/example/create'),
name: 'CreateArticle',
name: 'CreateArticle'
},
{
path: 'edit/:id(\\d+)',
component: () => import('@/views/example/edit'),
name: 'EditArticle',
meta: { noCache: true, activeMenu: '/example/list' },
hidden: true,
hidden: true
},
{
path: 'list',
component: () => import('@/views/example/list'),
name: 'ArticleList',
},
],
name: 'ArticleList'
}
]
},
{
......@@ -148,9 +155,9 @@ let asyncRoutes = [
{
path: 'index',
component: () => import('@/views/tab/index'),
name: 'Tabs',
},
],
name: 'Tabs'
}
]
},
{
......@@ -163,15 +170,15 @@ let asyncRoutes = [
path: '401',
component: () => import('@/views/error-page/401'),
name: 'Page401',
meta: { noCache: true },
meta: { noCache: true }
},
{
path: '404',
component: () => import('@/views/error-page/404'),
name: 'Page404',
meta: { noCache: true },
},
],
meta: { noCache: true }
}
]
},
{
......@@ -182,9 +189,9 @@ let asyncRoutes = [
{
path: 'log',
component: () => import('@/views/error-log/index'),
name: 'ErrorLogs',
},
],
name: 'ErrorLogs'
}
]
},
{
......@@ -196,24 +203,24 @@ let asyncRoutes = [
{
path: 'export-excel',
component: () => import('@/views/excel/export-excel'),
name: 'ExportExcel',
name: 'ExportExcel'
},
{
path: 'export-selected-excel',
component: () => import('@/views/excel/select-excel'),
name: 'SelectExcel',
name: 'SelectExcel'
},
{
path: 'export-merge-header',
component: () => import('@/views/excel/merge-header'),
name: 'MergeHeader',
name: 'MergeHeader'
},
{
path: 'upload-excel',
component: () => import('@/views/excel/upload-excel'),
name: 'UploadExcel',
},
],
name: 'UploadExcel'
}
]
},
{
......@@ -226,9 +233,9 @@ let asyncRoutes = [
{
path: 'download',
component: () => import('@/views/zip/index'),
name: 'ExportZip',
},
],
name: 'ExportZip'
}
]
},
{
......@@ -240,15 +247,15 @@ let asyncRoutes = [
{
path: 'index',
component: () => import('@/views/pdf/index'),
name: 'PDFS',
},
],
name: 'PDFS'
}
]
},
{
path: '/pdf/download',
name: 'PdfDown',
component: () => import('@/views/pdf/download'),
hidden: true,
hidden: true
},
{
......@@ -259,9 +266,9 @@ let asyncRoutes = [
{
path: 'index',
component: () => import('@/views/theme/index'),
name: 'Themes',
},
],
name: 'Themes'
}
]
},
{
......@@ -272,9 +279,9 @@ let asyncRoutes = [
{
path: 'index',
component: () => import('@/views/clipboard/index'),
name: 'ClipboardDemo',
},
],
name: 'ClipboardDemo'
}
]
},
{
......@@ -284,13 +291,13 @@ let asyncRoutes = [
children: [
{
path: 'https://github.com/PanJiaChen/vue-element-admin',
name: 'link',
},
],
name: 'link'
}
]
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true },
{ path: '*', redirect: '/404', hidden: true }
];
const asyncRoutesMap = [...coreRouter, ...asyncRoutes];
......
......@@ -2,8 +2,8 @@
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-09-09 12:16:28
* @LastEditTime: 2019-09-09 12:16:28
* @LastEditors: your name
* @LastEditTime: 2019-10-30 20:32:19
* @LastEditors: 一日看尽长安花
*/
import { constantRoutes } from '@/router';
import { getRoutes } from '@/api/role';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment