@liruiyi962464
2024-09-14T02:07:58.000000Z
字数 12110
阅读 98
代码
- 找到[ShiroConfig.java]文件,路径一般为\jeecg-boot\jeecg-boot-base\jeecg-boot-base-core\src\main\java\org\jeecg\config\shiro\ShiroConfig.java
- 在文件中增加下列代码,后端设置白名单
filterChainDefinitionMap.put("/TaskOd/taskOd/sumNum", "anon");
filterChainDefinitionMap.put("/TaskOd/taskOd/tendency", "anon");
filterChainDefinitionMap.put("/TaskUserAccount/taskUserAccount/userNUmBer", "anon");
- 找到[application-dev.yml]或者[application-dev.prod]文件
- 在文件中增加下列代码,后端设置白名单
shiro:
excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**
// 下列为补充内容,则可实现白名单
,/TaskOd/taskOd/sumNum,/TaskOd/taskOd/tendency,/TaskUserAccount/taskUserAccount/userNUmBer
它定义了一个路由,该路由指向modules/daping/daping路径,并且当访问这个路径时,会动态加载@/views/modules/daping/daping这个组件。这里使用了Vue的异步组件功能,@符号通常是Webpack别名配置中指向src目录的快捷方式。
export const constantRouterMap = [
{
path: '/modules/daping/daping',
component: () => import('@/views/modules/daping/daping')
},
在permission.js文件中你列出了不需要重定向的白名单路径。这里的路径应该是用户可以直接访问而不需要通过登录验证的URL。
const whiteList = [
'/modules/daping/daping', // 大屏展示页面
'/user/login', // 用户登录页面
'/user/register', // 用户注册页面
'/user/register-result', // 用户注册结果页面
'/user/alteration' // 用户信息修改页面
// 其他无需权限的路径...
]// no redirect whitelist
注意在permission.js文件中路径是在同级的文件夹开始,不是写相对路径,项目结构中modules文件夹和permission.js文件是处于同一层级,且modules文件夹内包含daping文件夹,而daping文件夹内包含daping.vue文件。
import Vue from 'vue'
import router from './router'
import store from './store'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import notification from 'ant-design-vue/es/notification'
import { ACCESS_TOKEN,INDEX_MAIN_PAGE_PATH, OAUTH2_LOGIN_PAGE_PATH } from '@/store/mutation-types'
import { generateIndexRouter, isOAuth2AppEnv } from '@/utils/util'
NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = [
'/modules/daping/daping', // 大屏展示页面
'/user/login', // 用户登录页面
'/user/register', // 用户注册页面
'/user/register-result', // 用户注册结果页面
'/user/alteration' // 用户信息修改页面
// 其他无需权限的路径...
]// no redirect whitelist
whiteList.push(OAUTH2_LOGIN_PAGE_PATH)
router.beforeEach((to, from, next) => {
NProgress.start() // start progress bar
if (Vue.ls.get(ACCESS_TOKEN)) {
/* has token */
if (to.path === '/user/login' || to.path === OAUTH2_LOGIN_PAGE_PATH) {
next({ path: INDEX_MAIN_PAGE_PATH })
NProgress.done()
} else {
if (store.getters.permissionList.length === 0) {
store.dispatch('GetPermissionList').then(res => {
const menuData = res.result.menu;
//console.log(res.message)
if (menuData === null || menuData === "" || menuData === undefined) {
return;
}
let constRoutes = [];
constRoutes = generateIndexRouter(menuData);
// 添加主界面路由
store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
// 根据roles权限生成可访问的路由表
// 动态添加可访问路由表
router.addRoutes(store.getters.addRouters)
const redirect = decodeURIComponent(from.query.redirect || to.path)
if (to.path === redirect) {
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
next({ ...to, replace: true })
} else {
// 跳转到目的路由
next({ path: redirect })
}
})
})
.catch(() => {
/* notification.error({
message: '系统提示',
description: '请求用户信息失败,请重试!'
})*/
store.dispatch('Logout').then(() => {
next({ path: '/user/login', query: { redirect: to.fullPath } })
})
})
} else {
next()
}
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,如果进入的页面是login页面并且当前是OAuth2app环境,就进入OAuth2登录页面
if (to.path === '/user/login' && isOAuth2AppEnv()) {
next({path: OAUTH2_LOGIN_PAGE_PATH})
} else {
// 在免登录白名单,直接进入
next()
}
NProgress.done()
} else {
// 如果当前是在OAuth2APP环境,就跳转到OAuth2登录页面
let path = isOAuth2AppEnv() ? OAUTH2_LOGIN_PAGE_PATH : '/user/login'
next({ path: path, query: { redirect: to.fullPath } })
NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
}
}
})
router.afterEach(() => {
NProgress.done() // finish progress bar
})
import { UserLayout, TabLayout, RouteView, BlankLayout, PageView } from '@/components/layouts'
/**
* 走菜单,走权限控制
* @type {[null,null]}
*/
export const asyncRouterMap = [
{
path: '/',
name: 'target',//dashboard
component: TabLayout,
meta: { title: '指标数据管理' },
redirect: '/views/modules/target/TaskIndicatorDataList',///dashboard/analysis
children: [
// // dashboard
// {
// path: '/dashboard',
// name: 'dashboard',
// redirect: '/dashboard/workplace',
// component: RouteView,
// meta: { title: '仪表盘', icon: 'dashboard', permission: [ 'dashboard' ] },
// children: [
// {
// path: '/dashboard/analysis',
// name: 'Analysis',
// component: () => import('@/views/dashboard/Analysis'),
// meta: { title: '分析页', permission: [ 'dashboard' ] }
// },
// {
// path: '/dashboard/monitor',
// name: 'Monitor',
// hidden: true,
// component: () => import('@/views/dashboard/Monitor'),
// meta: { title: '监控页', permission: [ 'dashboard' ] }
// },
// {
// path: '/dashboard/workplace',
// name: 'Workplace',
// component: () => import('@/views/dashboard/Workplace'),
// meta: { title: '工作台', permission: [ 'dashboard' ] }
// }
// ]
// },
//
// // forms
// {
// path: '/form',
// redirect: '/form/basic-form',
// component: PageView,
// meta: { title: '表单页', icon: 'form', permission: [ 'form' ] },
// children: [
// {
// path: '/form/base-form',
// name: 'BaseForm',
// component: () => import('@/views/form/BasicForm'),
// meta: { title: '基础表单', permission: [ 'form' ] }
// },
// {
// path: '/form/step-form',
// name: 'StepForm',
// component: () => import('@/views/form/stepForm/StepForm'),
// meta: { title: '分步表单', permission: [ 'form' ] }
// },
// {
// path: '/form/advanced-form',
// name: 'AdvanceForm',
// component: () => import('@/views/form/advancedForm/AdvancedForm'),
// meta: { title: '高级表单', permission: [ 'form' ] }
// }
// ]
// },
//
// // list
// {
// path: '/list',
// name: 'list',
// component: PageView,
// redirect: '/list/query-list',
// meta: { title: '列表页', icon: 'table', permission: [ 'table' ] },
// children: [
// {
// path: '/list/query-list',
// name: 'QueryList',
// component: () => import('@/views/list/TableList'),
// meta: { title: '查询表格', permission: [ 'table' ] }
// },
// {
// path: '/list/edit-table',
// name: 'EditList',
// component: () => import('@/views/list/TableInnerEditList'),
// meta: { title: '内联编辑表格', permission: [ 'table' ] }
// },
// {
// path: '/list/user-list',
// name: 'UserList',
// component: () => import('@/views/list/UserList'),
// meta: { title: '用户列表', permission: [ 'table' ] }
// },
// {
// path: '/list/role-list',
// name: 'RoleList',
// component: () => import('@/views/list/RoleList'),
// meta: { title: '角色列表', permission: [ 'table' ] }
// },
// {
// path: '/list/permission-list',
// name: 'PermissionList',
// component: () => import('@/views/list/PermissionList'),
// meta: { title: '权限列表', permission: [ 'table' ] }
// },
// {
// path: '/list/basic-list',
// name: 'BasicList',
// component: () => import('@/views/list/StandardList'),
// meta: { title: '标准列表', permission: [ 'table' ] }
// },
// {
// path: '/list/card',
// name: 'CardList',
// component: () => import('@/views/list/CardList'),
// meta: { title: '卡片列表', permission: [ 'table' ] }
// },
// {
// path: '/list/search',
// name: 'SearchList',
// component: () => import('@/views/list/search/SearchLayout'),
// redirect: '/list/search/article',
// meta: { title: '搜索列表', permission: [ 'table' ] },
// children: [
// {
// path: '/list/search/article',
// name: 'SearchArticles',
// component: () => import('../views/list/TableList'),
// meta: { title: '搜索列表(文章)', permission: [ 'table' ] }
// },
// {
// path: '/list/search/project',
// name: 'SearchProjects',
// component: () => import('../views/list/TableList'),
// meta: { title: '搜索列表(项目)', permission: [ 'table' ] }
// },
// {
// path: '/list/search/application',
// name: 'SearchApplications',
// component: () => import('../views/list/TableList'),
// meta: { title: '搜索列表(应用)', permission: [ 'table' ] }
// },
// ]
// },
// ]
// },
//
// // profile
// {
// path: '/profile',
// name: 'profile',
// component: RouteView,
// redirect: '/profile/basic',
// meta: { title: '详情页', icon: 'profile', permission: [ 'profile' ] },
// children: [
// {
// path: '/profile/basic',
// name: 'ProfileBasic',
// component: () => import('@/views/profile/basic/Index'),
// meta: { title: '基础详情页', permission: [ 'profile' ] }
// },
// {
// path: '/profile/advanced',
// name: 'ProfileAdvanced',
// component: () => import('@/views/profile/advanced/Advanced'),
// meta: { title: '高级详情页', permission: [ 'profile' ] }
// }
// ]
// },
//
// // result
// {
// path: '/result',
// name: 'result',
// component: PageView,
// redirect: '/result/success',
// meta: { title: '结果页', icon: 'check-circle-o', permission: [ 'result' ] },
// children: [
// {
// path: '/result/success',
// name: 'ResultSuccess',
// component: () => import(/* webpackChunkName: "result" */ '@/views/result/Success'),
// meta: { title: '成功', hiddenHeaderContent: true, permission: [ 'result' ] }
// },
// {
// path: '/result/fail',
// name: 'ResultFail',
// component: () => import(/* webpackChunkName: "result" */ '@/views/result/Error'),
// meta: { title: '失败', hiddenHeaderContent: true, permission: [ 'result' ] }
// }
// ]
// },
//
// // Exception
// {
// path: '/exception',
// name: 'exception',
// component: RouteView,
// redirect: '/exception/403',
// meta: { title: '异常页', icon: 'warning', permission: [ 'exception' ] },
// children: [
// {
// path: '/exception/403',
// name: 'Exception403',
// component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/403'),
// meta: { title: '403', permission: [ 'exception' ] }
// },
// {
// path: '/exception/404',
// name: 'Exception404',
// component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404'),
// meta: { title: '404', permission: [ 'exception' ] }
// },
// {
// path: '/exception/500',
// name: 'Exception500',
// component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/500'),
// meta: { title: '500', permission: [ 'exception' ] }
// }
// ]
// },
//
// // account
// {
// path: '/account',
// component: RouteView,
// name: 'account',
// meta: { title: '个人页', icon: 'user', keepAlive: true, permission: [ 'user' ] },
// children: [
// {
// path: '/account/center',
// name: 'center',
// component: () => import('@/views/account/center/Index'),
// meta: { title: '个人中心', keepAlive: true, permission: [ 'user' ] }
// },
// {
// path: '/account/settings',
// name: 'settings',
// component: () => import('@/views/account/settings/Index'),
// meta: { title: '个人设置', hideHeader: true, keepAlive: true, permission: [ 'user' ] },
// redirect: '/account/settings/base',
// alwaysShow: true,
// children: [
// {
// path: '/account/settings/base',
// name: 'BaseSettings',
// component: () => import('@/views/account/settings/BaseSetting'),
// meta: { title: '基本设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
// },
// {
// path: '/account/settings/security',
// name: 'SecuritySettings',
// component: () => import('@/views/account/settings/Security'),
// meta: { title: '安全设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
// },
// {
// path: '/account/settings/custom',
// name: 'CustomSettings',
// component: () => import('@/views/account/settings/Custom'),
// meta: { title: '个性化设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
// },
// {
// path: '/account/settings/binding',
// name: 'BindingSettings',
// component: () => import('@/views/account/settings/Binding'),
// meta: { title: '账户绑定', hidden: true, keepAlive: true, permission: [ 'user' ] }
// },
// {
// path: '/account/settings/notification',
// name: 'NotificationSettings',
// component: () => import('@/views/account/settings/Notification'),
// meta: { title: '新消息通知', hidden: true, keepAlive: true, permission: [ 'user' ] }
// },
// ]
// },
// ]
// }
]
},
{
path: '*', redirect: '/404', hidden: true
}
]
/**
* 基础路由
* @type { *[] }
*/
export const constantRouterMap = [
{
path: '/modules/daping/daping',
component: () => import('@/views/modules/daping/daping')
},
{
path: '/user',
component: UserLayout,
redirect: '/user/login',
hidden: true,
children: [
{
path: 'login',
name: 'login',
component: () => import(/* webpackChunkName: "user" */ '@/views/user/Login')
},
{
path: 'register',
name: 'register',
component: () => import(/* webpackChunkName: "user" */ '@/views/user/register/Register')
},
{
path: 'register-result',
name: 'registerResult',
component: () => import(/* webpackChunkName: "user" */ '@/views/user/register/RegisterResult')
},
{
path: 'alteration',
name: 'alteration',
component: () => import(/* webpackChunkName: "user" */ '@/views/user/alteration/Alteration')
},
]
},
// {
// path: '/',
// name: 'index',
// component: TabLayout,
// meta: {title: '首页'},
// redirect: '/dashboard/workplace',
// children: [
// {
// path: '/online',
// name: 'online',
// redirect: '/online',
// component: RouteView,
// meta: {title: '在线开发', icon: 'dashboard', permission: ['dashboard']},
// children: [
// {
// path: '/online/auto/:code',
// name: 'report',
// component: () => import('@/views/modules/online/cgreport/OnlCgreportAutoList')
// },
// ]
// },
// ]
// },
{
// OAuth2 APP页面路由
path: '/oauth2-app',
component: BlankLayout,
redirect: '/oauth2-app/login',
children: [
{
// OAuth2 登录路由
path: 'login',
name: 'login',
component: () => import(/* webpackChunkName: "oauth2-app.login" */ '@/views/user/oauth2/OAuth2Login')
},
]
},
{
path: '/test',
component: BlankLayout,
redirect: '/test/home',
children: [
{
path: 'home',
name: 'TestHome',
component: () => import('@/views/Home')
}
]
},
{
path: '/404',
component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404')
},
]