ctx.uts
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { isArray, parse } from "../utils";
type Page = {
path: string;
style?: UTSJSONObject;
meta?: UTSJSONObject;
};
type SubPackage = {
root: string;
pages: Page[];
};
type TabBarItem = {
text?: string;
pagePath: string;
iconPath?: string;
selectedIconPath?: string;
visible?: boolean;
};
type TabBar = {
custom?: boolean;
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;
};
type Ctx = {
appid: string;
globalStyle: UTSJSONObject;
pages: Page[];
uniIdRouter: UTSJSONObject;
theme: UTSJSONObject;
tabBar: TabBar;
subPackages: SubPackage[];
SAFE_CHAR_MAP_LOCALE: string[][];
color: UTSJSONObject;
};
// Android 端模块静态初始化时,空对象走 parsePt 的泛型回退会触发 toGenericType NPE。
// 这里保留 null,并在后续显式判空,避免在 clinit 阶段构造空壳 Ctx。
const ctx = parse<Ctx>({});
// PAGES 用于存储所有页面的路径及样式信息
export let PAGES: Page[] = [];
if (ctx != null && isArray(ctx.pages)) {
PAGES = [...ctx.pages];
}
// 遍历 ctx.subPackages,将所有子包下的页面信息合并到 PAGES 中
if (ctx != null && isArray(ctx.subPackages)) {
ctx.subPackages.forEach((a) => {
a.pages.forEach((b) => {
PAGES.push({
path: a.root + "/" + b.path, // 拼接子包根路径和页面路径
style: b.style,
meta: b.meta
});
});
});
}
// 确保每个页面路径都以 "/" 开头,符合 uni-app x 规范
PAGES.forEach((e) => {
if (!e.path.startsWith("/")) {
e.path = "/" + e.path;
}
});
// TABS 用于存储 tabBar 配置项
export let TABS: TabBarItem[] = [];
// Android 端静态初始化阶段,tabBar 可能为空;list 为可变属性,需读到局部变量再展开,否则无法 smart cast
const tabBar = ctx != null ? ctx.tabBar : null;
const tabBarList = tabBar != null ? tabBar.list : null;
if (tabBarList != null) {
TABS = [...tabBarList];
// 确保每个 tabBar 页面的路径都以 "/" 开头
TABS.forEach((e) => {
if (!e.pagePath.startsWith("/")) {
e.pagePath = "/" + e.pagePath;
}
});
}