@cloudbase/framework-plugin-low-code 0.7.25 → 0.7.26
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/generate.d.ts +2 -1
- package/lib/generate.d.ts.map +1 -1
- package/lib/generate.js +5 -4
- package/lib/index.d.ts +7 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +125 -78
- package/lib/utils/dataSource.d.ts +4 -0
- package/lib/utils/dataSource.d.ts.map +1 -1
- package/lib/utils/dataSource.js +27 -12
- package/lib/utils/postProcess.d.ts.map +1 -1
- package/lib/weapps-core/utils/style.d.ts.map +1 -1
- package/lib/weapps-core/utils/style.js +16 -7
- package/package.json +2 -3
- package/template/mp/app/app-global.js +4 -0
- package/template/mp/app/common.js +26 -0
- package/template/mp/app/handlers.js +15 -0
- package/template/mp/app/weapps-api.js +89 -0
- package/template/mp/app.js +114 -0
- package/template/mp/app.json +1 -0
- package/template/mp/app.wxss +15 -0
- package/template/mp/common/data-patch-test.js +60 -0
- package/template/mp/common/data-patch.js +44 -0
- package/template/mp/common/merge-renderer.js +67 -0
- package/template/mp/common/process.js +1 -0
- package/template/mp/common/style.js +34 -0
- package/template/mp/common/url.js +21 -0
- package/template/mp/common/util.js +395 -0
- package/template/mp/common/utils.wxs +11 -0
- package/template/mp/common/weapp-component.js +250 -0
- package/template/mp/common/weapp-page.js +204 -0
- package/template/mp/common/weapp-sdk.js +76 -0
- package/template/mp/common/widget.js +381 -0
- package/template/mp/common/wx_yypt_report_v2.js +460 -0
- package/template/mp/component/index.js +66 -0
- package/template/mp/component/index.json +4 -0
- package/template/mp/component/index.wxml +1 -0
- package/template/mp/component/index.wxss +1 -0
- package/template/mp/datasources/config.js.tpl +25 -0
- package/template/mp/datasources/dataset-profiles.js.tpl +5 -0
- package/template/mp/datasources/datasource-profiles.js.tpl +4 -0
- package/template/mp/datasources/index.js +31 -0
- package/template/mp/package.json +17 -0
- package/template/mp/page/api.js +1 -0
- package/template/mp/page/index.js +42 -0
- package/template/mp/page/index.json +3 -0
- package/template/mp/page/index.wxml +1 -0
- package/template/mp/page/index.wxss +3 -0
- package/template/mp/project.config.json +1 -0
package/lib/utils/dataSource.js
CHANGED
|
@@ -3,27 +3,29 @@ 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.getDatasetProfiles = exports.getDatasourceProfiles = exports.standardizeDataSource = exports.lowercaseKey = exports.mergeDependencies = exports.getDatasourceDatabaseName = exports.getAppDatasourceResourceName = exports.getDatasourceResourceName = exports.DATABASE_TYPE = exports.EXTERNAL_FUNCTION_TYPE = exports.CLOUD_FUNCTION_TYPE = void 0;
|
|
6
|
+
exports.getDatasetProfiles = exports.getDataVarProfiles = exports.getDatasourceProfiles = exports.standardizeDataSource = exports.lowercaseKey = exports.mergeDependencies = exports.getDatasourceDatabaseName = exports.getAppDatasourceResourceName = exports.getDatasourceResourceName = exports.DATABASE_TYPE = exports.EXTERNAL_FUNCTION_TYPE = exports.CLOUD_FUNCTION_TYPE = void 0;
|
|
7
7
|
const merge_package_json_1 = __importDefault(require("merge-package-json"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const util_1 = require("
|
|
11
|
-
const
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const expression_1 = require("@cloudbase/cals/lib/parser/expression");
|
|
10
|
+
const util_1 = require("../builder/mp/util");
|
|
11
|
+
const config_1 = require("../builder/config");
|
|
12
12
|
exports.CLOUD_FUNCTION_TYPE = 'cloud-function';
|
|
13
13
|
exports.EXTERNAL_FUNCTION_TYPE = 'http';
|
|
14
14
|
exports.DATABASE_TYPE = 'database';
|
|
15
15
|
function getDatasourceResourceName(datasrouce, mode) {
|
|
16
|
-
let suffix = mode ===
|
|
16
|
+
let suffix = mode === types_1.DEPLOY_MODE.PREVIEW ? `-preview` : '';
|
|
17
17
|
return `lcap-${datasrouce.id}-${datasrouce.name}${suffix}`;
|
|
18
18
|
}
|
|
19
19
|
exports.getDatasourceResourceName = getDatasourceResourceName;
|
|
20
20
|
function getAppDatasourceResourceName(appId, datasrouce, mode) {
|
|
21
|
-
let suffix = mode ===
|
|
21
|
+
let suffix = mode === types_1.DEPLOY_MODE.PREVIEW ? `-preview` : '';
|
|
22
22
|
return `lcap-${datasrouce.id}-${datasrouce.name}-${appId}${suffix}`;
|
|
23
23
|
}
|
|
24
24
|
exports.getAppDatasourceResourceName = getAppDatasourceResourceName;
|
|
25
25
|
function getDatasourceDatabaseName(dsConfig, mode) {
|
|
26
|
-
return dsConfig.type === exports.DATABASE_TYPE
|
|
26
|
+
return dsConfig.type === exports.DATABASE_TYPE
|
|
27
|
+
? getDatasourceResourceName(dsConfig, mode)
|
|
28
|
+
: null;
|
|
27
29
|
}
|
|
28
30
|
exports.getDatasourceDatabaseName = getDatasourceDatabaseName;
|
|
29
31
|
function mergeDependencies(...pkgs) {
|
|
@@ -33,7 +35,9 @@ function mergeDependencies(...pkgs) {
|
|
|
33
35
|
const formated = getDependencies(pkg);
|
|
34
36
|
for (let key in formated.dependencies) {
|
|
35
37
|
formated.dependencies[key] =
|
|
36
|
-
formated.dependencies[key] === '*' && ((_a = acc === null || acc === void 0 ? void 0 : acc.dependencies) === null || _a === void 0 ? void 0 : _a[key]) === '*'
|
|
38
|
+
formated.dependencies[key] === '*' && ((_a = acc === null || acc === void 0 ? void 0 : acc.dependencies) === null || _a === void 0 ? void 0 : _a[key]) === '*'
|
|
39
|
+
? 'latest'
|
|
40
|
+
: formated.dependencies[key];
|
|
37
41
|
}
|
|
38
42
|
const merged = (0, merge_package_json_1.default)(formated, acc);
|
|
39
43
|
return JSON.parse(merged);
|
|
@@ -109,6 +113,17 @@ function getDatasourceProfiles(datasources) {
|
|
|
109
113
|
})) || []);
|
|
110
114
|
}
|
|
111
115
|
exports.getDatasourceProfiles = getDatasourceProfiles;
|
|
116
|
+
function getDataVarProfiles(appData) {
|
|
117
|
+
const result = {
|
|
118
|
+
$global: (appData.vars && appData.vars.data) || [],
|
|
119
|
+
};
|
|
120
|
+
appData.pageInstanceList.forEach((pageInstance) => {
|
|
121
|
+
let p = pageInstance;
|
|
122
|
+
result[p.id] = (p.vars && p.vars.data) || [];
|
|
123
|
+
});
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
exports.getDataVarProfiles = getDataVarProfiles;
|
|
112
127
|
function _generateDynamicDataset(dataset) {
|
|
113
128
|
var _a;
|
|
114
129
|
let { state } = dataset;
|
|
@@ -121,13 +136,13 @@ function _generateDynamicDataset(dataset) {
|
|
|
121
136
|
let processed = {};
|
|
122
137
|
for (let paramKey in params) {
|
|
123
138
|
let bind = params[paramKey];
|
|
124
|
-
if (!bind.type || bind.type ===
|
|
139
|
+
if (!bind.type || bind.type === expression_1.PropBindType.static) {
|
|
125
140
|
let value = bind.value;
|
|
126
|
-
processed[paramKey] = `${
|
|
141
|
+
processed[paramKey] = `${config_1.REPLACE_SIGN}(app, $page) => (${typeof value === 'string' ? `'${value}'` : JSON.stringify(value)})${config_1.REPLACE_SIGN}`;
|
|
127
142
|
}
|
|
128
143
|
else {
|
|
129
144
|
let jsExp = (0, util_1.generateDataBind)(bind);
|
|
130
|
-
processed[paramKey] = `${
|
|
145
|
+
processed[paramKey] = `${config_1.REPLACE_SIGN}(app, $page) => (\n${jsExp || 'undefined'}\n)${config_1.REPLACE_SIGN}`;
|
|
131
146
|
}
|
|
132
147
|
}
|
|
133
148
|
config.initMethod.params = processed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postProcess.d.ts","sourceRoot":"","sources":["../../src/utils/postProcess.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postProcess.d.ts","sourceRoot":"","sources":["../../src/utils/postProcess.ts"],"names":[],"mappings":"AAKA,wBAAgB,wBAAwB,CAAC,eAAe,KAAA,EAAE,IAAI,KAAA,QAI7D;AAED,wBAAgB,0BAA0B,CAAC,WAAW,KAAA,EAAE,aAAa,KAAA,QAkBpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/weapps-core/utils/style.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAqBvD,wBAAgB,UAAU,CACxB,WAAW,GAAE,YAAiB,EAC9B,OAAO,GAAE;IACP,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACoD,GACrE,aAAa,
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/weapps-core/utils/style.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAqBvD,wBAAgB,UAAU,CACxB,WAAW,GAAE,YAAiB,EAC9B,OAAO,GAAE;IACP,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACoD,GACrE,aAAa,CAgNf;AAED,wBAAgB,2BAA2B,CAAC,SAAS,GAAE,YAAiB,GAAG,YAAY,CAUtF;AAyCD,wBAAgB,mBAAmB,CAAC,KAAK,GAAE,aAAkB,GAAG,aAAa,CAE5E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,GAAE,aAAkB,GAAG,aAAa,CAE5E;AAED,wBAAgB,uBAAuB,CAAC,KAAK,KAAoB,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,MAUhG;AA0BD,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAiBrD;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAcrD;AAED,wBAAgB,2BAA2B,CAAC,WAAW,GAAE,aAAkB,GAAG,aAAa,CAgB1F;AAED,wBAAgB,sBAAsB,CAAC,WAAW,GAAE,aAAkB,GAAG,aAAa,CAoBrF;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,SAAqB,UAQ7E"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -81,8 +92,7 @@ function toCssStyle(commonStyle = {}, options = { toRem: true, ignoreSelf: false
|
|
|
81
92
|
if ((0, uniq_1.default)((0, map_1.default)(radiusInfo, (val) => val)).length === 1) {
|
|
82
93
|
setStyleValue(style, 'borderRadius', _handleStyleNumValue(radiusInfo.topLeft, !!options.addPXUnit));
|
|
83
94
|
}
|
|
84
|
-
else if (radiusInfo.topLeft === radiusInfo.bottomRight &&
|
|
85
|
-
radiusInfo.topRight === radiusInfo.bottomLeft) {
|
|
95
|
+
else if (radiusInfo.topLeft === radiusInfo.bottomRight && radiusInfo.topRight === radiusInfo.bottomLeft) {
|
|
86
96
|
setStyleValue(style, 'borderRadius', `${_handleStyleNumValue(radiusInfo.topLeft, !!options.addPXUnit)} ${_handleStyleNumValue(radiusInfo.topRight, !!options.addPXUnit)}`);
|
|
87
97
|
}
|
|
88
98
|
else if (radiusInfo.topRight === radiusInfo.bottomLeft) {
|
|
@@ -155,7 +165,8 @@ function toCssStyle(commonStyle = {}, options = { toRem: true, ignoreSelf: false
|
|
|
155
165
|
});
|
|
156
166
|
}
|
|
157
167
|
if (self && !options.ignoreSelf) {
|
|
158
|
-
|
|
168
|
+
const _a = self, { cssFloat } = _a, restSelf = __rest(_a, ["cssFloat"]);
|
|
169
|
+
Object.assign(style, restSelf, { float: cssFloat });
|
|
159
170
|
}
|
|
160
171
|
if (options.toRpx) {
|
|
161
172
|
return translateStyleToRpx(style);
|
|
@@ -181,8 +192,7 @@ function setDistanceStyle(style, distance, attr, addPXUnit) {
|
|
|
181
192
|
if ((0, uniq_1.default)((0, map_1.default)(distance, (val) => val)).length === 1) {
|
|
182
193
|
setStyleValue(style, (0, common_1.camelcase)(`${attr}`), _handleStyleNumValue(distance.top, addPXUnit));
|
|
183
194
|
}
|
|
184
|
-
else if (distance.top === distance.bottom &&
|
|
185
|
-
distance.left === distance.right) {
|
|
195
|
+
else if (distance.top === distance.bottom && distance.left === distance.right) {
|
|
186
196
|
setStyleValue(style, (0, common_1.camelcase)(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)}`);
|
|
187
197
|
}
|
|
188
198
|
else if (distance.left === distance.right) {
|
|
@@ -300,8 +310,7 @@ function removeEffectTwiceStyle(commonStyle = {}) {
|
|
|
300
310
|
if (config_1.SELF_REMOVE_STYLE_KEY_LIST.includes(camelcaseKey)) {
|
|
301
311
|
return false;
|
|
302
312
|
}
|
|
303
|
-
if (config_1.SELF_REMOVE_WITH_PERCENTAGE_KEY_LIST.includes(camelcaseKey) &&
|
|
304
|
-
String(value).match(/.+%$/)) {
|
|
313
|
+
if (config_1.SELF_REMOVE_WITH_PERCENTAGE_KEY_LIST.includes(camelcaseKey) && String(value).match(/.+%$/)) {
|
|
305
314
|
return false;
|
|
306
315
|
}
|
|
307
316
|
setStyleValue(style, camelcaseKey, value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/framework-plugin-low-code",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.26",
|
|
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",
|
|
@@ -35,12 +35,11 @@
|
|
|
35
35
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@cloudbase/cals": "
|
|
38
|
+
"@cloudbase/cals": "0.3.17",
|
|
39
39
|
"@cloudbase/framework-core": "^1.8.16",
|
|
40
40
|
"@cloudbase/framework-plugin-auth": "^1.8.16",
|
|
41
41
|
"@cloudbase/framework-plugin-mp": "v1.3.6-beta.8",
|
|
42
42
|
"@cloudbase/framework-plugin-website": "^1.8.17",
|
|
43
|
-
"@cloudbase/lowcode-builder": "^1.0.1",
|
|
44
43
|
"@formily/react-schema-renderer": "1.1.7",
|
|
45
44
|
"archiver": "^4.0.1",
|
|
46
45
|
"axios": "^0.21.0",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<% mods.forEach((mod) => {%>
|
|
2
|
+
import * as <%= mod %> from '../lowcode/common/<%= mod %>'<%}) %>
|
|
3
|
+
|
|
4
|
+
const _weapps_app_common = {}
|
|
5
|
+
|
|
6
|
+
function getDefaultModule(targetModule) {
|
|
7
|
+
if (!targetModule) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
const keys = Object.keys(targetModule)
|
|
11
|
+
if (keys.length === 1 && keys[0] === 'default') {
|
|
12
|
+
return targetModule.default
|
|
13
|
+
}
|
|
14
|
+
return targetModule
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Object.defineProperties(_weapps_app_common, {
|
|
18
|
+
<% mods.forEach((mod) => {%>
|
|
19
|
+
<%= mod %>: {
|
|
20
|
+
get() {
|
|
21
|
+
return getDefaultModule(<%= mod %>)
|
|
22
|
+
}
|
|
23
|
+
},<%}) %>
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export default _weapps_app_common
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% pageModules.forEach(({id: pageId, lowCodes}) => { %>
|
|
2
|
+
<% lowCodes.filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
|
|
3
|
+
import <%= pageId%>_<%= mod.name%> from '../lowcode/<%= pageId%>/handler/<%= mod.name%>'
|
|
4
|
+
<% }) %>
|
|
5
|
+
<% }) %>
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<% pageModules.forEach(({id: pageId, lowCodes}) => { %>
|
|
10
|
+
export const <%=pageId %> = {
|
|
11
|
+
<% lowCodes.filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
|
|
12
|
+
['<%= mod.name%>']: <%= pageId%>_<%= mod.name%>,
|
|
13
|
+
<% }) %>
|
|
14
|
+
}
|
|
15
|
+
<% }) %>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { observable } from 'mobx'
|
|
2
|
+
import { createMpApp } from '@cloudbase/weda-client';
|
|
3
|
+
import { createComputed, formatEnum, enumOptions} from '<%= subLevelPath %>../common/util'
|
|
4
|
+
import process from '<%= subLevelPath %>../common/process'
|
|
5
|
+
import appGlobal from '<%= subLevelPath %>../app/app-global'
|
|
6
|
+
import { CLOUD_SDK, createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<% if (!isBare) {%>
|
|
10
|
+
import state from '../lowcode/state'
|
|
11
|
+
import computed from '../lowcode/computed'
|
|
12
|
+
import common from './common'
|
|
13
|
+
<%} else {%>
|
|
14
|
+
const state = {}
|
|
15
|
+
const computed ={}
|
|
16
|
+
const common = {}
|
|
17
|
+
<%}%>
|
|
18
|
+
|
|
19
|
+
const mainAppKey = '__weappsMainApp'
|
|
20
|
+
|
|
21
|
+
export const app = createGlboalApi()
|
|
22
|
+
export { process }
|
|
23
|
+
|
|
24
|
+
function createGlboalApi() {
|
|
25
|
+
const mpApp = createMpApp({
|
|
26
|
+
appConfig: <%= appConfig %>
|
|
27
|
+
})
|
|
28
|
+
const globalAPI = {
|
|
29
|
+
id: '<%= appId %>',
|
|
30
|
+
domain: '<%= domain %>',
|
|
31
|
+
platform: 'MINIPROGRAME',
|
|
32
|
+
pages: {},
|
|
33
|
+
session: {
|
|
34
|
+
//configure: sdk.configure,
|
|
35
|
+
//request: sdk.request,
|
|
36
|
+
//getSessionId: sdk.getSessionId,
|
|
37
|
+
},
|
|
38
|
+
state: observable(state),
|
|
39
|
+
computed: createComputed(computed),
|
|
40
|
+
common,
|
|
41
|
+
invoke(params) {
|
|
42
|
+
return app.__internal__.activePage.invokeComponentMethod(params)
|
|
43
|
+
},
|
|
44
|
+
...mpApp,
|
|
45
|
+
} // The global api exposed to lowcode
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
globalAPI.__internal__.enumOptions = enumOptions
|
|
49
|
+
globalAPI.utils.formatEnum = formatEnum
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated utils._getConfig
|
|
52
|
+
*/
|
|
53
|
+
globalAPI.utils._getConfig = () => {
|
|
54
|
+
return globalAPI.__internal__.getConfig()
|
|
55
|
+
}
|
|
56
|
+
globalAPI.utils.getWXContext = async function() {
|
|
57
|
+
const { Data } = await globalAPI.cloud.callWedaApi({
|
|
58
|
+
action: 'InvokeComponentWxModule',
|
|
59
|
+
data: {
|
|
60
|
+
Method: 'GetWxContext',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return typeof Data === 'string' ? JSON.parse(Data) : Data
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let dataset = createDataset('$global')
|
|
67
|
+
globalAPI.dataset = dataset
|
|
68
|
+
globalAPI.state.dataset = dataset
|
|
69
|
+
globalAPI.setState = (userSetState) => {
|
|
70
|
+
Object.keys(userSetState).forEach((keyPath) => {
|
|
71
|
+
globalAPI.utils.set(globalAPI.dataset.state, keyPath, userSetState[keyPath]);
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const subPackageName = '<%= subPackageName %>'
|
|
76
|
+
if (subPackageName) {
|
|
77
|
+
// is sub app
|
|
78
|
+
globalAPI.mainApp = appGlobal[mainAppKey]
|
|
79
|
+
const mpApp = getApp()
|
|
80
|
+
mpApp && (mpApp.subApp = globalAPI)
|
|
81
|
+
} else {
|
|
82
|
+
// is mainApp
|
|
83
|
+
appGlobal[mainAppKey] = globalAPI
|
|
84
|
+
}
|
|
85
|
+
// 避免被wx.cloud 覆盖
|
|
86
|
+
globalAPI.cloud = CLOUD_SDK
|
|
87
|
+
|
|
88
|
+
return globalAPI
|
|
89
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import lifeCycle from './lowcode/lifecycle'
|
|
2
|
+
import { app } from './app/weapps-api'
|
|
3
|
+
// 引入数据源管理器并进行初始化
|
|
4
|
+
import { setConfig, getAccessToken, EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index';
|
|
5
|
+
import { redirectToLogin, findLoginPage, getAuthConfig } from './common/util'
|
|
6
|
+
|
|
7
|
+
// 设置数据源请求的 loading 及 toast 处理
|
|
8
|
+
setConfig({
|
|
9
|
+
beforeDSRequest: (cfg) => {
|
|
10
|
+
if (!cfg.options || !cfg.options.showLoading) return
|
|
11
|
+
app.showLoading()
|
|
12
|
+
},
|
|
13
|
+
beforeCallFunction: async (params) => {
|
|
14
|
+
try {
|
|
15
|
+
const loginPage = findLoginPage();
|
|
16
|
+
|
|
17
|
+
let skip = false;
|
|
18
|
+
switch (params?.data?.methodName) {
|
|
19
|
+
case 'callWedaApi': {
|
|
20
|
+
if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
|
|
21
|
+
skip = true;
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 后续做过滤处理
|
|
28
|
+
if (!loginPage || (params?.data?.mode === 'c' && skip)) {
|
|
29
|
+
return params;
|
|
30
|
+
}
|
|
31
|
+
// await initTcb();
|
|
32
|
+
const { accessToken } = await getAccessToken();
|
|
33
|
+
if (accessToken) {
|
|
34
|
+
params.data.accessToken = accessToken;
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (app?.cloud?.currentUser?.userType === "externalUser" && e?.error === 'unauthenticated') {
|
|
38
|
+
app.showToast({
|
|
39
|
+
title: '登录态失效',
|
|
40
|
+
icon: 'error',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
console.error('beforeCallFunction error', e);
|
|
44
|
+
}
|
|
45
|
+
return params;
|
|
46
|
+
},
|
|
47
|
+
afterDSRequest: (cfg, error, result) => {
|
|
48
|
+
if (!cfg.options) return
|
|
49
|
+
if (cfg.options.showLoading) app.hideLoading()
|
|
50
|
+
if (!cfg.options.showToast) return
|
|
51
|
+
const isSuccess = !error && result && !result.code
|
|
52
|
+
app.showToast({ icon: isSuccess ? 'success' : 'error' })
|
|
53
|
+
},
|
|
54
|
+
async afterCallFunction(params, error, res) {
|
|
55
|
+
if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
|
|
56
|
+
const loginPage = findLoginPage();
|
|
57
|
+
if (loginPage) {
|
|
58
|
+
const authConfig = await getAuthConfig();
|
|
59
|
+
let isAnonymous = true;
|
|
60
|
+
try {
|
|
61
|
+
const { accessToken } = await getAccessToken();
|
|
62
|
+
isAnonymous = !accessToken;
|
|
63
|
+
} catch (e) { }
|
|
64
|
+
if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
|
|
65
|
+
redirectToLogin();
|
|
66
|
+
} else if (authConfig.RejectStrategy == 'show_warning') {
|
|
67
|
+
app.showToast({
|
|
68
|
+
title: '接口无访问权限',
|
|
69
|
+
icon: 'error',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
App({
|
|
78
|
+
onLaunch(options) {
|
|
79
|
+
this.app = app
|
|
80
|
+
const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
|
|
81
|
+
let { query = {} } = options
|
|
82
|
+
EXTRA_API.setParams('$global', query)
|
|
83
|
+
createStateDataSourceVar('$global', generateParamsParser({ app }))
|
|
84
|
+
|
|
85
|
+
onLaunch && onLaunch.call(this, options)
|
|
86
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
87
|
+
// 挂运营平台上报对象到app里
|
|
88
|
+
app.yyptReport = wxReport
|
|
89
|
+
<% }%>
|
|
90
|
+
},
|
|
91
|
+
onShow(options) {
|
|
92
|
+
const fn = lifeCycle.onShow || lifeCycle.onAppShow
|
|
93
|
+
fn && fn.call(this, options)
|
|
94
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
95
|
+
wxReport.startReport()
|
|
96
|
+
<% }%>
|
|
97
|
+
},
|
|
98
|
+
onHide() {
|
|
99
|
+
const fn = lifeCycle.onHide || lifeCycle.onAppHide
|
|
100
|
+
fn && fn.call(this)
|
|
101
|
+
},
|
|
102
|
+
onError(msg) {
|
|
103
|
+
const fn = lifeCycle.onError || lifeCycle.onAppError
|
|
104
|
+
fn && fn.call(this, msg)
|
|
105
|
+
},
|
|
106
|
+
onPageNotFound() {
|
|
107
|
+
const fn = lifeCycle.onPageNotFound
|
|
108
|
+
fn && fn.call(this)
|
|
109
|
+
},
|
|
110
|
+
onUnhandledRejection() {
|
|
111
|
+
const fn = lifeCycle.onUnhandledRejection
|
|
112
|
+
fn && fn.call(this)
|
|
113
|
+
},
|
|
114
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= JSON.stringify(content, ' ', 2) %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** common.wxss **/
|
|
2
|
+
page {
|
|
3
|
+
/* 修复小程序 Picker 组件滑动体验问题 */
|
|
4
|
+
touch-action: pan-y;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
page view, page element, page text, page image {
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** import styles specified by material libs*/<% importStyles.map(style => {%>
|
|
12
|
+
@import '<%= style %>';<%})%>
|
|
13
|
+
|
|
14
|
+
/** import lowcode styles */
|
|
15
|
+
@import 'lowcode/style.wxss';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import { getDatapatch } from './data-patch.js'
|
|
3
|
+
|
|
4
|
+
const cases = [
|
|
5
|
+
{
|
|
6
|
+
desc: 'New component',
|
|
7
|
+
base: {},
|
|
8
|
+
data: { id1: { a: 1 } },
|
|
9
|
+
patch: { id1: { a: 1 } }
|
|
10
|
+
}, {
|
|
11
|
+
desc: 'Component prop update',
|
|
12
|
+
base: { id1: { a: 1, b: 2 } },
|
|
13
|
+
data: { id1: { a: 1, b: 3 } },
|
|
14
|
+
patch: { 'id1.b': 3 }
|
|
15
|
+
}, {
|
|
16
|
+
desc: 'More than 1/3 of props changed',
|
|
17
|
+
base: { id1: { a: 1, b: 2, c: 3 } },
|
|
18
|
+
data: { id1: { a: 1, b: 4, c: 5 } },
|
|
19
|
+
patch: { id1: { a: 1, b: 4, c: 5 } }
|
|
20
|
+
}, {
|
|
21
|
+
desc: 'New multiple components',
|
|
22
|
+
base: {},
|
|
23
|
+
data: { id1: { a: 1 }, id2: { c: 2 }, id3: [{ c: 1 }] },
|
|
24
|
+
patch: { id1: { a: 1 }, id2: { c: 2 }, id3: [{ c: 1 }] }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
desc: 'Update component prop in array',
|
|
28
|
+
base: { id1: [{ a: 1 }, { a: 2 }, { a: 8 }] },
|
|
29
|
+
data: { id1: [{ a: 1 }, { a: 3 }, { a: 8 }] },
|
|
30
|
+
patch: { 'id1[1].a': 3 }
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
desc: 'Update component prop in 2d array',
|
|
34
|
+
base: { id1: [[{ a: 1 }, { a: 2 }], [{ a: 1 }]] },
|
|
35
|
+
data: { id1: [[{ a: 1 }, { a: 3 }], [{ a: 1 }]] },
|
|
36
|
+
patch: { 'id1[0][1].a': 3 }
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
desc: 'Add component in array',
|
|
40
|
+
base: { id1: [{ a: 1 }, { a: 2 }] },
|
|
41
|
+
data: { id1: [{ a: 1 }, { a: 2 }, { a: 9 }] },
|
|
42
|
+
patch: { 'id1[2]': { a: 9 } }
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
desc: 'Add 2 components in array',
|
|
46
|
+
base: { id1: [{ a: 1 }, { a: 2 }] },
|
|
47
|
+
data: { id1: [{ a: 1 }, { a: 2 }, { a: 9 }, { a: 8 }] },
|
|
48
|
+
patch: { 'id1[2]': { a: 9 }, 'id1[3]': { a: 8 } }
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
desc: 'array: delete component',
|
|
52
|
+
base: { id1: [{ a: 1 }, { a: 2 }, { a: 2 }] },
|
|
53
|
+
data: { id1: [{ a: 1 }, { a: 2 }] },
|
|
54
|
+
patch: { id1: [{ a: 1 }, { a: 2 }] }
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
for (const c of cases) {
|
|
59
|
+
assert.deepStrictEqual(getDatapatch(c.base, c.data), c.patch, c.desc)
|
|
60
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
export function getDatapatch(base, pendingData) {
|
|
3
|
+
const patch = {}
|
|
4
|
+
for (const widgetId in pendingData) {
|
|
5
|
+
const baseWidget = base[widgetId]
|
|
6
|
+
const pendingWidget = pendingData[widgetId]
|
|
7
|
+
if (!baseWidget) {
|
|
8
|
+
patch[widgetId] = pendingWidget
|
|
9
|
+
} else {
|
|
10
|
+
patchProp(baseWidget, pendingWidget, patch, widgetId)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return patch
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function patchProp(baseWidget, pendingWidget, patch, prefixes) {
|
|
17
|
+
if (Array.isArray(pendingWidget)) {
|
|
18
|
+
if (pendingWidget.length < baseWidget.length) { // array element deleted
|
|
19
|
+
patch[prefixes] = pendingWidget
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
for (let i = 0; i < pendingWidget.length; i++) {
|
|
23
|
+
if (!baseWidget[i]) { // new array element
|
|
24
|
+
patch[prefixes + '[' + i + ']'] = pendingWidget[i]
|
|
25
|
+
} else {
|
|
26
|
+
patchProp(baseWidget[i], pendingWidget[i], patch, prefixes + '[' + i + ']')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
if (pendingWidget._waIf === false && baseWidget._waIf === false) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
const allProps = Object.keys(pendingWidget)
|
|
34
|
+
// Attention: since setData will copy data deeply, if property is object, it should be treated as different
|
|
35
|
+
const differentProps = allProps.filter(prop => typeof pendingWidget[prop] === 'object' || pendingWidget[prop] !== baseWidget[prop])
|
|
36
|
+
if (differentProps.length === 1 || differentProps.length <= allProps.length / 3) {
|
|
37
|
+
differentProps.map(patchProp => {
|
|
38
|
+
patch[prefixes + '.' + patchProp] = pendingWidget[patchProp]
|
|
39
|
+
})
|
|
40
|
+
} else {
|
|
41
|
+
patch[prefixes] = pendingWidget
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { autorun } from 'mobx'
|
|
2
|
+
import { touchObj, throttle } from './util'
|
|
3
|
+
import { resolveWidgetData } from './widget'
|
|
4
|
+
import { getDatapatch } from './data-patch'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
// Attention, must be called at the end of attached or page load to make sure user init take effect
|
|
8
|
+
initMergeRenderer(widgets) {
|
|
9
|
+
this.flushPendingData = throttle(this.flushPendingData.bind(this), 18)
|
|
10
|
+
|
|
11
|
+
const dataFactory = {
|
|
12
|
+
// <%= dataPropNames.pageState %>: () => pageState,
|
|
13
|
+
// <%= dataPropNames.pageComputed %>: () => pageComputed,
|
|
14
|
+
}
|
|
15
|
+
for (const id in widgets) {
|
|
16
|
+
const props = widgets[id]
|
|
17
|
+
dataFactory['<%= dataPropNames.widgetProp %>' + id] = () => resolveWidgetData(props)
|
|
18
|
+
}
|
|
19
|
+
const disposers = []
|
|
20
|
+
for (const k in dataFactory) {
|
|
21
|
+
const disposer = autorun(r => {
|
|
22
|
+
this.requestRender({ [k]: dataFactory[k]() })
|
|
23
|
+
})
|
|
24
|
+
disposers.push(disposer)
|
|
25
|
+
}
|
|
26
|
+
this.flushPendingData() // Prepare data for first paint
|
|
27
|
+
return disposers
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
// setData merging
|
|
31
|
+
pendingData: null,
|
|
32
|
+
_settingData: false, // flag to prevent multiple setData at the same time
|
|
33
|
+
flushPendingData() {
|
|
34
|
+
if (!this.pendingData || this._settingData) { return }
|
|
35
|
+
const patch = getDatapatch(this.data, this.pendingData)
|
|
36
|
+
this.pendingData = null
|
|
37
|
+
const label = `setData ${this.is} ${this.id}(${Object.keys(patch).join(',')})`
|
|
38
|
+
|
|
39
|
+
if (Object.keys(patch).length < 1) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
this._settingData = true
|
|
43
|
+
const lastUpdateTime = Date.now()
|
|
44
|
+
this.setData(patch, () => {<% if(debug) {%>
|
|
45
|
+
const elapsedTime = Date.now() - lastUpdateTime;
|
|
46
|
+
if(elapsedTime > 16) {
|
|
47
|
+
console.warn(label, elapsedTime)
|
|
48
|
+
}else {
|
|
49
|
+
console.info(label, elapsedTime)
|
|
50
|
+
}<%} %>
|
|
51
|
+
this._settingData = false;
|
|
52
|
+
this.flushPendingData()
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
requestRender(data) {
|
|
56
|
+
if(!this._pageActive) {
|
|
57
|
+
// The callback of wx.chooseLocation occured when page is inactive
|
|
58
|
+
console.warn(`Attention, you're updating widgets(${Object.keys(data).join(',')}) of inactive page(${this.is})`)
|
|
59
|
+
}
|
|
60
|
+
if (!this.pendingData) {
|
|
61
|
+
this.pendingData = {}
|
|
62
|
+
}
|
|
63
|
+
wx.nextTick(this.flushPendingData)
|
|
64
|
+
touchObj(data) // Touch all props to monitor data deeply, FIXME
|
|
65
|
+
Object.assign(this.pendingData, data)
|
|
66
|
+
},
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { env: { buildType: 'mp' } }
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { toDash } from './util'
|
|
2
|
+
/**
|
|
3
|
+
* Convert HtmlElement.style object to css declarations
|
|
4
|
+
*/
|
|
5
|
+
export function styleToCss(style) {
|
|
6
|
+
const styleDeclars = [] // ['color: red;', 'background-color: green']
|
|
7
|
+
for (const key in style) {
|
|
8
|
+
styleDeclars.push(toDash(key) + ':' + style[key] + ';')
|
|
9
|
+
}
|
|
10
|
+
return styleDeclars.join('')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function concatClassList(classList1 = [], classList2 = []) {
|
|
14
|
+
if (!Array.isArray(classList1)) {
|
|
15
|
+
classList1 = [classList1]
|
|
16
|
+
}
|
|
17
|
+
if (!Array.isArray(classList2)) {
|
|
18
|
+
classList2 = [classList2]
|
|
19
|
+
}
|
|
20
|
+
return classList1.concat(classList2)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function px2rpx(object) {
|
|
24
|
+
let reg = /\b(\d+(\.\d+)?)px\b/g
|
|
25
|
+
for (const key in object) {
|
|
26
|
+
let value = object[key]
|
|
27
|
+
if (typeof value === 'string') {
|
|
28
|
+
object[key] = value.replace(reg, function (item, value) {
|
|
29
|
+
return `${value}rpx`
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return object
|
|
34
|
+
}
|