@cloudbase/framework-plugin-low-code 0.7.0 → 0.7.2-beta.1

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 (76) 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 +11 -11
  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.js +6 -6
  18. package/lib/builder/mp/wxml.js +4 -4
  19. package/lib/builder/service/builder/copy.js +11 -11
  20. package/lib/builder/service/builder/generate.js +56 -52
  21. package/lib/builder/service/builder/index.js +2 -2
  22. package/lib/builder/service/builder/plugin.js +2 -2
  23. package/lib/builder/service/builder/webpack.js +24 -23
  24. package/lib/builder/types/common.js +1 -0
  25. package/lib/builder/util/common.d.ts.map +1 -1
  26. package/lib/builder/util/common.js +8 -6
  27. package/lib/builder/util/console.js +1 -1
  28. package/lib/builder/util/generateFiles.js +2 -2
  29. package/lib/builder/util/index.js +1 -1
  30. package/lib/builder/util/junk.js +4 -2
  31. package/lib/builder/util/mp.js +1 -1
  32. package/lib/builder/util/net.js +1 -1
  33. package/lib/builder/util/style.js +1 -1
  34. package/lib/builder/util/weapp.js +1 -1
  35. package/lib/generate.js +2 -2
  36. package/lib/generator/config/index.js +2 -2
  37. package/lib/generator/core/generate.js +36 -34
  38. package/lib/generator/core/index.js +4 -4
  39. package/lib/generator/core/material.js +14 -14
  40. package/lib/generator/types/common.js +6 -3
  41. package/lib/generator/util/common.d.ts.map +1 -1
  42. package/lib/generator/util/common.js +1 -1
  43. package/lib/generator/util/index.js +1 -1
  44. package/lib/generator/util/style.js +2 -2
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +104 -66
  47. package/lib/utils/common.d.ts +1 -1
  48. package/lib/utils/common.d.ts.map +1 -1
  49. package/lib/utils/common.js +2 -2
  50. package/lib/utils/dataSource.js +2 -2
  51. package/lib/utils/index.js +1 -1
  52. package/lib/utils/postProcess.js +3 -3
  53. package/lib/weapps-core/config/index.js +1 -1
  54. package/lib/weapps-core/index.js +2 -2
  55. package/lib/weapps-core/types/index.js +1 -1
  56. package/lib/weapps-core/utils/appbuild.js +6 -3
  57. package/lib/weapps-core/utils/common.js +3 -2
  58. package/lib/weapps-core/utils/formily.js +37 -37
  59. package/lib/weapps-core/utils/index.js +1 -1
  60. package/lib/weapps-core/utils/style.js +15 -15
  61. package/package.json +1 -1
  62. package/template/html/index.html.ejs +1 -1
  63. package/template/mp/app/weapps-api.js +16 -6
  64. package/template/mp/app.js +59 -48
  65. package/template/mp/common/util.js +52 -4
  66. package/template/mp/common/weapp-page.js +16 -3
  67. package/template/mp/package.json +2 -2
  68. package/template/mp/page/index.js +3 -1
  69. package/template/package.json +2 -2
  70. package/template/src/app/global-api.js +20 -5
  71. package/template/src/handlers/FieldMiddleware/renderer.jsx +411 -321
  72. package/template/src/handlers/render.jsx +114 -97
  73. package/template/src/handlers/utils/common.js +28 -22
  74. package/template/src/index.jsx +3 -2
  75. package/template/src/pages/app.tpl +26 -25
  76. package/template/src/utils/formatEnum.js +42 -0
@@ -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.0",
3
+ "version": "0.7.2-beta.1",
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",
@@ -448,7 +448,7 @@
448
448
  ></script>
449
449
  <script
450
450
  crossorigin="anonymous"
451
- src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.8-alpha.11/dist/h5.browser.js?v=1"
451
+ src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.8-alpha.12/dist/h5.browser.js?v=1"
452
452
  ></script>
453
453
  <script>
454
454
  // zxing polifill
@@ -1,5 +1,5 @@
1
1
  import { observable } from 'mobx'
2
- import { createComputed, formatDate, getter, setter } from '<%= subLevelPath %>../common/util'
2
+ import { createComputed, formatDate, getter, setter, formatEnum, enumOptions} from '<%= subLevelPath %>../common/util'
3
3
  import process from '<%= subLevelPath %>../common/process'
4
4
  import { DS_SDK, CLOUD_SDK, createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
5
5
  import appGlobal from '<%= subLevelPath %>../app/app-global'
@@ -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: {
@@ -33,12 +38,13 @@ function createGlboalApi() {
33
38
  //request: sdk.request,
34
39
  //getSessionId: sdk.getSessionId,
35
40
  },
41
+ enumOptions: enumOptions,
36
42
  state: observable(state),
37
43
  computed: createComputed(computed),
38
44
  common,
39
45
  relaunchHome: function () {
40
46
  let wx_pages = getCurrentPages();
41
- const { pages = [] } = globalAPI.utils._getConfig();
47
+ const { pages = [] } = globalAPI.__internal__.getConfig();
42
48
  if (
43
49
  wx_pages[0]?.route?.match(/pages\/(.*)\/index/)?.[1] === pages[0]?.id
44
50
  ) {
@@ -51,10 +57,14 @@ function createGlboalApi() {
51
57
  },
52
58
  utils: {
53
59
  formatDate,
60
+ formatEnum,
54
61
  get: getter,
55
62
  set: setter,
56
- _getConfig: function () {
57
- return <%= appConfig %>;
63
+ /**
64
+ * @deprecated
65
+ */
66
+ _getConfig(){
67
+ return globalAPI.__internal__.getConfig()
58
68
  },
59
69
  async getWXContext() {
60
70
  const { Data } = await globalAPI.cloud.callWedaApi({
@@ -66,7 +76,7 @@ function createGlboalApi() {
66
76
  return typeof Data === 'string' ? JSON.parse(Data) : Data
67
77
  },
68
78
  getCurrentPage: function(){
69
- return globalAPI.activePage
79
+ return globalAPI.__internal__.activePage
70
80
  }
71
81
  },
72
82
  // ... 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) {
@@ -3,6 +3,8 @@
3
3
  import { findForItemsOfWidget, mpCompToWidget } from './widget'
4
4
  import lodashGet from 'lodash.get';
5
5
  import lodashSet from 'lodash.set';
6
+ import { observable } from 'mobx';
7
+ import { app } from '../app/weapps-api'
6
8
  import { getAccessToken } from '@cloudbase/weda-cloud-sdk'
7
9
 
8
10
  /**
@@ -233,7 +235,7 @@ export function setter(context, path, value = undefined) {
233
235
 
234
236
  export function findLoginPage() {
235
237
  const { app } = getApp();
236
- const { pages = [] } = app.utils._getConfig();
238
+ const { pages = [] } = app.__internal__.getConfig();
237
239
  return pages.find(item => item.type === 'login');
238
240
  }
239
241
 
@@ -310,8 +312,11 @@ export async function checkAuth(app, appId, $page) {
310
312
  const [isAccess, authConfig] = await Promise.all(requestList);
311
313
  app.hideNavigationBarLoading();
312
314
 
315
+ const { accessToken } = await getAccessToken()
316
+ const isAnonymousUser = !accessToken
317
+
313
318
  if (!isAccess) {
314
- if (loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
319
+ if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
315
320
  redirectToLogin($page);
316
321
  } else {
317
322
  app.showToast({
@@ -322,8 +327,7 @@ export async function checkAuth(app, appId, $page) {
322
327
  } else if (loginPage && authConfig.NeedLogin) {
323
328
  // 此分支逻辑本不应该前端判断是否登录,历史原因后端短期内搞不定,后续后端优化后删除
324
329
  try {
325
- const { accessToken } = await getAccessToken()
326
- if (!accessToken) {
330
+ if (isAnonymousUser) {
327
331
  redirectToLogin($page);
328
332
  }
329
333
  } catch (e) {
@@ -646,8 +650,52 @@ class CustomDate {
646
650
 
647
651
  const dataInstance = new CustomDate();
648
652
  export const formatDate = new CustomDate().format.bind(dataInstance);
653
+
654
+ let loading = {};
655
+ export let enumOptions = observable({});
656
+ export function formatEnum(path, optionname) {
657
+ // 判断是单选还是多选
658
+ let isSingle = Array.isArray(path);
659
+ // 获取到options
660
+ let parseOptions = getEnumOptions(optionname);
661
+ if (parseOptions === '') {
662
+ return !isSingle ? path : path.join(',');
663
+ }
664
+ let multiTmp = [];
665
+ let value = !isSingle
666
+ ? JSON.parse(parseOptions)?.find((item) => item?.key === path)?.value
667
+ : JSON.parse(parseOptions)
668
+ ?.filter((item) => path.some((pathValue) => item?.key === pathValue))
669
+ .map((item) => multiTmp.push(item?.value));
670
+ // 对多选或者单选有不同处理
671
+ return !isSingle ? value : multiTmp?.join(',');
672
+ }
673
+ function getEnumOptions(optionName) {
674
+ if (enumOptions[optionName]) {
675
+ return enumOptions[optionName];
676
+ }
677
+ if (!loading[optionName]) {
678
+ loading[optionName] = true;
679
+ getGeneralOptions(optionName).then((data) => {
680
+ enumOptions[optionName] = data?.Items[0]?.Config;
681
+ });
682
+ }
683
+ return '';
684
+ }
685
+ export async function getGeneralOptions(optionName) {
686
+ return app.cloud.callWedaApi({
687
+ action: 'DescribeGeneralOptionsDetailList',
688
+ data: {
689
+ PageSize: 1,
690
+ PageIndex: 1,
691
+ LikeNameOrTitle: optionName,
692
+ },
693
+ });
694
+ }
695
+
649
696
  export const utils = {
650
697
  formatDate,
651
698
  get: getter,
652
699
  set: setter,
700
+ formatEnum
653
701
  };
@@ -14,6 +14,7 @@ export function createPage(
14
14
  app,
15
15
  $page,
16
16
  context,
17
+ pageAttributes
17
18
  ) {
18
19
  const evtHandlers = createEventHandlers(evtListeners, context);
19
20
 
@@ -32,6 +33,18 @@ export function createPage(
32
33
  if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
33
34
  return res?.target?.dataset?.weda_share_info;
34
35
  }
36
+ if (res?.from === 'menu' && pageAttributes?.appShareMessage) {
37
+ let { enable, pageId, params, imageUrl, title } = pageAttributes.appShareMessage;
38
+ if (enable) {
39
+ pageId = pageId ? pageId.replace(/^(\.)?\//, '') : pageId;
40
+ let realPath = `/pages/${pageId}/index` + (params ? '?' + params.map(pair => pair.key + '=' + pair.value).join('&') : '');
41
+ return {
42
+ path: realPath,
43
+ imageUrl,
44
+ title
45
+ };
46
+ }
47
+ }
35
48
  try {
36
49
  return lifecycle?.['onShareAppMessage']?.() || {};
37
50
  } catch (error) {
@@ -76,7 +89,7 @@ export function createPage(
76
89
  onLoad(options) {
77
90
  const $page = this.getWeAppInst()
78
91
 
79
- app.activePage = $page;
92
+ app.__internal__.activePage = $page;
80
93
  setConfig({ currentPageId: $page.uuid });
81
94
  this._pageActive = true;
82
95
 
@@ -96,7 +109,7 @@ export function createPage(
96
109
  },
97
110
  async onShow() {
98
111
  const $page = this.getWeAppInst()
99
- app.activePage = $page;
112
+ app.__internal__.activePage = $page;
100
113
  setConfig({ currentPageId: $page.uuid });
101
114
  $page.widgets = this._widgets;
102
115
  this._pageActive = true;
@@ -119,7 +132,7 @@ export function createPage(
119
132
  },
120
133
 
121
134
  getWeAppInst() {
122
- if(!this.$WEAPPS_PAGE){
135
+ if (!this.$WEAPPS_PAGE) {
123
136
  $page.state = observable(pageState);
124
137
  let dataset = createDataset($page.uuid);
125
138
  $page.dataset = dataset;
@@ -3,7 +3,7 @@
3
3
  "version": "1.0.0",
4
4
  "scripts": {},
5
5
  "dependencies": {
6
- "@cloudbase/weda-cloud-sdk": "1.0.8-alpha.11",
6
+ "@cloudbase/weda-cloud-sdk": "1.0.8-alpha.12",
7
7
  "@cloudbase/oauth": "0.1.1-alpha.2",
8
8
  "mobx": "^5.15.4",
9
9
  "lodash.get": "^4.4.2",
@@ -14,4 +14,4 @@
14
14
  })
15
15
  %>
16
16
  }
17
- }
17
+ }
@@ -34,7 +34,9 @@ const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
34
34
  },<%}) %>
35
35
  }
36
36
 
37
+ const pageAttributes = <%= pageAttributes?JSON.stringify(pageAttributes):'{}' %>
38
+
37
39
  $page.id = '<%= pageName %>'
38
40
  $page.uuid = '<%= pageUUID %>'
39
41
  $page.handler = handlers
40
- createPage(lifecyle, widgetProps, state, computed, evtListeners, dataBinds, app, $page, context)
42
+ createPage(lifecyle, widgetProps, state, computed, evtListeners, dataBinds, app, $page, context,pageAttributes)
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "dependencies": {
8
8
  "@cloudbase/js-sdk": "1.5.3-alpha.0",
9
- "@cloudbase/weda-cloud-sdk": "1.0.8-alpha.11",
9
+ "@cloudbase/weda-cloud-sdk": "1.0.8-alpha.12",
10
10
  "@tcwd/weapps-core": "2.2.6",
11
11
  "@tcwd/weapps-sdk": "1.2.9",
12
12
  "@zxing/library": "^0.18.6",
@@ -60,4 +60,4 @@
60
60
  "webpack-cli": "^4.2.0",
61
61
  "webpack-dev-server": "^3.11.0"
62
62
  }
63
- }
63
+ }