permission.js 896 B

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