爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const whiteList = [
  4. "/",
  5. // 注意入口页必须直接写 '/'
  6. // { pattern: /^\/pages\/list.*/ }, // 支持正则表达式
  7. "/pages/component/home",
  8. "/pages/component/recycle",
  9. "/pages/component/my",
  10. "/pages/component/home",
  11. "/pages/wxUserInfo",
  12. "/pages/subcomponent/inspection-report.vue",
  13. "/pages/subcomponent/inspection-detail.vue",
  14. {
  15. pattern: /^\/pages\/index\/*/
  16. }
  17. ];
  18. async function routerInterception() {
  19. const list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
  20. list.forEach((item) => {
  21. common_vendor.index.addInterceptor(item, {
  22. invoke(e) {
  23. const url = e.url.split("?")[0];
  24. if (url !== "/pages/index/index") {
  25. common_vendor.index.setStorageSync("toRouter", url);
  26. }
  27. let pass;
  28. if (whiteList) {
  29. pass = whiteList.some((item2) => {
  30. if (typeof item2 === "object" && item2.pattern) {
  31. return item2.pattern.test(url);
  32. }
  33. return url === item2;
  34. });
  35. }
  36. let userInfo = common_vendor.index.getStorageSync("token");
  37. common_vendor.index.__f__("log", "at utils/router-interception.js:45", userInfo, "是否路由导航");
  38. if (!pass && !userInfo) {
  39. common_vendor.index.showToast({
  40. title: "请先登录",
  41. icon: "none"
  42. });
  43. common_vendor.index.navigateTo({
  44. url: "/pages/index/index"
  45. });
  46. return false;
  47. }
  48. return e;
  49. },
  50. fail(err) {
  51. common_vendor.index.__f__("log", "at utils/router-interception.js:61", err);
  52. }
  53. });
  54. });
  55. }
  56. exports.routerInterception = routerInterception;
  57. //# sourceMappingURL=../../.sourcemap/mp-weixin/utils/router-interception.js.map