@cloudbase/lowcode-builder 0.1.0 → 0.1.4
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/builder/core/index.d.ts +1 -0
- package/lib/builder/core/index.js +3 -1
- package/lib/builder/h5/copy.js +17 -3
- package/lib/builder/mp/index.js +58 -48
- package/lib/builder/mp/wxml.js +5 -1
- package/package.json +6 -5
- package/template/html/index.html.ejs +6 -9
- package/template/mp/app/weapps-api.js +17 -45
- package/template/mp/app.js +66 -66
- package/template/mp/common/weapp-page.js +3 -1
- package/template/mp/datasources/config.js.tpl +1 -1
- package/template/mp/datasources/datasource-profiles.js.tpl +1 -1
- package/template/mp/datasources/index.js +13 -4
- package/template/mp/package.json +12 -11
- package/template/package.json +4 -2
- package/template/src/app/global-api.js +6 -83
- package/template/src/app/material-actions.js +15 -13
- package/template/src/datasources/index.js +15 -2
- package/template/src/index.jsx +1 -1
- package/template/webpack/web.prod.js +62 -41
- package/lib/generate.d.ts +0 -1
- package/lib/generate.js +0 -60
- package/lib/tests/build.d.ts +0 -1
- package/lib/tests/build.js +0 -19
- package/lib/tests/build.test.d.ts +0 -1
- package/lib/tests/build.test.js +0 -22
- package/lib/tests/data.d.ts +0 -18
- package/lib/tests/data.js +0 -94216
- package/lib/utils/postProcess copy.d.ts +0 -2
- package/lib/utils/postProcess copy.js +0 -27
- package/template/src/pages/composite.tpl +0 -151
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IInstallOpts } from '../service/webpack';
|
|
2
|
+
export { getCompileDirs } from '../util';
|
|
2
3
|
import { IMaterialItem, IWeAppData, IPlugin, IExtraData } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
3
4
|
import { BuildType, GenerateMpType, WebpackBuildCallBack, WebpackModeType } from '../types/common';
|
|
4
5
|
import { DEPLOY_MODE, RUNTIME } from '../../types';
|
|
@@ -3,10 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.version = exports.installDep = exports.cleanComponentDir = exports.buildWedaApp = void 0;
|
|
6
|
+
exports.version = exports.installDep = exports.cleanComponentDir = exports.buildWedaApp = exports.getCompileDirs = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const webpack_1 = require("../service/webpack");
|
|
9
9
|
const util_1 = require("../util");
|
|
10
|
+
var util_2 = require("../util");
|
|
11
|
+
Object.defineProperty(exports, "getCompileDirs", { enumerable: true, get: function () { return util_2.getCompileDirs; } });
|
|
10
12
|
const common_1 = require("../types/common");
|
|
11
13
|
const index_1 = require("../mp/index");
|
|
12
14
|
const path_1 = __importDefault(require("path"));
|
package/lib/builder/h5/copy.js
CHANGED
|
@@ -55,7 +55,7 @@ exports.runCopy = runCopy;
|
|
|
55
55
|
async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDir) {
|
|
56
56
|
const localPkg = (0, common_1.getCurrentPackageJson)();
|
|
57
57
|
await Promise.all(dependencies.map(async (componentLib) => {
|
|
58
|
-
var _a;
|
|
58
|
+
var _a, _b, _c, _d, _e;
|
|
59
59
|
const { name, version } = componentLib;
|
|
60
60
|
const materialNameVersion = `${name}@${version}`;
|
|
61
61
|
const materialDir = path.join(materialsDir, materialNameVersion);
|
|
@@ -86,6 +86,9 @@ async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDi
|
|
|
86
86
|
// 副作用修改了dependence定义,trycatch 不阻塞主流程
|
|
87
87
|
try {
|
|
88
88
|
const meta = (0, common_1.readComponentLibMata)(librariesDir);
|
|
89
|
+
if (meta === null || meta === void 0 ? void 0 : meta.schemaVersion) {
|
|
90
|
+
componentLib['schemaVersion'] = meta === null || meta === void 0 ? void 0 : meta.schemaVersion;
|
|
91
|
+
}
|
|
89
92
|
let [major] = ((_a = meta === null || meta === void 0 ? void 0 : meta.schemaVersion) === null || _a === void 0 ? void 0 : _a.split('.')) || [];
|
|
90
93
|
if (Number(major) >= 3) {
|
|
91
94
|
componentLib['isPlainProps'] = true;
|
|
@@ -94,8 +97,19 @@ async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDi
|
|
|
94
97
|
catch (e) { }
|
|
95
98
|
try {
|
|
96
99
|
const packageJson = fs_extra_1.default.readJsonSync(path.join(materialDir, 'package.json'));
|
|
97
|
-
if (packageJson.
|
|
98
|
-
|
|
100
|
+
if ((_c = (_b = packageJson.weda) === null || _b === void 0 ? void 0 : _b.platform) === null || _c === void 0 ? void 0 : _c.web) {
|
|
101
|
+
const entries = (_e = (_d = packageJson.weda) === null || _d === void 0 ? void 0 : _d.platform) === null || _e === void 0 ? void 0 : _e.web;
|
|
102
|
+
componentLib['entries'] = {
|
|
103
|
+
entry: path.posix.relative(srcDir, entries.entry),
|
|
104
|
+
components: path.posix.relative(srcDir, entries.components),
|
|
105
|
+
actions: path.posix.relative(srcDir, entries.actions),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
else if (packageJson.lowcode) {
|
|
109
|
+
const entry = path.posix.relative(srcDir, packageJson.lowcode);
|
|
110
|
+
componentLib['entries'] = {
|
|
111
|
+
entry,
|
|
112
|
+
};
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
115
|
catch (e) { }
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -93,31 +93,42 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
93
93
|
const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
|
|
94
94
|
await generateFramework(mainAppData, miniprogramRoot, buildContext);
|
|
95
95
|
// #3 生成主包根路径文件
|
|
96
|
-
let appFileData = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
96
|
+
let appFileData = {};
|
|
97
|
+
if (weapps.find((item) => !item.mpPkgUrl)) {
|
|
98
|
+
await generateFramework(mainAppData, miniprogramRoot, buildContext);
|
|
99
|
+
// 有了 framework app 之后,并且是源码的方式,追加 app 引用
|
|
100
|
+
if (mainAppData.mpPkgUrl) {
|
|
101
|
+
let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
|
|
102
|
+
let appJsContent = await fs.readFile(appJsPath);
|
|
103
|
+
await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
|
|
104
|
+
}
|
|
105
|
+
appFileData = {
|
|
106
|
+
...appFileData,
|
|
107
|
+
'common/style.js': {},
|
|
108
|
+
'common/utils.wxs': {
|
|
109
|
+
domain: domain,
|
|
110
|
+
},
|
|
111
|
+
'common/util.js': {
|
|
112
|
+
isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
113
|
+
},
|
|
114
|
+
'common/widget.js': {},
|
|
115
|
+
'common/url.js': {},
|
|
116
|
+
'common/weapp-sdk.js': {},
|
|
117
|
+
'common/weapp-page.js': {
|
|
118
|
+
dataPropNames: wxmlDataPrefix,
|
|
119
|
+
debug: buildContext.debugMode,
|
|
120
|
+
},
|
|
121
|
+
'common/weapp-component.js': {},
|
|
122
|
+
'common/merge-renderer.js': {
|
|
123
|
+
dataPropNames: wxmlDataPrefix,
|
|
124
|
+
debug: buildContext.debugMode,
|
|
125
|
+
},
|
|
126
|
+
'common/process.js': {},
|
|
127
|
+
'common/data-patch.js': {},
|
|
128
|
+
'common/event-emitter.js': {},
|
|
129
|
+
'common/watch.js': {},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
121
132
|
if (mainAppData.mpPkgUrl) {
|
|
122
133
|
// 合并 project 和 app json
|
|
123
134
|
if (!projectConfigJson.setting) {
|
|
@@ -142,9 +153,6 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
142
153
|
}
|
|
143
154
|
appJson.subpackages = subpackages;
|
|
144
155
|
await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
|
|
145
|
-
let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
|
|
146
|
-
let appJsContent = await fs.readFile(appJsPath);
|
|
147
|
-
await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
|
|
148
156
|
}
|
|
149
157
|
else {
|
|
150
158
|
appFileData = {
|
|
@@ -178,26 +186,28 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
178
186
|
await fs.move(path_1.default.join(projDir, config_1.materialsDirName), path_1.default.join(miniprogramRoot, config_1.materialsDirName));
|
|
179
187
|
}
|
|
180
188
|
// 生成数据源
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
189
|
+
if (weapps.find((item) => !item.mpPkgUrl)) {
|
|
190
|
+
const datasourceFileData = {
|
|
191
|
+
'datasources/index.js': {},
|
|
192
|
+
'datasources/config.js.tpl': {
|
|
193
|
+
envID: mainAppData.envId,
|
|
194
|
+
appID: appId,
|
|
195
|
+
resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
|
|
196
|
+
isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
|
|
197
|
+
},
|
|
198
|
+
'datasources/datasource-profiles.js.tpl': {
|
|
199
|
+
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(weapps.reduce((datasources, app) => {
|
|
200
|
+
datasources.push(...(app.datasources || []));
|
|
201
|
+
return datasources;
|
|
202
|
+
}, [])), { EOL: false }),
|
|
203
|
+
},
|
|
204
|
+
'datasources/dataset-profiles.js.tpl': {
|
|
205
|
+
datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, weapps), { EOL: true }),
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
console.log('Generating ' + em('datasources') + ' files');
|
|
209
|
+
await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot, buildContext);
|
|
210
|
+
}
|
|
201
211
|
// 生成子包
|
|
202
212
|
await Promise.all(weapps.map(async (app, index) => {
|
|
203
213
|
if (index == 0) {
|
package/lib/builder/mp/wxml.js
CHANGED
|
@@ -105,7 +105,11 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
105
105
|
elements.push({
|
|
106
106
|
type: 'element',
|
|
107
107
|
name: tagName,
|
|
108
|
-
attributes: {
|
|
108
|
+
attributes: {
|
|
109
|
+
name: data0.name.type && data0.name.type !== 'static'
|
|
110
|
+
? `{{${id}.name}}`
|
|
111
|
+
: data0.name.value,
|
|
112
|
+
},
|
|
109
113
|
elements: [],
|
|
110
114
|
_order: xIndex || 0,
|
|
111
115
|
_parent: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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",
|
|
@@ -26,14 +26,15 @@
|
|
|
26
26
|
"dev": "tsc -w",
|
|
27
27
|
"develop": "tsc -w",
|
|
28
28
|
"build": "tsc",
|
|
29
|
-
"test": "jest"
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:build": "ts-node ./__test__/build.ts"
|
|
30
31
|
},
|
|
31
32
|
"bugs": {
|
|
32
33
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@cloudbase/cals": "0.3.3",
|
|
36
|
-
"@cloudbase/lowcode-generator": "0.
|
|
36
|
+
"@cloudbase/cals": "^0.3.3",
|
|
37
|
+
"@cloudbase/lowcode-generator": "^0.6.13",
|
|
37
38
|
"axios": "^0.21.0",
|
|
38
39
|
"chalk": "^2.4.2",
|
|
39
40
|
"compare-versions": "^3.6.0",
|
|
@@ -67,4 +68,4 @@
|
|
|
67
68
|
"ts-node": "^10.4.0",
|
|
68
69
|
"typescript": "^4.4.2"
|
|
69
70
|
}
|
|
70
|
-
}
|
|
71
|
+
}
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
<% if(mode !== 'production'){ %>
|
|
27
27
|
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
|
|
28
28
|
<script>new VConsole()</script> -->
|
|
29
|
-
<% }%> <% Array.isArray(jsApis) &&
|
|
30
|
-
|
|
29
|
+
<% }%> <% Array.isArray(jsApis) && jsApis.filter(function(item){return
|
|
30
|
+
!!item}).forEach(function(jsApi){%>
|
|
31
31
|
<script src="<%=jsApi %>"></script>
|
|
32
32
|
<% })%>
|
|
33
33
|
|
|
@@ -373,10 +373,8 @@
|
|
|
373
373
|
<div id="root" class="main-wrap"></div>
|
|
374
374
|
<% if(canUseVite){ %>
|
|
375
375
|
<script type="module" src="/src/index.jsx"></script>
|
|
376
|
-
<% } %>
|
|
377
|
-
|
|
378
|
-
<% if(!isAdminPortal){ %>
|
|
379
|
-
<script src="//imgcache.qq.com/qcloud/cloudbase-js-sdk/1.5.3-alpha.0/cloudbase.full.js"></script>
|
|
376
|
+
<% } %> <% if(!isAdminPortal){ %>
|
|
377
|
+
<script src="https://imgcache.qq.com/qcloud/cloudbase-js-sdk/1.5.3-alpha.0/cloudbase.full.js"></script>
|
|
380
378
|
<% }%>
|
|
381
379
|
<script>
|
|
382
380
|
if (window.cloudbase) {
|
|
@@ -431,10 +429,9 @@
|
|
|
431
429
|
}
|
|
432
430
|
</script>
|
|
433
431
|
<script
|
|
434
|
-
src="
|
|
432
|
+
src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/ajax/libs/mobx/5.15.7/mobx.umd.js"
|
|
435
433
|
crossorigin="anonymous"
|
|
436
434
|
></script>
|
|
437
|
-
<script src="
|
|
438
|
-
<script src="//qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/npm/@zxing/library@0.18.6/umd/index.min.js"></script>
|
|
435
|
+
<script src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/npm/@zxing/library@0.18.6/umd/index.min.js"></script>
|
|
439
436
|
</body>
|
|
440
437
|
</html>
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { observable } from 'mobx'
|
|
2
|
-
import {
|
|
2
|
+
import { createMpApp } from '@cloudbase/weda-client';
|
|
3
|
+
import { createComputed } from '<%= subLevelPath %>../common/util'
|
|
3
4
|
import process from '<%= subLevelPath %>../common/process'
|
|
4
|
-
import { DS_SDK, CLOUD_SDK, createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
|
|
5
5
|
import appGlobal from '<%= subLevelPath %>../app/app-global'
|
|
6
|
-
import
|
|
6
|
+
import { createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
|
|
7
7
|
|
|
8
8
|
<% if (!isBare) {%>
|
|
9
9
|
import state from '../lowcode/state'
|
|
10
|
-
import computed from '../lowcode/computed'
|
|
11
|
-
import common from './common'
|
|
10
|
+
import computed from '../lowcode/computed'
|
|
11
|
+
import common from './common'
|
|
12
12
|
<%} else {%>
|
|
13
13
|
const state = {}
|
|
14
|
-
const computed ={}
|
|
15
|
-
const common = {}
|
|
16
|
-
<%}%>
|
|
14
|
+
const computed = {}
|
|
15
|
+
const common = {}
|
|
16
|
+
<%}%>
|
|
17
17
|
|
|
18
18
|
const mainAppKey = '__weappsMainApp'
|
|
19
19
|
|
|
@@ -21,12 +21,11 @@ export const app = createGlboalApi()
|
|
|
21
21
|
export { process }
|
|
22
22
|
|
|
23
23
|
function createGlboalApi() {
|
|
24
|
+
const mpApp = createMpApp();
|
|
24
25
|
const globalAPI = {
|
|
25
26
|
id: '<%= appId %>',
|
|
26
27
|
domain: '<%= domain %>',
|
|
27
|
-
platform: 'MINIPROGRAME',
|
|
28
28
|
activePage: null,
|
|
29
|
-
dataSources: DS_SDK,
|
|
30
29
|
pages: {},
|
|
31
30
|
session: {
|
|
32
31
|
//configure: sdk.configure,
|
|
@@ -36,11 +35,7 @@ function createGlboalApi() {
|
|
|
36
35
|
state: observable(state),
|
|
37
36
|
computed: createComputed(computed),
|
|
38
37
|
common,
|
|
39
|
-
|
|
40
|
-
formatDate,
|
|
41
|
-
get: getter,
|
|
42
|
-
set: setter,
|
|
43
|
-
},
|
|
38
|
+
...mpApp
|
|
44
39
|
// ... other sdk apis & apis from mp
|
|
45
40
|
} // The global api exposed to lowcode
|
|
46
41
|
|
|
@@ -52,18 +47,16 @@ function createGlboalApi() {
|
|
|
52
47
|
globalAPI.utils.set(globalAPI.dataset.state, keyPath, userSetState[keyPath]);
|
|
53
48
|
});
|
|
54
49
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
/**
|
|
51
|
+
* 内部通用的设置状态变量值的方法
|
|
52
|
+
* varPath 结构为 $global.<变量名> 即全局变量
|
|
53
|
+
* $page.<变量名> 即当前页面变量
|
|
54
|
+
* <pageId>.<变量名> 指定页面 pageId 的变量 (应当避免修改非当前页面的变量值)
|
|
55
|
+
*/
|
|
61
56
|
globalAPI._setStateVal = (config) => {
|
|
62
57
|
// @ts-ignore
|
|
63
58
|
EXTRA_API.setState(config.varPath, config.val);
|
|
64
59
|
};
|
|
65
|
-
// mount wx apis
|
|
66
|
-
Object.assign(globalAPI, weappApis)
|
|
67
60
|
|
|
68
61
|
const subPackageName = '<%= subPackageName %>'
|
|
69
62
|
if (subPackageName) {
|
|
@@ -75,33 +68,12 @@ function createGlboalApi() {
|
|
|
75
68
|
// is mainApp
|
|
76
69
|
appGlobal[mainAppKey] = globalAPI
|
|
77
70
|
}
|
|
78
|
-
// 避免被wx.cloud 覆盖
|
|
79
|
-
globalAPI.cloud = CLOUD_SDK
|
|
80
71
|
|
|
81
72
|
// # expose some sdk modules
|
|
82
73
|
/* const sdkModsIncluded = ['flow', 'getPageOptions', 'getLaunchOptions']
|
|
83
74
|
sdkModsIncluded.forEach(key => {
|
|
84
75
|
globalAPI[key] = sdk[key]
|
|
85
76
|
}) */
|
|
86
|
-
|
|
87
|
-
globalAPI.scanCode = (options) => {
|
|
88
|
-
const {enableDefaultBehavior, ...restOptions} = options;
|
|
89
|
-
const shouldReturnPromise = (!restOptions.success && !restOptions.complete && !restOptions.fail);
|
|
90
|
-
if(shouldReturnPromise) {
|
|
91
|
-
return new Promise((resolve, reject) => {
|
|
92
|
-
scanCode(restOptions).then((res) => {
|
|
93
|
-
if(enableDefaultBehavior) {
|
|
94
|
-
globalAPI.showModal({
|
|
95
|
-
title: '扫描到以下内容',
|
|
96
|
-
content: res.result,
|
|
97
|
-
showCancel: false,
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
resolve(res)
|
|
101
|
-
})
|
|
102
|
-
.catch(reject)
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
}
|
|
77
|
+
|
|
106
78
|
return globalAPI
|
|
107
79
|
}
|
package/template/mp/app.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { setConfig } from '
|
|
1
|
+
import { setConfig } from './datasources/index'
|
|
2
2
|
import lifeCycle from './lowcode/lifecycle'
|
|
3
3
|
import { app } from './app/weapps-api'
|
|
4
4
|
import WxReportV2 from './common/wx_yypt_report_v2'
|
|
5
5
|
// 引入数据源管理器并进行初始化
|
|
6
6
|
import { EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
|
|
7
7
|
const $app = app;
|
|
8
|
-
<% if(yyptConfig.yyptAppKey) { %>
|
|
8
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
9
9
|
const wxReport = new WxReportV2({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
appKey: '<%= yyptConfig.yyptAppKey %>', // 填入你申请的运营平台的应用key(必填)
|
|
11
|
+
reportUrl: '<%= yyptConfig.reportUrl %><%= yyptConfig.yyptAppKey %>', // 上报url(把后端上报接口需要先挂网关,该url填写网关地址)
|
|
12
|
+
autoReportPV: true, // 是否自动上报页面PV
|
|
13
|
+
// getRemoteParamsUrl获取远程参数url,主要用于获取intervalTime、reportLogsNum和stopReport参数,
|
|
14
|
+
// 返回格式{stopReport:true,intervalTime:3,reportLogsNum:5}
|
|
15
|
+
getRemoteParamsUrl: '',
|
|
16
|
+
stopReport: <%= yyptConfig.stopReport %>, // 停止上报
|
|
17
|
+
intervalTime: 3, // 间隔多久执行一次上报,默认3秒
|
|
18
|
+
reportLogsNum: 5, // 每次合并上报记录条数,默认5次
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
// 设置数据源请求的 loading 及 toast 处理
|
|
22
|
-
setConfig({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
<% }%>
|
|
37
|
-
App({
|
|
38
|
-
onLaunch(options) {
|
|
39
|
-
this.app = app
|
|
40
|
-
const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
|
|
41
|
-
let { query={} } = options
|
|
42
|
-
EXTRA_API.setParams('$global', query )
|
|
43
|
-
createStateDataSourceVar('$global', generateParamsParser({app}))
|
|
21
|
+
// 设置数据源请求的 loading 及 toast 处理
|
|
22
|
+
setConfig({
|
|
23
|
+
beforeDSRequest: (cfg) => {
|
|
24
|
+
if (!cfg.options || !cfg.options.showLoading) return
|
|
25
|
+
app.showLoading()
|
|
26
|
+
},
|
|
27
|
+
afterDSRequest: (cfg, error, result) => {
|
|
28
|
+
if (!cfg.options) return
|
|
29
|
+
if (cfg.options.showLoading) app.hideLoading()
|
|
30
|
+
if (!cfg.options.showToast) return
|
|
31
|
+
const isSuccess = !error && result && !result.code
|
|
32
|
+
app.showToast({ icon: isSuccess ? 'success' : 'error' })
|
|
33
|
+
}
|
|
34
|
+
})
|
|
44
35
|
|
|
45
|
-
onLaunch && onLaunch.call(this, options)
|
|
46
|
-
<% if(yyptConfig.yyptAppKey) { %>
|
|
47
|
-
// 挂运营平台上报对象到app里
|
|
48
|
-
app.yyptReport = wxReport
|
|
49
36
|
<% }%>
|
|
37
|
+
App({
|
|
38
|
+
onLaunch(options) {
|
|
39
|
+
this.app = app
|
|
40
|
+
const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
|
|
41
|
+
let { query = {} } = options
|
|
42
|
+
EXTRA_API.setParams('$global', query)
|
|
43
|
+
createStateDataSourceVar('$global', generateParamsParser({ app }))
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const fn = lifeCycle.onError || lifeCycle.onAppError
|
|
69
|
-
fn && fn.call(this, msg)
|
|
70
|
-
},
|
|
71
|
-
onPageNotFound() {
|
|
72
|
-
const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
|
|
73
|
-
fn && fn.call(this)
|
|
74
|
-
},
|
|
75
|
-
onUnhandledRejection() {
|
|
76
|
-
const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
|
|
77
|
-
fn && fn.call(this)
|
|
45
|
+
onLaunch && onLaunch.call(this, options)
|
|
46
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
47
|
+
// 挂运营平台上报对象到app里
|
|
48
|
+
app.yyptReport = wxReport
|
|
49
|
+
<% }%>
|
|
50
|
+
|
|
51
|
+
// 初始私有全局数据
|
|
52
|
+
this.$$global = {
|
|
53
|
+
homePageId: '<%= appConfig.homePageId %>'
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
onShow(options) {
|
|
57
|
+
const fn = lifeCycle.onShow || lifeCycle.onAppShow
|
|
58
|
+
fn && fn.call(this, options)
|
|
59
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
60
|
+
wxReport.startReport()
|
|
61
|
+
<% }%>
|
|
78
62
|
},
|
|
79
|
-
|
|
63
|
+
onHide() {
|
|
64
|
+
const fn = lifeCycle.onHide || lifeCycle.onAppHide
|
|
65
|
+
fn && fn.call(this)
|
|
66
|
+
},
|
|
67
|
+
onError(msg) {
|
|
68
|
+
const fn = lifeCycle.onError || lifeCycle.onAppError
|
|
69
|
+
fn && fn.call(this, msg)
|
|
70
|
+
},
|
|
71
|
+
onPageNotFound() {
|
|
72
|
+
const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
|
|
73
|
+
fn && fn.call(this)
|
|
74
|
+
},
|
|
75
|
+
onUnhandledRejection() {
|
|
76
|
+
const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
|
|
77
|
+
fn && fn.call(this)
|
|
78
|
+
},
|
|
79
|
+
})
|
|
@@ -2,7 +2,7 @@ import { observable } from 'mobx';
|
|
|
2
2
|
import { createComputed, createEventHandlers, checkAuth } from './util';
|
|
3
3
|
import { createWidgets, createInitData, disposeWidget } from './widget';
|
|
4
4
|
import mergeRenderer from './merge-renderer';
|
|
5
|
-
import { createDataset, EXTRA_API, createStateDataSourceVar, generateParamsParser } from '../datasources/index';
|
|
5
|
+
import { createDataset, EXTRA_API, createStateDataSourceVar, generateParamsParser, setConfig } from '../datasources/index';
|
|
6
6
|
import { runWatchers } from './watch'
|
|
7
7
|
|
|
8
8
|
export function createPage(
|
|
@@ -71,6 +71,7 @@ export function createPage(
|
|
|
71
71
|
...mergeRenderer,
|
|
72
72
|
onLoad(options) {
|
|
73
73
|
const $page = this.getWeAppInst()
|
|
74
|
+
setConfig({ currentPageId: $page.uuid });
|
|
74
75
|
app.activePage = $page;
|
|
75
76
|
this._pageActive = true;
|
|
76
77
|
|
|
@@ -97,6 +98,7 @@ export function createPage(
|
|
|
97
98
|
},
|
|
98
99
|
async onShow() {
|
|
99
100
|
const $page = this.getWeAppInst()
|
|
101
|
+
setConfig({ currentPageId: $page.uuid });
|
|
100
102
|
app.activePage = $page;
|
|
101
103
|
this._pageActive = true;
|
|
102
104
|
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WEDA_CLOUD_SDK } from '@cloudbase/weda-client'
|
|
2
|
+
const {
|
|
2
3
|
setConfig,
|
|
3
4
|
initTcb,
|
|
4
|
-
CLOUD_SDK
|
|
5
|
-
|
|
5
|
+
CLOUD_SDK,
|
|
6
|
+
createDataset,
|
|
7
|
+
createStateDataSourceVar,
|
|
8
|
+
generateParamsParser,
|
|
9
|
+
EXTRA_API,
|
|
10
|
+
DS_API,
|
|
11
|
+
DS_SDK
|
|
12
|
+
} = WEDA_CLOUD_SDK
|
|
13
|
+
|
|
6
14
|
export {
|
|
7
15
|
createDataset,
|
|
8
16
|
createStateDataSourceVar,
|
|
@@ -11,7 +19,8 @@ export {
|
|
|
11
19
|
CLOUD_SDK,
|
|
12
20
|
DS_API,
|
|
13
21
|
DS_SDK,
|
|
14
|
-
|
|
22
|
+
setConfig
|
|
23
|
+
}
|
|
15
24
|
|
|
16
25
|
import config from './config'
|
|
17
26
|
|
package/template/mp/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lcap-<%= appId%>",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"scripts": {
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"scripts": {},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@cloudbase/weda-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
"@cloudbase/weda-client": "stable",
|
|
7
|
+
"mobx": "^5.15.4",
|
|
8
|
+
"lodash.get": "^4.4.2",
|
|
9
|
+
"lodash.set": "^4.3.2",
|
|
10
|
+
"miniprogram-gesture": "^1.0.6",
|
|
11
|
+
"miniprogram-api-promise": "^1.0.4"<% Object.keys(extraDeps).map(depName => {%>,
|
|
12
|
+
"<%= depName%>": "<%= extraDeps[depName]%>"<%
|
|
13
|
+
})
|
|
13
14
|
%>
|
|
14
|
-
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
}
|