@cloudbase/framework-plugin-low-code 0.7.1 → 0.7.2

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.
Files changed (79) hide show
  1. package/lib/builder/config/common.js +1 -1
  2. package/lib/builder/config/index.js +2 -2
  3. package/lib/builder/config/mp.js +1 -1
  4. package/lib/builder/core/copy.js +3 -3
  5. package/lib/builder/core/generate.js +13 -13
  6. package/lib/builder/core/index.js +13 -13
  7. package/lib/builder/core/material.js +6 -6
  8. package/lib/builder/core/plugin.js +3 -3
  9. package/lib/builder/core/prepare.js +2 -2
  10. package/lib/builder/core/webpack.js +5 -5
  11. package/lib/builder/mp/index.d.ts.map +1 -1
  12. package/lib/builder/mp/index.js +50 -49
  13. package/lib/builder/mp/lowcode.js +4 -4
  14. package/lib/builder/mp/materials.js +16 -16
  15. package/lib/builder/mp/mixMode.js +12 -12
  16. package/lib/builder/mp/mp_config.js +11 -11
  17. package/lib/builder/mp/util.d.ts.map +1 -1
  18. package/lib/builder/mp/util.js +12 -9
  19. package/lib/builder/mp/wxml.d.ts.map +1 -1
  20. package/lib/builder/mp/wxml.js +7 -6
  21. package/lib/builder/service/builder/copy.js +11 -11
  22. package/lib/builder/service/builder/generate.js +58 -54
  23. package/lib/builder/service/builder/index.js +2 -2
  24. package/lib/builder/service/builder/plugin.js +2 -2
  25. package/lib/builder/service/builder/webpack.js +24 -23
  26. package/lib/builder/types/common.js +1 -0
  27. package/lib/builder/util/common.d.ts.map +1 -1
  28. package/lib/builder/util/common.js +8 -6
  29. package/lib/builder/util/console.js +1 -1
  30. package/lib/builder/util/generateFiles.js +2 -2
  31. package/lib/builder/util/index.js +1 -1
  32. package/lib/builder/util/junk.js +4 -2
  33. package/lib/builder/util/mp.js +1 -1
  34. package/lib/builder/util/net.js +1 -1
  35. package/lib/builder/util/style.js +1 -1
  36. package/lib/builder/util/weapp.js +1 -1
  37. package/lib/generate.js +2 -2
  38. package/lib/generator/config/index.js +2 -2
  39. package/lib/generator/core/generate.js +36 -34
  40. package/lib/generator/core/index.js +4 -4
  41. package/lib/generator/core/material.js +14 -14
  42. package/lib/generator/types/common.js +6 -3
  43. package/lib/generator/util/common.d.ts.map +1 -1
  44. package/lib/generator/util/common.js +1 -1
  45. package/lib/generator/util/index.js +1 -1
  46. package/lib/generator/util/style.js +2 -2
  47. package/lib/index.d.ts.map +1 -1
  48. package/lib/index.js +104 -66
  49. package/lib/utils/common.d.ts +1 -1
  50. package/lib/utils/common.d.ts.map +1 -1
  51. package/lib/utils/common.js +2 -2
  52. package/lib/utils/dataSource.d.ts.map +1 -1
  53. package/lib/utils/dataSource.js +4 -11
  54. package/lib/utils/index.js +1 -1
  55. package/lib/utils/postProcess.js +3 -3
  56. package/lib/weapps-core/config/index.js +1 -1
  57. package/lib/weapps-core/index.js +2 -2
  58. package/lib/weapps-core/types/index.js +1 -1
  59. package/lib/weapps-core/utils/appbuild.js +6 -3
  60. package/lib/weapps-core/utils/common.js +3 -2
  61. package/lib/weapps-core/utils/formily.js +37 -37
  62. package/lib/weapps-core/utils/index.js +1 -1
  63. package/lib/weapps-core/utils/style.js +15 -15
  64. package/package.json +1 -1
  65. package/template/mp/app/weapps-api.js +16 -5
  66. package/template/mp/app.js +59 -48
  67. package/template/mp/common/util.js +9 -4
  68. package/template/mp/common/weapp-component.js +26 -7
  69. package/template/mp/common/weapp-page.js +45 -2
  70. package/template/mp/common/widget.js +1 -0
  71. package/template/mp/package.json +1 -1
  72. package/template/package.json +2 -2
  73. package/template/src/app/global-api.js +37 -3
  74. package/template/src/handlers/FieldMiddleware/renderer.jsx +12 -0
  75. package/template/src/handlers/actionHandler/utils.js +1 -3
  76. package/template/src/handlers/utils/common.js +27 -21
  77. package/template/src/handlers/utils/widgets.js +16 -4
  78. package/template/src/index.jsx +3 -2
  79. package/template/src/pages/composite.tpl +25 -7
@@ -17,9 +17,9 @@ function serialize(webRuntimeAppData) {
17
17
  vars: webRuntimeAppData.vars || { data: [] },
18
18
  dataset: webRuntimeAppData.dataset,
19
19
  };
20
- common_1.setValidValue(weAppData, 'appConfig', webRuntimeAppData.appConfig);
21
- common_1.setValidValue(weAppData, 'themeVars', webRuntimeAppData.themeVars);
22
- common_1.setValidValue(weAppData, 'presetColors', webRuntimeAppData.presetColors);
20
+ (0, common_1.setValidValue)(weAppData, 'appConfig', webRuntimeAppData.appConfig);
21
+ (0, common_1.setValidValue)(weAppData, 'themeVars', webRuntimeAppData.themeVars);
22
+ (0, common_1.setValidValue)(weAppData, 'presetColors', webRuntimeAppData.presetColors);
23
23
  handlePageInstanceList(webRuntimeAppData.pageInstanceList, weAppData.pageInstanceList);
24
24
  function handlePageInstanceList(pageInstanceList, collection) {
25
25
  pageInstanceList.map((pageData) => {
@@ -27,20 +27,20 @@ function serialize(webRuntimeAppData) {
27
27
  const newPage = {
28
28
  id: pageData.id,
29
29
  };
30
- common_1.setValidValue(newPage, 'isHome', pageData.isHome);
31
- common_1.setValidValue(newPage, 'data', readDynamicData(pageData));
32
- common_1.setValidValue(newPage, 'commonStyle', style_1.removeInvalidStyleFormValue(pageData.style));
33
- common_1.setValidValue(newPage, 'styleBindPath', pageData.styleBindPath);
34
- if (common_1.isValidStyleBind(pageData.styleBind)) {
35
- common_1.setValidValue(newPage, 'styleBind', pageData.styleBind);
30
+ (0, common_1.setValidValue)(newPage, 'isHome', pageData.isHome);
31
+ (0, common_1.setValidValue)(newPage, 'data', readDynamicData(pageData));
32
+ (0, common_1.setValidValue)(newPage, 'commonStyle', (0, style_1.removeInvalidStyleFormValue)(pageData.style));
33
+ (0, common_1.setValidValue)(newPage, 'styleBindPath', pageData.styleBindPath);
34
+ if ((0, common_1.isValidStyleBind)(pageData.styleBind)) {
35
+ (0, common_1.setValidValue)(newPage, 'styleBind', pageData.styleBind);
36
36
  }
37
- if (common_1.isValidClassNameListBind(pageData.classNameListBind)) {
38
- common_1.setValidValue(newPage, 'classNameListBind', pageData.classNameListBind);
37
+ if ((0, common_1.isValidClassNameListBind)(pageData.classNameListBind)) {
38
+ (0, common_1.setValidValue)(newPage, 'classNameListBind', pageData.classNameListBind);
39
39
  }
40
- common_1.setValidValue(newPage, 'componentInstances', readComponents(pageData.componentSchemaJson.properties));
41
- common_1.setValidValue(newPage, 'listeners', readListeners(pageData.listenerInstances));
42
- common_1.setValidValue(newPage, 'pluginInstances', pageData.pluginInstances);
43
- common_1.setValidValue(newPage, 'lowCodes', pageData.codeModules);
40
+ (0, common_1.setValidValue)(newPage, 'componentInstances', readComponents(pageData.componentSchemaJson.properties));
41
+ (0, common_1.setValidValue)(newPage, 'listeners', readListeners(pageData.listenerInstances));
42
+ (0, common_1.setValidValue)(newPage, 'pluginInstances', pageData.pluginInstances);
43
+ (0, common_1.setValidValue)(newPage, 'lowCodes', pageData.codeModules);
44
44
  if ((_a = pageData.children) === null || _a === void 0 ? void 0 : _a.length) {
45
45
  newPage.children = newPage.children || [];
46
46
  handlePageInstanceList(pageData.children, newPage.children);
@@ -60,41 +60,41 @@ function serialize(webRuntimeAppData) {
60
60
  if (srcProps) {
61
61
  const cmpParts = srcProps.sourceKey.split(':');
62
62
  cmps[key] = { genericComp: srcCmp['genericComp'] };
63
- common_1.setValidValue(cmps[key], 'xComponent', {
63
+ (0, common_1.setValidValue)(cmps[key], 'xComponent', {
64
64
  moduleName: cmpParts[0],
65
65
  name: cmpParts[1],
66
66
  });
67
67
  const componentXProps = {};
68
- common_1.setValidValue(componentXProps, 'data', readDynamicData(srcProps));
69
- common_1.setValidValue(componentXProps, 'listeners', readListeners(srcProps.listenerInstances));
70
- common_1.setValidValue(componentXProps, 'staticResourceAttribute', srcProps.staticResourceAttribute);
71
- common_1.setValidValue(componentXProps, 'directives', readDirectives(srcProps));
72
- common_1.setValidValue(componentXProps, 'customDataForm', srcProps.customDataForm);
73
- common_1.setValidValue(componentXProps, 'style', srcProps.style);
74
- common_1.setValidValue(componentXProps, 'commonStyle', style_1.removeInvalidStyleFormValue(srcProps.commonStyle));
75
- common_1.setValidValue(componentXProps, 'styleBindPath', srcProps.styleBindPath);
68
+ (0, common_1.setValidValue)(componentXProps, 'data', readDynamicData(srcProps));
69
+ (0, common_1.setValidValue)(componentXProps, 'listeners', readListeners(srcProps.listenerInstances));
70
+ (0, common_1.setValidValue)(componentXProps, 'staticResourceAttribute', srcProps.staticResourceAttribute);
71
+ (0, common_1.setValidValue)(componentXProps, 'directives', readDirectives(srcProps));
72
+ (0, common_1.setValidValue)(componentXProps, 'customDataForm', srcProps.customDataForm);
73
+ (0, common_1.setValidValue)(componentXProps, 'style', srcProps.style);
74
+ (0, common_1.setValidValue)(componentXProps, 'commonStyle', (0, style_1.removeInvalidStyleFormValue)(srcProps.commonStyle));
75
+ (0, common_1.setValidValue)(componentXProps, 'styleBindPath', srcProps.styleBindPath);
76
76
  if ((_a = srcProps.styleBind) === null || _a === void 0 ? void 0 : _a.bindDataPath) {
77
77
  componentXProps.styleBind = {
78
78
  type: srcProps.styleBind.type,
79
79
  value: srcProps.styleBind.bindDataPath,
80
80
  };
81
81
  }
82
- if (common_1.isValidClassNameListBind(srcProps.classNameListBind)) {
82
+ if ((0, common_1.isValidClassNameListBind)(srcProps.classNameListBind)) {
83
83
  const classList = srcProps.classNameListBind;
84
- common_1.setValidValue(componentXProps, 'classListBind', {
84
+ (0, common_1.setValidValue)(componentXProps, 'classListBind', {
85
85
  type: classList.type,
86
86
  value: classList.bindDataPath,
87
87
  });
88
88
  }
89
89
  if (srcProps.classNameList) {
90
- common_1.setValidValue(componentXProps, 'classList', srcProps.classNameList);
90
+ (0, common_1.setValidValue)(componentXProps, 'classList', srcProps.classNameList);
91
91
  }
92
- common_1.setValidValue(cmps[key], 'xProps', componentXProps);
93
- common_1.setValidValue(cmps[key], 'xIndex', srcCmp['x-index']);
92
+ (0, common_1.setValidValue)(cmps[key], 'xProps', componentXProps);
93
+ (0, common_1.setValidValue)(cmps[key], 'xIndex', srcCmp['x-index']);
94
94
  const excludeKeys = (srcProps.dataTypes || [])
95
95
  .filter((dataType) => dataType.type !== 'slot')
96
96
  .map((dataType) => dataType.propertyPath);
97
- common_1.setValidValue(cmps[key], 'properties', readComponents(srcCmp.properties, excludeKeys));
97
+ (0, common_1.setValidValue)(cmps[key], 'properties', readComponents(srcCmp.properties, excludeKeys));
98
98
  }
99
99
  else {
100
100
  cmps[key] = { properties: readComponents(srcCmp.properties) };
@@ -212,7 +212,7 @@ function deserialize(weAppData) {
212
212
  page.vars = srcPage.vars ? srcPage.vars : page.vars;
213
213
  page.isHome = srcPage.isHome || false;
214
214
  page.style = srcPage.commonStyle || {};
215
- common_1.setValidValue(page, 'styleBindPath', srcPage.styleBindPath);
215
+ (0, common_1.setValidValue)(page, 'styleBindPath', srcPage.styleBindPath);
216
216
  page.codeModules = srcPage.lowCodes || [];
217
217
  page.pluginInstances = srcPage.pluginInstances || [];
218
218
  page.componentSchemaJson = {
@@ -264,7 +264,7 @@ function readCmpInstances(cmps) {
264
264
  xProps.style = cmp.xProps.style || {};
265
265
  xProps.commonStyle = cmp.xProps.commonStyle || {};
266
266
  xProps.staticResourceAttribute = cmp.xProps.staticResourceAttribute || [];
267
- common_1.setValidValue(xProps, 'styleBindPath', cmp.xProps.styleBindPath);
267
+ (0, common_1.setValidValue)(xProps, 'styleBindPath', cmp.xProps.styleBindPath);
268
268
  let { classList, classListBind } = cmp.xProps;
269
269
  const { styleBind } = cmp.xProps;
270
270
  const legacyClassList = classList;
@@ -277,9 +277,9 @@ function readCmpInstances(cmps) {
277
277
  classListBind = classListBind;
278
278
  }
279
279
  }
280
- classList && common_1.setValidValue(xProps, 'classNameList', classList);
280
+ classList && (0, common_1.setValidValue)(xProps, 'classNameList', classList);
281
281
  classListBind &&
282
- common_1.setValidValue(xProps, 'classNameListBind', {
282
+ (0, common_1.setValidValue)(xProps, 'classNameListBind', {
283
283
  type: classListBind.type,
284
284
  propertyPath: 'classNameList',
285
285
  bindDataPath: classListBind.value,
@@ -330,10 +330,10 @@ function readCmpInstances(cmps) {
330
330
  xProps.data = xProps.data || {};
331
331
  xProps.data._visible = true;
332
332
  }
333
- common_1.setValidValue(target, 'x-component', xCmp.toLocaleLowerCase());
334
- common_1.setValidValue(xProps, 'customDataForm', cmp.xProps.customDataForm);
333
+ (0, common_1.setValidValue)(target, 'x-component', xCmp.toLocaleLowerCase());
334
+ (0, common_1.setValidValue)(xProps, 'customDataForm', cmp.xProps.customDataForm);
335
335
  target['x-props'] = xProps;
336
- common_1.setValidValue(target, 'x-index', cmp.xIndex);
336
+ (0, common_1.setValidValue)(target, 'x-index', cmp.xIndex);
337
337
  }
338
338
  }
339
339
  return properties;
@@ -7,7 +7,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
7
7
  o[k2] = m[k];
8
8
  }));
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./formily"), exports);
@@ -76,9 +76,9 @@ function toCssStyle(commonStyle = {}, options = { toRem: true, ignoreSelf: false
76
76
  if (radius !== undefined) {
77
77
  setStyleValue(style, 'borderRadius', _handleStyleNumValue(radius, !!options.addPXUnit));
78
78
  }
79
- if (radiusInfo && !common_1.isEmptyObj(radiusInfo)) {
79
+ if (radiusInfo && !(0, common_1.isEmptyObj)(radiusInfo)) {
80
80
  if (Object.keys(radiusInfo).length === 4) {
81
- if (uniq_1.default(map_1.default(radiusInfo, (val) => val)).length === 1) {
81
+ if ((0, uniq_1.default)((0, map_1.default)(radiusInfo, (val) => val)).length === 1) {
82
82
  setStyleValue(style, 'borderRadius', _handleStyleNumValue(radiusInfo.topLeft, !!options.addPXUnit));
83
83
  }
84
84
  else if (radiusInfo.topLeft === radiusInfo.bottomRight &&
@@ -120,7 +120,7 @@ function toCssStyle(commonStyle = {}, options = { toRem: true, ignoreSelf: false
120
120
  setStyleValue(style, 'backgroundSize', _handleStyleNumValue(size, !!options.addPXUnit));
121
121
  }
122
122
  setStyleValue(style, 'backgroundPosition', position);
123
- if (positionObj && !common_1.isEmptyObj(positionObj)) {
123
+ if (positionObj && !(0, common_1.isEmptyObj)(positionObj)) {
124
124
  style.background += ` ${_handleStyleNumValue(positionObj.left, !!options.addPXUnit)} ${_handleStyleNumValue(positionObj.top, !!options.addPXUnit)}`;
125
125
  }
126
126
  }
@@ -166,7 +166,7 @@ exports.toCssStyle = toCssStyle;
166
166
  function removeInvalidStyleFormValue(styleForm = {}) {
167
167
  return Object.keys(styleForm).reduce((result, key) => {
168
168
  const propStyleFormData = styleForm[key];
169
- if (common_1.isPlainObject(propStyleFormData)) {
169
+ if ((0, common_1.isPlainObject)(propStyleFormData)) {
170
170
  setStyleValue(result, key, removeInvalidStyleFormValue(propStyleFormData));
171
171
  }
172
172
  else {
@@ -178,24 +178,24 @@ function removeInvalidStyleFormValue(styleForm = {}) {
178
178
  exports.removeInvalidStyleFormValue = removeInvalidStyleFormValue;
179
179
  function setDistanceStyle(style, distance, attr, addPXUnit) {
180
180
  if (Object.keys(distance).length === 4) {
181
- if (uniq_1.default(map_1.default(distance, (val) => val)).length === 1) {
182
- setStyleValue(style, common_1.camelcase(`${attr}`), _handleStyleNumValue(distance.top, addPXUnit));
181
+ if ((0, uniq_1.default)((0, map_1.default)(distance, (val) => val)).length === 1) {
182
+ setStyleValue(style, (0, common_1.camelcase)(`${attr}`), _handleStyleNumValue(distance.top, addPXUnit));
183
183
  }
184
184
  else if (distance.top === distance.bottom &&
185
185
  distance.left === distance.right) {
186
- setStyleValue(style, common_1.camelcase(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)}`);
186
+ setStyleValue(style, (0, common_1.camelcase)(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)}`);
187
187
  }
188
188
  else if (distance.left === distance.right) {
189
- setStyleValue(style, common_1.camelcase(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)}`);
189
+ setStyleValue(style, (0, common_1.camelcase)(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)}`);
190
190
  }
191
191
  else {
192
- setStyleValue(style, common_1.camelcase(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)} ${_handleStyleNumValue(distance.left, addPXUnit)}`);
192
+ setStyleValue(style, (0, common_1.camelcase)(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)} ${_handleStyleNumValue(distance.left, addPXUnit)}`);
193
193
  }
194
194
  }
195
195
  else {
196
196
  config_1.DISTANCE_KEY_LIST.forEach((key) => {
197
197
  if (distance[key] !== undefined)
198
- setStyleValue(style, common_1.camelcase(`${attr}_${key}`), _handleStyleNumValue(distance[key], addPXUnit));
198
+ setStyleValue(style, (0, common_1.camelcase)(`${attr}_${key}`), _handleStyleNumValue(distance[key], addPXUnit));
199
199
  });
200
200
  }
201
201
  }
@@ -227,10 +227,10 @@ function setStyleValue(object, key, value) {
227
227
  if (key === 'open') {
228
228
  return;
229
229
  }
230
- if (common_1.isEmptyObj(value)) {
230
+ if ((0, common_1.isEmptyObj)(value)) {
231
231
  return;
232
232
  }
233
- object[common_1.camelcase(key)] = value;
233
+ object[(0, common_1.camelcase)(key)] = value;
234
234
  }
235
235
  function calPxToREM(px) {
236
236
  if (Number.isNaN(px / 28))
@@ -280,7 +280,7 @@ exports.toRPX = toRPX;
280
280
  function removeWrapperBadEffectStyle(commonStyle = {}) {
281
281
  return Object.keys(commonStyle).reduce((result, key) => {
282
282
  const value = commonStyle[key];
283
- const camelcaseKey = common_1.camelcase(key);
283
+ const camelcaseKey = (0, common_1.camelcase)(key);
284
284
  if (config_1.WRAPPER_REMOVE_STYLE_KEY_LIST.includes(camelcaseKey)) {
285
285
  return result;
286
286
  }
@@ -296,7 +296,7 @@ function removeEffectTwiceStyle(commonStyle = {}) {
296
296
  const style = {};
297
297
  Object.keys(commonStyle).map((key) => {
298
298
  const value = commonStyle[key];
299
- const camelcaseKey = common_1.camelcase(key);
299
+ const camelcaseKey = (0, common_1.camelcase)(key);
300
300
  if (config_1.SELF_REMOVE_STYLE_KEY_LIST.includes(camelcaseKey)) {
301
301
  return false;
302
302
  }
@@ -313,7 +313,7 @@ function toCssText(style, className = '.some-class-name') {
313
313
  const attrText = Object.keys(style)
314
314
  .map((key) => {
315
315
  const value = style[key];
316
- return `${common_1.kebabCase(key)}: ${value};`;
316
+ return `${(0, common_1.kebabCase)(key)}: ${value};`;
317
317
  })
318
318
  .join('\n');
319
319
  return `${className} { ${attrText} }\n`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/framework-plugin-low-code",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
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",
@@ -25,7 +25,12 @@ function createGlboalApi() {
25
25
  id: '<%= appId %>',
26
26
  domain: '<%= domain %>',
27
27
  platform: 'MINIPROGRAME',
28
- activePage: null,
28
+ __internal__: {
29
+ activePage: null,
30
+ getConfig: function () {
31
+ return <%= appConfig %>;
32
+ },
33
+ },
29
34
  dataSources: DS_SDK,
30
35
  pages: {},
31
36
  session: {
@@ -39,7 +44,7 @@ function createGlboalApi() {
39
44
  common,
40
45
  relaunchHome: function () {
41
46
  let wx_pages = getCurrentPages();
42
- const { pages = [] } = globalAPI.utils._getConfig();
47
+ const { pages = [] } = globalAPI.__internal__.getConfig();
43
48
  if (
44
49
  wx_pages[0]?.route?.match(/pages\/(.*)\/index/)?.[1] === pages[0]?.id
45
50
  ) {
@@ -50,13 +55,19 @@ function createGlboalApi() {
50
55
  });
51
56
  }
52
57
  },
58
+ invoke(params) {
59
+ return app.activePage.invokeComponentMethod(params)
60
+ },
53
61
  utils: {
54
62
  formatDate,
55
63
  formatEnum,
56
64
  get: getter,
57
65
  set: setter,
58
- _getConfig: function () {
59
- return <%= appConfig %>;
66
+ /**
67
+ * @deprecated
68
+ */
69
+ _getConfig(){
70
+ return globalAPI.__internal__.getConfig()
60
71
  },
61
72
  async getWXContext() {
62
73
  const { Data } = await globalAPI.cloud.callWedaApi({
@@ -68,7 +79,7 @@ function createGlboalApi() {
68
79
  return typeof Data === 'string' ? JSON.parse(Data) : Data
69
80
  },
70
81
  getCurrentPage: function(){
71
- return globalAPI.activePage
82
+ return globalAPI.__internal__.activePage
72
83
  }
73
84
  },
74
85
  // ... other sdk apis & apis from mp
@@ -20,64 +20,75 @@ const wxReport = new WxReportV2({
20
20
  });
21
21
  <% }%>
22
22
 
23
- // 设置数据源请求的 loading 及 toast 处理
24
- setConfig({
25
- beforeDSRequest: (cfg) => {
26
- if (!cfg.options || !cfg.options.showLoading) return
27
- app.showLoading()
28
- },
29
- beforeCallFunction: async (params) => {
30
- try {
31
- const loginPage = findLoginPage();
23
+ // 设置数据源请求的 loading 及 toast 处理
24
+ setConfig({
25
+ beforeDSRequest: (cfg) => {
26
+ if (!cfg.options || !cfg.options.showLoading) return
27
+ app.showLoading()
28
+ },
29
+ beforeCallFunction: async (params) => {
30
+ try {
31
+ const loginPage = findLoginPage();
32
32
 
33
- let skip = false;
34
- switch (params?.data?.methodName){
35
- case 'callWedaApi': {
36
- if(['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)){
37
- skip = true;
33
+ let skip = false;
34
+ switch (params?.data?.methodName) {
35
+ case 'callWedaApi': {
36
+ if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
37
+ skip = true;
38
+ }
39
+ break;
38
40
  }
39
- break;
40
41
  }
41
- }
42
42
 
43
- // 后续做过滤处理
44
- if (!loginPage || (params?.data?.mode === 'c' && skip)) {
45
- return params;
46
- }
47
- // await initTcb();
48
- const { accessToken } = await getAccessToken();
49
- if (accessToken) {
50
- params.data.accessToken = accessToken;
51
- }
52
- } catch (e) {
53
- console.error('beforeCallFunction error', e);
54
- }
55
- return params;
56
- },
57
- afterDSRequest: (cfg, error, result) => {
58
- if (!cfg.options) return
59
- if (cfg.options.showLoading) app.hideLoading()
60
- if (!cfg.options.showToast) return
61
- const isSuccess = !error && result && !result.code
62
- app.showToast({ icon: isSuccess ? 'success' : 'error' })
63
- },
64
- async afterCallFunction(params, error, res) {
65
- if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure','InvalidAccessToken'].includes(res?.result?.code)) {
66
- const loginPage = findLoginPage();
67
- if (loginPage) {
68
- const authConfig = await getAuthConfig();
69
- if (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login') {
70
- redirectToLogin();
71
- } else if (authConfig.RejectStrategy == 'show_warning') {
43
+ // 后续做过滤处理
44
+ if (!loginPage || (params?.data?.mode === 'c' && skip)) {
45
+ return params;
46
+ }
47
+ // await initTcb();
48
+ const { accessToken } = await getAccessToken();
49
+ if (accessToken) {
50
+ params.data.accessToken = accessToken;
51
+ }
52
+ } catch (e) {
53
+ if (app?.cloud?.currentUser?.userType === "externalUser" && e?.error === 'unauthenticated') {
72
54
  app.showToast({
73
- title: '接口无访问权限',
55
+ title: '登录态失效',
74
56
  icon: 'error',
75
57
  });
76
58
  }
59
+ console.error('beforeCallFunction error', e);
60
+ }
61
+ return params;
62
+ },
63
+ afterDSRequest: (cfg, error, result) => {
64
+ if (!cfg.options) return
65
+ if (cfg.options.showLoading) app.hideLoading()
66
+ if (!cfg.options.showToast) return
67
+ const isSuccess = !error && result && !result.code
68
+ app.showToast({ icon: isSuccess ? 'success' : 'error' })
69
+ },
70
+ async afterCallFunction(params, error, res) {
71
+ if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
72
+ const loginPage = findLoginPage();
73
+ if (loginPage) {
74
+ const authConfig = await getAuthConfig();
75
+ let isAnonymous = true;
76
+ try {
77
+ const { accessToken } = await getAccessToken();
78
+ isAnonymous = !accessToken;
79
+ } catch (e) { }
80
+ if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
81
+ redirectToLogin();
82
+ } else if (authConfig.RejectStrategy == 'show_warning') {
83
+ app.showToast({
84
+ title: '接口无访问权限',
85
+ icon: 'error',
86
+ });
87
+ }
88
+ }
77
89
  }
78
90
  }
79
- }
80
- })
91
+ })
81
92
 
82
93
  App({
83
94
  onLaunch(options) {
@@ -235,7 +235,7 @@ export function setter(context, path, value = undefined) {
235
235
 
236
236
  export function findLoginPage() {
237
237
  const { app } = getApp();
238
- const { pages = [] } = app.utils._getConfig();
238
+ const { pages = [] } = app.__internal__.getConfig();
239
239
  return pages.find(item => item.type === 'login');
240
240
  }
241
241
 
@@ -312,8 +312,14 @@ export async function checkAuth(app, appId, $page) {
312
312
  const [isAccess, authConfig] = await Promise.all(requestList);
313
313
  app.hideNavigationBarLoading();
314
314
 
315
+ let isAnonymousUser = true;
316
+ try {
317
+ const { accessToken } = await getAccessToken();
318
+ isAnonymousUser = !accessToken;
319
+ } catch (e) { }
320
+
315
321
  if (!isAccess) {
316
- if (loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
322
+ if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
317
323
  redirectToLogin($page);
318
324
  } else {
319
325
  app.showToast({
@@ -324,8 +330,7 @@ export async function checkAuth(app, appId, $page) {
324
330
  } else if (loginPage && authConfig.NeedLogin) {
325
331
  // 此分支逻辑本不应该前端判断是否登录,历史原因后端短期内搞不定,后续后端优化后删除
326
332
  try {
327
- const { accessToken } = await getAccessToken()
328
- if (!accessToken) {
333
+ if (isAnonymousUser) {
329
334
  redirectToLogin($page);
330
335
  }
331
336
  } catch (e) {
@@ -3,6 +3,7 @@ import { createEventHandlers, createComputed } from './util'
3
3
  import { createWidgets, mpCompToWidget, disposeWidget } from './widget'
4
4
  import mergeRenderer from './merge-renderer'
5
5
  import sdk from './weapp-sdk'
6
+ import lodashGet from 'lodash.get';
6
7
 
7
8
  /**
8
9
  * Lowcodes of all components
@@ -48,7 +49,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
48
49
  },
49
50
  attached() {
50
51
  const $comp = this.getWeAppInst()
51
- if(!$comp) return
52
+ if (!$comp) return
52
53
 
53
54
  $comp.props.events = createPropEvents(events, this)
54
55
  $comp.widgets = {}
@@ -57,6 +58,19 @@ export function createComponent(key, behaviors, properties, events, handler, dat
57
58
 
58
59
  try {
59
60
  lifeCycle.onAttached && lifeCycle.onAttached.call($comp)
61
+ this.__handlerAttached__ = (e) => {
62
+ const widget = lodashGet(widgets, e.target.id);
63
+ widget._methods = e.detail.methods;
64
+ }
65
+ this.__handlerDetached__ = (e) => {
66
+ const widget = lodashGet(widgets, e.target.id);
67
+ delete widget._methods;
68
+ }
69
+ if ($comp.methods) {
70
+ this.triggerEvent('attached', {
71
+ 'methods': $comp.methods
72
+ })
73
+ }
60
74
  } catch (e) {
61
75
  console.error('Component lifecycle(attached) error', this.is, e)
62
76
  }
@@ -69,29 +83,33 @@ export function createComponent(key, behaviors, properties, events, handler, dat
69
83
  },
70
84
  detached() {
71
85
  const $comp = this.getWeAppInst()
72
- if(!$comp) return
86
+ if (!$comp) return
73
87
 
74
88
  $comp.widgets = null
75
89
  disposeWidget(this._virtualRootWidget)
76
90
  this._disposers.forEach(dispose => dispose())
77
91
  lifeCycle.onDetached && lifeCycle.onDetached.call($comp)
92
+
93
+ if ($comp?.methods) {
94
+ this.triggerEvent('detached');
95
+ }
78
96
  }
79
97
  },
80
98
 
81
99
  pageLifetimes: {
82
100
  show() {
83
101
  const $comp = this.getWeAppInst()
84
- if(!$comp) return
102
+ if (!$comp) return
85
103
  lifeCycle.onPageShow && lifeCycle.onPageShow.call($comp)
86
104
  },
87
105
  hide() {
88
106
  const $comp = this.getWeAppInst()
89
- if(!$comp) return
107
+ if (!$comp) return
90
108
  lifeCycle.onPageHide && lifeCycle.onPageHide.call($comp)
91
109
  },
92
110
  resize(size) {
93
111
  const $comp = this.getWeAppInst()
94
- if(!$comp) return
112
+ if (!$comp) return
95
113
  lifeCycle.onPageResize && lifeCycle.onPageResize.call($comp, size)
96
114
  }
97
115
  },
@@ -119,12 +137,12 @@ export function createComponent(key, behaviors, properties, events, handler, dat
119
137
  return widget.$comp
120
138
  },
121
139
  _runWatch() {
122
- const { watchEffects = {}} = index
140
+ const { watchEffects = {} } = index
123
141
  Object.keys(watchEffects).map(name => {
124
142
  const fn = watchEffects[name]
125
143
  if (fn instanceof Function) {
126
144
  const $comp = this.getWeAppInst()
127
- if(!$comp) return
145
+ if (!$comp) return
128
146
  this._disposers.push(autorun(fn.bind($comp)))
129
147
  } else {
130
148
  console.error(`WatchEffect(${name}) of ${key} is not a function.`)
@@ -155,6 +173,7 @@ export function create$comp(w) {
155
173
  get classList() { return w.classList },
156
174
  },
157
175
  lib,
176
+ methods: undefined,
158
177
  i18n: {
159
178
  ...sdk.i18n,
160
179
  t(key, data) {
@@ -3,6 +3,8 @@ import { createComputed, createEventHandlers, checkAuth } from './util';
3
3
  import { createWidgets, createInitData, disposeWidget } from './widget';
4
4
  import mergeRenderer from './merge-renderer';
5
5
  import { createDataset, EXTRA_API, createStateDataSourceVar, generateParamsParser, setConfig } from '../datasources/index';
6
+ import lodashGet from 'lodash.get';
7
+
6
8
 
7
9
  export function createPage(
8
10
  lifecycle,
@@ -67,6 +69,28 @@ export function createPage(
67
69
  this._rootWidget = rootWidget;
68
70
  this._widgets = widgets;
69
71
  this._pageActive = true;
72
+ this.__handlerAttached__ = (e) => {
73
+ if (!$page.componentMethods) {
74
+ $page.componentMethods = {};
75
+ }
76
+ const [id, index = 0] = e.target.id.split('-');
77
+ if (!$page.componentMethods[id]) {
78
+ $page.componentMethods[id] = [];
79
+ }
80
+ $page.componentMethods[id][index] = e.detail.methods;
81
+ };
82
+ this.__handlerDetached__ = (e) => {
83
+ const [id, index = 0] = e.target.id.split('-');
84
+ if ($page.componentMethods) {
85
+ const components = $page.componentMethods[id];
86
+ if (components) {
87
+ components[index] = undefined;
88
+ if (components.filter(com => com !== undefined).length === 0) {
89
+ delete $page.componentMethods[id];
90
+ }
91
+ }
92
+ }
93
+ }
70
94
  this._disposers = this.initMergeRenderer(widgets);
71
95
  },
72
96
  detached() {
@@ -89,7 +113,7 @@ export function createPage(
89
113
  onLoad(options) {
90
114
  const $page = this.getWeAppInst()
91
115
 
92
- app.activePage = $page;
116
+ app.__internal__.activePage = $page;
93
117
  setConfig({ currentPageId: $page.uuid });
94
118
  this._pageActive = true;
95
119
 
@@ -109,7 +133,7 @@ export function createPage(
109
133
  },
110
134
  async onShow() {
111
135
  const $page = this.getWeAppInst()
112
- app.activePage = $page;
136
+ app.__internal__.activePage = $page;
113
137
  setConfig({ currentPageId: $page.uuid });
114
138
  $page.widgets = this._widgets;
115
139
  this._pageActive = true;
@@ -143,7 +167,26 @@ export function createPage(
143
167
  app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
144
168
  });
145
169
  };
170
+ $page.invokeComponentMethod = ({ component, method, params }) => {
171
+ const components = lodashGet($page.componentMethods, component);
172
+ let componentInstance = undefined
173
+ if (Array.isArray(components)) {
174
+ if(components.length > 1){
175
+ throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
176
+ }
177
+ componentInstance = components[0]
178
+ // components.forEach(component => {
179
+ // component[method](params);
180
+ // })
181
+ } else {
182
+ componentInstance = components
183
+ }
146
184
 
185
+ if(!componentInstance?.[method] || typeof componentInstance[method]!= 'function') {
186
+ throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
187
+ }
188
+ return componentInstance[method](params);
189
+ };
147
190
  this.$WEAPPS_PAGE = $page;
148
191
  }
149
192
  return this.$WEAPPS_PAGE