acdr-ui/dist/dev/mp-weixin/interceptors/route.js
2024-10-01 09:15:35 +08:00

40 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../common/vendor.js");
require("../store/index.js");
const utils_index = require("../utils/index.js");
const store_user = require("../store/user.js");
const loginRoute = "/modules/pet/login/index";
const isLogined = () => {
const userStore = store_user.useUserStore();
return userStore.isLogined;
};
const navigateToInterceptor = {
// 注意这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
invoke({ url }) {
const path = url.split("?")[0];
let needLoginPages = [];
{
needLoginPages = utils_index.getNeedLoginPages();
}
const isNeedLogin = needLoginPages.includes(path);
if (!isNeedLogin) {
return true;
}
const hasLogin = isLogined();
if (hasLogin) {
return true;
}
const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}`;
common_vendor.index.navigateTo({ url: redirectRoute });
return false;
}
};
const routeInterceptor = {
install() {
common_vendor.index.addInterceptor("navigateTo", navigateToInterceptor);
common_vendor.index.addInterceptor("reLaunch", navigateToInterceptor);
common_vendor.index.addInterceptor("redirectTo", navigateToInterceptor);
}
};
exports.routeInterceptor = routeInterceptor;