血透系统PC前端

xt_permission.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import router from "./router";
  2. import store from "./store";
  3. import NProgress from "nprogress"; // progress bar
  4. import "nprogress/nprogress.css"; // progress bar style
  5. NProgress.configure({ showSpinner: false }); // NProgress Configuration
  6. const loginWhiteList = ["/token/verify", "/401", "/404"]; // 登录验证白名单
  7. const permissionWhiteList = loginWhiteList.concat(["/"]); // 权限验证白名单
  8. router.beforeEach((to, from, next) => {
  9. // 线上注释
  10. // if (!store.getters.configlist || store.getters.configlist === undefined || store.getters.configlist.length <= 0) {
  11. // store.dispatch('VerifyConfigList', []).then(() => {
  12. // next()
  13. // })
  14. // }
  15. // if (store.getters.permission_routers === undefined) {
  16. // store.dispatch('xt_GenerateRoutes', []).then(() => {
  17. // next()
  18. // })
  19. // } else {
  20. // next()
  21. // }
  22. // return
  23. // 线上注释
  24. NProgress.start();
  25. // console.log(store.getters.current_role_urls.indexOf(to.path))
  26. // alert('path:' + to.path)
  27. // 如果 url 带有 lt (login_token)参数,则跳转到验证 token 时等待的页面
  28. if (to.query.lt != null && to.query.lt.length > 0) {
  29. // alert('will go to verify token: ' + to.query.lt)
  30. next({ path: "/token/verify", query: { token: to.query.lt } });
  31. // 否则 如果没有 user 信息,则前往 sso 登录
  32. } else if (store.getters.xt_user.user.id === 0) {
  33. if (loginWhiteList.indexOf(to.path) !== -1) {
  34. // alert('登录白名单内,跳过登录')
  35. next();
  36. } else {
  37. // alert('前往登录')
  38. window.location.href = process.env.BASE_API + "/login"; // sso 地址
  39. }
  40. // 否则 如果当前 url 不需要验证访问权限,则通过
  41. } else if (permissionWhiteList.indexOf(to.path) !== -1) {
  42. // alert('权限验证白名单内,直接进入')
  43. next();
  44. // 否则 如果拥有当前 url 的权限,则通过
  45. // } else if (store.getters.current_role_urls.indexOf(to.path) !== -1) {
  46. // // alert('权限验证通过')
  47. // next()
  48. // 否则 跳转401 (未经授权)
  49. } else {
  50. // console.log(store.getters.current_role_urls)
  51. // console.log(store.getters.current_role_urls.indexOf(to.path))
  52. // alert('401')
  53. next();
  54. // next({ path: '/404' })
  55. }
  56. });
  57. router.afterEach(() => {
  58. NProgress.done();
  59. });