permission.ts 640 B

12345678910111213141516171819202122232425
  1. import router from "./router";
  2. import {getToken} from "@/utils/auth";
  3. const whiteList = [
  4. "/check",
  5. ];
  6. router.beforeEach((to, from, next) => {
  7. // next();
  8. // 验证 TOKEN
  9. if (getToken()) {
  10. /* 登录成功 */
  11. next();
  12. } else {
  13. /* 未登录 */
  14. if (whiteList.indexOf(to.path) !== -1) {
  15. // 在免登录白名单,直接进入
  16. next();
  17. } else {
  18. // 否则全部重定向到登录页
  19. window.location.href = 'http://10.8.11.123:8089/cas/login?service=http://10.8.11.98:9888/check'
  20. // window.location.href = 'http://10.8.11.123:8089/cas/login?service=http://localhost/check'
  21. }
  22. }
  23. });