@mybricks/to-code-taro 1.0.3 → 1.0.5
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/dist/cjs/core/comlib/_AesEncode.js +115 -0
- package/dist/cjs/core/comlib/_BackTo.js +80 -0
- package/dist/cjs/core/comlib/_CallPhone.js +58 -0
- package/dist/cjs/core/comlib/_ChooseFile.js +103 -0
- package/dist/cjs/core/comlib/_ChooseMedia.js +70 -0
- package/dist/cjs/core/comlib/_Connector.js +92 -0
- package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +79 -0
- package/dist/cjs/core/comlib/_Format.js +123 -0
- package/dist/cjs/core/comlib/_GetLocation.js +60 -0
- package/dist/cjs/core/comlib/_GetStorage.js +68 -0
- package/dist/cjs/core/comlib/_GetSystemInfo.js +62 -0
- package/dist/cjs/core/comlib/_OpenCamera.js +73 -0
- package/dist/cjs/core/comlib/_OpenPetalMap.js +49 -0
- package/dist/cjs/core/comlib/_OpenUrl.js +62 -0
- package/dist/cjs/core/comlib/_RemoveStorage.js +68 -0
- package/dist/cjs/core/comlib/_Router.js +100 -0
- package/dist/cjs/core/comlib/_ScanQrcode.js +9 -10
- package/dist/cjs/core/comlib/_SetStorage.js +10 -19
- package/dist/cjs/core/comlib/_Share.js +58 -0
- package/dist/cjs/core/comlib/_ShowToast.js +23 -50
- package/dist/cjs/core/comlib/_TextToSpeech.js +120 -0
- package/dist/cjs/core/comlib/_TimerDebounce.js +72 -0
- package/dist/cjs/core/comlib/_TimerDelay.js +63 -0
- package/dist/cjs/core/comlib/_TimerThrottle.js +75 -0
- package/dist/cjs/core/comlib/_Vibrate.js +60 -0
- package/dist/cjs/core/comlib/index.js +68 -2
- package/dist/cjs/core/utils/ComContext.js +3 -3
- package/dist/cjs/core/utils/PopupRenderer.js +63 -0
- package/dist/cjs/core/utils/hooks.js +16 -14
- package/dist/cjs/core/utils/index.js +15 -3
- package/dist/cjs/core/utils/{page.js → pageRouter.js} +28 -14
- package/dist/cjs/core/utils/popupRouter.js +98 -0
- package/dist/cjs/core/utils/useContext.js +9 -1
- package/dist/cjs/core/utils/with.js +37 -13
- package/dist/cjs/generate/generateTaroProjectJson.js +30 -0
- package/dist/cjs/handleSlot.d.ts +2 -0
- package/dist/cjs/handleSlot.js +19 -5
- package/dist/cjs/processors/processComEvents.js +47 -5
- package/dist/cjs/processors/processScene.js +9 -5
- package/dist/cjs/processors/processSceneLogic.js +9 -5
- package/dist/cjs/shims-taro.d.ts +20 -0
- package/dist/cjs/taro-template.json +493 -351
- package/dist/cjs/toCodeTaro.d.ts +1 -1
- package/dist/cjs/toCodeTaro.js +13 -1
- package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
- package/dist/cjs/utils/builder/buildResult.js +26 -0
- package/dist/cjs/utils/config/handlePageConfig.d.ts +2 -1
- package/dist/cjs/utils/config/handlePageConfig.js +3 -2
- package/dist/cjs/utils/context/createEventQueries.js +1 -1
- package/dist/cjs/utils/logic/handleProcess.js +26 -5
- package/dist/cjs/utils/templates/scene.d.ts +3 -1
- package/dist/cjs/utils/templates/scene.js +16 -4
- package/dist/esm/core/comlib/_AesEncode.js +85 -0
- package/dist/esm/core/comlib/_BackTo.js +66 -0
- package/dist/esm/core/comlib/_CallPhone.js +30 -0
- package/dist/esm/core/comlib/_ChooseFile.js +81 -0
- package/dist/esm/core/comlib/_ChooseMedia.js +38 -0
- package/dist/esm/core/comlib/_Connector.js +60 -0
- package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +56 -0
- package/dist/esm/core/comlib/_Format.js +102 -0
- package/dist/esm/core/comlib/_GetLocation.js +26 -0
- package/dist/esm/core/comlib/_GetStorage.js +44 -0
- package/dist/esm/core/comlib/_GetSystemInfo.js +32 -0
- package/dist/esm/core/comlib/_OpenCamera.js +44 -0
- package/dist/esm/core/comlib/_OpenPetalMap.js +28 -0
- package/dist/esm/core/comlib/_OpenUrl.js +36 -0
- package/dist/esm/core/comlib/_RemoveStorage.js +42 -0
- package/dist/esm/core/comlib/_Router.js +113 -0
- package/dist/esm/core/comlib/_ScanQrcode.js +10 -11
- package/dist/esm/core/comlib/_SetStorage.js +13 -25
- package/dist/esm/core/comlib/_Share.js +28 -0
- package/dist/esm/core/comlib/_ShowToast.js +32 -55
- package/dist/esm/core/comlib/_TextToSpeech.js +117 -0
- package/dist/esm/core/comlib/_TimerDebounce.js +66 -0
- package/dist/esm/core/comlib/_TimerDelay.js +47 -0
- package/dist/esm/core/comlib/_TimerThrottle.js +69 -0
- package/dist/esm/core/comlib/_Vibrate.js +34 -0
- package/dist/esm/core/comlib/index.js +35 -1
- package/dist/esm/core/utils/ComContext.js +1 -1
- package/dist/esm/core/utils/PopupRenderer.js +27 -0
- package/dist/esm/core/utils/hooks.js +24 -16
- package/dist/esm/core/utils/index.js +3 -1
- package/dist/esm/core/utils/pageRouter.js +69 -0
- package/dist/esm/core/utils/popupRouter.js +116 -0
- package/dist/esm/core/utils/useContext.js +14 -2
- package/dist/esm/core/utils/with.js +62 -19
- package/dist/esm/generate/generateTaroProjectJson.js +35 -1
- package/dist/esm/handleSlot.d.ts +2 -0
- package/dist/esm/handleSlot.js +20 -4
- package/dist/esm/processors/processComEvents.js +62 -5
- package/dist/esm/processors/processScene.js +11 -3
- package/dist/esm/processors/processSceneLogic.js +15 -5
- package/dist/esm/shims-taro.d.ts +20 -0
- package/dist/esm/taro-template.json +493 -351
- package/dist/esm/toCodeTaro.d.ts +1 -1
- package/dist/esm/toCodeTaro.js +16 -1
- package/dist/esm/utils/builder/buildResult.d.ts +1 -0
- package/dist/esm/utils/builder/buildResult.js +21 -0
- package/dist/esm/utils/config/handlePageConfig.d.ts +2 -1
- package/dist/esm/utils/config/handlePageConfig.js +5 -1
- package/dist/esm/utils/context/createEventQueries.js +2 -1
- package/dist/esm/utils/logic/handleProcess.js +31 -4
- package/dist/esm/utils/templates/scene.d.ts +3 -1
- package/dist/esm/utils/templates/scene.js +13 -5
- package/package.json +4 -2
- package/dist/esm/core/utils/page.js +0 -50
package/dist/esm/toCodeTaro.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface ToTaroCodeConfig {
|
|
|
24
24
|
callName?: string;
|
|
25
25
|
};
|
|
26
26
|
getComponentPackageName: (props?: any) => string;
|
|
27
|
-
getUtilsPackageName: () => string;
|
|
27
|
+
getUtilsPackageName: (props?: any) => string;
|
|
28
28
|
getPageId?: (id: string) => string;
|
|
29
29
|
getBus?: (namespace: string) => {
|
|
30
30
|
title: string;
|
package/dist/esm/toCodeTaro.js
CHANGED
|
@@ -91,9 +91,23 @@ var getCode = function getCode(params, config) {
|
|
|
91
91
|
var jsModulesCollector = createJSModulesCollector();
|
|
92
92
|
var pageConfigHandler = new HandlePageConfig();
|
|
93
93
|
|
|
94
|
+
// 提前识别所有弹窗场景
|
|
95
|
+
var popupIds = new Set();
|
|
96
|
+
tojson.scenes.forEach(function (s) {
|
|
97
|
+
var _s$deps;
|
|
98
|
+
if (s.type === 'popup' || (_s$deps = s.deps) !== null && _s$deps !== void 0 && _s$deps.some(function (dep) {
|
|
99
|
+
return dep.namespace === 'mybricks.taro.popup';
|
|
100
|
+
})) {
|
|
101
|
+
popupIds.add(s.id);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
94
105
|
// ========== 第六步:处理场景 ==========
|
|
95
106
|
processScenes(scenes, {
|
|
96
|
-
config: config,
|
|
107
|
+
config: _objectSpread(_objectSpread({}, config), {}, {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
hasPopups: popupIds.size > 0
|
|
110
|
+
}),
|
|
97
111
|
globalVarTypeDef: globalVarTypeDef,
|
|
98
112
|
defaultFxsMap: defaultFxsMap,
|
|
99
113
|
abstractEventTypeDefMap: abstractEventTypeDefMap,
|
|
@@ -128,6 +142,7 @@ var getCode = function getCode(params, config) {
|
|
|
128
142
|
jsModulesMap: jsModulesCollector.getMap(),
|
|
129
143
|
globalTabBarConfig: pageConfigHandler.getTabBarConfig(),
|
|
130
144
|
tabBarImageFiles: pageConfigHandler.getTabBarImageFiles(),
|
|
145
|
+
popupIds: Array.from(popupIds),
|
|
131
146
|
config: config
|
|
132
147
|
});
|
|
133
148
|
files.push.apply(files, _toConsumableArray(finalResultData.files));
|
|
@@ -14,6 +14,7 @@ export var buildFinalResults = function buildFinalResults(params) {
|
|
|
14
14
|
jsModulesMap = params.jsModulesMap,
|
|
15
15
|
globalTabBarConfig = params.globalTabBarConfig,
|
|
16
16
|
tabBarImageFiles = params.tabBarImageFiles,
|
|
17
|
+
popupIds = params.popupIds,
|
|
17
18
|
config = params.config;
|
|
18
19
|
var files = [];
|
|
19
20
|
|
|
@@ -44,6 +45,26 @@ export var buildFinalResults = function buildFinalResults(params) {
|
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
// 生成弹窗汇总文件 (popup.ts)
|
|
49
|
+
if (popupIds.length > 0) {
|
|
50
|
+
var registryContent = "";
|
|
51
|
+
popupIds.forEach(function (id) {
|
|
52
|
+
registryContent += "import Scene_".concat(id, " from '../popupComponents/").concat(id, "/index';\n");
|
|
53
|
+
});
|
|
54
|
+
registryContent += "\nexport const POPUP_MAP: Record<string, any> = {\n";
|
|
55
|
+
popupIds.forEach(function (id) {
|
|
56
|
+
registryContent += " '".concat(id, "': Scene_").concat(id, ",\n");
|
|
57
|
+
});
|
|
58
|
+
registryContent += "};\n\n";
|
|
59
|
+
registryContent += "export const POPUP_IDS = ".concat(JSON.stringify(popupIds), ";\n");
|
|
60
|
+
files.push({
|
|
61
|
+
type: "popup",
|
|
62
|
+
content: registryContent,
|
|
63
|
+
importManager: new ImportManager(config),
|
|
64
|
+
name: "popup"
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
// 添加 TabBar 配置项(如果存在)
|
|
48
69
|
if (globalTabBarConfig) {
|
|
49
70
|
files.push({
|
|
@@ -10,9 +10,10 @@ export declare class HandlePageConfig {
|
|
|
10
10
|
/**
|
|
11
11
|
* 处理页面配置(提取 systemPage 组件数据)
|
|
12
12
|
* @param scene 场景数据
|
|
13
|
+
* @param isPopup 是否为弹窗场景
|
|
13
14
|
* @returns 页面配置内容
|
|
14
15
|
*/
|
|
15
|
-
handle(scene: ReturnType<typeof toCode>["scenes"][0]["scene"]): string | undefined;
|
|
16
|
+
handle(scene: ReturnType<typeof toCode>["scenes"][0]["scene"], isPopup?: boolean): string | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* 获取全局 TabBar 配置
|
|
18
19
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
3
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
4
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
@@ -19,10 +20,12 @@ export var HandlePageConfig = /*#__PURE__*/function () {
|
|
|
19
20
|
/**
|
|
20
21
|
* 处理页面配置(提取 systemPage 组件数据)
|
|
21
22
|
* @param scene 场景数据
|
|
23
|
+
* @param isPopup 是否为弹窗场景
|
|
22
24
|
* @returns 页面配置内容
|
|
23
25
|
*/
|
|
24
26
|
function handle(scene) {
|
|
25
27
|
var _systemPageCom$model;
|
|
28
|
+
var isPopup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
26
29
|
// 提取 systemPage 组件数据,生成 pageConfigContent
|
|
27
30
|
var pageConfigContent;
|
|
28
31
|
var systemPageCom = Object.values(scene.coms || {}).find(function (com) {
|
|
@@ -30,7 +33,8 @@ export var HandlePageConfig = /*#__PURE__*/function () {
|
|
|
30
33
|
return ((_com$def = com.def) === null || _com$def === void 0 ? void 0 : _com$def.namespace) === 'mybricks.taro.systemPage';
|
|
31
34
|
});
|
|
32
35
|
if (systemPageCom !== null && systemPageCom !== void 0 && (_systemPageCom$model = systemPageCom.model) !== null && _systemPageCom$model !== void 0 && _systemPageCom$model.data) {
|
|
33
|
-
var systemPageData = systemPageCom.model.data;
|
|
36
|
+
var systemPageData = _objectSpread({}, systemPageCom.model.data);
|
|
37
|
+
|
|
34
38
|
// 生成页面配置
|
|
35
39
|
pageConfigContent = generatePageConfigContent(systemPageData);
|
|
36
40
|
|
|
@@ -65,8 +65,9 @@ export var createEventQueries = function createEventQueries(events) {
|
|
|
65
65
|
getFxEvents: createGetFxEvents(events),
|
|
66
66
|
getEffectEvent: createGetEffectEvent(events),
|
|
67
67
|
getEventByDiagramId: function getEventByDiagramId(diagramId) {
|
|
68
|
+
// 兼容:部分 event 没有 diagramId 字段,而是直接用 id 存储 diagramId
|
|
68
69
|
return events.find(function (event) {
|
|
69
|
-
return event.diagramId === diagramId;
|
|
70
|
+
return event.diagramId === diagramId || event.id === diagramId;
|
|
70
71
|
});
|
|
71
72
|
},
|
|
72
73
|
/** 获取场景/区块的输入项事件 */
|
|
@@ -119,15 +119,42 @@ export var handleProcess = function handleProcess(event, config) {
|
|
|
119
119
|
}
|
|
120
120
|
if (componentType === "js") {
|
|
121
121
|
if (category === "scene") {
|
|
122
|
-
var _config$getPageId;
|
|
122
|
+
var _targetScene$deps, _config$getPageId;
|
|
123
|
+
var _sceneId = props.meta.model.data._sceneId;
|
|
124
|
+
var targetScene = config.getSceneById(_sceneId);
|
|
125
|
+
var isPopup = (targetScene === null || targetScene === void 0 ? void 0 : targetScene.type) === 'popup' || (targetScene === null || targetScene === void 0 || (_targetScene$deps = targetScene.deps) === null || _targetScene$deps === void 0 ? void 0 : _targetScene$deps.some(function (dep) {
|
|
126
|
+
return dep.namespace === 'mybricks.taro.popup';
|
|
127
|
+
}));
|
|
128
|
+
var controllerName = isPopup ? "popupRouter" : "pageRouter";
|
|
123
129
|
config.addParentDependencyImport({
|
|
124
130
|
packageName: config.getComponentPackageName(),
|
|
125
|
-
dependencyNames: [
|
|
131
|
+
dependencyNames: [controllerName],
|
|
126
132
|
importType: "named"
|
|
127
133
|
});
|
|
128
|
-
var _sceneId = props.meta.model.data._sceneId;
|
|
129
134
|
var operateName = props.meta.model.data.openType === "redirect" ? "replace" : "open";
|
|
130
|
-
code += "".concat(indent, "/** \u6253\u5F00 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "
|
|
135
|
+
code += "".concat(indent, "/** \u6253\u5F00 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(controllerName, ".").concat(operateName, "(\"").concat(((_config$getPageId = config.getPageId) === null || _config$getPageId === void 0 ? void 0 : _config$getPageId.call(config, _sceneId)) || _sceneId, "\", ").concat(nextValue, ")");
|
|
136
|
+
} else if (category === "frameOutput") {
|
|
137
|
+
var _pinProxies;
|
|
138
|
+
// 场景/弹窗输出(commit/cancel/apply/close)
|
|
139
|
+
var currentScene = config.getCurrentScene();
|
|
140
|
+
// pinProxies 的结构在不同数据/版本里不完全一致,这里按最小字段兼容
|
|
141
|
+
var pinProxy = currentScene === null || currentScene === void 0 || (_pinProxies = currentScene.pinProxies) === null || _pinProxies === void 0 ? void 0 : _pinProxies["".concat(props.meta.id, "-").concat(props.id)];
|
|
142
|
+
if (pinProxy !== null && pinProxy !== void 0 && pinProxy.frameId && pinProxy !== null && pinProxy !== void 0 && pinProxy.pinId) {
|
|
143
|
+
var method = pinProxy.pinId;
|
|
144
|
+
var _controllerName = config.isPopup ? "popupRouter" : "pageRouter";
|
|
145
|
+
config.addParentDependencyImport({
|
|
146
|
+
packageName: config.getComponentPackageName(),
|
|
147
|
+
dependencyNames: [_controllerName],
|
|
148
|
+
importType: "named"
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// 仅支持 Page 内置的四种输出方法
|
|
152
|
+
if (["commit", "cancel", "apply", "close"].includes(method)) {
|
|
153
|
+
var sceneId = pinProxy.frameId || (currentScene === null || currentScene === void 0 ? void 0 : currentScene.id);
|
|
154
|
+
var argCode = nextValue ? ", ".concat(nextValue) : "";
|
|
155
|
+
code += "".concat(indent, "/** ").concat(props.meta.title, " \u8F93\u51FA ").concat(method, " */") + "\n".concat(indent).concat(nextCode).concat(_controllerName, ".").concat(method, "(\"").concat(sceneId, "\"").concat(argCode, ")");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
131
158
|
} else if (category === "normal") {
|
|
132
159
|
var componentNameWithId = getComponentNameWithId(props, config, event);
|
|
133
160
|
code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(componentNameWithId, "(").concat(runType === "input" ? nextValue : "", ")");
|
|
@@ -7,13 +7,15 @@ export declare const genSlotDefineCode: (indent: string) => string;
|
|
|
7
7
|
/** 生成控制器初始化代码 */
|
|
8
8
|
export declare const genControllerInitCode: (indent: string, providerName: string) => string;
|
|
9
9
|
/** 生成完整的函数组件模板 */
|
|
10
|
-
export declare const genComponentTemplate: ({ componentName, combinedJsCode, uiResult, outputsConfig, scopeName, utilsPackageName, }: {
|
|
10
|
+
export declare const genComponentTemplate: ({ componentName, combinedJsCode, uiResult, outputsConfig, scopeName, utilsPackageName, isPopup, hasPopups, }: {
|
|
11
11
|
componentName: string;
|
|
12
12
|
combinedJsCode: string;
|
|
13
13
|
uiResult: string;
|
|
14
14
|
outputsConfig?: Record<string, Record<string, any>>;
|
|
15
15
|
scopeName?: string;
|
|
16
16
|
utilsPackageName?: string;
|
|
17
|
+
isPopup?: boolean;
|
|
18
|
+
hasPopups?: boolean;
|
|
17
19
|
}) => string;
|
|
18
20
|
/** 生成 useEffect 包装代码 */
|
|
19
21
|
export declare const wrapInEffect: (indent: string, effectCode: string) => string;
|
|
@@ -33,12 +33,20 @@ export var genComponentTemplate = function genComponentTemplate(_ref) {
|
|
|
33
33
|
uiResult = _ref.uiResult,
|
|
34
34
|
outputsConfig = _ref.outputsConfig,
|
|
35
35
|
scopeName = _ref.scopeName,
|
|
36
|
-
utilsPackageName = _ref.utilsPackageName
|
|
36
|
+
utilsPackageName = _ref.utilsPackageName,
|
|
37
|
+
_ref$isPopup = _ref.isPopup,
|
|
38
|
+
isPopup = _ref$isPopup === void 0 ? false : _ref$isPopup,
|
|
39
|
+
_ref$hasPopups = _ref.hasPopups,
|
|
40
|
+
hasPopups = _ref$hasPopups === void 0 ? false : _ref$hasPopups;
|
|
37
41
|
// 使用 WithWrapper 作为高阶组件包裹根组件
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
var code = "function ".concat(componentName, "() {\n") + "".concat(combinedJsCode, "\n") + " return (\n" + " <>\n" + "".concat(uiResult.split('\n').map(function (line) {
|
|
43
|
+
return " ".concat(line);
|
|
44
|
+
}).join('\n'), "\n") + (hasPopups ? " <PopupRenderer popupMap={POPUP_MAP} />\n" : "") + " </>\n" + " );\n" + "}\n\n";
|
|
45
|
+
if (isPopup) {
|
|
46
|
+
code += "(".concat(componentName, " as any).isPopup = true;\n\n");
|
|
47
|
+
}
|
|
48
|
+
code += "export default WithWrapper(".concat(componentName, ")");
|
|
49
|
+
return code;
|
|
42
50
|
};
|
|
43
51
|
|
|
44
52
|
/** 生成 useEffect 包装代码 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mybricks/to-code-taro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "To code for Taro",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@babel/runtime": "^7.26.0",
|
|
42
|
-
"@mybricks/to-code-react": "^0.0.5-next.160"
|
|
42
|
+
"@mybricks/to-code-react": "^0.0.5-next.160",
|
|
43
|
+
"@types/crypto-js": "^4.2.2",
|
|
44
|
+
"crypto-js": "^4.2.0"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@types/node": "^20.0.0",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import Taro from '@tarojs/taro';
|
|
4
|
-
import { Page } from "../mybricks";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Taro 路由实现
|
|
8
|
-
*/
|
|
9
|
-
var TaroRouter = /*#__PURE__*/function () {
|
|
10
|
-
function TaroRouter() {
|
|
11
|
-
_classCallCheck(this, TaroRouter);
|
|
12
|
-
}
|
|
13
|
-
_createClass(TaroRouter, [{
|
|
14
|
-
key: "getParams",
|
|
15
|
-
value: function getParams(name) {
|
|
16
|
-
var _instance$router;
|
|
17
|
-
var instance = Taro.getCurrentInstance();
|
|
18
|
-
return {
|
|
19
|
-
value: (_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}, {
|
|
23
|
-
key: "push",
|
|
24
|
-
value: function push(name, _ref) {
|
|
25
|
-
var value = _ref.value;
|
|
26
|
-
var url = "/pages/".concat(name, "/index");
|
|
27
|
-
var queryString = value ? "?data=".concat(encodeURIComponent(JSON.stringify(value))) : '';
|
|
28
|
-
Taro.navigateTo({
|
|
29
|
-
url: url + queryString
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}, {
|
|
33
|
-
key: "replace",
|
|
34
|
-
value: function replace(name, _ref2) {
|
|
35
|
-
var value = _ref2.value;
|
|
36
|
-
var url = "/pages/".concat(name, "/index");
|
|
37
|
-
var queryString = value ? "?data=".concat(encodeURIComponent(JSON.stringify(value))) : '';
|
|
38
|
-
Taro.redirectTo({
|
|
39
|
-
url: url + queryString
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
key: "pop",
|
|
44
|
-
value: function pop() {
|
|
45
|
-
Taro.navigateBack();
|
|
46
|
-
}
|
|
47
|
-
}]);
|
|
48
|
-
return TaroRouter;
|
|
49
|
-
}();
|
|
50
|
-
export var page = new Page(new TaroRouter());
|