permission.js 923 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { getToken } from "@/utils/auth";
  2. // 登录页面
  3. const loginPage = "/pages/login";
  4. // 页面白名单
  5. const whiteList = [
  6. "/pages/meeting/index",//会议系统
  7. "/pages/door/index",//门禁识别
  8. "/pages/door/setting/index",//门禁配置
  9. ];
  10. // 检查地址白名单
  11. function checkWhite(url) {
  12. const path = url.split("?")[0];
  13. return whiteList.indexOf(path) !== -1;
  14. }
  15. // 页面跳转验证拦截器
  16. let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
  17. list.forEach((item) => {
  18. uni.addInterceptor(item, {
  19. invoke(to) {
  20. if (getToken()) {
  21. if (to.url === loginPage) {
  22. uni.reLaunch({ url: "/pages/meeting/index" });
  23. }
  24. return true;
  25. } else {
  26. if (checkWhite(to.url)) {
  27. return true;
  28. }
  29. uni.reLaunch({ url: loginPage });
  30. return false;
  31. }
  32. },
  33. fail(err) {
  34. console.log(err);
  35. },
  36. });
  37. });