Files
WAI_Project_UNIX/cool/ctx/index.ts

94 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

2025-09-17 19:21:56 +08:00
import { isArray, parse } from "../utils";
2025-07-21 16:47:04 +08:00
type Page = {
path: string;
style?: UTSJSONObject;
meta?: UTSJSONObject;
2025-07-21 16:47:04 +08:00
};
type SubPackage = {
root: string;
pages: Page[];
};
export type TabBarItem = {
text?: string;
pagePath: string;
iconPath?: string;
selectedIconPath?: string;
visible?: boolean;
};
export type TabBar = {
2025-07-22 14:55:22 +08:00
custom?: boolean;
2025-07-21 16:47:04 +08:00
color?: string;
selectedColor?: string;
backgroundColor?: string;
borderStyle?: string;
blurEffect?: "dark" | "extralight" | "light" | "none";
list?: TabBarItem[];
position?: "top" | "bottom";
fontSize?: string;
iconWidth?: string;
spacing?: string;
height?: string;
backgroundImage?: string;
backgroundRepeat?: "repeat" | "repeat-x" | "repeat-y" | "no-repeat";
redDotColor?: string;
};
export type Ctx = {
appid: string;
globalStyle: UTSJSONObject;
pages: Page[];
uniIdRouter: UTSJSONObject;
theme: UTSJSONObject;
tabBar: TabBar;
subPackages: SubPackage[];
SAFE_CHAR_MAP_LOCALE: string[][];
2025-07-26 17:42:36 +08:00
color: UTSJSONObject;
2025-07-21 16:47:04 +08:00
};
// 初始化 ctx 对象,不可修改!!
2025-09-17 19:21:56 +08:00
export const ctx = parse<Ctx>({})!;
console.log(ctx);
2025-07-21 16:47:04 +08:00
// PAGES 用于存储所有页面的路径及样式信息
export let PAGES: Page[] = [...ctx.pages];
// 遍历 ctx.subPackages将所有子包下的页面信息合并到 PAGES 中
if (isArray(ctx.subPackages)) {
ctx.subPackages.forEach((a) => {
a.pages.forEach((b) => {
PAGES.push({
path: a.root + "/" + b.path, // 拼接子包根路径和页面路径
style: b.style,
meta: b.meta
2025-07-21 16:47:04 +08:00
});
});
});
}
// 确保每个页面路径都以 "/" 开头,符合 uni-app x 规范
PAGES.forEach((e) => {
if (!e.path.startsWith("/")) {
e.path = "/" + e.path;
}
});
// TABS 用于存储 tabBar 配置项
export let TABS: TabBarItem[] = [];
// 如果 tabBar 配置存在且列表不为空,则初始化 TABS
2025-09-17 19:21:56 +08:00
if (ctx.tabBar.list != null) {
TABS = ctx.tabBar.list;
2025-07-21 16:47:04 +08:00
// 确保每个 tabBar 页面的路径都以 "/" 开头
TABS.forEach((e) => {
if (!e.pagePath.startsWith("/")) {
e.pagePath = "/" + e.pagePath;
}
});
}