[关闭]
@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
  • 在文件中增加下列代码,后端设置白名单
  1. filterChainDefinitionMap.put("/TaskOd/taskOd/sumNum", "anon");
  2. filterChainDefinitionMap.put("/TaskOd/taskOd/tendency", "anon");
  3. filterChainDefinitionMap.put("/TaskUserAccount/taskUserAccount/userNUmBer", "anon");

方案二

  • 找到[application-dev.yml]或者[application-dev.prod]文件
  • 在文件中增加下列代码,后端设置白名单
  1. shiro:
  2. excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**
  3. // 下列为补充内容,则可实现白名单
  4. ,/TaskOd/taskOd/sumNum,/TaskOd/taskOd/tendency,/TaskUserAccount/taskUserAccount/userNUmBer

前端修改项

Router.config.js文件中配置大屏的路径

它定义了一个路由,该路由指向modules/daping/daping路径,并且当访问这个路径时,会动态加载@/views/modules/daping/daping这个组件。这里使用了Vue的异步组件功能,@符号通常是Webpack别名配置中指向src目录的快捷方式。

  1. export const constantRouterMap = [
  2.   {
  3.     path: '/modules/daping/daping',
  4.     component: () => import('@/views/modules/daping/daping')
  5.   },

permission.js文件中配置相对的大屏路径

在permission.js文件中你列出了不需要重定向的白名单路径。这里的路径应该是用户可以直接访问而不需要通过登录验证的URL。

  1. const whiteList = [
  2. '/modules/daping/daping', // 大屏展示页面
  3. '/user/login', // 用户登录页面
  4. '/user/register', // 用户注册页面
  5. '/user/register-result', // 用户注册结果页面
  6. '/user/alteration' // 用户信息修改页面
  7. // 其他无需权限的路径...
  8. ]// no redirect whitelist

注意在permission.js文件中路径是在同级的文件夹开始,不是写相对路径,项目结构中modules文件夹permission.js文件是处于同一层级,且modules文件夹内包含daping文件夹,而daping文件夹内包含daping.vue文件。

permission.js

  1. import Vue from 'vue'
  2. import router from './router'
  3. import store from './store'
  4. import NProgress from 'nprogress' // progress bar
  5. import 'nprogress/nprogress.css' // progress bar style
  6. import notification from 'ant-design-vue/es/notification'
  7. import { ACCESS_TOKEN,INDEX_MAIN_PAGE_PATH, OAUTH2_LOGIN_PAGE_PATH } from '@/store/mutation-types'
  8. import { generateIndexRouter, isOAuth2AppEnv } from '@/utils/util'
  9. NProgress.configure({ showSpinner: false }) // NProgress Configuration
  10. const whiteList = [
  11. '/modules/daping/daping', // 大屏展示页面
  12. '/user/login', // 用户登录页面
  13. '/user/register', // 用户注册页面
  14. '/user/register-result', // 用户注册结果页面
  15. '/user/alteration' // 用户信息修改页面
  16. // 其他无需权限的路径...
  17. ]// no redirect whitelist
  18. whiteList.push(OAUTH2_LOGIN_PAGE_PATH)
  19. router.beforeEach((to, from, next) => {
  20. NProgress.start() // start progress bar
  21. if (Vue.ls.get(ACCESS_TOKEN)) {
  22. /* has token */
  23. if (to.path === '/user/login' || to.path === OAUTH2_LOGIN_PAGE_PATH) {
  24. next({ path: INDEX_MAIN_PAGE_PATH })
  25. NProgress.done()
  26. } else {
  27. if (store.getters.permissionList.length === 0) {
  28. store.dispatch('GetPermissionList').then(res => {
  29. const menuData = res.result.menu;
  30. //console.log(res.message)
  31. if (menuData === null || menuData === "" || menuData === undefined) {
  32. return;
  33. }
  34. let constRoutes = [];
  35. constRoutes = generateIndexRouter(menuData);
  36. // 添加主界面路由
  37. store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
  38. // 根据roles权限生成可访问的路由表
  39. // 动态添加可访问路由表
  40. router.addRoutes(store.getters.addRouters)
  41. const redirect = decodeURIComponent(from.query.redirect || to.path)
  42. if (to.path === redirect) {
  43. // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
  44. next({ ...to, replace: true })
  45. } else {
  46. // 跳转到目的路由
  47. next({ path: redirect })
  48. }
  49. })
  50. })
  51. .catch(() => {
  52. /* notification.error({
  53. message: '系统提示',
  54. description: '请求用户信息失败,请重试!'
  55. })*/
  56. store.dispatch('Logout').then(() => {
  57. next({ path: '/user/login', query: { redirect: to.fullPath } })
  58. })
  59. })
  60. } else {
  61. next()
  62. }
  63. }
  64. } else {
  65. if (whiteList.indexOf(to.path) !== -1) {
  66. // 在免登录白名单,如果进入的页面是login页面并且当前是OAuth2app环境,就进入OAuth2登录页面
  67. if (to.path === '/user/login' && isOAuth2AppEnv()) {
  68. next({path: OAUTH2_LOGIN_PAGE_PATH})
  69. } else {
  70. // 在免登录白名单,直接进入
  71. next()
  72. }
  73. NProgress.done()
  74. } else {
  75. // 如果当前是在OAuth2APP环境,就跳转到OAuth2登录页面
  76. let path = isOAuth2AppEnv() ? OAUTH2_LOGIN_PAGE_PATH : '/user/login'
  77. next({ path: path, query: { redirect: to.fullPath } })
  78. NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
  79. }
  80. }
  81. })
  82. router.afterEach(() => {
  83. NProgress.done() // finish progress bar
  84. })

router.config.js

  1. import { UserLayout, TabLayout, RouteView, BlankLayout, PageView } from '@/components/layouts'
  2. /**
  3. * 走菜单,走权限控制
  4. * @type {[null,null]}
  5. */
  6. export const asyncRouterMap = [
  7. {
  8. path: '/',
  9. name: 'target',//dashboard
  10. component: TabLayout,
  11. meta: { title: '指标数据管理' },
  12. redirect: '/views/modules/target/TaskIndicatorDataList',///dashboard/analysis
  13. children: [
  14. // // dashboard
  15. // {
  16. // path: '/dashboard',
  17. // name: 'dashboard',
  18. // redirect: '/dashboard/workplace',
  19. // component: RouteView,
  20. // meta: { title: '仪表盘', icon: 'dashboard', permission: [ 'dashboard' ] },
  21. // children: [
  22. // {
  23. // path: '/dashboard/analysis',
  24. // name: 'Analysis',
  25. // component: () => import('@/views/dashboard/Analysis'),
  26. // meta: { title: '分析页', permission: [ 'dashboard' ] }
  27. // },
  28. // {
  29. // path: '/dashboard/monitor',
  30. // name: 'Monitor',
  31. // hidden: true,
  32. // component: () => import('@/views/dashboard/Monitor'),
  33. // meta: { title: '监控页', permission: [ 'dashboard' ] }
  34. // },
  35. // {
  36. // path: '/dashboard/workplace',
  37. // name: 'Workplace',
  38. // component: () => import('@/views/dashboard/Workplace'),
  39. // meta: { title: '工作台', permission: [ 'dashboard' ] }
  40. // }
  41. // ]
  42. // },
  43. //
  44. // // forms
  45. // {
  46. // path: '/form',
  47. // redirect: '/form/basic-form',
  48. // component: PageView,
  49. // meta: { title: '表单页', icon: 'form', permission: [ 'form' ] },
  50. // children: [
  51. // {
  52. // path: '/form/base-form',
  53. // name: 'BaseForm',
  54. // component: () => import('@/views/form/BasicForm'),
  55. // meta: { title: '基础表单', permission: [ 'form' ] }
  56. // },
  57. // {
  58. // path: '/form/step-form',
  59. // name: 'StepForm',
  60. // component: () => import('@/views/form/stepForm/StepForm'),
  61. // meta: { title: '分步表单', permission: [ 'form' ] }
  62. // },
  63. // {
  64. // path: '/form/advanced-form',
  65. // name: 'AdvanceForm',
  66. // component: () => import('@/views/form/advancedForm/AdvancedForm'),
  67. // meta: { title: '高级表单', permission: [ 'form' ] }
  68. // }
  69. // ]
  70. // },
  71. //
  72. // // list
  73. // {
  74. // path: '/list',
  75. // name: 'list',
  76. // component: PageView,
  77. // redirect: '/list/query-list',
  78. // meta: { title: '列表页', icon: 'table', permission: [ 'table' ] },
  79. // children: [
  80. // {
  81. // path: '/list/query-list',
  82. // name: 'QueryList',
  83. // component: () => import('@/views/list/TableList'),
  84. // meta: { title: '查询表格', permission: [ 'table' ] }
  85. // },
  86. // {
  87. // path: '/list/edit-table',
  88. // name: 'EditList',
  89. // component: () => import('@/views/list/TableInnerEditList'),
  90. // meta: { title: '内联编辑表格', permission: [ 'table' ] }
  91. // },
  92. // {
  93. // path: '/list/user-list',
  94. // name: 'UserList',
  95. // component: () => import('@/views/list/UserList'),
  96. // meta: { title: '用户列表', permission: [ 'table' ] }
  97. // },
  98. // {
  99. // path: '/list/role-list',
  100. // name: 'RoleList',
  101. // component: () => import('@/views/list/RoleList'),
  102. // meta: { title: '角色列表', permission: [ 'table' ] }
  103. // },
  104. // {
  105. // path: '/list/permission-list',
  106. // name: 'PermissionList',
  107. // component: () => import('@/views/list/PermissionList'),
  108. // meta: { title: '权限列表', permission: [ 'table' ] }
  109. // },
  110. // {
  111. // path: '/list/basic-list',
  112. // name: 'BasicList',
  113. // component: () => import('@/views/list/StandardList'),
  114. // meta: { title: '标准列表', permission: [ 'table' ] }
  115. // },
  116. // {
  117. // path: '/list/card',
  118. // name: 'CardList',
  119. // component: () => import('@/views/list/CardList'),
  120. // meta: { title: '卡片列表', permission: [ 'table' ] }
  121. // },
  122. // {
  123. // path: '/list/search',
  124. // name: 'SearchList',
  125. // component: () => import('@/views/list/search/SearchLayout'),
  126. // redirect: '/list/search/article',
  127. // meta: { title: '搜索列表', permission: [ 'table' ] },
  128. // children: [
  129. // {
  130. // path: '/list/search/article',
  131. // name: 'SearchArticles',
  132. // component: () => import('../views/list/TableList'),
  133. // meta: { title: '搜索列表(文章)', permission: [ 'table' ] }
  134. // },
  135. // {
  136. // path: '/list/search/project',
  137. // name: 'SearchProjects',
  138. // component: () => import('../views/list/TableList'),
  139. // meta: { title: '搜索列表(项目)', permission: [ 'table' ] }
  140. // },
  141. // {
  142. // path: '/list/search/application',
  143. // name: 'SearchApplications',
  144. // component: () => import('../views/list/TableList'),
  145. // meta: { title: '搜索列表(应用)', permission: [ 'table' ] }
  146. // },
  147. // ]
  148. // },
  149. // ]
  150. // },
  151. //
  152. // // profile
  153. // {
  154. // path: '/profile',
  155. // name: 'profile',
  156. // component: RouteView,
  157. // redirect: '/profile/basic',
  158. // meta: { title: '详情页', icon: 'profile', permission: [ 'profile' ] },
  159. // children: [
  160. // {
  161. // path: '/profile/basic',
  162. // name: 'ProfileBasic',
  163. // component: () => import('@/views/profile/basic/Index'),
  164. // meta: { title: '基础详情页', permission: [ 'profile' ] }
  165. // },
  166. // {
  167. // path: '/profile/advanced',
  168. // name: 'ProfileAdvanced',
  169. // component: () => import('@/views/profile/advanced/Advanced'),
  170. // meta: { title: '高级详情页', permission: [ 'profile' ] }
  171. // }
  172. // ]
  173. // },
  174. //
  175. // // result
  176. // {
  177. // path: '/result',
  178. // name: 'result',
  179. // component: PageView,
  180. // redirect: '/result/success',
  181. // meta: { title: '结果页', icon: 'check-circle-o', permission: [ 'result' ] },
  182. // children: [
  183. // {
  184. // path: '/result/success',
  185. // name: 'ResultSuccess',
  186. // component: () => import(/* webpackChunkName: "result" */ '@/views/result/Success'),
  187. // meta: { title: '成功', hiddenHeaderContent: true, permission: [ 'result' ] }
  188. // },
  189. // {
  190. // path: '/result/fail',
  191. // name: 'ResultFail',
  192. // component: () => import(/* webpackChunkName: "result" */ '@/views/result/Error'),
  193. // meta: { title: '失败', hiddenHeaderContent: true, permission: [ 'result' ] }
  194. // }
  195. // ]
  196. // },
  197. //
  198. // // Exception
  199. // {
  200. // path: '/exception',
  201. // name: 'exception',
  202. // component: RouteView,
  203. // redirect: '/exception/403',
  204. // meta: { title: '异常页', icon: 'warning', permission: [ 'exception' ] },
  205. // children: [
  206. // {
  207. // path: '/exception/403',
  208. // name: 'Exception403',
  209. // component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/403'),
  210. // meta: { title: '403', permission: [ 'exception' ] }
  211. // },
  212. // {
  213. // path: '/exception/404',
  214. // name: 'Exception404',
  215. // component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404'),
  216. // meta: { title: '404', permission: [ 'exception' ] }
  217. // },
  218. // {
  219. // path: '/exception/500',
  220. // name: 'Exception500',
  221. // component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/500'),
  222. // meta: { title: '500', permission: [ 'exception' ] }
  223. // }
  224. // ]
  225. // },
  226. //
  227. // // account
  228. // {
  229. // path: '/account',
  230. // component: RouteView,
  231. // name: 'account',
  232. // meta: { title: '个人页', icon: 'user', keepAlive: true, permission: [ 'user' ] },
  233. // children: [
  234. // {
  235. // path: '/account/center',
  236. // name: 'center',
  237. // component: () => import('@/views/account/center/Index'),
  238. // meta: { title: '个人中心', keepAlive: true, permission: [ 'user' ] }
  239. // },
  240. // {
  241. // path: '/account/settings',
  242. // name: 'settings',
  243. // component: () => import('@/views/account/settings/Index'),
  244. // meta: { title: '个人设置', hideHeader: true, keepAlive: true, permission: [ 'user' ] },
  245. // redirect: '/account/settings/base',
  246. // alwaysShow: true,
  247. // children: [
  248. // {
  249. // path: '/account/settings/base',
  250. // name: 'BaseSettings',
  251. // component: () => import('@/views/account/settings/BaseSetting'),
  252. // meta: { title: '基本设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
  253. // },
  254. // {
  255. // path: '/account/settings/security',
  256. // name: 'SecuritySettings',
  257. // component: () => import('@/views/account/settings/Security'),
  258. // meta: { title: '安全设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
  259. // },
  260. // {
  261. // path: '/account/settings/custom',
  262. // name: 'CustomSettings',
  263. // component: () => import('@/views/account/settings/Custom'),
  264. // meta: { title: '个性化设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
  265. // },
  266. // {
  267. // path: '/account/settings/binding',
  268. // name: 'BindingSettings',
  269. // component: () => import('@/views/account/settings/Binding'),
  270. // meta: { title: '账户绑定', hidden: true, keepAlive: true, permission: [ 'user' ] }
  271. // },
  272. // {
  273. // path: '/account/settings/notification',
  274. // name: 'NotificationSettings',
  275. // component: () => import('@/views/account/settings/Notification'),
  276. // meta: { title: '新消息通知', hidden: true, keepAlive: true, permission: [ 'user' ] }
  277. // },
  278. // ]
  279. // },
  280. // ]
  281. // }
  282. ]
  283. },
  284. {
  285. path: '*', redirect: '/404', hidden: true
  286. }
  287. ]
  288. /**
  289. * 基础路由
  290. * @type { *[] }
  291. */
  292. export const constantRouterMap = [
  293. {
  294. path: '/modules/daping/daping',
  295. component: () => import('@/views/modules/daping/daping')
  296. },
  297. {
  298. path: '/user',
  299. component: UserLayout,
  300. redirect: '/user/login',
  301. hidden: true,
  302. children: [
  303. {
  304. path: 'login',
  305. name: 'login',
  306. component: () => import(/* webpackChunkName: "user" */ '@/views/user/Login')
  307. },
  308. {
  309. path: 'register',
  310. name: 'register',
  311. component: () => import(/* webpackChunkName: "user" */ '@/views/user/register/Register')
  312. },
  313. {
  314. path: 'register-result',
  315. name: 'registerResult',
  316. component: () => import(/* webpackChunkName: "user" */ '@/views/user/register/RegisterResult')
  317. },
  318. {
  319. path: 'alteration',
  320. name: 'alteration',
  321. component: () => import(/* webpackChunkName: "user" */ '@/views/user/alteration/Alteration')
  322. },
  323. ]
  324. },
  325. // {
  326. // path: '/',
  327. // name: 'index',
  328. // component: TabLayout,
  329. // meta: {title: '首页'},
  330. // redirect: '/dashboard/workplace',
  331. // children: [
  332. // {
  333. // path: '/online',
  334. // name: 'online',
  335. // redirect: '/online',
  336. // component: RouteView,
  337. // meta: {title: '在线开发', icon: 'dashboard', permission: ['dashboard']},
  338. // children: [
  339. // {
  340. // path: '/online/auto/:code',
  341. // name: 'report',
  342. // component: () => import('@/views/modules/online/cgreport/OnlCgreportAutoList')
  343. // },
  344. // ]
  345. // },
  346. // ]
  347. // },
  348. {
  349. // OAuth2 APP页面路由
  350. path: '/oauth2-app',
  351. component: BlankLayout,
  352. redirect: '/oauth2-app/login',
  353. children: [
  354. {
  355. // OAuth2 登录路由
  356. path: 'login',
  357. name: 'login',
  358. component: () => import(/* webpackChunkName: "oauth2-app.login" */ '@/views/user/oauth2/OAuth2Login')
  359. },
  360. ]
  361. },
  362. {
  363. path: '/test',
  364. component: BlankLayout,
  365. redirect: '/test/home',
  366. children: [
  367. {
  368. path: 'home',
  369. name: 'TestHome',
  370. component: () => import('@/views/Home')
  371. }
  372. ]
  373. },
  374. {
  375. path: '/404',
  376. component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404')
  377. },
  378. ]
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注