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

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

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