36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
/** 前端公开路由清单,供路由守卫和跨标签退出共用;后端接口仍须独立鉴权。 */
|
|
const authPages = new Set([
|
|
"/login",
|
|
"/register",
|
|
"/signup",
|
|
"/forgot-password",
|
|
"/forgot_password",
|
|
"/oauth/bind",
|
|
"/oauth/callback",
|
|
"/official-site",
|
|
]);
|
|
const shopPages = new Set([
|
|
"/products",
|
|
"/products/cloud-server",
|
|
"/products/cvm",
|
|
"/products/dedicated-server",
|
|
"/products/dedicated-server/customize",
|
|
]);
|
|
|
|
// 商品可匿名浏览,但 edit_position 表示编辑用户购物车,不能按公开商品页放行。
|
|
export function isPublicShop(route) {
|
|
if (Object.hasOwn(route.query || {}, "edit_position")) return false;
|
|
const path = route.path.replace(/\/+$/, "") || "/";
|
|
// 动态商品入口由页面统一校验编号;非法编号也应显示公开错误,而不是被误送到登录页。
|
|
return shopPages.has(path) || /^\/products\/[^/]+$/.test(path);
|
|
}
|
|
export function isAuthPage(path) {
|
|
return authPages.has(path.replace(/\/+$/, "") || "/");
|
|
}
|
|
// /home.htm 是待核验的过渡入口,公开仅表示能打开核验页,不表示已获登录权限。
|
|
export function isPublicRoute(route) {
|
|
return (
|
|
route.path === "/home.htm" || isAuthPage(route.path) || isPublicShop(route)
|
|
);
|
|
}
|