@mybricks/to-code-taro 1.2.6 → 1.2.8
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/package.json +1 -1
- package/dist/cjs/abstractEventTypeDef.d.ts +0 -11
- package/dist/cjs/abstractEventTypeDef.js +0 -93
- package/dist/cjs/generate/compressImages.d.ts +0 -16
- package/dist/cjs/generate/compressImages.js +0 -76
- package/dist/cjs/generate/generateTaroProjectJson.d.ts +0 -13
- package/dist/cjs/generate/generateTaroProjectJson.js +0 -225
- package/dist/cjs/generate/generateTaroTempalteJson.d.ts +0 -15
- package/dist/cjs/generate/generateTaroTempalteJson.js +0 -103
- package/dist/cjs/generate/utils/appConfig.d.ts +0 -21
- package/dist/cjs/generate/utils/appConfig.js +0 -57
- package/dist/cjs/generate/utils/commonDir.d.ts +0 -21
- package/dist/cjs/generate/utils/commonDir.js +0 -63
- package/dist/cjs/generate/utils/customTabBar.d.ts +0 -11
- package/dist/cjs/generate/utils/customTabBar.js +0 -73
- package/dist/cjs/generate/utils/fileNode.d.ts +0 -21
- package/dist/cjs/generate/utils/fileNode.js +0 -67
- package/dist/cjs/generate/utils/index.d.ts +0 -7
- package/dist/cjs/generate/utils/index.js +0 -29
- package/dist/cjs/generate/utils/pageImages.d.ts +0 -14
- package/dist/cjs/generate/utils/pageImages.js +0 -36
- package/dist/cjs/generate/utils/tabBarImages.d.ts +0 -14
- package/dist/cjs/generate/utils/tabBarImages.js +0 -36
- package/dist/cjs/handleCom.d.ts +0 -8
- package/dist/cjs/handleCom.js +0 -280
- package/dist/cjs/handleDom.d.ts +0 -21
- package/dist/cjs/handleDom.js +0 -52
- package/dist/cjs/handleExtension.d.ts +0 -10
- package/dist/cjs/handleExtension.js +0 -300
- package/dist/cjs/handleGlobal.d.ts +0 -11
- package/dist/cjs/handleGlobal.js +0 -191
- package/dist/cjs/handleModule.d.ts +0 -15
- package/dist/cjs/handleModule.js +0 -104
- package/dist/cjs/handleSlot.d.ts +0 -29
- package/dist/cjs/handleSlot.js +0 -153
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/index.js +0 -48
- package/dist/cjs/processors/processComEvents.d.ts +0 -9
- package/dist/cjs/processors/processComEvents.js +0 -163
- package/dist/cjs/processors/processModule.d.ts +0 -31
- package/dist/cjs/processors/processModule.js +0 -159
- package/dist/cjs/processors/processScene.d.ts +0 -32
- package/dist/cjs/processors/processScene.js +0 -198
- package/dist/cjs/processors/processSceneLogic.d.ts +0 -7
- package/dist/cjs/processors/processSceneLogic.js +0 -230
- package/dist/cjs/shims-taro.d.ts +0 -20
- package/dist/cjs/taro-template.json +0 -154
- package/dist/cjs/toCodeTaro.d.ts +0 -168
- package/dist/cjs/toCodeTaro.js +0 -326
- package/dist/cjs/utils/builder/buildResult.d.ts +0 -24
- package/dist/cjs/utils/builder/buildResult.js +0 -163
- package/dist/cjs/utils/common/ImportManager.d.ts +0 -26
- package/dist/cjs/utils/common/ImportManager.js +0 -123
- package/dist/cjs/utils/common/helper.d.ts +0 -12
- package/dist/cjs/utils/common/helper.js +0 -52
- package/dist/cjs/utils/common/object.d.ts +0 -5
- package/dist/cjs/utils/common/object.js +0 -58
- package/dist/cjs/utils/common/string.d.ts +0 -18
- package/dist/cjs/utils/common/string.js +0 -59
- package/dist/cjs/utils/config/content/converter.d.ts +0 -17
- package/dist/cjs/utils/config/content/converter.js +0 -84
- package/dist/cjs/utils/config/content/index.d.ts +0 -10
- package/dist/cjs/utils/config/content/index.js +0 -33
- package/dist/cjs/utils/config/content/pageConfig.d.ts +0 -10
- package/dist/cjs/utils/config/content/pageConfig.js +0 -80
- package/dist/cjs/utils/config/content/saveBase64Image.d.ts +0 -24
- package/dist/cjs/utils/config/content/saveBase64Image.js +0 -113
- package/dist/cjs/utils/config/content/tabBarConfig.d.ts +0 -28
- package/dist/cjs/utils/config/content/tabBarConfig.js +0 -74
- package/dist/cjs/utils/config/content/types.d.ts +0 -73
- package/dist/cjs/utils/config/content/types.js +0 -17
- package/dist/cjs/utils/config/content/validator.d.ts +0 -13
- package/dist/cjs/utils/config/content/validator.js +0 -67
- package/dist/cjs/utils/config/handlePageConfig.d.ts +0 -31
- package/dist/cjs/utils/config/handlePageConfig.js +0 -88
- package/dist/cjs/utils/context/buildContext.d.ts +0 -31
- package/dist/cjs/utils/context/buildContext.js +0 -76
- package/dist/cjs/utils/context/buildFrameMap.d.ts +0 -16
- package/dist/cjs/utils/context/buildFrameMap.js +0 -106
- package/dist/cjs/utils/context/buildGlobalData.d.ts +0 -13
- package/dist/cjs/utils/context/buildGlobalData.js +0 -58
- package/dist/cjs/utils/context/collectJSModules.d.ts +0 -41
- package/dist/cjs/utils/context/collectJSModules.js +0 -93
- package/dist/cjs/utils/context/createEventQueries.d.ts +0 -45
- package/dist/cjs/utils/context/createEventQueries.js +0 -99
- package/dist/cjs/utils/context/createProvider.d.ts +0 -21
- package/dist/cjs/utils/context/createProvider.js +0 -49
- package/dist/cjs/utils/index.d.ts +0 -10
- package/dist/cjs/utils/index.js +0 -60
- package/dist/cjs/utils/logic/convertNamespace.d.ts +0 -11
- package/dist/cjs/utils/logic/convertNamespace.js +0 -43
- package/dist/cjs/utils/logic/genJSModules.d.ts +0 -16
- package/dist/cjs/utils/logic/genJSModules.js +0 -114
- package/dist/cjs/utils/logic/handleProcess.d.ts +0 -9
- package/dist/cjs/utils/logic/handleProcess.js +0 -462
- package/dist/cjs/utils/logic/processChildren.d.ts +0 -26
- package/dist/cjs/utils/logic/processChildren.js +0 -121
- package/dist/cjs/utils/style/color.d.ts +0 -4
- package/dist/cjs/utils/style/color.js +0 -45
- package/dist/cjs/utils/style/converter.d.ts +0 -7
- package/dist/cjs/utils/style/converter.js +0 -175
- package/dist/cjs/utils/style/getComponentClassName.d.ts +0 -16
- package/dist/cjs/utils/style/getComponentClassName.js +0 -47
- package/dist/cjs/utils/style/pxtransform.d.ts +0 -4
- package/dist/cjs/utils/style/pxtransform.js +0 -62
- package/dist/cjs/utils/style/types.d.ts +0 -23
- package/dist/cjs/utils/style/types.js +0 -17
- package/dist/cjs/utils/templates/component.d.ts +0 -19
- package/dist/cjs/utils/templates/component.js +0 -86
- package/dist/cjs/utils/templates/index.d.ts +0 -32
- package/dist/cjs/utils/templates/index.js +0 -116
- package/dist/cjs/utils/templates/renderManager.d.ts +0 -18
- package/dist/cjs/utils/templates/renderManager.js +0 -152
- package/dist/cjs/utils/templates/scene.d.ts +0 -23
- package/dist/cjs/utils/templates/scene.js +0 -113
- package/dist/esm/abstractEventTypeDef.d.ts +0 -11
- package/dist/esm/abstractEventTypeDef.js +0 -63
- package/dist/esm/generate/compressImages.d.ts +0 -16
- package/dist/esm/generate/compressImages.js +0 -108
- package/dist/esm/generate/generateTaroProjectJson.d.ts +0 -13
- package/dist/esm/generate/generateTaroProjectJson.js +0 -228
- package/dist/esm/generate/generateTaroTempalteJson.d.ts +0 -15
- package/dist/esm/generate/generateTaroTempalteJson.js +0 -94
- package/dist/esm/generate/utils/appConfig.d.ts +0 -21
- package/dist/esm/generate/utils/appConfig.js +0 -49
- package/dist/esm/generate/utils/commonDir.d.ts +0 -21
- package/dist/esm/generate/utils/commonDir.js +0 -53
- package/dist/esm/generate/utils/customTabBar.d.ts +0 -11
- package/dist/esm/generate/utils/customTabBar.js +0 -52
- package/dist/esm/generate/utils/fileNode.d.ts +0 -21
- package/dist/esm/generate/utils/fileNode.js +0 -62
- package/dist/esm/generate/utils/index.d.ts +0 -7
- package/dist/esm/generate/utils/index.js +0 -8
- package/dist/esm/generate/utils/pageImages.d.ts +0 -14
- package/dist/esm/generate/utils/pageImages.js +0 -15
- package/dist/esm/generate/utils/tabBarImages.d.ts +0 -14
- package/dist/esm/generate/utils/tabBarImages.js +0 -15
- package/dist/esm/handleCom.d.ts +0 -8
- package/dist/esm/handleCom.js +0 -350
- package/dist/esm/handleDom.d.ts +0 -21
- package/dist/esm/handleDom.js +0 -26
- package/dist/esm/handleExtension.d.ts +0 -10
- package/dist/esm/handleExtension.js +0 -243
- package/dist/esm/handleGlobal.d.ts +0 -11
- package/dist/esm/handleGlobal.js +0 -157
- package/dist/esm/handleModule.d.ts +0 -15
- package/dist/esm/handleModule.js +0 -73
- package/dist/esm/handleSlot.d.ts +0 -29
- package/dist/esm/handleSlot.js +0 -215
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.js +0 -4
- package/dist/esm/processors/processComEvents.d.ts +0 -9
- package/dist/esm/processors/processComEvents.js +0 -170
- package/dist/esm/processors/processModule.d.ts +0 -31
- package/dist/esm/processors/processModule.js +0 -177
- package/dist/esm/processors/processScene.d.ts +0 -32
- package/dist/esm/processors/processScene.js +0 -234
- package/dist/esm/processors/processSceneLogic.d.ts +0 -7
- package/dist/esm/processors/processSceneLogic.js +0 -247
- package/dist/esm/shims-taro.d.ts +0 -20
- package/dist/esm/taro-template.json +0 -154
- package/dist/esm/toCodeTaro.d.ts +0 -168
- package/dist/esm/toCodeTaro.js +0 -367
- package/dist/esm/utils/builder/buildResult.d.ts +0 -24
- package/dist/esm/utils/builder/buildResult.js +0 -119
- package/dist/esm/utils/common/ImportManager.d.ts +0 -26
- package/dist/esm/utils/common/ImportManager.js +0 -131
- package/dist/esm/utils/common/helper.d.ts +0 -12
- package/dist/esm/utils/common/helper.js +0 -33
- package/dist/esm/utils/common/object.d.ts +0 -5
- package/dist/esm/utils/common/object.js +0 -32
- package/dist/esm/utils/common/string.d.ts +0 -18
- package/dist/esm/utils/common/string.js +0 -37
- package/dist/esm/utils/config/content/converter.d.ts +0 -17
- package/dist/esm/utils/config/content/converter.js +0 -106
- package/dist/esm/utils/config/content/index.d.ts +0 -10
- package/dist/esm/utils/config/content/index.js +0 -11
- package/dist/esm/utils/config/content/pageConfig.d.ts +0 -10
- package/dist/esm/utils/config/content/pageConfig.js +0 -43
- package/dist/esm/utils/config/content/saveBase64Image.d.ts +0 -24
- package/dist/esm/utils/config/content/saveBase64Image.js +0 -127
- package/dist/esm/utils/config/content/tabBarConfig.d.ts +0 -28
- package/dist/esm/utils/config/content/tabBarConfig.js +0 -89
- package/dist/esm/utils/config/content/types.d.ts +0 -73
- package/dist/esm/utils/config/content/types.js +0 -1
- package/dist/esm/utils/config/content/validator.d.ts +0 -13
- package/dist/esm/utils/config/content/validator.js +0 -64
- package/dist/esm/utils/config/handlePageConfig.d.ts +0 -31
- package/dist/esm/utils/config/handlePageConfig.js +0 -89
- package/dist/esm/utils/context/buildContext.d.ts +0 -31
- package/dist/esm/utils/context/buildContext.js +0 -65
- package/dist/esm/utils/context/buildFrameMap.d.ts +0 -16
- package/dist/esm/utils/context/buildFrameMap.js +0 -131
- package/dist/esm/utils/context/buildGlobalData.d.ts +0 -13
- package/dist/esm/utils/context/buildGlobalData.js +0 -44
- package/dist/esm/utils/context/collectJSModules.d.ts +0 -41
- package/dist/esm/utils/context/collectJSModules.js +0 -87
- package/dist/esm/utils/context/createEventQueries.d.ts +0 -45
- package/dist/esm/utils/context/createEventQueries.js +0 -99
- package/dist/esm/utils/context/createProvider.d.ts +0 -21
- package/dist/esm/utils/context/createProvider.js +0 -33
- package/dist/esm/utils/index.d.ts +0 -10
- package/dist/esm/utils/index.js +0 -12
- package/dist/esm/utils/logic/convertNamespace.d.ts +0 -11
- package/dist/esm/utils/logic/convertNamespace.js +0 -27
- package/dist/esm/utils/logic/genJSModules.d.ts +0 -16
- package/dist/esm/utils/logic/genJSModules.js +0 -33
- package/dist/esm/utils/logic/handleProcess.d.ts +0 -9
- package/dist/esm/utils/logic/handleProcess.js +0 -520
- package/dist/esm/utils/logic/processChildren.d.ts +0 -26
- package/dist/esm/utils/logic/processChildren.js +0 -101
- package/dist/esm/utils/style/color.d.ts +0 -4
- package/dist/esm/utils/style/color.js +0 -17
- package/dist/esm/utils/style/converter.d.ts +0 -7
- package/dist/esm/utils/style/converter.js +0 -175
- package/dist/esm/utils/style/getComponentClassName.d.ts +0 -16
- package/dist/esm/utils/style/getComponentClassName.js +0 -37
- package/dist/esm/utils/style/pxtransform.d.ts +0 -4
- package/dist/esm/utils/style/pxtransform.js +0 -54
- package/dist/esm/utils/style/types.d.ts +0 -23
- package/dist/esm/utils/style/types.js +0 -1
- package/dist/esm/utils/templates/component.d.ts +0 -19
- package/dist/esm/utils/templates/component.js +0 -55
- package/dist/esm/utils/templates/index.d.ts +0 -32
- package/dist/esm/utils/templates/index.js +0 -97
- package/dist/esm/utils/templates/renderManager.d.ts +0 -18
- package/dist/esm/utils/templates/renderManager.js +0 -145
- package/dist/esm/utils/templates/scene.d.ts +0 -23
- package/dist/esm/utils/templates/scene.js +0 -66
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/** 缩进 */
|
|
2
|
-
export var indentation = function indentation(level) {
|
|
3
|
-
return " ".repeat(level);
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 根据 schema.type 推导变量默认 initValue
|
|
8
|
-
* - string: ''(未提供 initValue)
|
|
9
|
-
* - number: 0
|
|
10
|
-
* - boolean: false
|
|
11
|
-
* - array: []
|
|
12
|
-
* - object: {}
|
|
13
|
-
* - 其他/未知: 优先使用 initValue,否则 {}
|
|
14
|
-
*/
|
|
15
|
-
export var getInitValueBySchema = function getInitValueBySchema(schema, initValue) {
|
|
16
|
-
// 允许显式传入 undefined 以外的任意值(包括 null / 0 / '' / false)
|
|
17
|
-
if (initValue !== undefined) return initValue;
|
|
18
|
-
var type = schema === null || schema === void 0 ? void 0 : schema.type;
|
|
19
|
-
switch (type) {
|
|
20
|
-
case "string":
|
|
21
|
-
return "";
|
|
22
|
-
case "number":
|
|
23
|
-
return 0;
|
|
24
|
-
case "boolean":
|
|
25
|
-
return false;
|
|
26
|
-
case "array":
|
|
27
|
-
return [];
|
|
28
|
-
case "object":
|
|
29
|
-
return {};
|
|
30
|
-
default:
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
-
import { indentation } from "./helper";
|
|
3
|
-
|
|
4
|
-
/** 生成对象代码 */
|
|
5
|
-
export var genObjectCode = function genObjectCode(object, config) {
|
|
6
|
-
var initialIndent = config.initialIndent,
|
|
7
|
-
indentSize = config.indentSize;
|
|
8
|
-
var keys = Object.keys(object);
|
|
9
|
-
if (keys.length === 0) return "{}";
|
|
10
|
-
var result = "{\n";
|
|
11
|
-
keys.forEach(function (key, idx) {
|
|
12
|
-
var value = object[key];
|
|
13
|
-
var formattedValue;
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
formattedValue = JSON.stringify(value);
|
|
16
|
-
} else if (value && _typeof(value) === "object") {
|
|
17
|
-
formattedValue = genObjectCode(value, {
|
|
18
|
-
initialIndent: initialIndent + indentSize,
|
|
19
|
-
indentSize: indentSize
|
|
20
|
-
});
|
|
21
|
-
} else if (typeof value === "string") {
|
|
22
|
-
formattedValue = JSON.stringify(value);
|
|
23
|
-
} else {
|
|
24
|
-
formattedValue = String(value);
|
|
25
|
-
}
|
|
26
|
-
result += indentation(initialIndent + indentSize) + "".concat(JSON.stringify(key), ": ").concat(formattedValue);
|
|
27
|
-
if (idx < keys.length - 1) result += ",";
|
|
28
|
-
result += "\n";
|
|
29
|
-
});
|
|
30
|
-
result += indentation(initialIndent) + "}";
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** 将第一个字符转大写 */
|
|
2
|
-
export declare const firstCharToUpperCase: (str: string) => string;
|
|
3
|
-
/** 将第一个字符转小写 */
|
|
4
|
-
export declare const firstCharToLowerCase: (str: string) => string;
|
|
5
|
-
/** 驼峰转中划线 */
|
|
6
|
-
export declare const camelToKebab: (str: string) => string;
|
|
7
|
-
/** 中划线转驼峰 */
|
|
8
|
-
export declare const kebabToCamel: (str: string) => string;
|
|
9
|
-
/** 检查字符串是否包含中文 */
|
|
10
|
-
export declare const hasChinese: (str: string) => boolean;
|
|
11
|
-
/**
|
|
12
|
-
* 获取安全的变量名
|
|
13
|
-
* 优先使用 title,如果 title 包含中文则使用 id
|
|
14
|
-
*/
|
|
15
|
-
export declare const getSafeVarName: (com: {
|
|
16
|
-
title?: string;
|
|
17
|
-
id: string;
|
|
18
|
-
}) => string;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** 将第一个字符转大写 */
|
|
2
|
-
export var firstCharToUpperCase = function firstCharToUpperCase(str) {
|
|
3
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
/** 将第一个字符转小写 */
|
|
7
|
-
export var firstCharToLowerCase = function firstCharToLowerCase(str) {
|
|
8
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/** 驼峰转中划线 */
|
|
12
|
-
export var camelToKebab = function camelToKebab(str) {
|
|
13
|
-
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/** 中划线转驼峰 */
|
|
17
|
-
export var kebabToCamel = function kebabToCamel(str) {
|
|
18
|
-
return str.replace(/-([a-z])/g, function (_, char) {
|
|
19
|
-
return char.toUpperCase();
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/** 检查字符串是否包含中文 */
|
|
24
|
-
export var hasChinese = function hasChinese(str) {
|
|
25
|
-
return /[\u4e00-\u9fa5]/.test(str);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 获取安全的变量名
|
|
30
|
-
* 优先使用 title,如果 title 包含中文则使用 id
|
|
31
|
-
*/
|
|
32
|
-
export var getSafeVarName = function getSafeVarName(com) {
|
|
33
|
-
if (com.title && !hasChinese(com.title)) {
|
|
34
|
-
return com.title;
|
|
35
|
-
}
|
|
36
|
-
return com.id;
|
|
37
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TabBarItemSource, TaroTabBarConfig } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* 将 TabBar 数据转换为 Taro 配置格式
|
|
4
|
-
* @param tabBar TabBar 项数组(来自 toJson.tabbar)
|
|
5
|
-
* @param pageIdToPath 页面 ID 到路径的映射函数,默认格式为 `pages/${pageId}/index`
|
|
6
|
-
* @param processIcon 处理图标的函数(可选,用于处理 base64 图片)
|
|
7
|
-
* @returns Taro TabBar 配置,如果验证失败则返回 null
|
|
8
|
-
*/
|
|
9
|
-
export declare function convertToTaroTabBarConfig(tabBar: TabBarItemSource[] | undefined | null, pageIdToPath?: (pageId: string) => string, processIcon?: (iconPath: string | undefined, index: number, type: 'normal' | 'selected') => string | undefined): TaroTabBarConfig | null;
|
|
10
|
-
/**
|
|
11
|
-
* 获取入口页面 ID
|
|
12
|
-
* 如果启用 TabBar,返回第一个 TabBar 项的页面 ID;否则返回 null
|
|
13
|
-
* @param tabBar TabBar 项数组
|
|
14
|
-
* @param defaultEntryPageId 默认入口页面 ID(当 TabBar 未启用时使用)
|
|
15
|
-
* @returns 入口页面 ID
|
|
16
|
-
*/
|
|
17
|
-
export declare function getEntryPageId(tabBar: TabBarItemSource[] | undefined | null, defaultEntryPageId?: string): string | null;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
-
import { validateTabBar } from "./validator";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* TabBar 数据转换器
|
|
6
|
-
* 负责将 toJson.tabbar 格式转换为 Taro 配置格式
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 将单个 TabBar 项转换为 Taro 格式
|
|
11
|
-
* @param item TabBar 项
|
|
12
|
-
* @param pageIdToPath 页面 ID 到路径的映射函数
|
|
13
|
-
* @param index TabBar 项的索引(用于生成文件名)
|
|
14
|
-
* @param processIcon 处理图标的函数(可选,用于处理 base64 图片)
|
|
15
|
-
* @returns Taro TabBar 项
|
|
16
|
-
*/
|
|
17
|
-
function convertTabBarItem(item, pageIdToPath) {
|
|
18
|
-
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
19
|
-
var processIcon = arguments.length > 3 ? arguments[3] : undefined;
|
|
20
|
-
var pagePath = pageIdToPath(item.scene.id);
|
|
21
|
-
var text = item.text || item.scene.title || '';
|
|
22
|
-
var taroItem = {
|
|
23
|
-
pagePath: pagePath,
|
|
24
|
-
text: text
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// 添加图标路径(如果存在)
|
|
28
|
-
if (item.normalIconPath) {
|
|
29
|
-
taroItem.iconPath = processIcon ? processIcon(item.normalIconPath, index, 'normal') : item.normalIconPath.replace(/^\/?@\//, "");
|
|
30
|
-
}
|
|
31
|
-
if (item.selectedIconPath) {
|
|
32
|
-
taroItem.selectedIconPath = processIcon ? processIcon(item.selectedIconPath, index, 'selected') : item.selectedIconPath.replace(/^\/?@\//, "");
|
|
33
|
-
}
|
|
34
|
-
return taroItem;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 从文本样式中提取颜色
|
|
39
|
-
* @param textStyle 文本样式对象
|
|
40
|
-
* @returns 颜色值(如果有)
|
|
41
|
-
*/
|
|
42
|
-
function extractColorFromTextStyle(textStyle) {
|
|
43
|
-
if (!textStyle || _typeof(textStyle) !== 'object') {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
return textStyle.color || textStyle.colorValue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 将 TabBar 数据转换为 Taro 配置格式
|
|
51
|
-
* @param tabBar TabBar 项数组(来自 toJson.tabbar)
|
|
52
|
-
* @param pageIdToPath 页面 ID 到路径的映射函数,默认格式为 `pages/${pageId}/index`
|
|
53
|
-
* @param processIcon 处理图标的函数(可选,用于处理 base64 图片)
|
|
54
|
-
* @returns Taro TabBar 配置,如果验证失败则返回 null
|
|
55
|
-
*/
|
|
56
|
-
export function convertToTaroTabBarConfig(tabBar) {
|
|
57
|
-
var pageIdToPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (pageId) {
|
|
58
|
-
return "pages/".concat(pageId, "/index");
|
|
59
|
-
};
|
|
60
|
-
var processIcon = arguments.length > 2 ? arguments[2] : undefined;
|
|
61
|
-
// 验证 TabBar 配置
|
|
62
|
-
var validation = validateTabBar(tabBar);
|
|
63
|
-
if (!validation.useTabBar) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// 转换 TabBar 项
|
|
68
|
-
var list = validation.validItems.map(function (item, index) {
|
|
69
|
-
return convertTabBarItem(item, pageIdToPath, index, processIcon);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// 构建 TabBar 配置
|
|
73
|
-
var config = {
|
|
74
|
-
custom: true,
|
|
75
|
-
list: list
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// 从第一个 TabBar 项的样式中提取颜色(如果存在)
|
|
79
|
-
var firstItem = validation.validItems[0];
|
|
80
|
-
if (firstItem) {
|
|
81
|
-
var normalColor = extractColorFromTextStyle(firstItem.normalTextStyle);
|
|
82
|
-
var selectedColor = extractColorFromTextStyle(firstItem.selectedTextStyle);
|
|
83
|
-
if (normalColor) {
|
|
84
|
-
config.color = normalColor;
|
|
85
|
-
}
|
|
86
|
-
if (selectedColor) {
|
|
87
|
-
config.selectedColor = selectedColor;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return config;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 获取入口页面 ID
|
|
95
|
-
* 如果启用 TabBar,返回第一个 TabBar 项的页面 ID;否则返回 null
|
|
96
|
-
* @param tabBar TabBar 项数组
|
|
97
|
-
* @param defaultEntryPageId 默认入口页面 ID(当 TabBar 未启用时使用)
|
|
98
|
-
* @returns 入口页面 ID
|
|
99
|
-
*/
|
|
100
|
-
export function getEntryPageId(tabBar, defaultEntryPageId) {
|
|
101
|
-
var validation = validateTabBar(tabBar);
|
|
102
|
-
if (validation.useTabBar && validation.validItems.length > 0) {
|
|
103
|
-
return validation.validItems[0].scene.id;
|
|
104
|
-
}
|
|
105
|
-
return defaultEntryPageId || null;
|
|
106
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 页面配置工具
|
|
3
|
-
* 负责从 systemPage 组件数据生成 definePageConfig 配置字符串
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* 从 systemPage 组件数据生成 definePageConfig 配置字符串
|
|
7
|
-
* @param systemPageData systemPage 组件的 model.data
|
|
8
|
-
* @returns definePageConfig 配置字符串
|
|
9
|
-
*/
|
|
10
|
-
export declare function generatePageConfigContent(systemPageData?: any): string;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 页面配置工具
|
|
3
|
-
* 负责从 systemPage 组件数据生成 definePageConfig 配置字符串
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { colorToHex } from "../../index";
|
|
7
|
-
var TARO_NAVIGATION_BAR_PROPERTIES = ['navigationBarBackgroundColor', 'navigationBarTextStyle', 'navigationBarTitleText', 'navigationStyle'];
|
|
8
|
-
var TARO_PAGE_CONFIG_TEMPLATE_PROPERTIES = ['navigationBarBackgroundColor', 'navigationBarTextStyle', 'navigationBarTitleText', 'navigationStyle', 'transparentTitle', 'backgroundColor', 'backgroundTextStyle', 'backgroundColorTop', 'backgroundColorBottom', 'enablePullDownRefresh', 'onReachBottomDistance', 'pageOrientation', 'disableScroll', 'disableSwipeBack', 'enableShareAppMessage', 'enableShareTimeline', 'usingComponents', 'renderer'];
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 从 systemPage 组件数据生成 definePageConfig 配置字符串
|
|
12
|
-
* @param systemPageData systemPage 组件的 model.data
|
|
13
|
-
* @returns definePageConfig 配置字符串
|
|
14
|
-
*/
|
|
15
|
-
export function generatePageConfigContent(systemPageData) {
|
|
16
|
-
var pageConfig = {
|
|
17
|
-
enableShareAppMessage: true,
|
|
18
|
-
enableShareTimeline: true
|
|
19
|
-
};
|
|
20
|
-
if (systemPageData) {
|
|
21
|
-
// 1. 处理导航栏隐藏逻辑:如果是 none,强制设置 navigationStyle 为 custom 以隐藏默认导航栏
|
|
22
|
-
if (systemPageData.useNavigationStyle === "none") {
|
|
23
|
-
pageConfig.navigationStyle = "custom";
|
|
24
|
-
}
|
|
25
|
-
var propertiesToUse = systemPageData.useNavigationStyle === "default" ? TARO_NAVIGATION_BAR_PROPERTIES : TARO_PAGE_CONFIG_TEMPLATE_PROPERTIES;
|
|
26
|
-
|
|
27
|
-
// 2. 从 systemPageData 中提取配置属性
|
|
28
|
-
propertiesToUse.forEach(function (prop) {
|
|
29
|
-
var value = systemPageData[prop];
|
|
30
|
-
if (value !== undefined && value !== null) {
|
|
31
|
-
// 特殊处理:将 RGBA 颜色转换为 WeChat 要求的 Hex 格式
|
|
32
|
-
if (prop.includes("BackgroundColor") || prop === "backgroundColor" || prop === "backgroundColorTop" || prop === "backgroundColorBottom") {
|
|
33
|
-
value = colorToHex(value);
|
|
34
|
-
}
|
|
35
|
-
pageConfig[prop] = value;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 生成配置字符串
|
|
41
|
-
var configContent = JSON.stringify(pageConfig, null, 2).replace(/^\{/, "").replace(/\}$/, "").trim();
|
|
42
|
-
return "export default definePageConfig({\n ".concat(configContent, "\n})");
|
|
43
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base64 图片处理工具
|
|
3
|
-
* 负责将 base64 图片保存为本地文件
|
|
4
|
-
*/
|
|
5
|
-
import type { ImageFileInfo } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* 处理 TabBar 图标,如果是 base64 则准备保存为文件
|
|
8
|
-
* @param iconPath 图标路径(可能是 base64 或普通路径)
|
|
9
|
-
* @param tabBarIndex TabBar 项的索引
|
|
10
|
-
* @param type 图标类型('normal' 或 'selected')
|
|
11
|
-
* @param imageFiles 用于收集需要保存的图片文件的数组(可选)
|
|
12
|
-
* @returns 处理后的图标路径(用于 app.config.ts),如果不是 base64 则返回原路径
|
|
13
|
-
*/
|
|
14
|
-
export declare function processTabBarIcon(iconPath: string | undefined, tabBarIndex: number, type: "normal" | "selected", imageFiles?: ImageFileInfo[]): string | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* 处理页面/组件 data 中的 base64 图片
|
|
17
|
-
* - 图片文件保存到 src/assets/<pageId>/ 目录(与 tabbar 同级)
|
|
18
|
-
* - data 中替换为 "@/assets/<pageId>/<fileName>"
|
|
19
|
-
*/
|
|
20
|
-
export declare function processPageBase64Image(value: string, pageId: string, imageFiles: ImageFileInfo[], nameHint: string, index: number): string;
|
|
21
|
-
/**
|
|
22
|
-
* 替换字符串中的 base64 图片(支持 url(data:image/...) 形式)
|
|
23
|
-
*/
|
|
24
|
-
export declare function replaceBase64InText(value: string, pageId: string, imageFiles: ImageFileInfo[], nameHint: string, getIndex: () => number): string;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base64 图片处理工具
|
|
3
|
-
* 负责将 base64 图片保存为本地文件
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* MIME 类型到文件扩展名的映射
|
|
8
|
-
*/
|
|
9
|
-
var MIME_TO_EXT = {
|
|
10
|
-
png: 'png',
|
|
11
|
-
jpg: 'jpg',
|
|
12
|
-
jpeg: 'jpg',
|
|
13
|
-
gif: 'gif',
|
|
14
|
-
webp: 'webp',
|
|
15
|
-
svg: 'svg'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Base64 图片解析结果
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 从 base64 字符串中提取图片格式和 base64 数据
|
|
24
|
-
* @param base64Str base64 字符串
|
|
25
|
-
* @returns 解析结果或 null
|
|
26
|
-
*/
|
|
27
|
-
function parseBase64Image(base64Str) {
|
|
28
|
-
if (typeof base64Str !== "string") return null;
|
|
29
|
-
var match = base64Str.match(/^data:image\/([^;]+);base64,(.+)$/);
|
|
30
|
-
if (!match) return null;
|
|
31
|
-
return {
|
|
32
|
-
mimeType: match[1],
|
|
33
|
-
base64Data: match[2]
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 根据 MIME 类型获取文件扩展名
|
|
39
|
-
* @param mimeType MIME 类型
|
|
40
|
-
* @returns 文件扩展名,默认为 'png'
|
|
41
|
-
*/
|
|
42
|
-
var getFileExtension = function getFileExtension(mimeType) {
|
|
43
|
-
var _MIME_TO_EXT$mimeType;
|
|
44
|
-
return (_MIME_TO_EXT$mimeType = MIME_TO_EXT[mimeType.toLowerCase()]) !== null && _MIME_TO_EXT$mimeType !== void 0 ? _MIME_TO_EXT$mimeType : "png";
|
|
45
|
-
};
|
|
46
|
-
var sanitizeName = function sanitizeName(name) {
|
|
47
|
-
return name.replace(/[^a-zA-Z0-9_]/g, "_").slice(0, 64) || "img";
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 生成唯一的文件名
|
|
52
|
-
* @param index TabBar 项的索引
|
|
53
|
-
* @param type 图标类型
|
|
54
|
-
* @param extension 文件扩展名
|
|
55
|
-
* @returns 文件名
|
|
56
|
-
*/
|
|
57
|
-
var generateFileName = function generateFileName(index, type, extension) {
|
|
58
|
-
return "tabbar_".concat(index, "_").concat(type, ".").concat(extension);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 处理 TabBar 图标,如果是 base64 则准备保存为文件
|
|
63
|
-
* @param iconPath 图标路径(可能是 base64 或普通路径)
|
|
64
|
-
* @param tabBarIndex TabBar 项的索引
|
|
65
|
-
* @param type 图标类型('normal' 或 'selected')
|
|
66
|
-
* @param imageFiles 用于收集需要保存的图片文件的数组(可选)
|
|
67
|
-
* @returns 处理后的图标路径(用于 app.config.ts),如果不是 base64 则返回原路径
|
|
68
|
-
*/
|
|
69
|
-
export function processTabBarIcon(iconPath, tabBarIndex, type, imageFiles) {
|
|
70
|
-
if (!iconPath) return undefined;
|
|
71
|
-
var parsed = parseBase64Image(iconPath);
|
|
72
|
-
if (!parsed) return iconPath.replace(/^\/?@\//, "");
|
|
73
|
-
var extension = getFileExtension(parsed.mimeType);
|
|
74
|
-
var fileName = generateFileName(tabBarIndex, type, extension);
|
|
75
|
-
var fileSystemPath = "src/assets/tabbar/".concat(fileName);
|
|
76
|
-
var configPath = "assets/tabbar/".concat(fileName);
|
|
77
|
-
if (imageFiles) {
|
|
78
|
-
try {
|
|
79
|
-
imageFiles.push({
|
|
80
|
-
filePath: fileSystemPath,
|
|
81
|
-
fileContent: Buffer.from(parsed.base64Data, "base64")
|
|
82
|
-
});
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.error("\u5904\u7406 TabBar \u56FE\u6807\u5931\u8D25: ".concat(error));
|
|
85
|
-
return iconPath;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return configPath;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 处理页面/组件 data 中的 base64 图片
|
|
93
|
-
* - 图片文件保存到 src/assets/<pageId>/ 目录(与 tabbar 同级)
|
|
94
|
-
* - data 中替换为 "@/assets/<pageId>/<fileName>"
|
|
95
|
-
*/
|
|
96
|
-
export function processPageBase64Image(value, pageId, imageFiles, nameHint, index) {
|
|
97
|
-
var parsed = parseBase64Image(value);
|
|
98
|
-
if (!parsed) return value;
|
|
99
|
-
var extension = getFileExtension(parsed.mimeType);
|
|
100
|
-
var safeName = sanitizeName(nameHint);
|
|
101
|
-
var finalName = index > 1 ? "".concat(safeName, "_").concat(index) : safeName;
|
|
102
|
-
var fileName = "".concat(finalName, ".").concat(extension);
|
|
103
|
-
var fileSystemPath = "src/assets/".concat(pageId, "/").concat(fileName);
|
|
104
|
-
var aliasPath = "@/assets/".concat(pageId, "/").concat(fileName);
|
|
105
|
-
imageFiles.push({
|
|
106
|
-
filePath: fileSystemPath,
|
|
107
|
-
fileContent: Buffer.from(parsed.base64Data, "base64")
|
|
108
|
-
});
|
|
109
|
-
return aliasPath;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 替换字符串中的 base64 图片(支持 url(data:image/...) 形式)
|
|
114
|
-
*/
|
|
115
|
-
export function replaceBase64InText(value, pageId, imageFiles, nameHint, getIndex) {
|
|
116
|
-
if (typeof value !== "string") return value;
|
|
117
|
-
var result = value;
|
|
118
|
-
// 支持一个字符串中多处 base64
|
|
119
|
-
while (true) {
|
|
120
|
-
var match = result.match(/data:image\/[^;]+;base64,[a-zA-Z0-9+/=]+/);
|
|
121
|
-
if (!match) break;
|
|
122
|
-
var currentIndex = getIndex();
|
|
123
|
-
var replaced = processPageBase64Image(match[0], pageId, imageFiles, nameHint, currentIndex);
|
|
124
|
-
result = result.replace(match[0], replaced);
|
|
125
|
-
}
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TabBar 配置工具
|
|
3
|
-
* 负责从 tabBar 数据生成 app.config.ts 中的 tabBar 配置字符串
|
|
4
|
-
*/
|
|
5
|
-
import type { TaroTabBarConfig, ImageFileInfo } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* 从 tabBar 数据生成 TabBar 配置JSON(用于 app.config.ts)
|
|
8
|
-
* @param tabBar tabBar 数据数组(来自 scenes[x].coms[id].model.data.tabBar)
|
|
9
|
-
* @param pageIdToPath 页面 ID 到路径的映射函数(默认使用 pages/${pageId}/index)
|
|
10
|
-
* @param imageFiles 用于收集需要保存的图片文件的数组(可选)
|
|
11
|
-
* @returns TabBar 配置JSON,如果验证失败则返回 null
|
|
12
|
-
*/
|
|
13
|
-
export declare function generateTabBarConfigContent(tabBar: any[] | undefined, pageIdToPath?: (pageId: string) => string, imageFiles?: ImageFileInfo[]): TaroTabBarConfig | null;
|
|
14
|
-
/**
|
|
15
|
-
* 将 TabBar 配置转换为 app.config.ts 中的字符串格式
|
|
16
|
-
* @param config TabBar 配置
|
|
17
|
-
* @param indent 缩进字符串,默认为 2 个空格
|
|
18
|
-
* @returns 配置字符串
|
|
19
|
-
*/
|
|
20
|
-
export declare function formatTabBarConfigForAppConfig(config: TaroTabBarConfig, indent?: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* 生成转换后的自定义Tabbar项配置文件内容
|
|
23
|
-
* 增加页面路径pagePath
|
|
24
|
-
* normalIconPath/selectedIconPath替换成本地图片路径
|
|
25
|
-
* @param tabBar tabBar 数据数组(来自 scenes[x].coms[id].model.data.tabBar)
|
|
26
|
-
* @param config TabBar 配置
|
|
27
|
-
*/
|
|
28
|
-
export declare function generateCustomTabBarFileContent(tabBar: any[] | undefined, config: TaroTabBarConfig): string;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
/**
|
|
3
|
-
* TabBar 配置工具
|
|
4
|
-
* 负责从 tabBar 数据生成 app.config.ts 中的 tabBar 配置字符串
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { convertToTaroTabBarConfig } from "./converter";
|
|
8
|
-
import { processTabBarIcon } from "./saveBase64Image";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 从 tabBar 数据生成 TabBar 配置JSON(用于 app.config.ts)
|
|
12
|
-
* @param tabBar tabBar 数据数组(来自 scenes[x].coms[id].model.data.tabBar)
|
|
13
|
-
* @param pageIdToPath 页面 ID 到路径的映射函数(默认使用 pages/${pageId}/index)
|
|
14
|
-
* @param imageFiles 用于收集需要保存的图片文件的数组(可选)
|
|
15
|
-
* @returns TabBar 配置JSON,如果验证失败则返回 null
|
|
16
|
-
*/
|
|
17
|
-
export function generateTabBarConfigContent(tabBar) {
|
|
18
|
-
var pageIdToPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (pageId) {
|
|
19
|
-
return "pages/".concat(pageId, "/index");
|
|
20
|
-
};
|
|
21
|
-
var imageFiles = arguments.length > 2 ? arguments[2] : undefined;
|
|
22
|
-
if (!tabBar || !Array.isArray(tabBar)) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 转换为 Taro 配置格式
|
|
27
|
-
// 如果启用 base64 处理,传入 processTabBarIcon 函数
|
|
28
|
-
var iconProcessor = imageFiles ? function (iconPath, index, type) {
|
|
29
|
-
return processTabBarIcon(iconPath, index, type, imageFiles);
|
|
30
|
-
} : undefined;
|
|
31
|
-
var config = convertToTaroTabBarConfig(tabBar, pageIdToPath, iconProcessor);
|
|
32
|
-
if (!config) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return config;
|
|
36
|
-
|
|
37
|
-
// 转换为 app.config.ts 中的字符串格式
|
|
38
|
-
// return formatTabBarConfigForAppConfig(config);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 将 TabBar 配置转换为 app.config.ts 中的字符串格式
|
|
43
|
-
* @param config TabBar 配置
|
|
44
|
-
* @param indent 缩进字符串,默认为 2 个空格
|
|
45
|
-
* @returns 配置字符串
|
|
46
|
-
*/
|
|
47
|
-
export function formatTabBarConfigForAppConfig(config) {
|
|
48
|
-
var indent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : " ";
|
|
49
|
-
// 使用 JSON.stringify 生成结构化的字符串,然后进行微调以符合 TypeScript 习惯(如去掉引号)
|
|
50
|
-
var tabBarJson = JSON.stringify(config, null, 2);
|
|
51
|
-
|
|
52
|
-
// 格式化:将双引号改为单引号,并将 key 的引号去掉(如果符合变量命名规范)
|
|
53
|
-
var formattedJson = tabBarJson.replace(/"([^"]+)":/g, "$1:") // 去掉 key 的引号
|
|
54
|
-
.replace(/"/g, "'"); // 将双引号改为单引号
|
|
55
|
-
|
|
56
|
-
// 添加缩进,并前置 "tabBar: "
|
|
57
|
-
var lines = formattedJson.split("\n");
|
|
58
|
-
return lines.map(function (line, index) {
|
|
59
|
-
if (index === 0) return "".concat(indent, "tabBar: ").concat(line);
|
|
60
|
-
return "".concat(indent).concat(line);
|
|
61
|
-
}).join("\n");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 生成转换后的自定义Tabbar项配置文件内容
|
|
66
|
-
* 增加页面路径pagePath
|
|
67
|
-
* normalIconPath/selectedIconPath替换成本地图片路径
|
|
68
|
-
* @param tabBar tabBar 数据数组(来自 scenes[x].coms[id].model.data.tabBar)
|
|
69
|
-
* @param config TabBar 配置
|
|
70
|
-
*/
|
|
71
|
-
export function generateCustomTabBarFileContent(tabBar, config) {
|
|
72
|
-
var customTabbarConfig = tabBar.map(function (item, index) {
|
|
73
|
-
var _config$list$index = config.list[index],
|
|
74
|
-
iconPath = _config$list$index.iconPath,
|
|
75
|
-
selectedIconPath = _config$list$index.selectedIconPath;
|
|
76
|
-
var cleanPath = function cleanPath(p) {
|
|
77
|
-
if (!p) return undefined;
|
|
78
|
-
var cleaned = p.replace(/^\/?@\//, "").replace(/^\//, "");
|
|
79
|
-
return "/".concat(cleaned);
|
|
80
|
-
};
|
|
81
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
82
|
-
pagePath: config.list[index].pagePath,
|
|
83
|
-
normalIconPath: cleanPath(iconPath),
|
|
84
|
-
selectedIconPath: cleanPath(selectedIconPath)
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
var tabBarJson = JSON.stringify(customTabbarConfig, null, 2);
|
|
88
|
-
return "export default ".concat(tabBarJson, " as any");
|
|
89
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TabBar 相关类型定义
|
|
3
|
-
*/
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
/// <reference types="node" />
|
|
6
|
-
/**
|
|
7
|
-
* TabBar 项源数据(来自 toJson.tabbar)
|
|
8
|
-
*/
|
|
9
|
-
export interface TabBarItemSource {
|
|
10
|
-
scene: {
|
|
11
|
-
id: string;
|
|
12
|
-
title?: string;
|
|
13
|
-
};
|
|
14
|
-
text?: string;
|
|
15
|
-
type?: string;
|
|
16
|
-
normalIconUseImg?: boolean;
|
|
17
|
-
selectedIconUseImg?: boolean;
|
|
18
|
-
normalIcon?: string;
|
|
19
|
-
selectedIcon?: string;
|
|
20
|
-
normalFontIconStyle?: Record<string, any>;
|
|
21
|
-
selectedFontIconStyle?: Record<string, any>;
|
|
22
|
-
normalIconPath?: string;
|
|
23
|
-
selectedIconPath?: string;
|
|
24
|
-
normalTextStyle?: Record<string, any>;
|
|
25
|
-
selectedTextStyle?: Record<string, any>;
|
|
26
|
-
normalIconStyle?: Record<string, any>;
|
|
27
|
-
selectedIconStyle?: Record<string, any>;
|
|
28
|
-
normalBackgroundStyle?: Record<string, any>;
|
|
29
|
-
selectedBackgroundStyle?: Record<string, any>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 转换后的自定义Tabbar项配置
|
|
33
|
-
* 增加页面路径pagePath
|
|
34
|
-
* normalIconPath/selectedIconPath替换成本地图片路径
|
|
35
|
-
*/
|
|
36
|
-
export interface CustomTabbarConfig extends TabBarItemSource {
|
|
37
|
-
pagePath: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Taro TabBar 项配置
|
|
41
|
-
*/
|
|
42
|
-
export interface TaroTabBarItem {
|
|
43
|
-
pagePath: string;
|
|
44
|
-
text: string;
|
|
45
|
-
iconPath?: string;
|
|
46
|
-
selectedIconPath?: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Taro TabBar 配置
|
|
50
|
-
*/
|
|
51
|
-
export interface TaroTabBarConfig {
|
|
52
|
-
custom?: boolean;
|
|
53
|
-
color?: string;
|
|
54
|
-
selectedColor?: string;
|
|
55
|
-
backgroundColor?: string;
|
|
56
|
-
borderStyle?: string;
|
|
57
|
-
list: TaroTabBarItem[];
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* TabBar 验证结果
|
|
61
|
-
*/
|
|
62
|
-
export interface TabBarValidationResult {
|
|
63
|
-
useTabBar: boolean;
|
|
64
|
-
validItems: TabBarItemSource[];
|
|
65
|
-
error?: string;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 图片文件信息
|
|
69
|
-
*/
|
|
70
|
-
export interface ImageFileInfo {
|
|
71
|
-
filePath: string;
|
|
72
|
-
fileContent: Buffer;
|
|
73
|
-
}
|