@cloudbase/lowcode-builder 0.0.5 → 0.1.3
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 +2 -0
- package/lib/builder/core/index.js +7 -1
- package/lib/builder/h5/copy.js +17 -3
- package/lib/builder/mp/wxml.js +5 -1
- package/lib/tests/build.js +2 -0
- package/lib/tests/build.test.js +2 -0
- package/package.json +5 -3
- 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/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';
|
|
@@ -37,6 +38,7 @@ export interface IBuildWedaApp extends IBaseAppProps {
|
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
|
|
41
|
+
export declare function cleanComponentDir(): Promise<void>;
|
|
40
42
|
export declare function installDep(dir: any, opts?: IInstallOpts): Promise<void>;
|
|
41
43
|
export declare const version: any;
|
|
42
44
|
export default buildWedaApp;
|
|
@@ -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.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"));
|
|
@@ -122,6 +124,10 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
exports.buildWedaApp = buildWedaApp;
|
|
127
|
+
async function cleanComponentDir() {
|
|
128
|
+
return fs_extra_1.default.emptyDir((0, util_1.getCompileDirs)().materialsDir);
|
|
129
|
+
}
|
|
130
|
+
exports.cleanComponentDir = cleanComponentDir;
|
|
125
131
|
function installDep(dir, opts = {}) {
|
|
126
132
|
return (0, webpack_1.installDependencies)(dir, opts);
|
|
127
133
|
}
|
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/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/lib/tests/build.js
CHANGED
|
@@ -7,10 +7,12 @@ const index_1 = require("../index");
|
|
|
7
7
|
const data_1 = __importDefault(require("./data"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const common_1 = require("../src/builder/types/common");
|
|
10
11
|
const outPath = path_1.default.resolve(__dirname, '.temp');
|
|
11
12
|
fs_extra_1.default.emptyDirSync(outPath);
|
|
12
13
|
(0, index_1.buildWedaApp)({
|
|
13
14
|
...data_1.default,
|
|
15
|
+
buildTypeList: [common_1.BuildType.WEB],
|
|
14
16
|
output: { path: outPath },
|
|
15
17
|
}).then((dir) => {
|
|
16
18
|
console.log(dir);
|
package/lib/tests/build.test.js
CHANGED
|
@@ -7,12 +7,14 @@ const index_1 = require("../index");
|
|
|
7
7
|
const data_1 = __importDefault(require("./data"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const common_1 = require("../lib/builder/types/common");
|
|
10
11
|
describe('build', () => {
|
|
11
12
|
it('needs tests', async () => {
|
|
12
13
|
const outPath = path_1.default.resolve(__dirname, './temp');
|
|
13
14
|
fs_extra_1.default.emptyDir(outPath);
|
|
14
15
|
let dir = await (0, index_1.buildWedaApp)({
|
|
15
16
|
...data_1.default,
|
|
17
|
+
buildTypeList: [common_1.BuildType.WEB],
|
|
16
18
|
output: { path: outPath },
|
|
17
19
|
});
|
|
18
20
|
console.log(dir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.3",
|
|
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
36
|
"@cloudbase/cals": "0.3.3",
|
|
36
|
-
"@cloudbase/lowcode-generator": "0.
|
|
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",
|
|
@@ -64,6 +65,7 @@
|
|
|
64
65
|
"csstype": "^2.6.10",
|
|
65
66
|
"jest": "^26.0.1",
|
|
66
67
|
"ts-jest": "^27.0.5",
|
|
68
|
+
"ts-node": "^10.4.0",
|
|
67
69
|
"typescript": "^4.4.2"
|
|
68
70
|
}
|
|
69
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
|
+
}
|
package/template/package.json
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@cloudbase/js-sdk": "1.5.3-alpha.0",
|
|
9
|
-
"@cloudbase/weda-cloud-sdk": "stable",
|
|
10
9
|
"@tcwd/weapps-core": "2.2.6",
|
|
11
10
|
"@tcwd/weapps-sdk": "1.2.9",
|
|
12
11
|
"@zxing/library": "^0.18.6",
|
|
12
|
+
"@cloudbase/weda-client": "stable",
|
|
13
13
|
"fastclick": "^1.0.6",
|
|
14
14
|
"lodash": "^4.17.19",
|
|
15
15
|
"mobx": "^5.15.4",
|
|
@@ -54,8 +54,10 @@
|
|
|
54
54
|
"mini-css-extract-plugin": "^0.8.0",
|
|
55
55
|
"hard-source-webpack-plugin": "^0.13.1",
|
|
56
56
|
"html-webpack-plugin": "^3.2.0",
|
|
57
|
+
"ts-loader": "^8.3.0",
|
|
58
|
+
"typescript": "^4.4.4",
|
|
57
59
|
"webpack": "^4.41.4",
|
|
58
60
|
"webpack-cli": "^4.2.0",
|
|
59
61
|
"webpack-dev-server": "^3.11.0"
|
|
60
62
|
}
|
|
61
|
-
}
|
|
63
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as sdk from '@tcwd/weapps-sdk';
|
|
2
2
|
import { createComputed } from 'utils';
|
|
3
|
-
import { DS_SDK, CLOUD_SDK, createDataset, EXTRA_API } from '../datasources';
|
|
4
3
|
import store, { subPackageName } from '../store';
|
|
5
4
|
import computed from '../store/computed';
|
|
6
5
|
import common from './common';
|
|
@@ -8,6 +7,8 @@ import { formatDate } from '../utils/date';
|
|
|
8
7
|
import { getter, setter, _isMobile } from '../utils';
|
|
9
8
|
import actionMap from './material-actions';
|
|
10
9
|
import { scanCodeApi } from '../utils/scan-code-action';
|
|
10
|
+
import { createWebApp, ACTIONS_KEY, ROUTER_KEY } from '@cloudbase/weda-client';
|
|
11
|
+
import { createDataset, EXTRA_API } from '../datasources/index'
|
|
11
12
|
|
|
12
13
|
const mainAppKey = '__weappsMainApp';
|
|
13
14
|
const appGlobal = process.env.isMiniprogram ? getApp() : window;
|
|
@@ -20,10 +21,10 @@ export function setCurrentPage(pageCtx) {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function createGlboalApi() {
|
|
24
|
+
const mpApp = createWebApp();
|
|
23
25
|
const globalAPI = {
|
|
24
26
|
id: '<%= appId %>',
|
|
25
27
|
domain: '<%= domain %>',
|
|
26
|
-
platform: 'WEB',
|
|
27
28
|
formActions: {},
|
|
28
29
|
pages: {},
|
|
29
30
|
session: {
|
|
@@ -34,12 +35,7 @@ function createGlboalApi() {
|
|
|
34
35
|
state: store,
|
|
35
36
|
computed: createComputed(computed.global),
|
|
36
37
|
common,
|
|
37
|
-
|
|
38
|
-
utils: {
|
|
39
|
-
formatDate,
|
|
40
|
-
get: getter,
|
|
41
|
-
set: setter,
|
|
42
|
-
},
|
|
38
|
+
...mpApp
|
|
43
39
|
// ... other sdk apis & apis from mp
|
|
44
40
|
}; // The global api exposed to lowcode
|
|
45
41
|
|
|
@@ -81,8 +77,6 @@ function createGlboalApi() {
|
|
|
81
77
|
sdkModsIncluded.forEach((key) => {
|
|
82
78
|
globalAPI[key] = sdk[key];
|
|
83
79
|
});
|
|
84
|
-
// 避免被wx.cloud 覆盖
|
|
85
|
-
globalAPI.cloud = CLOUD_SDK;
|
|
86
80
|
|
|
87
81
|
return globalAPI;
|
|
88
82
|
}
|
|
@@ -103,80 +97,9 @@ function createPageApi() {
|
|
|
103
97
|
export const mountAPIs = (sdks) => {
|
|
104
98
|
Object.keys(sdks).forEach((item) => {
|
|
105
99
|
let action = sdks[item];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
case 'showToast': {
|
|
109
|
-
action = function (obj) {
|
|
110
|
-
if (obj.icon === 'error' && !obj.image) {
|
|
111
|
-
return sdks[item]({
|
|
112
|
-
...obj,
|
|
113
|
-
image:
|
|
114
|
-
'data:image/svg+xml,%3Csvg%20width%3D%22120%22%20height%3D%22120%22%20viewBox%3D%220,0,24,24%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2010.586l5.657-5.657%201.414%201.414L13.414%2012l5.657%205.657-1.414%201.414L12%2013.414l-5.657%205.657-1.414-1.414L10.586%2012%204.929%206.343%206.343%204.93%2012%2010.586z%22%20fill-rule%3D%22evenodd%22%20fill%3D%22white%22%2F%3E%3C%2Fsvg%3E',
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return sdks[item](obj);
|
|
118
|
-
};
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
case 'showModal': {
|
|
122
|
-
const OFFICIAL_COMPONENT_LIB = 'gsd-h5-react';
|
|
123
|
-
const showModal =
|
|
124
|
-
actionMap[OFFICIAL_COMPONENT_LIB] &&
|
|
125
|
-
actionMap[OFFICIAL_COMPONENT_LIB].showModal;
|
|
126
|
-
if (!_isMobile() && showModal) {
|
|
127
|
-
action = function (params) {
|
|
128
|
-
return showModal({ data: params });
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
case 'scanCode': {
|
|
134
|
-
action = (options) => {
|
|
135
|
-
if (
|
|
136
|
-
!options ||
|
|
137
|
-
(!options.success && !options.fail && !options.complete)
|
|
138
|
-
) {
|
|
139
|
-
return new Promise((resolve, reject) => {
|
|
140
|
-
scanCodeApi({
|
|
141
|
-
...options,
|
|
142
|
-
success: resolve,
|
|
143
|
-
fail: reject,
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
scanCodeApi(options);
|
|
148
|
-
};
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
case 'navigateTo':
|
|
152
|
-
case 'reLaunch':
|
|
153
|
-
case 'redirectTo': {
|
|
154
|
-
action = function (obj) {
|
|
155
|
-
if (obj.mode === 'web' && process.env.isMiniprogram) {
|
|
156
|
-
console.warn('url navigation can only be used in h5 build');
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const { url, ...restOpts } = obj;
|
|
160
|
-
if (obj.mode === 'web') {
|
|
161
|
-
if (item === 'navigateTo') {
|
|
162
|
-
window.open(url);
|
|
163
|
-
} else {
|
|
164
|
-
window.location.href = url;
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
return sdks[item]({
|
|
168
|
-
...restOpts,
|
|
169
|
-
pageId: restOpts.pageId
|
|
170
|
-
? restOpts.pageId.replace(/^(\.)?\//, '')
|
|
171
|
-
: restOpts.pageId,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
100
|
+
if (!(item in ACTIONS_KEY) && !(item in ROUTER_KEY)) {
|
|
101
|
+
app[item] = action;
|
|
177
102
|
}
|
|
178
|
-
|
|
179
|
-
app[item] = action;
|
|
180
103
|
});
|
|
181
104
|
return app;
|
|
182
105
|
};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// Imports all material actions
|
|
2
|
-
<% materials.map((material,index) => { if(material.
|
|
3
|
-
import <%= _.camelCase(material.name)%>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<% }
|
|
8
|
-
|
|
9
|
-
<%
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
2
|
+
<% materials.map((material,index) => { if(material.entries && material.entries.actions){ %>
|
|
3
|
+
import * as <%= _.camelCase(material.name)%>Actions_<%= index%> from 'libraries/<%=material.name%>@<%= material.version %>/<%=material.entries.actions%>';
|
|
4
|
+
<% } else if(material.entries && material.entries.entry) {%>
|
|
5
|
+
import <%= _.camelCase(material.name)%>_<%= index%> from 'libraries/<%=material.name%>@<%= material.version %>/<%=material.entries.entry%>';
|
|
6
|
+
const <%= _.camelCase(material.name)%>Actions_<%= index%> = <%= _.camelCase(material.name)%>_<%= index%>.actions
|
|
7
|
+
<% } else { (material.actions || []).map(act => {%>
|
|
8
|
+
import <%= _.camelCase(material.name)%>_<%=act.name%> from 'libraries/<%=material.name%>@<%= material.version %>/actions/<%= act.name %>'
|
|
9
|
+
<% }) }}) %>
|
|
10
|
+
export default {
|
|
11
|
+
<% materials.map((material, index) => {
|
|
12
|
+
%> ['<%= material.name%>']:<% if(material.entries && (material.entries.entry || material.entries.actions)){ %> <%=_.camelCase(material.name)%>Actions_<%= index%>,
|
|
13
|
+
<% }else{ %> {<% (material.actions || []).map(act => { %>
|
|
14
|
+
['<%= act.name%>']: <%= _.camelCase(material.name)%>_<%=act.name%>,<%})%>
|
|
15
|
+
},
|
|
16
|
+
<%}}) %>}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WEDA_CLOUD_SDK } from '@cloudbase/weda-client'
|
|
2
2
|
import config from './config';
|
|
3
3
|
|
|
4
|
+
const {
|
|
5
|
+
setConfig,
|
|
6
|
+
initTcb,
|
|
7
|
+
CLOUD_SDK,
|
|
8
|
+
createDataset,
|
|
9
|
+
createStateDataSourceVar,
|
|
10
|
+
generateParamsParser,
|
|
11
|
+
EXTRA_API,
|
|
12
|
+
DS_API,
|
|
13
|
+
DS_SDK
|
|
14
|
+
} = WEDA_CLOUD_SDK
|
|
15
|
+
|
|
4
16
|
export {
|
|
5
17
|
createDataset,
|
|
6
18
|
createStateDataSourceVar,
|
|
@@ -9,7 +21,8 @@ export {
|
|
|
9
21
|
CLOUD_SDK,
|
|
10
22
|
DS_API,
|
|
11
23
|
DS_SDK,
|
|
12
|
-
|
|
24
|
+
setConfig
|
|
25
|
+
}
|
|
13
26
|
|
|
14
27
|
setConfig(config);
|
|
15
28
|
initTcb();
|
package/template/src/index.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import * as ReactDOM from 'react-dom'
|
|
3
|
-
import { setConfig } from '
|
|
3
|
+
import { setConfig } from './datasources/index'
|
|
4
4
|
import App from './router'
|
|
5
5
|
import './utils/monitor-jssdk.min'
|
|
6
6
|
import './index.less'
|
|
@@ -6,9 +6,10 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
6
6
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
7
7
|
const themeVars = require('./themeVars');
|
|
8
8
|
const HappyPack = require('happypack');
|
|
9
|
-
const core =
|
|
9
|
+
const core = 7;
|
|
10
10
|
const happyThreadPool = HappyPack.ThreadPool({ size: core });
|
|
11
11
|
|
|
12
|
+
const TS_LOADER_ID = 'ts-loader';
|
|
12
13
|
module.exports = function (options) {
|
|
13
14
|
const {
|
|
14
15
|
context,
|
|
@@ -22,54 +23,69 @@ module.exports = function (options) {
|
|
|
22
23
|
definePlugin = {},
|
|
23
24
|
} = options;
|
|
24
25
|
const isDevelopment = mode !== 'production';
|
|
26
|
+
const babelLoader = {
|
|
27
|
+
loader: 'babel-loader',
|
|
28
|
+
options: {
|
|
29
|
+
compact: false,
|
|
30
|
+
cacheDirectory: true,
|
|
31
|
+
cwd: context,
|
|
32
|
+
presets: [
|
|
33
|
+
[
|
|
34
|
+
'@babel/preset-env',
|
|
35
|
+
{
|
|
36
|
+
modules: false,
|
|
37
|
+
targets: {
|
|
38
|
+
esmodules: true,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
'@babel/preset-react',
|
|
43
|
+
],
|
|
44
|
+
plugins: [
|
|
45
|
+
[
|
|
46
|
+
'babel-plugin-import',
|
|
47
|
+
{
|
|
48
|
+
libraryName: '@govcloud/gsd-kbone-react',
|
|
49
|
+
libraryDirectory: 'lib/components',
|
|
50
|
+
camel2DashComponentName: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
'@babel/plugin-proposal-class-properties',
|
|
54
|
+
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
55
|
+
'@babel/plugin-proposal-export-default-from',
|
|
56
|
+
'@babel/plugin-proposal-export-namespace-from',
|
|
57
|
+
'@babel/plugin-proposal-optional-chaining',
|
|
58
|
+
'@babel/plugin-proposal-partial-application',
|
|
59
|
+
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
|
|
60
|
+
].filter(Boolean),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
25
64
|
let plugins = [
|
|
26
65
|
new HappyPack({
|
|
27
|
-
id:
|
|
66
|
+
id: TS_LOADER_ID,
|
|
28
67
|
loaders: [
|
|
68
|
+
babelLoader,
|
|
29
69
|
{
|
|
30
|
-
loader: '
|
|
70
|
+
loader: 'ts-loader',
|
|
31
71
|
options: {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
targets: {
|
|
40
|
-
esmodules: true,
|
|
41
|
-
},
|
|
42
|
-
useBuiltIns: 'usage',
|
|
43
|
-
corejs: '2.6.12',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
'@babel/preset-react',
|
|
47
|
-
],
|
|
48
|
-
plugins: [
|
|
49
|
-
[
|
|
50
|
-
'babel-plugin-import',
|
|
51
|
-
{
|
|
52
|
-
libraryName: '@govcloud/gsd-kbone-react',
|
|
53
|
-
libraryDirectory: 'lib/components',
|
|
54
|
-
camel2DashComponentName: false,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
'@babel/plugin-proposal-class-properties',
|
|
58
|
-
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
59
|
-
'@babel/plugin-proposal-export-default-from',
|
|
60
|
-
'@babel/plugin-proposal-export-namespace-from',
|
|
61
|
-
'@babel/plugin-proposal-optional-chaining',
|
|
62
|
-
'@babel/plugin-proposal-partial-application',
|
|
63
|
-
[
|
|
64
|
-
'@babel/plugin-proposal-pipeline-operator',
|
|
65
|
-
{ proposal: 'minimal' },
|
|
66
|
-
],
|
|
67
|
-
].filter(Boolean),
|
|
72
|
+
compilerOptions: {
|
|
73
|
+
target: 'ESNext',
|
|
74
|
+
module: 'ESNext',
|
|
75
|
+
esModuleInterop: true,
|
|
76
|
+
},
|
|
77
|
+
happyPackMode: true,
|
|
78
|
+
transpileOnly: true,
|
|
68
79
|
},
|
|
69
80
|
},
|
|
70
81
|
],
|
|
71
82
|
threadPool: happyThreadPool,
|
|
72
83
|
}),
|
|
84
|
+
new HappyPack({
|
|
85
|
+
id: 'babel',
|
|
86
|
+
loaders: [babelLoader],
|
|
87
|
+
threadPool: happyThreadPool,
|
|
88
|
+
}),
|
|
73
89
|
new HtmlWebpackPlugin({
|
|
74
90
|
template: htmlTemplatePath,
|
|
75
91
|
filename: 'index.html',
|
|
@@ -125,7 +141,7 @@ module.exports = function (options) {
|
|
|
125
141
|
},
|
|
126
142
|
devtool: isDevelopment ? 'eval' : false,
|
|
127
143
|
resolve: {
|
|
128
|
-
extensions: ['.js', '.jsx', '.tsx', '.json', '.scss', '.css'],
|
|
144
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.scss', '.css'],
|
|
129
145
|
modules: [...resolveModules],
|
|
130
146
|
symlinks: false,
|
|
131
147
|
cacheWithContext: false,
|
|
@@ -135,10 +151,15 @@ module.exports = function (options) {
|
|
|
135
151
|
},
|
|
136
152
|
module: {
|
|
137
153
|
rules: [
|
|
154
|
+
{
|
|
155
|
+
test: /\.tsx?$/,
|
|
156
|
+
exclude: /node_modules\/(?!@cloudbase\/weda-ui)|gsd-kbone-react/,
|
|
157
|
+
use: [`happypack/loader?id=${TS_LOADER_ID}`],
|
|
158
|
+
},
|
|
138
159
|
{
|
|
139
160
|
test: /\.(js|jsx)$/,
|
|
161
|
+
exclude: /node_modules\/(?!@cloudbase\/weda-ui)|gsd-kbone-react/,
|
|
140
162
|
use: ['happypack/loader?id=babel'],
|
|
141
|
-
exclude: /node_modules\/(?!@cloudbase\/weda-ui)/,
|
|
142
163
|
},
|
|
143
164
|
{
|
|
144
165
|
test: /\.(scss|sass)$/,
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { observer } from "mobx-react-lite";
|
|
3
|
-
import { observable } from "mobx";
|
|
4
|
-
import { get } from 'lodash'
|
|
5
|
-
|
|
6
|
-
import { AppRender } from "handlers/render";
|
|
7
|
-
import { createComputed } from "../../../../utils";
|
|
8
|
-
import { createWidgets, retryDataBinds, WidgetsContext, resolveComponentProps } from 'handlers/utils'
|
|
9
|
-
import getStateFn from "./lowcode/state.js";
|
|
10
|
-
import computed from "./lowcode/computed.js";
|
|
11
|
-
import lifecycle from "./lowcode/lifecycle.js";
|
|
12
|
-
import { app, $page } from '../../../../app/global-api'
|
|
13
|
-
|
|
14
|
-
<% handlersImports.forEach(handler => { %>
|
|
15
|
-
import handler$<%= handler.name %> from "./lowcode/handler/<%= handler.name %>.js";
|
|
16
|
-
<% }) %>
|
|
17
|
-
|
|
18
|
-
// Import Components
|
|
19
|
-
<% var componentsMap = {}; useComponents.forEach(compItem => {%>
|
|
20
|
-
<% if(compItem.entry){ %><% if(!componentsMap[compItem.moduleName]){ componentsMap[compItem.moduleName] = true %>
|
|
21
|
-
import <%= compItem.moduleNameVar %> from "libraries/<%= compItem.moduleName %>@<%= compItem.version %>/<%= compItem.entry %>";
|
|
22
|
-
<% } %>const { <%= compItem.name %>: <%= compItem.var %> } = <%= compItem.moduleNameVar %>.components
|
|
23
|
-
<% } else { %>import <%= compItem.var %> from "libraries/<%= compItem.moduleName %>@<%= compItem.version %>/components/<%= compItem.name %>";<% } %>
|
|
24
|
-
<%}) %>
|
|
25
|
-
|
|
26
|
-
import * as constObj from '../../libCommonRes/const'
|
|
27
|
-
import * as toolsObj from '../../libCommonRes/tools'
|
|
28
|
-
|
|
29
|
-
import "./lowcode/style.less";
|
|
30
|
-
|
|
31
|
-
const pluginInstances = [];
|
|
32
|
-
|
|
33
|
-
class CompositeCompWrapper extends React.Component {
|
|
34
|
-
|
|
35
|
-
$WEAPPS_COMP = {}
|
|
36
|
-
|
|
37
|
-
componentDidUpdate() {
|
|
38
|
-
const { data } = this.props
|
|
39
|
-
for(let prop in data) {
|
|
40
|
-
// 更新 propsData
|
|
41
|
-
this.propsData[prop] = data[prop]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
constructor(props) {
|
|
47
|
-
super(props);
|
|
48
|
-
|
|
49
|
-
this.compConfig = <%= JSON.stringify(compConfig, null, 2) %>
|
|
50
|
-
this.virtualFields = Object.assign({}, props.pageVirtualFields || {}, {
|
|
51
|
-
<% useComponents.forEach(compItem => {%>
|
|
52
|
-
"<%= compItem.key %>": <% if(compItem.isPlainProps) {%> (props) => <<%= compItem.var %> {...resolveComponentProps(props, 1)} /> <% } else {%> (props) => <<%= compItem.var %>{...resolveComponentProps(props, 0)} /> <% }%>,
|
|
53
|
-
<%}) %>
|
|
54
|
-
});
|
|
55
|
-
this.events = (<%= emitEvents %>).reduce((obj, trigger) => {
|
|
56
|
-
obj[trigger] = (event) => {
|
|
57
|
-
this.props.emit(trigger, event)
|
|
58
|
-
};
|
|
59
|
-
return obj
|
|
60
|
-
}, {});
|
|
61
|
-
this.handler = this.$WEAPPS_COMP.handler = {
|
|
62
|
-
<% handlersImports.forEach(handler => { %>
|
|
63
|
-
<%= handler.name %>: handler$<%= handler.name %>.bind(this),
|
|
64
|
-
<% }) %>
|
|
65
|
-
};
|
|
66
|
-
this.componentSchema = <%= componentSchema %>;
|
|
67
|
-
const widgetContext = <%= widgets %>
|
|
68
|
-
const dataBinds = <%= dataBinds %>
|
|
69
|
-
const defaultProps = <%= JSON.stringify(defaultProps, null, 2) %>
|
|
70
|
-
this.propsData = observable(Object.assign({}, defaultProps, this.props.data || {}))
|
|
71
|
-
this.$WEAPPS_COMP.lib = { const: constObj, tools: toolsObj }
|
|
72
|
-
this.$WEAPPS_COMP.props = { ...this.props, events: this.events, data: this.propsData }
|
|
73
|
-
this.state = this.$WEAPPS_COMP.state = observable(getStateFn.bind(this)())
|
|
74
|
-
this.computed = this.$WEAPPS_COMP.computed = createComputed(computed, this)
|
|
75
|
-
this.node = this.$WEAPPS_COMP.node = this.createWidgetNode(this) || {}
|
|
76
|
-
this.widgets = createWidgets(widgetContext, dataBinds, {})
|
|
77
|
-
// widgets 内的 dataBinds 可能需要关联 widgets,需要重新执行 dataBinds
|
|
78
|
-
retryDataBinds()
|
|
79
|
-
Object.keys(this.widgets || {}).forEach(widgetId => {
|
|
80
|
-
// 将实例 ownerWidget 挂到内部组件上。内部组件就可以通过 $comp.node.ownerWidget 获取到所在的组件实例
|
|
81
|
-
this.widgets[widgetId].ownerWidget = this.node
|
|
82
|
-
})
|
|
83
|
-
this.pageListenerInstances = [];
|
|
84
|
-
this.createCompAPI(this)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
createWidgetNode(compThis) {
|
|
88
|
-
// 当为数组时,需要判断自己属于 widgets 的哪一项
|
|
89
|
-
const {
|
|
90
|
-
compositeParent,
|
|
91
|
-
forIndexes,
|
|
92
|
-
id
|
|
93
|
-
} = compThis.props
|
|
94
|
-
let widgetData = compositeParent
|
|
95
|
-
? compositeParent.$WEAPPS_COMP.widgets[id]
|
|
96
|
-
: $page.widgets[id]
|
|
97
|
-
if(Array.isArray(widgetData)) {
|
|
98
|
-
widgetData = widgetData.length > 0 ? get(widgetData, forIndexes) : {}
|
|
99
|
-
}
|
|
100
|
-
widgetData = widgetData || {}
|
|
101
|
-
widgetData.getOwnerWidget = () => compThis.node.ownerWidget
|
|
102
|
-
widgetData.getConfig = () => compThis.compConfig
|
|
103
|
-
|
|
104
|
-
return widgetData
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
createCompAPI(compThis) {
|
|
108
|
-
compThis.$WEAPPS_COMP = {
|
|
109
|
-
compConfig: compThis.compConfig,
|
|
110
|
-
widgets: compThis.widgets,
|
|
111
|
-
node: compThis.node,
|
|
112
|
-
handler: compThis.handler,
|
|
113
|
-
lib: { const: constObj, tools: toolsObj },
|
|
114
|
-
get props() {
|
|
115
|
-
return {...compThis.props, events: compThis.events, data: compThis.propsData }
|
|
116
|
-
},
|
|
117
|
-
get state() {
|
|
118
|
-
return compThis.state
|
|
119
|
-
},
|
|
120
|
-
get computed() {
|
|
121
|
-
return compThis.computed
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
componentDidMount() {
|
|
127
|
-
lifecycle.onAttached && lifecycle.onAttached.bind(this)()
|
|
128
|
-
lifecycle.onReady && lifecycle.onReady.bind(this)()
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
componentWillUnmount() {
|
|
132
|
-
lifecycle.onDetached && lifecycle.onDetached.bind(this)()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
render() {
|
|
136
|
-
return (
|
|
137
|
-
<WidgetsContext.Provider value={{ parent: this }}>
|
|
138
|
-
<AppRender
|
|
139
|
-
className={this.props.className}
|
|
140
|
-
virtualFields={this.virtualFields}
|
|
141
|
-
componentSchema={this.componentSchema}
|
|
142
|
-
codeContext={this}
|
|
143
|
-
/>
|
|
144
|
-
</WidgetsContext.Provider>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export default observer((props) => (
|
|
150
|
-
<CompositeCompWrapper {...props}></CompositeCompWrapper>
|
|
151
|
-
));
|