permission.js 941 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import router from './router';
  2. import { getSessionID, getConfig } from '@/utils/auth';
  3. import NProgress from 'nprogress';
  4. import 'nprogress/nprogress.css';
  5. NProgress.configure({ showSpinner: false });
  6. const whiteList = ['/login', '/EnterSys']; // 重定向白名单
  7. // 全局前置守卫
  8. router.beforeEach(async (to, from, next) => {
  9. NProgress.start();
  10. const { isHas } = getConfig();
  11. if (getSessionID() && isHas) {
  12. if (to.path === '/login') {
  13. next({ path: '/' });
  14. NProgress.done();
  15. } else {
  16. next();
  17. }
  18. } else if (whiteList.includes(to.path)) {
  19. // 在登录白名单中,直接进入
  20. next();
  21. } else {
  22. // 其他无权访问的页面将重定向到登录页面
  23. if (process.env.NODE_ENV === 'production') {
  24. window.location.href = '/';
  25. } else {
  26. next('/login');
  27. }
  28. NProgress.done();
  29. }
  30. });
  31. // 全局后置钩子
  32. router.afterEach(() => {
  33. NProgress.done();
  34. });