@blocklet/pages-kit 0.4.130 → 0.4.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/data-source.js +0 -3
- package/lib/cjs/utils/route.js +120 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/data-source.js +0 -3
- package/lib/esm/utils/route.js +116 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/state.d.ts +15 -2
- package/lib/types/utils/route.d.ts +26 -0
- package/package.json +1 -1
|
@@ -19,9 +19,6 @@ function setPageDataSource(page, state, locale, pageData) {
|
|
|
19
19
|
if (!section) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
if (!section.isTemplateSection) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
22
|
// 确保 section.locales 存在
|
|
26
23
|
section.locales = (0, lodash_1.cloneDeep)(section.locales || {});
|
|
27
24
|
section.locales[locale] = (0, lodash_1.cloneDeep)(section.locales[locale] || {});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateParamCombinations = generateParamCombinations;
|
|
4
|
+
exports.getRouteMetaDataByOptionIds = getRouteMetaDataByOptionIds;
|
|
5
|
+
// 递归生成参数组合的辅助函数
|
|
6
|
+
function generateParamCombinations({ basePath, params, routeId, paramsOptions = [], currentIndex = 0, currentParams = [], currentOptionIds = [], // 添加参数跟踪所有使用的选项ID
|
|
7
|
+
result = [], }) {
|
|
8
|
+
// 如果已处理完所有参数或没有参数选项,返回结果
|
|
9
|
+
if (currentIndex >= params.length || !paramsOptions || paramsOptions.length === 0) {
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
// 获取当前级别的参数
|
|
13
|
+
const currentParam = params[currentIndex];
|
|
14
|
+
if (!currentParam)
|
|
15
|
+
return result;
|
|
16
|
+
// 筛选出当前参数的选项
|
|
17
|
+
const currentOptions = paramsOptions.filter((option) => option.paramId === currentParam.id);
|
|
18
|
+
if (currentOptions.length === 0) {
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
// 处理每个选项
|
|
22
|
+
for (const option of currentOptions) {
|
|
23
|
+
// 如果选项名为空,跳过
|
|
24
|
+
if (!option.name || !option.name.trim()) {
|
|
25
|
+
/* eslint-disable-next-line no-continue */
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
// 创建当前选项的参数数组拷贝
|
|
29
|
+
const nextParams = [...currentParams];
|
|
30
|
+
nextParams[currentIndex] = option.name;
|
|
31
|
+
// 跟踪选项ID
|
|
32
|
+
const nextOptionIds = [...currentOptionIds];
|
|
33
|
+
nextOptionIds[currentIndex] = option.id;
|
|
34
|
+
// 根据参数替换路径中的占位符
|
|
35
|
+
let currentPath = basePath;
|
|
36
|
+
for (let i = 0; i <= currentIndex; i++) {
|
|
37
|
+
const param = params[i];
|
|
38
|
+
const paramValue = nextParams[i];
|
|
39
|
+
if (param && param.name && paramValue) {
|
|
40
|
+
const paramPlaceholder = `:${param.name}`;
|
|
41
|
+
// 使用字符串分割和连接确保类型安全
|
|
42
|
+
currentPath = currentPath.split(paramPlaceholder).join(paramValue);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// 如果这是最后一个参数并且已有值,添加结果
|
|
46
|
+
if (currentIndex === params.length - 1) {
|
|
47
|
+
result.push({
|
|
48
|
+
path: currentPath,
|
|
49
|
+
paramValues: [...nextParams],
|
|
50
|
+
originalRouteId: routeId,
|
|
51
|
+
paramOptionIds: [...nextOptionIds],
|
|
52
|
+
routeMetaData: option.routeMetaData,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// 如果有子选项,递归处理下一级
|
|
56
|
+
if (option.paramsOptions && option.paramsOptions.length > 0 && currentIndex < params.length - 1) {
|
|
57
|
+
generateParamCombinations({
|
|
58
|
+
basePath: currentPath,
|
|
59
|
+
params,
|
|
60
|
+
routeId,
|
|
61
|
+
paramsOptions: option.paramsOptions,
|
|
62
|
+
currentIndex: currentIndex + 1,
|
|
63
|
+
currentParams: nextParams,
|
|
64
|
+
currentOptionIds: nextOptionIds,
|
|
65
|
+
result,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 根据参数选项ID列表获取对应的路由元数据
|
|
73
|
+
* @param paramOptionIds - 参数选项ID数组
|
|
74
|
+
* @param route - 路由对象
|
|
75
|
+
* @returns 对应的路由元数据或undefined
|
|
76
|
+
*/
|
|
77
|
+
function getRouteMetaDataByOptionIds(paramOptionIds, route) {
|
|
78
|
+
if (!paramOptionIds.length || !route.params || !route.paramsOptions) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
// 递归查找匹配的参数选项
|
|
82
|
+
function findOptionWithMetaData(optionId, paramsOptions, depth) {
|
|
83
|
+
const option = paramsOptions.find((opt) => opt.id === optionId);
|
|
84
|
+
if (!option) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
// 如果是最后一个参数且有元数据,直接返回
|
|
88
|
+
if (depth === paramOptionIds.length - 1) {
|
|
89
|
+
return { option, remainingIds: [] };
|
|
90
|
+
}
|
|
91
|
+
// 如果有子选项且有下一级参数ID,递归查找下一级
|
|
92
|
+
const nextIndex = depth + 1;
|
|
93
|
+
if (option.paramsOptions && option.paramsOptions.length > 0 && nextIndex < paramOptionIds.length) {
|
|
94
|
+
const nextOptionId = paramOptionIds[nextIndex];
|
|
95
|
+
if (nextOptionId) {
|
|
96
|
+
const nextResult = findOptionWithMetaData(nextOptionId, option.paramsOptions, nextIndex);
|
|
97
|
+
if (nextResult) {
|
|
98
|
+
return nextResult;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// 返回当前选项和剩余未处理的ID
|
|
103
|
+
return { option, remainingIds: paramOptionIds.slice(depth + 1) };
|
|
104
|
+
}
|
|
105
|
+
// 从第一个参数选项ID开始查找
|
|
106
|
+
const firstOptionId = paramOptionIds[0];
|
|
107
|
+
if (!firstOptionId) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const result = findOptionWithMetaData(firstOptionId, route.paramsOptions, 0);
|
|
111
|
+
if (!result) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
// 如果还有未处理的ID,则路径不完整
|
|
115
|
+
if (result.remainingIds.length > 0) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
// 返回找到的选项的元数据
|
|
119
|
+
return result.option.routeMetaData;
|
|
120
|
+
}
|