@cloudbase/lowcode-builder 1.8.18 → 1.8.20
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/builder.web.js +13 -21
- package/lib/builder/config/index.d.ts +2 -2
- package/lib/builder/config/index.js +2 -2
- package/lib/builder/h5/index.d.ts +1 -1
- package/lib/builder/h5/index.js +42 -4
- package/lib/builder/mp/index.js +17 -7
- package/lib/builder/mp/util.js +11 -8
- package/lib/builder/util/process.js +12 -15
- package/lib/utils/transform.d.ts +3 -0
- package/lib/utils/transform.js +35 -0
- package/package.json +7 -4
- package/template/.DS_Store +0 -0
- package/template/html/index.html.ejs +2 -2
- package/template/mp/.DS_Store +0 -0
- package/template/mp/common/.DS_Store +0 -0
- package/template/mp/common/util.js +12 -4
- package/template/mp/common/weapp-page.js +87 -78
- package/template/mp/package.json +2 -2
- package/template/mp/page/index.js +2 -1
- package/lib/builder.web.js +0 -79
- package/template/mp/common/url.js +0 -21
|
@@ -6,12 +6,12 @@ export declare const materialsDirName = "materials";
|
|
|
6
6
|
* src/template的代码,在IDE编辑器插件中构建builder
|
|
7
7
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
8
8
|
*/
|
|
9
|
-
export declare const builderTemplateURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.
|
|
9
|
+
export declare const builderTemplateURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.19.zip";
|
|
10
10
|
/**
|
|
11
11
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
12
12
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
13
13
|
*/
|
|
14
|
-
export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/
|
|
14
|
+
export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm.1.8.19.zip";
|
|
15
15
|
/**
|
|
16
16
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
17
17
|
*/
|
|
@@ -45,12 +45,12 @@ exports.materialsDirName = 'materials'; // materials diretory of current project
|
|
|
45
45
|
* src/template的代码,在IDE编辑器插件中构建builder
|
|
46
46
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
47
47
|
*/
|
|
48
|
-
exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.
|
|
48
|
+
exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.19.zip';
|
|
49
49
|
/**
|
|
50
50
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
51
51
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
52
52
|
*/
|
|
53
|
-
exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/
|
|
53
|
+
exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm.1.8.19.zip';
|
|
54
54
|
/**
|
|
55
55
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
56
56
|
*/
|
|
@@ -5,7 +5,7 @@ import { IPlatformApp } from '@cloudbase/cals';
|
|
|
5
5
|
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
6
6
|
import { IBuildContext } from '../mp/BuildContext';
|
|
7
7
|
import { IBuildWedaApp } from '../core';
|
|
8
|
-
export declare function buildH5App({ buildContext, i18nConfig, extraData, cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployOptions, ignoreInstall, cdnEndpoints, }: {
|
|
8
|
+
export declare function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployOptions, ignoreInstall, cdnEndpoints, }: {
|
|
9
9
|
buildContext: Omit<IBuildContext, 'mainAppData'>;
|
|
10
10
|
cals: IPlatformApp;
|
|
11
11
|
subAppCalsList: IPlatformApp[];
|
package/lib/builder/h5/index.js
CHANGED
|
@@ -45,7 +45,8 @@ const config_1 = require("../config");
|
|
|
45
45
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
46
46
|
const junk = __importStar(require("../util/junk"));
|
|
47
47
|
const url_1 = require("url");
|
|
48
|
-
|
|
48
|
+
const transform_1 = require("../../utils/transform");
|
|
49
|
+
async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, ignoreInstall = false, cdnEndpoints, }) {
|
|
49
50
|
var _a, _b, _c;
|
|
50
51
|
const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode } = buildContext;
|
|
51
52
|
if (!deployOptions.mode) {
|
|
@@ -57,11 +58,12 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals, buildType
|
|
|
57
58
|
if (buildTypeList.includes(common_1.BuildType.APP) ||
|
|
58
59
|
buildTypeList.includes(common_1.BuildType.XPAGE_PC) ||
|
|
59
60
|
buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL)) {
|
|
60
|
-
if (!
|
|
61
|
-
|
|
61
|
+
if (!_cals.extra) {
|
|
62
|
+
_cals.extra = {};
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
_cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
|
|
64
65
|
}
|
|
66
|
+
const cals = processCals(_cals);
|
|
65
67
|
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
66
68
|
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
|
|
67
69
|
const { allAppUsedComps } = (0, mp_1.handleUsedComponents)({
|
|
@@ -199,3 +201,39 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals, buildType
|
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
203
|
exports.buildH5App = buildH5App;
|
|
204
|
+
function processCals(cals) {
|
|
205
|
+
return walkThroughJson(cals, (key, value, prefix) => {
|
|
206
|
+
if (/^:(.*)$/.test(key)) {
|
|
207
|
+
try {
|
|
208
|
+
return (0, transform_1.BabelTransform)(value, { IIFE: true });
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
return value;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return value;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function _isPlainObj(obj) {
|
|
218
|
+
return typeof obj === 'object' && obj !== null;
|
|
219
|
+
}
|
|
220
|
+
function walkThroughJson(obj, callback, path = '') {
|
|
221
|
+
/**
|
|
222
|
+
* 跳过数据源 state 的处理
|
|
223
|
+
*/
|
|
224
|
+
if (/dataset\.state$/.test(path)) {
|
|
225
|
+
return obj;
|
|
226
|
+
}
|
|
227
|
+
if (typeof obj === 'object' && Array.isArray(obj)) {
|
|
228
|
+
return obj.map((item, index) => {
|
|
229
|
+
const prefix = path ? `${path}.${index}` : String(index);
|
|
230
|
+
return _isPlainObj(item) ? walkThroughJson(item, callback, prefix) : callback(index, item, prefix);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
for (const key in obj) {
|
|
234
|
+
const value = obj[key];
|
|
235
|
+
const prefix = path ? `${path}.${key}` : key;
|
|
236
|
+
obj[key] = _isPlainObj(value) ? walkThroughJson(value, callback, prefix) : callback(key, value, prefix);
|
|
237
|
+
}
|
|
238
|
+
return obj;
|
|
239
|
+
}
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -106,11 +106,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployOptions, opti
|
|
|
106
106
|
isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
107
107
|
},
|
|
108
108
|
'common/widget.js': {},
|
|
109
|
-
'common/
|
|
110
|
-
'common/weapp-page.js': {
|
|
111
|
-
dataPropNames: wxmlDataPrefix,
|
|
112
|
-
debug: buildContext.debugMode,
|
|
113
|
-
},
|
|
109
|
+
'common/weapp-page.js': {},
|
|
114
110
|
'common/weapp-component.js': {},
|
|
115
111
|
'common/merge-renderer.js': {
|
|
116
112
|
dataPropNames: wxmlDataPrefix,
|
|
@@ -310,12 +306,21 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
310
306
|
console.log(`Generating ${em('page')} files`);
|
|
311
307
|
(0, generateFiles_1.cleanDir)(path_1.default.join(appRoot, 'pages'), []);
|
|
312
308
|
await Promise.all(weapp.pageInstanceList.map(async (page) => {
|
|
313
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
309
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
314
310
|
// # Generating page
|
|
315
311
|
const rootPath = weapp.rootPath || '';
|
|
316
312
|
const usingComponents = {};
|
|
317
313
|
const componentGenerics = {};
|
|
318
314
|
const componentInstances = (0, util_2.processRepeaterSchema)(ctx, page.componentInstances);
|
|
315
|
+
const { allAppUsedComps = [] } = handleUsedComponents({
|
|
316
|
+
buildContext: ctx,
|
|
317
|
+
weapps: [
|
|
318
|
+
{
|
|
319
|
+
...weapp,
|
|
320
|
+
pageInstanceList: [page],
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
});
|
|
319
324
|
const wxml = (0, wxml_1.generateWxml)({ ...ctx, rootPath, isPage: true }, componentInstances, `Page ${rootPath ? path_1.default.join(rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, usingComponents, componentGenerics);
|
|
320
325
|
const importor = (0, util_3.generateLowcodeImportor)(page.lowCodes);
|
|
321
326
|
const pageFileName = (0, lodash_1.get)(pageConfigs, `${page.id}.pageFileName`, 'index');
|
|
@@ -343,6 +348,11 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
343
348
|
importor,
|
|
344
349
|
query: (0, util_2.createTemplateQuery)(ctx, (_f = page.dataset) === null || _f === void 0 ? void 0 : _f.query),
|
|
345
350
|
eventFlows: (0, util_2.createTemplateEventFlows)(ctx, page.eventFlows),
|
|
351
|
+
resetShare: ((_j = (_h = (_g = page === null || page === void 0 ? void 0 : page.data) === null || _g === void 0 ? void 0 : _g.appShareMessage) === null || _h === void 0 ? void 0 : _h.value) === null || _j === void 0 ? void 0 : _j.enable) ||
|
|
352
|
+
((_k = allAppUsedComps === null || allAppUsedComps === void 0 ? void 0 : allAppUsedComps[cals_1.OFFICIAL_LIB_KEY]) === null || _k === void 0 ? void 0 : _k.has('Share')) ||
|
|
353
|
+
/* 从 enablePageRoot 的版本开始支持按需reset share
|
|
354
|
+
* 否则默认都开启
|
|
355
|
+
*/ !ctx.enablePageRoot,
|
|
346
356
|
},
|
|
347
357
|
[`index.json|${pageFileName}.json`]: {
|
|
348
358
|
usingComponents,
|
|
@@ -353,7 +363,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
353
363
|
content: wxml,
|
|
354
364
|
},
|
|
355
365
|
[`index.wxss|${pageFileName}.wxss`]: {
|
|
356
|
-
subWxss: rootPath && !((
|
|
366
|
+
subWxss: rootPath && !((_l = ctx.mainAppData) === null || _l === void 0 ? void 0 : _l.mpPkgUrl)
|
|
357
367
|
? `@import "${path_1.default.posix.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
|
|
358
368
|
: '',
|
|
359
369
|
content: (0, weapps_core_1.toCssText)((0, cals_1.processCommonStyle2CSSProperties)(page.commonStyle, {
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -9,21 +9,24 @@ const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
|
|
|
9
9
|
const cals_1 = require("@cloudbase/cals");
|
|
10
10
|
const config_1 = require("../config");
|
|
11
11
|
function extractWidgetProps(props, compInfo, processCssUnit = 'rpx') {
|
|
12
|
-
var _a, _b;
|
|
13
|
-
const { classList, staticResourceAttribute = [] } = props;
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const { classList, staticResourceAttribute = [], data = {}, style } = props;
|
|
14
14
|
const staticProps = {
|
|
15
|
-
style: (
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
style: style && ((_a = Object.keys(style || {})) === null || _a === void 0 ? void 0 : _a.length)
|
|
16
|
+
? (0, cals_1.processCSSPropertiesUnit)(style || {}, processCssUnit)
|
|
17
|
+
: {
|
|
18
|
+
...(0, cals_1.processCommonStyle2CSSProperties)(props.commonStyle || {}, {
|
|
19
|
+
defaultUnit: processCssUnit,
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
18
22
|
classList: classList || [],
|
|
19
23
|
};
|
|
20
24
|
if (staticResourceAttribute === null || staticResourceAttribute === void 0 ? void 0 : staticResourceAttribute.length) {
|
|
21
25
|
staticProps._staticResourceAttribute = staticResourceAttribute;
|
|
22
26
|
}
|
|
23
|
-
const { data = {} } = props;
|
|
24
27
|
Object.assign(staticProps, generatedDynamicData(data, compInfo).staticProps);
|
|
25
|
-
if ((
|
|
26
|
-
staticProps._waForKey = (
|
|
28
|
+
if ((_b = props.directives) === null || _b === void 0 ? void 0 : _b.waForKey) {
|
|
29
|
+
staticProps._waForKey = (_c = props.directives) === null || _c === void 0 ? void 0 : _c.waForKey.value;
|
|
27
30
|
}
|
|
28
31
|
return staticProps;
|
|
29
32
|
}
|
|
@@ -3,25 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.promisifyProcess = void 0;
|
|
4
4
|
function promisifyProcess(p, opts = {}) {
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
6
7
|
let stdout = '';
|
|
7
8
|
let stderr = '';
|
|
8
|
-
p.stdout
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
stderr += data;
|
|
19
|
-
}));
|
|
9
|
+
(_b = (_a = p.stdout) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, 'data', opts.onStdout ||
|
|
10
|
+
((data) => {
|
|
11
|
+
console.log(`${data}`);
|
|
12
|
+
stdout += data;
|
|
13
|
+
}));
|
|
14
|
+
(_d = (_c = p.stderr) === null || _c === void 0 ? void 0 : _c.on) === null || _d === void 0 ? void 0 : _d.call(_c, 'data', opts.onStderr ||
|
|
15
|
+
((data) => {
|
|
16
|
+
console.error(`${data}`);
|
|
17
|
+
stderr += data;
|
|
18
|
+
}));
|
|
20
19
|
p.on('error', reject);
|
|
21
20
|
p.on('exit', (exitCode) => {
|
|
22
|
-
exitCode === 0
|
|
23
|
-
? resolve(exitCode)
|
|
24
|
-
: reject(new Error(stderr || String(exitCode)));
|
|
21
|
+
exitCode === 0 ? resolve(exitCode) : reject(new Error(stderr || String(exitCode)));
|
|
25
22
|
});
|
|
26
23
|
});
|
|
27
24
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BabelTransform = void 0;
|
|
4
|
+
const core_1 = require("@babel/core");
|
|
5
|
+
function BabelTransform(code, options = {}) {
|
|
6
|
+
var _a;
|
|
7
|
+
const { IIFE = false } = options;
|
|
8
|
+
try {
|
|
9
|
+
const simpleWrapped = `(\n${code || 'undefined'}\n)`;
|
|
10
|
+
const { code: expression } = (0, core_1.transformSync)(IIFE ? `(()=>${simpleWrapped})()` : simpleWrapped, {
|
|
11
|
+
// plugins: ['transform-modules-commonjs', 'transform-react-jsx'],
|
|
12
|
+
cwd: __dirname,
|
|
13
|
+
sourceType: 'script',
|
|
14
|
+
comments: false,
|
|
15
|
+
// minified: true,
|
|
16
|
+
presets: [
|
|
17
|
+
[
|
|
18
|
+
'@babel/preset-env',
|
|
19
|
+
{
|
|
20
|
+
targets: {
|
|
21
|
+
// esmodules: true,
|
|
22
|
+
browsers: ['defaults', 'iOS >= 10', 'safari >= 10'],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
],
|
|
27
|
+
}) || {};
|
|
28
|
+
return ((_a = expression === null || expression === void 0 ? void 0 : expression.replace) === null || _a === void 0 ? void 0 : _a.call(expression, /;$/, '')) || code;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error(`transform [${code}] fail:`, e === null || e === void 0 ? void 0 : e.message);
|
|
32
|
+
return code;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.BabelTransform = BabelTransform;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.20",
|
|
4
4
|
"description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
|
|
5
5
|
"author": "yhsunshining@gmail.com",
|
|
6
6
|
"homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
|
|
@@ -32,14 +32,17 @@
|
|
|
32
32
|
"test": "jest",
|
|
33
33
|
"test:build": "ts-node ./__tests__/build.ts",
|
|
34
34
|
"dev:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
|
|
35
|
-
"build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js"
|
|
35
|
+
"build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js",
|
|
36
|
+
"build:template": "./scripts/buildTemplate.sh"
|
|
36
37
|
},
|
|
37
38
|
"bugs": {
|
|
38
39
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
42
|
+
"@babel/core": "^7.11.6",
|
|
43
|
+
"@babel/preset-env": "^7.4.4",
|
|
44
|
+
"@cloudbase/cals": "^1.0.15",
|
|
45
|
+
"@cloudbase/lowcode-generator": "^1.8.9",
|
|
43
46
|
"axios": "^0.21.0",
|
|
44
47
|
"browserfs": "^1.4.3",
|
|
45
48
|
"browserify-zlib": "^0.2.0",
|
|
Binary file
|
|
@@ -525,7 +525,7 @@
|
|
|
525
525
|
crossorigin="anonymous"
|
|
526
526
|
src="<%=
|
|
527
527
|
cdnEndpoints.cdngo
|
|
528
|
-
%>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.
|
|
528
|
+
%>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.42/dist/h5.browser.js"
|
|
529
529
|
></script>
|
|
530
530
|
<script
|
|
531
531
|
crossorigin
|
|
@@ -551,7 +551,7 @@
|
|
|
551
551
|
crossorigin
|
|
552
552
|
src="<%=
|
|
553
553
|
cdnEndpoints.cdngo
|
|
554
|
-
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.
|
|
554
|
+
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.f12ad33da9108405a333.bundle.js"
|
|
555
555
|
></script>
|
|
556
556
|
</body>
|
|
557
557
|
</html>
|
|
Binary file
|
|
Binary file
|
|
@@ -96,7 +96,9 @@ export function createEventHandlers(
|
|
|
96
96
|
* 取消判断待兼容
|
|
97
97
|
*/
|
|
98
98
|
if (pageId !== id /* || (__internal__ && !__internal__.active)*/) {
|
|
99
|
-
|
|
99
|
+
if (!name?.includes?.('onDataChange')) {
|
|
100
|
+
console.error(`Action error: [${name}] 页面生命周期结束,链式调用中断`);
|
|
101
|
+
}
|
|
100
102
|
return false;
|
|
101
103
|
}
|
|
102
104
|
}
|
|
@@ -160,7 +162,7 @@ export function createEventHandlers(
|
|
|
160
162
|
}
|
|
161
163
|
} catch (e) {
|
|
162
164
|
if (e.message) {
|
|
163
|
-
e.
|
|
165
|
+
e._target = `${currentTarget?.id || ''}[${trigger}:${l.key}]`
|
|
164
166
|
}
|
|
165
167
|
nextEventHandles[0].handlerName = l.key ? `${prefix}$${l.key}_fail` : '';
|
|
166
168
|
nextEventHandles[0].event.detail = isIfAction ? event.detail : e;
|
|
@@ -175,12 +177,12 @@ export function createEventHandlers(
|
|
|
175
177
|
const nextHandler = nextEventHandles[0];
|
|
176
178
|
|
|
177
179
|
if (!self[nextHandler.handlerName] && error) {
|
|
178
|
-
console.error(`Action error:`, error);
|
|
180
|
+
console.error(`Action error:`, generateErrorDebugMessage(error), error?.stack);
|
|
179
181
|
if (!looseError) {
|
|
180
182
|
if (app.__internal__?.env?.type !== 'production') {
|
|
181
183
|
app.showModal({
|
|
182
184
|
title: `事件响应失败`,
|
|
183
|
-
content: error
|
|
185
|
+
content: generateErrorDebugMessage(error) || error.errMsg || '',
|
|
184
186
|
showCancel: false,
|
|
185
187
|
});
|
|
186
188
|
} else {
|
|
@@ -231,6 +233,12 @@ export function createEventHandlers(
|
|
|
231
233
|
|
|
232
234
|
return evtHandlers;
|
|
233
235
|
}
|
|
236
|
+
|
|
237
|
+
function generateErrorDebugMessage(error) {
|
|
238
|
+
return `${error?._target ? `${error?._target}:` : ''}${error?.message || ''}`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
234
242
|
export function getDeep(target, key, keySeparator = '.') {
|
|
235
243
|
if (key == null) {
|
|
236
244
|
return target;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { observable } from 'mobx';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
createComputed,
|
|
4
|
+
createEventHandlers,
|
|
5
|
+
checkAuth,
|
|
6
|
+
getMpEventHandlerName,
|
|
7
|
+
generateDatasetQuery,
|
|
8
|
+
generateEventFlows,
|
|
9
|
+
} from './util';
|
|
10
|
+
import { createWidgets, createInitData, disposeWidget, getWidget } from './widget';
|
|
4
11
|
import mergeRenderer from './merge-renderer';
|
|
5
12
|
import {
|
|
6
13
|
createDataset,
|
|
@@ -10,10 +17,62 @@ import {
|
|
|
10
17
|
setConfig,
|
|
11
18
|
} from '../datasources/index';
|
|
12
19
|
import { runWatchers } from './watch';
|
|
13
|
-
import { $w as baseAPI } from '../app/weapps-api'
|
|
14
|
-
import { Event } from './event-emitter'
|
|
20
|
+
import { $w as baseAPI } from '../app/weapps-api';
|
|
21
|
+
import { Event } from './event-emitter';
|
|
22
|
+
import { generatePageUrl } from '@cloudbase/weda-client';
|
|
23
|
+
|
|
24
|
+
const wxApp = getApp();
|
|
15
25
|
|
|
16
|
-
|
|
26
|
+
function extractLifecycles(ctx, lifecycle, appShareMessage, resetShare = true) {
|
|
27
|
+
const result = {};
|
|
28
|
+
Object.keys(lifecycle).map((name) => {
|
|
29
|
+
result[name] = function () {
|
|
30
|
+
return lifecycle[name].apply(this._getInstance(), arguments);
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (resetShare) {
|
|
35
|
+
result['onShareAppMessage'] = (res) => {
|
|
36
|
+
if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
|
|
37
|
+
return res?.target?.dataset?.weda_share_info;
|
|
38
|
+
} else if (res?.from === 'menu' && appShareMessage?.enable) {
|
|
39
|
+
let { pageId, params, imageUrl, title, packageName } = appShareMessage || {};
|
|
40
|
+
return {
|
|
41
|
+
path: generatePageUrl({
|
|
42
|
+
pageId,
|
|
43
|
+
packageName,
|
|
44
|
+
params,
|
|
45
|
+
}),
|
|
46
|
+
imageUrl: ctx.app?.__internal__?.resolveStaticResourceUrl?.(imageUrl) || imageUrl,
|
|
47
|
+
title,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return lifecycle?.['onShareAppMessage']?.() || {};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.log(error);
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 更新设备信息 窗口信息
|
|
60
|
+
result['onResize'] = (res) => {
|
|
61
|
+
let device = baseAPI.device;
|
|
62
|
+
if (!device) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const width = res?.size?.windowWidth;
|
|
66
|
+
const height = res?.size?.windowHeight;
|
|
67
|
+
if (width !== device?.viewport?.width || height !== device?.viewport?.height) {
|
|
68
|
+
device.viewport = {
|
|
69
|
+
width,
|
|
70
|
+
height,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
17
76
|
|
|
18
77
|
export function createPage({
|
|
19
78
|
app,
|
|
@@ -30,70 +89,20 @@ export function createPage({
|
|
|
30
89
|
eventFlows = [],
|
|
31
90
|
pageContext = {},
|
|
32
91
|
pageAttributes = {},
|
|
92
|
+
resetShare = true,
|
|
33
93
|
}) {
|
|
34
94
|
const evtHandlers = createEventHandlers(evtListeners);
|
|
35
95
|
|
|
36
|
-
function extractLifecycles() {
|
|
37
|
-
const result = {};
|
|
38
|
-
Object.keys(lifecycle).map((name) => {
|
|
39
|
-
result[name] = function () {
|
|
40
|
-
return lifecycle[name].apply(this._getInstance(), arguments);
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
result['onShareAppMessage'] = (res) => {
|
|
45
|
-
if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
|
|
46
|
-
return res?.target?.dataset?.weda_share_info;
|
|
47
|
-
} else if (res?.from === 'menu' && pageAttributes?.appShareMessage) {
|
|
48
|
-
let { enable, pageId, params, imageUrl, title } = pageAttributes.appShareMessage;
|
|
49
|
-
if (enable) {
|
|
50
|
-
pageId = pageId ? pageId.replace(/^(\.)?\//, '') : pageId;
|
|
51
|
-
let realPath =
|
|
52
|
-
`/pages/${pageId}/index` +
|
|
53
|
-
(params ? '?' + params.map((pair) => pair.key + '=' + pair.value).join('&') : '');
|
|
54
|
-
return {
|
|
55
|
-
path: realPath,
|
|
56
|
-
imageUrl: app?.__internal__?.resolveStaticResourceUrl?.(imageUrl) || imageUrl,
|
|
57
|
-
title,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
return lifecycle?.['onShareAppMessage']?.() || {};
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.log(error);
|
|
65
|
-
return {};
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// 更新设备信息 窗口信息
|
|
70
|
-
result['onResize'] = (res) => {
|
|
71
|
-
let device = baseAPI.device;
|
|
72
|
-
if (!device) {
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
const width = res?.size?.windowWidth;
|
|
76
|
-
const height = res?.size?.windowHeight;
|
|
77
|
-
if (width !== device?.viewport?.width || height !== device?.viewport?.height) {
|
|
78
|
-
device.viewport = {
|
|
79
|
-
width,
|
|
80
|
-
height
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
96
|
return Component({
|
|
88
97
|
_componentType: 'page',
|
|
89
98
|
data: {
|
|
90
99
|
...createInitData(widgetProps, dataBinds),
|
|
91
100
|
_isCheckingAtuh: false,
|
|
92
|
-
weDaHasLogin: false
|
|
101
|
+
weDaHasLogin: false,
|
|
93
102
|
},
|
|
94
103
|
lifetimes: {
|
|
95
104
|
attached() {
|
|
96
|
-
this._disposers = []
|
|
105
|
+
this._disposers = [];
|
|
97
106
|
const $page = this._getInstance();
|
|
98
107
|
this._pageActive = true;
|
|
99
108
|
/**
|
|
@@ -125,8 +134,8 @@ export function createPage({
|
|
|
125
134
|
},
|
|
126
135
|
pageLifetimes: {
|
|
127
136
|
// 组件所在页面的生命周期函数,定义下给运营平台上报用
|
|
128
|
-
show: function () {
|
|
129
|
-
hide: function () {
|
|
137
|
+
show: function () {},
|
|
138
|
+
hide: function () {},
|
|
130
139
|
},
|
|
131
140
|
methods: {
|
|
132
141
|
_pageActive: true,
|
|
@@ -135,28 +144,28 @@ export function createPage({
|
|
|
135
144
|
_disposers: [],
|
|
136
145
|
|
|
137
146
|
/** page lifecycles **/
|
|
138
|
-
...extractLifecycles(),
|
|
147
|
+
...extractLifecycles({ app }, lifecycle, pageAttributes?.appShareMessage, resetShare),
|
|
139
148
|
...evtHandlers,
|
|
140
149
|
...mergeRenderer,
|
|
141
150
|
async beforePageCustomLaunch(query) {
|
|
142
151
|
if (!this._beforePageCustomLaunchPromise) {
|
|
143
152
|
this._beforePageCustomLaunchPromise = new Promise(async (resolve) => {
|
|
144
|
-
await wxApp.globaldata?._beforePageCustomLaunchPromise
|
|
153
|
+
await wxApp.globaldata?._beforePageCustomLaunchPromise;
|
|
145
154
|
const $page = this._getInstance();
|
|
146
155
|
if (query) {
|
|
147
156
|
EXTRA_API.setParams($page.uuid, query);
|
|
148
157
|
}
|
|
149
158
|
try {
|
|
150
|
-
this.setData({ _isCheckingAtuh: true })
|
|
159
|
+
this.setData({ _isCheckingAtuh: true });
|
|
151
160
|
const auth = await checkAuth(app, app.id, $page);
|
|
152
|
-
if(auth) {
|
|
161
|
+
if (auth) {
|
|
153
162
|
this.setData({
|
|
154
163
|
weDaHasLogin: true,
|
|
155
164
|
});
|
|
156
165
|
createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page, $w: $page.__internal__?.$w }));
|
|
157
166
|
}
|
|
158
167
|
} finally {
|
|
159
|
-
this.setData({ _isCheckingAtuh: false })
|
|
168
|
+
this.setData({ _isCheckingAtuh: false });
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
// eslint-disable-next-line no-restricted-syntax
|
|
@@ -164,16 +173,16 @@ export function createPage({
|
|
|
164
173
|
if ($page.dataset.query[queryId]?._schema?.trigger === 'auto') {
|
|
165
174
|
try {
|
|
166
175
|
$page.dataset.query[queryId].trigger();
|
|
167
|
-
this._disposers.push(() => $page.dataset.query[queryId].destroy())
|
|
176
|
+
this._disposers.push(() => $page.dataset.query[queryId].destroy());
|
|
168
177
|
} catch (e) {
|
|
169
178
|
console.error(`query ${queryId} 初始化失败:`, e);
|
|
170
179
|
}
|
|
171
180
|
}
|
|
172
181
|
}
|
|
173
|
-
resolve()
|
|
174
|
-
})
|
|
182
|
+
resolve();
|
|
183
|
+
});
|
|
175
184
|
}
|
|
176
|
-
return this._beforePageCustomLaunchPromise
|
|
185
|
+
return this._beforePageCustomLaunchPromise;
|
|
177
186
|
},
|
|
178
187
|
async onLoad(options) {
|
|
179
188
|
const $page = this._getInstance();
|
|
@@ -184,7 +193,7 @@ export function createPage({
|
|
|
184
193
|
|
|
185
194
|
this._query = decodePageQuery(options || {});
|
|
186
195
|
|
|
187
|
-
await this.beforePageCustomLaunch?.(this._query)
|
|
196
|
+
await this.beforePageCustomLaunch?.(this._query);
|
|
188
197
|
|
|
189
198
|
const hook = lifecycle.onLoad || lifecycle.onPageLoad;
|
|
190
199
|
await hook?.call?.($page, this._query);
|
|
@@ -215,7 +224,7 @@ export function createPage({
|
|
|
215
224
|
$page.__internal__.active = this._pageActive;
|
|
216
225
|
app.__internal__.activePage = $page;
|
|
217
226
|
|
|
218
|
-
await this.beforePageCustomLaunch?.(this._query)
|
|
227
|
+
await this.beforePageCustomLaunch?.(this._query);
|
|
219
228
|
|
|
220
229
|
const hook = lifecycle.onShow || lifecycle.onPageShow;
|
|
221
230
|
await hook?.call?.($page);
|
|
@@ -235,9 +244,9 @@ export function createPage({
|
|
|
235
244
|
const keyName = getMpEventHandlerName(id, triggerName);
|
|
236
245
|
const event = new Event({
|
|
237
246
|
type: triggerName,
|
|
238
|
-
detail: params
|
|
239
|
-
})
|
|
240
|
-
return this[keyName]?.call?.(this, event)
|
|
247
|
+
detail: params,
|
|
248
|
+
});
|
|
249
|
+
return this[keyName]?.call?.(this, event);
|
|
241
250
|
},
|
|
242
251
|
_getInstance() {
|
|
243
252
|
let $page = this.$WEAPPS_PAGE;
|
|
@@ -255,8 +264,8 @@ export function createPage({
|
|
|
255
264
|
$page.handler = Object.keys(handlers).reduce((result, key) => {
|
|
256
265
|
try {
|
|
257
266
|
result[key] = handlers[key].bind($page);
|
|
258
|
-
} catch(e) {
|
|
259
|
-
console.error('添加页面handler失败', e)
|
|
267
|
+
} catch (e) {
|
|
268
|
+
console.error('添加页面handler失败', e);
|
|
260
269
|
}
|
|
261
270
|
return result;
|
|
262
271
|
}, {});
|
|
@@ -266,7 +275,7 @@ export function createPage({
|
|
|
266
275
|
$w: $page.__internal__.$w,
|
|
267
276
|
$app: app,
|
|
268
277
|
$page,
|
|
269
|
-
})
|
|
278
|
+
});
|
|
270
279
|
$page.dataset = dataset;
|
|
271
280
|
$page.state.dataset = dataset;
|
|
272
281
|
$page.setState = (userSetState) => {
|
|
@@ -276,7 +285,7 @@ export function createPage({
|
|
|
276
285
|
};
|
|
277
286
|
|
|
278
287
|
const { widgets, rootWidget } = createWidgets(widgetProps, dataBinds, this, $page.widgets);
|
|
279
|
-
$page.widgets = widgets
|
|
288
|
+
$page.widgets = widgets;
|
|
280
289
|
$page._rootWidget = rootWidget;
|
|
281
290
|
|
|
282
291
|
$page.invokeComponentMethod = ({ component, method, params }) => {
|