Files
jiapuapp/utils/navigation-routes.js
T
2026-07-27 06:50:23 +08:00

401 lines
11 KiB
JavaScript

// 本文件是 52 个活动页面导航语义的唯一运行时所有者。页面只能使用路由键,
// 不得自行复制路径、父页、允许来源、参数或流程结果规则。
const defineRoute = (route) =>
Object.freeze({
...route,
parentParamMap: Object.freeze(route.parentParamMap || {}),
requiredParams: Object.freeze(route.requiredParams || []),
optionalParams: Object.freeze(route.optionalParams || []),
allowedSources: Object.freeze(route.allowedSources || []),
resultOperations: Object.freeze(route.resultOperations || []),
});
const defineNoticeTarget = (routeKey, params) =>
Object.freeze({ routeKey, params: Object.freeze(params) });
export const NOTICE_TARGETS = Object.freeze({
GENEALOGY_REVIEW: defineNoticeTarget("G10", ["genealogyId"]),
GENEALOGY_HOME: defineNoticeTarget("G01", ["genealogyId"]),
});
export const ROUTES = Object.freeze({
A01: defineRoute({
path: "/pages/auth/a01-entry",
kind: "auth-root",
parent: null,
resultOperations: ["password-reset"],
}),
A04: defineRoute({
path: "/pages/auth/a04-register",
kind: "page",
parent: "A01",
allowedSources: ["A01"],
}),
A05: defineRoute({
path: "/pages/auth/a05-reset-password",
kind: "page",
parent: "A01",
allowedSources: ["A01"],
}),
G01: defineRoute({
path: "/pages/genealogy/g01-my-genealogies",
kind: "root",
parent: null,
optionalParams: ["genealogyId"],
resultOperations: ["genealogy-created"],
}),
G03: defineRoute({
path: "/pages/genealogy/g03-create-genealogy",
kind: "flow",
parent: "G01",
allowedSources: ["G01"],
}),
G05: defineRoute({
path: "/pages/genealogy/g05-genealogy-overview",
kind: "page",
parent: "G01",
requiredParams: ["genealogyId"],
allowedSources: ["G01", "G03", "G06", "G09"],
}),
G06: defineRoute({
path: "/pages/genealogy/g06-search-genealogies",
kind: "page",
parent: "G01",
optionalParams: ["mode"],
allowedSources: ["G01", "G03", "G09"],
}),
G08: defineRoute({
path: "/pages/genealogy/g08-join-application",
kind: "flow",
parent: "G06",
requiredParams: ["genealogyId"],
optionalParams: ["source"],
allowedSources: ["G01", "G05", "G06", "G09"],
}),
G09: defineRoute({
path: "/pages/genealogy/g09-my-applications",
kind: "page",
parent: "G01",
optionalParams: ["status"],
allowedSources: ["G01", "G05", "G06", "G08"],
}),
G10: defineRoute({
path: "/pages/genealogy/g10-application-review",
kind: "page",
parent: "G01",
requiredParams: ["genealogyId"],
allowedSources: ["G01", "G05", "N01", "N02"],
}),
G11: defineRoute({
path: "/pages/genealogy/g11-genealogy-settings",
kind: "flow",
parent: "G05",
requiredParams: ["genealogyId"],
allowedSources: ["G05"],
}),
G12: defineRoute({
path: "/pages/genealogy/g12-generation-poems",
kind: "flow",
parent: "G05",
requiredParams: ["genealogyId"],
allowedSources: ["G01", "G05"],
}),
T01: defineRoute({
path: "/pages/tree/t01-tree-overview",
kind: "page",
parent: "G05",
requiredParams: ["genealogyId"],
optionalParams: ["selectedId"],
allowedSources: ["G01", "G05", "T04", "T06", "T07"],
}),
T03: defineRoute({
path: "/pages/tree/t03-member-profile",
kind: "single",
parent: "T01",
parentParamMap: { selectedId: "personId" },
requiredParams: ["genealogyId", "personId"],
allowedSources: ["T01", "T07", "R02"],
resultOperations: ["member-open-requested"],
}),
T04: defineRoute({
path: "/pages/tree/t04-add-relative",
kind: "flow",
parent: "T01",
parentParamMap: { selectedId: "personId" },
requiredParams: ["genealogyId"],
optionalParams: ["personId", "mode", "relationType"],
allowedSources: ["T01"],
}),
T05: defineRoute({
path: "/pages/tree/t05-edit-member",
kind: "flow",
parent: "T03",
requiredParams: ["genealogyId", "personId"],
allowedSources: ["T01", "T03"],
}),
T06: defineRoute({
path: "/pages/tree/t06-edit-relationship",
kind: "flow",
parent: "T01",
parentParamMap: { selectedId: "personId" },
requiredParams: ["genealogyId", "personId"],
optionalParams: ["mode"],
allowedSources: ["T01"],
}),
T07: defineRoute({
path: "/pages/tree/t07-member-directory",
kind: "page",
parent: "T01",
requiredParams: ["genealogyId"],
allowedSources: ["T01"],
}),
T08: defineRoute({
path: "/pages/tree/t08-member-states",
kind: "page",
parent: "T03",
requiredParams: ["genealogyId", "personId"],
allowedSources: ["T03"],
}),
F01: defineRoute({
path: "/pages/family/f01-family-feed",
kind: "root",
parent: null,
optionalParams: ["genealogyId"],
}),
F02: defineRoute({
path: "/pages/family/f02-publish-feed",
kind: "flow",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
F03: defineRoute({
path: "/pages/family/f03-feed-detail",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId", "feedId"],
allowedSources: ["F01"],
}),
F04: defineRoute({
path: "/pages/family/f04-article-list",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
F05: defineRoute({
path: "/pages/family/f05-article-detail",
kind: "page",
parent: "F04",
requiredParams: ["genealogyId", "articleId"],
allowedSources: ["F04"],
}),
F06: defineRoute({
path: "/pages/family/f06-article-editor",
kind: "flow",
parent: "F04",
requiredParams: ["genealogyId", "mode"],
optionalParams: ["articleId"],
allowedSources: ["F04", "F05"],
}),
F07: defineRoute({
path: "/pages/family/f07-album-list",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
F08: defineRoute({
path: "/pages/family/f08-album-detail",
kind: "page",
parent: "F07",
requiredParams: ["genealogyId", "albumId"],
allowedSources: ["F07"],
}),
F09: defineRoute({
path: "/pages/family/f09-media-upload",
kind: "flow",
parent: "F08",
requiredParams: ["genealogyId", "albumId"],
allowedSources: ["F08"],
}),
F10: defineRoute({
path: "/pages/family/f10-video-list",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
R01: defineRoute({
path: "/pages/records/r01-people-list",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
R02: defineRoute({
path: "/pages/records/r02-person-detail",
kind: "flow",
parent: "R01",
requiredParams: ["genealogyId", "mode"],
optionalParams: ["personId"],
allowedSources: ["R01"],
}),
R03: defineRoute({
path: "/pages/records/r03-gift-list",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
R04: defineRoute({
path: "/pages/records/r04-gift-editor",
kind: "flow",
parent: "R03",
requiredParams: ["genealogyId", "mode"],
optionalParams: ["relativeId"],
allowedSources: ["R03"],
}),
R05: defineRoute({
path: "/pages/records/r05-ritual-list",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
R06: defineRoute({
path: "/pages/records/r06-ritual-detail",
kind: "page",
parent: "R05",
requiredParams: ["genealogyId", "ceremonyId"],
allowedSources: ["R05"],
}),
R07: defineRoute({
path: "/pages/records/r07-ritual-editor",
kind: "flow",
parent: "R05",
requiredParams: ["genealogyId", "mode"],
optionalParams: ["ceremonyId"],
allowedSources: ["R05", "R06"],
}),
R08: defineRoute({
path: "/pages/records/r08-growth-journal",
kind: "page",
parent: "R02",
requiredParams: ["genealogyId", "personId"],
allowedSources: ["R02", "T03"],
}),
R09: defineRoute({
path: "/pages/records/r09-life-events",
kind: "page",
parent: "R02",
requiredParams: ["genealogyId", "personId"],
allowedSources: ["R02", "T03"],
}),
R10: defineRoute({
path: "/pages/records/r10-memo-list",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
R11: defineRoute({
path: "/pages/records/r11-merit-records",
kind: "page",
parent: "F01",
requiredParams: ["genealogyId"],
allowedSources: ["F01"],
}),
N01: defineRoute({
path: "/pages/notification/n01-message-center",
kind: "page",
parent: "G01",
optionalParams: ["genealogyId"],
allowedSources: ["G01", "M01"],
}),
N02: defineRoute({
path: "/pages/notification/n02-message-detail",
kind: "page",
parent: "N01",
requiredParams: ["id"],
allowedSources: ["N01"],
}),
M01: defineRoute({
path: "/pages/profile/m01-profile-home",
kind: "root",
parent: null,
}),
M02: defineRoute({
path: "/pages/profile/m02-edit-profile",
kind: "flow",
parent: "M01",
allowedSources: ["M01"],
}),
M03: defineRoute({
path: "/pages/profile/m03-security-settings",
kind: "page",
parent: "M01",
allowedSources: ["M01"],
}),
M04: defineRoute({
path: "/pages/profile/m04-change-password",
kind: "flow",
parent: "M03",
allowedSources: ["M03"],
}),
M05: defineRoute({
path: "/pages/profile/m05-change-phone",
kind: "flow",
parent: "M03",
allowedSources: ["M03"],
}),
M06: defineRoute({
path: "/pages/profile/m06-help-center",
kind: "page",
parent: "M01",
allowedSources: ["M01"],
}),
M07: defineRoute({
path: "/pages/profile/m07-feedback",
kind: "flow",
parent: "M06",
allowedSources: ["M01", "M06"],
}),
M08: defineRoute({
path: "/pages/profile/m08-promotion",
kind: "page",
parent: "M01",
allowedSources: ["M01"],
}),
M09: defineRoute({
path: "/pages/profile/m09-vip-orders",
kind: "page",
parent: "M01",
allowedSources: ["M01"],
}),
M10: defineRoute({
path: "/pages/profile/m10-about-settings",
kind: "page",
parent: "M01",
allowedSources: ["M01"],
}),
});
export const ROOT_ROUTE_KEYS = Object.freeze(["A01", "G01", "F01", "M01"]);
export const getRoute = (routeKey) =>
typeof routeKey === "string" &&
Object.prototype.hasOwnProperty.call(ROUTES, routeKey)
? ROUTES[routeKey]
: null;
export const getRouteKeyByPath = (path) => {
if (typeof path !== "string") return null;
const normalizedPath = `/${path.replace(/^\/+/, "")}`;
return (
Object.keys(ROUTES).find(
(routeKey) => ROUTES[routeKey].path === normalizedPath,
) || null
);
};