2026-06-20 02:34:10 +08:00
|
|
|
import { create } from "zustand";
|
|
|
|
|
|
2026-06-20 12:46:08 +08:00
|
|
|
export type RouteKey =
|
|
|
|
|
| "home"
|
|
|
|
|
| "store"
|
|
|
|
|
| "today"
|
|
|
|
|
| "play-link"
|
|
|
|
|
| "setting"
|
2026-07-23 01:29:55 +08:00
|
|
|
| "setting/login"
|
2026-07-11 23:33:44 +08:00
|
|
|
| "gallery"
|
2026-06-20 22:15:59 +08:00
|
|
|
| "task-queue"
|
2026-08-30 20:19:15 +08:00
|
|
|
| "update"
|
2026-06-28 03:37:07 +08:00
|
|
|
| "oobe"
|
2026-07-12 01:24:31 +08:00
|
|
|
| "oobe/language"
|
|
|
|
|
| "oobe/agreement"
|
|
|
|
|
| "oobe/version"
|
|
|
|
|
| "oobe/beta-test"
|
2026-07-23 01:29:55 +08:00
|
|
|
| "oobe/login"
|
|
|
|
|
| "oobe/welcome"
|
2026-07-12 01:24:31 +08:00
|
|
|
| "oobe/finish"
|
2026-06-28 03:37:07 +08:00
|
|
|
| "oobe/about-info"
|
2026-08-04 01:28:16 +08:00
|
|
|
| "oobe/legal"
|
2026-08-31 03:04:23 +08:00
|
|
|
| "upvp"
|
|
|
|
|
| "upvp/complete"
|
|
|
|
|
| "upvp/version"
|
|
|
|
|
| "upvp/check"
|
|
|
|
|
| "upvp/beta-test"
|
|
|
|
|
| "upvp/finish"
|
2026-06-20 12:46:08 +08:00
|
|
|
| "debug"
|
|
|
|
|
| "debug-splash"
|
|
|
|
|
| "debug-display"
|
2026-06-20 22:15:59 +08:00
|
|
|
| "debug-version-card"
|
2026-08-31 02:20:25 +08:00
|
|
|
| "debug-update"
|
2026-07-12 01:24:31 +08:00
|
|
|
| "debug-task"
|
2026-09-04 18:56:43 +08:00
|
|
|
| "debug-resource"
|
2026-09-04 19:34:58 +08:00
|
|
|
| "debug-crash"
|
|
|
|
|
| "debug-routes";
|
2026-06-28 03:37:07 +08:00
|
|
|
export type TitleBarMode = "default" | "sub" | "window" | "oobe";
|
2026-06-20 02:34:10 +08:00
|
|
|
|
|
|
|
|
export type TransitionDirection = "forward" | "backward";
|
|
|
|
|
|
|
|
|
|
interface RouteItem {
|
|
|
|
|
key: RouteKey;
|
|
|
|
|
label: string;
|
|
|
|
|
path: string;
|
|
|
|
|
hidden?: boolean;
|
2026-06-28 03:37:07 +08:00
|
|
|
backable?: boolean;
|
2026-06-20 02:34:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const routes: RouteItem[] = [
|
|
|
|
|
{ key: "home", label: "首页", path: "/home" },
|
2026-07-11 23:33:44 +08:00
|
|
|
{ key: "gallery", label: "实例", path: "/gallery" },
|
2026-06-20 02:34:10 +08:00
|
|
|
{ key: "store", label: "资源", path: "/store" },
|
|
|
|
|
{ key: "today", label: "资讯", path: "/today" },
|
|
|
|
|
{ key: "play-link", label: "联机", path: "/play-link" },
|
|
|
|
|
{ key: "setting", label: "设置", path: "/setting" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const allRoutes: RouteItem[] = [
|
|
|
|
|
...routes,
|
2026-07-23 01:29:55 +08:00
|
|
|
{ key: "setting/login", label: "登录", path: "/setting/login", hidden: true, backable: true },
|
2026-06-20 22:15:59 +08:00
|
|
|
{ key: "task-queue", label: "任务队列", path: "/task-queue", hidden: true },
|
2026-08-30 20:19:15 +08:00
|
|
|
{ key: "update", label: "更新日志", path: "/update", hidden: true, backable: true },
|
2026-06-28 03:37:07 +08:00
|
|
|
{ key: "oobe", label: "OOBE", path: "/oobe", hidden: true },
|
2026-07-12 01:24:31 +08:00
|
|
|
{ key: "oobe/language", label: "语言设置", path: "/oobe/language", hidden: true },
|
|
|
|
|
{ key: "oobe/agreement", label: "同意协议", path: "/oobe/agreement", hidden: true },
|
|
|
|
|
{ key: "oobe/version", label: "当前版本", path: "/oobe/version", hidden: true },
|
|
|
|
|
{ key: "oobe/beta-test", label: "测试协议", path: "/oobe/beta-test", hidden: true },
|
2026-07-23 01:29:55 +08:00
|
|
|
{ key: "oobe/login", label: "登录", path: "/oobe/login", hidden: true },
|
|
|
|
|
{ key: "oobe/welcome", label: "欢迎", path: "/oobe/welcome", hidden: true },
|
2026-07-12 01:24:31 +08:00
|
|
|
{ key: "oobe/finish", label: "完成", path: "/oobe/finish", hidden: true },
|
2026-06-28 03:37:07 +08:00
|
|
|
{ key: "oobe/about-info", label: "关于信息", path: "/oobe/about-info", hidden: true, backable: true },
|
2026-08-04 01:28:16 +08:00
|
|
|
{ key: "oobe/legal", label: "法律信息", path: "/oobe/legal", hidden: true },
|
2026-08-31 03:04:23 +08:00
|
|
|
{ key: "upvp", label: "更新引导", path: "/upvp", hidden: true },
|
|
|
|
|
{ key: "upvp/complete", label: "更新已完成", path: "/upvp/complete", hidden: true },
|
|
|
|
|
{ key: "upvp/version", label: "当前版本", path: "/upvp/version", hidden: true },
|
|
|
|
|
{ key: "upvp/check", label: "检查版本", path: "/upvp/check", hidden: true },
|
|
|
|
|
{ key: "upvp/beta-test", label: "测试协议", path: "/upvp/beta-test", hidden: true },
|
|
|
|
|
{ key: "upvp/finish", label: "完成", path: "/upvp/finish", hidden: true },
|
2026-06-20 02:34:10 +08:00
|
|
|
{ key: "debug", label: "调试", path: "/debug", hidden: true },
|
2026-06-20 12:46:08 +08:00
|
|
|
{ key: "debug-splash", label: "启动动画调试", path: "/debug/splash", hidden: true },
|
|
|
|
|
{ key: "debug-display", label: "显示效果调试", path: "/debug/display", hidden: true },
|
|
|
|
|
{ key: "debug-version-card", label: "版本卡片调试", path: "/debug/version-card", hidden: true },
|
2026-08-31 02:20:25 +08:00
|
|
|
{ key: "debug-update", label: "更新功能测试", path: "/debug/update", hidden: true },
|
2026-06-20 22:15:59 +08:00
|
|
|
{ key: "debug-task", label: "任务队列调试", path: "/debug/task", hidden: true },
|
2026-09-04 18:56:43 +08:00
|
|
|
{ key: "debug-resource", label: "资源与内存", path: "/debug/resource", hidden: true },
|
2026-09-04 19:34:58 +08:00
|
|
|
{ key: "debug-crash", label: "崩溃测试", path: "/debug/crash", hidden: true },
|
|
|
|
|
{ key: "debug-routes", label: "页面跳转", path: "/debug/routes", hidden: true },
|
2026-06-20 02:34:10 +08:00
|
|
|
];
|
|
|
|
|
|
2026-06-20 12:46:08 +08:00
|
|
|
const topLevelKeys = new Set(routes.map((r) => r.key));
|
|
|
|
|
|
2026-06-28 03:37:07 +08:00
|
|
|
function getRouteTitleBarMode(key: RouteKey): TitleBarMode {
|
2026-08-31 03:04:23 +08:00
|
|
|
if (key === "oobe" || key.startsWith("oobe/") || key === "upvp" || key.startsWith("upvp/")) return "oobe";
|
2026-06-28 03:37:07 +08:00
|
|
|
return topLevelKeys.has(key) ? "default" : "sub";
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-20 02:34:10 +08:00
|
|
|
function startTransition(dir: TransitionDirection, callback: () => void) {
|
|
|
|
|
document.documentElement.dataset.transitionDir = dir;
|
|
|
|
|
if (document.startViewTransition) {
|
|
|
|
|
document.startViewTransition(callback);
|
|
|
|
|
} else {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface RouteState {
|
|
|
|
|
current: RouteKey;
|
|
|
|
|
titleBarMode: TitleBarMode;
|
|
|
|
|
direction: TransitionDirection;
|
2026-06-28 03:37:07 +08:00
|
|
|
history: RouteKey[];
|
2026-08-04 01:28:16 +08:00
|
|
|
/** 资源中心选中的分类(原版游戏 / MOD / 整合包) */
|
|
|
|
|
storeSection: "game" | "mod" | "modpack";
|
2026-06-20 02:34:10 +08:00
|
|
|
navigate: (key: RouteKey) => void;
|
|
|
|
|
setTitleBarMode: (mode: TitleBarMode) => void;
|
2026-08-04 01:28:16 +08:00
|
|
|
setStoreSection: (section: "game" | "mod" | "modpack") => void;
|
2026-06-20 02:34:10 +08:00
|
|
|
goBack: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useRouteStore = create<RouteState>((set, get) => ({
|
|
|
|
|
current: "home",
|
|
|
|
|
titleBarMode: "default",
|
|
|
|
|
direction: "forward",
|
2026-06-28 03:37:07 +08:00
|
|
|
history: [],
|
2026-08-04 01:28:16 +08:00
|
|
|
storeSection: "game",
|
2026-06-20 02:34:10 +08:00
|
|
|
navigate: (key) => {
|
2026-06-28 03:37:07 +08:00
|
|
|
const prev = get().current;
|
|
|
|
|
if (prev === key) return;
|
2026-06-20 02:34:10 +08:00
|
|
|
startTransition("forward", () => {
|
|
|
|
|
set({
|
|
|
|
|
current: key,
|
2026-06-28 03:37:07 +08:00
|
|
|
titleBarMode: getRouteTitleBarMode(key),
|
2026-06-20 02:34:10 +08:00
|
|
|
direction: "forward",
|
2026-06-28 03:37:07 +08:00
|
|
|
history: [...get().history, prev],
|
2026-06-20 02:34:10 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
setTitleBarMode: (mode) => set({ titleBarMode: mode }),
|
2026-08-04 01:28:16 +08:00
|
|
|
setStoreSection: (section) => set({ storeSection: section }),
|
2026-06-20 02:34:10 +08:00
|
|
|
goBack: () => {
|
2026-06-28 03:37:07 +08:00
|
|
|
const { history } = get();
|
|
|
|
|
if (history.length === 0) return;
|
|
|
|
|
const prev = history[history.length - 1];
|
|
|
|
|
startTransition("backward", () => {
|
|
|
|
|
set({
|
|
|
|
|
current: prev,
|
|
|
|
|
titleBarMode: getRouteTitleBarMode(prev),
|
|
|
|
|
history: history.slice(0, -1),
|
|
|
|
|
direction: "backward",
|
2026-06-20 02:34:10 +08:00
|
|
|
});
|
2026-06-28 03:37:07 +08:00
|
|
|
});
|
2026-06-20 02:34:10 +08:00
|
|
|
},
|
|
|
|
|
}));
|