|
|
- "use strict";
- const common_vendor = require("../common/vendor.js");
- const whiteList = [
- "/",
- // 注意入口页必须直接写 '/'
- // { pattern: /^\/pages\/list.*/ }, // 支持正则表达式
- "/pages/component/home",
- "/pages/component/recycle",
- "/pages/component/my",
- "/pages/component/home",
- "/pages/wxUserInfo",
- "/pages/subcomponent/inspection-report.vue",
- "/pages/subcomponent/inspection-detail.vue",
- {
- pattern: /^\/pages\/index\/*/
- }
- ];
- async function routerInterception() {
- const list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
- list.forEach((item) => {
- common_vendor.index.addInterceptor(item, {
- invoke(e) {
- const url = e.url.split("?")[0];
- if (url !== "/pages/index/index") {
- common_vendor.index.setStorageSync("toRouter", url);
- }
- let pass;
- if (whiteList) {
- pass = whiteList.some((item2) => {
- if (typeof item2 === "object" && item2.pattern) {
- return item2.pattern.test(url);
- }
- return url === item2;
- });
- }
- let userInfo = common_vendor.index.getStorageSync("token");
- common_vendor.index.__f__("log", "at utils/router-interception.js:45", userInfo, "是否路由导航");
- if (!pass && !userInfo) {
- common_vendor.index.showToast({
- title: "请先登录",
- icon: "none"
- });
- common_vendor.index.navigateTo({
- url: "/pages/index/index"
- });
- return false;
- }
- return e;
- },
- fail(err) {
- common_vendor.index.__f__("log", "at utils/router-interception.js:61", err);
- }
- });
- });
- }
- exports.routerInterception = routerInterception;
- //# sourceMappingURL=../../.sourcemap/mp-weixin/utils/router-interception.js.map
|