@cloudbase/lowcode-builder 1.8.27 → 1.8.29

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.
@@ -22,7 +22,6 @@ export declare function generateConfig(data: {
22
22
  isPrivateMode?: boolean;
23
23
  endpointType?: IBuildContext['endpointType'] | '';
24
24
  }, root: string): Promise<void>;
25
- export declare function normalizePageId(pageId: any): string;
26
25
  export declare function writeLowCodeFiles(ctx: IBuildContext, appData: IWeAppData, outDir: string): Promise<void>;
27
26
  /**
28
27
  * TODO: 与 cals 里的实现进行整合
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.handleUsedComponents = exports.writeLowCodeFiles = exports.normalizePageId = exports.generateConfig = exports.generateWxMp = void 0;
29
+ exports.handleUsedComponents = exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const util_1 = require("util");
@@ -288,20 +288,6 @@ async function generateConfig(data, root) {
288
288
  }, templateDir, root);
289
289
  }
290
290
  exports.generateConfig = generateConfig;
291
- /**
292
- * pageId 名称管理器
293
- * 因为 pageId 命名为非法
294
- */
295
- const _MANAGER_PAGE_ID_LIST = [];
296
- const _MANAGER_PAGE_ID_MAP = {};
297
- function normalizePageId(pageId) {
298
- if (!_MANAGER_PAGE_ID_MAP[pageId]) {
299
- _MANAGER_PAGE_ID_MAP[pageId] = `$${_MANAGER_PAGE_ID_LIST.length}`;
300
- _MANAGER_PAGE_ID_LIST.push(pageId);
301
- }
302
- return _MANAGER_PAGE_ID_MAP[pageId];
303
- }
304
- exports.normalizePageId = normalizePageId;
305
291
  async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
306
292
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!ctx.isProduction);
307
293
  console.log(`Generating ${em(weapp.rootPath ? 'subApp' : 'app')} to ${appRoot}`);
@@ -349,7 +335,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
349
335
  stringifyObj: util_1.inspect,
350
336
  },
351
337
  [`index.js|${pageFileName}.js`]: {
352
- pageNameVar: normalizePageId(page.id),
338
+ pageNameVar: (0, lowcode_generator_1.normalizePageId)(page.id),
353
339
  pageName: page.id,
354
340
  pageSource: page.data.src || '',
355
341
  eventHandlers: (0, util_2.createEventHandlers)(ctx, componentInstances, 'this', page),
@@ -419,7 +405,7 @@ async function generateFramework(ctx, appData, outDir, options) {
419
405
  (0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList || [], (p) => {
420
406
  allCodeModules.push({
421
407
  id: p.id,
422
- pageNameVar: normalizePageId(p.id),
408
+ pageNameVar: (0, lowcode_generator_1.normalizePageId)(p.id),
423
409
  lowCodes: p.lowCodes || [],
424
410
  });
425
411
  });
@@ -271,6 +271,10 @@ function getListenersHandlers(listeners = [], id, componentApi) {
271
271
  handler = `function({data}){ return $w[data.id]?.[data.method](data.data)}`;
272
272
  break;
273
273
  }
274
+ case `${weapps_core_1.ActionType.Platform}:invoke`: {
275
+ handler = `function({data, $w}){ return $app.invoke({...data, component: $w[data?.component]?._widget});}`;
276
+ break;
277
+ }
274
278
  default: {
275
279
  handler = `function({data}){ return $app.${(_c = l.handler) === null || _c === void 0 ? void 0 : _c.name}(data)}`;
276
280
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.8.27",
3
+ "version": "1.8.29",
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",
@@ -41,8 +41,8 @@
41
41
  "dependencies": {
42
42
  "@babel/core": "7.12.3",
43
43
  "@babel/preset-env": "7.12.1",
44
- "@cloudbase/cals": "^1.0.17",
45
- "@cloudbase/lowcode-generator": "^1.8.10",
44
+ "@cloudbase/cals": "^1.0.20",
45
+ "@cloudbase/lowcode-generator": "^1.8.11",
46
46
  "axios": "^0.21.0",
47
47
  "browserfs": "^1.4.3",
48
48
  "browserify-zlib": "^0.2.0",
@@ -525,7 +525,7 @@
525
525
  crossorigin="anonymous"
526
526
  src="<%=
527
527
  cdnEndpoints.cdngo
528
- %>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.43/dist/h5.browser.js"
528
+ %>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.45/dist/h5.browser.js"
529
529
  ></script>
530
530
  <script
531
531
  crossorigin
@@ -551,7 +551,7 @@
551
551
  crossorigin
552
552
  src="<%=
553
553
  cdnEndpoints.cdngo
554
- %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.badd82789c12ea6c7007.bundle.js"
554
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.70be648bc34aeb4c9760.bundle.js"
555
555
  ></script>
556
556
  </body>
557
557
  </html>
@@ -111,8 +111,9 @@ function createGlboalApi() {
111
111
 
112
112
  let dataset = createDataset('$global')
113
113
  dataset.query = generateDatasetQuery({<% Object.entries(appQuery).map(([id, item])=>{%>
114
- <%= id %>: { <% const { dataBinds, eventHandlers, ...rest } = item %>
114
+ <%= id %>: { <% const { dataBinds, eventHandlers, handler, ...rest } = item %>
115
115
  ...(<%= stringifyObj(rest, {depth: null}) %>),
116
+ handler: <%= handler %>,
116
117
  dataBinds: {<%= printBoundData(dataBinds) %>},
117
118
  eventHandlers: {<% printEventHandler(eventHandlers) %>}
118
119
  },<%}) %>
@@ -1,25 +1,31 @@
1
1
  <%= importor.lifecycle? "import lifeCycle from './lowcode/lifecycle'" : "const lifeCycle = {}" %>
2
- import { app, $app } from './app/weapps-api'
2
+ import { app, $app } from './app/weapps-api';
3
3
  // 引入数据源管理器并进行初始化
4
- import { setConfig, getAccessToken, EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
5
- import { redirectToLogin, findLoginPage, getAuthConfig, checkAnonymous } from './common/util'
4
+ import {
5
+ setConfig,
6
+ getAccessToken,
7
+ EXTRA_API,
8
+ createStateDataSourceVar,
9
+ generateParamsParser,
10
+ } from './datasources/index';
11
+ import { redirectToLogin, findLoginPage, getAuthConfig, checkAnonymous } from './common/util';
6
12
 
7
13
  // 防止报类型不匹配warning
8
14
  const originWarn = console.warn;
9
15
  const warningSkipRegexp = /(type-uncompatible)|(slot "[\w-]*?" is not found)/;
10
16
  console.warn = (...args) => {
11
- // 只看第一条
12
- const shouldSkip = args.length > 0 && args[0][0] === '[' && args[0][1] === 'C' && warningSkipRegexp.test(args[0]);
13
- if(!shouldSkip) {
14
- originWarn(...args);
15
- }
16
- }
17
+ // 只看第一条
18
+ const shouldSkip = args.length > 0 && args[0][0] === '[' && args[0][1] === 'C' && warningSkipRegexp.test(args[0]);
19
+ if (!shouldSkip) {
20
+ originWarn(...args);
21
+ }
22
+ };
17
23
 
18
24
  // 设置数据源请求的 loading 及 toast 处理
19
25
  setConfig({
20
26
  beforeDSRequest: (cfg) => {
21
- if (!cfg.options || !cfg.options.showLoading) return
22
- app.showLoading()
27
+ if (!cfg.options || !cfg.options.showLoading) return;
28
+ app.showLoading();
23
29
  },
24
30
  beforeCallFunction: async (params) => {
25
31
  try {
@@ -46,7 +52,7 @@ setConfig({
46
52
  params.data.accessToken = accessToken;
47
53
  }
48
54
  } catch (e) {
49
- if (app?.cloud?.currentUser?.userType === "externalUser" && e?.error === 'unauthenticated') {
55
+ if (app?.cloud?.currentUser?.userType === 'externalUser' && e?.error === 'unauthenticated') {
50
56
  app.showToast({
51
57
  title: '登录态失效',
52
58
  icon: 'error',
@@ -57,25 +63,45 @@ setConfig({
57
63
  return params;
58
64
  },
59
65
  afterDSRequest: (cfg, error, result) => {
60
- if (!cfg.options) return
61
- if (cfg.options.showLoading) app.hideLoading()
62
- if (!cfg.options.showToast) return
63
- const isSuccess = !error && result && !result.code
64
- app.showToast({ icon: isSuccess ? 'success' : 'error' })
66
+ if (!cfg.options) return;
67
+ if (cfg.options.showLoading) app.hideLoading();
68
+ if (!cfg.options.showToast) return;
69
+ const isSuccess = !error && result && !result.code;
70
+ app.showToast({ icon: isSuccess ? 'success' : 'error' });
65
71
  },
66
72
  async afterCallFunction(params, error, res) {
67
- if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
73
+ const oauthError =
74
+ error?.message?.includes?.('PERMISSION_DENIED') ||
75
+ error?.code === 'unauthenticated' ||
76
+ error?.error === 'unauthenticated' ||
77
+ error?.code === 'invalid_grant' ||
78
+ error?.error === 'invalid_grant' ||
79
+ error?.code === 'INVALID_ACCESS_TOKEN' ||
80
+ (error?.code === 'OPERATION_FAIL' && /^\[INVALID_ACCESS_TOKEN\]/.test(error?.message || ''));
81
+
82
+ if (
83
+ params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' &&
84
+ (['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code) ||
85
+ oauthError)
86
+ ) {
68
87
  const loginPage = findLoginPage();
69
88
  if (loginPage) {
70
89
  const authConfig = await getAuthConfig();
71
- if (authConfig.RejectStrategy == 'to_login') {
90
+ if (authConfig.RejectStrategy === 'to_login') {
72
91
  if (['InnerError.AuthFailure'].includes(res?.result?.code)) {
73
92
  const isAnonymous = await checkAnonymous();
74
93
  if (!isAnonymous) return;
75
94
  // 匿名用户越权去登录
76
95
  }
77
96
  redirectToLogin();
78
- } else if (authConfig.RejectStrategy == 'show_warning') {
97
+ } else if (authConfig.RejectStrategy === 'show_warning') {
98
+ if (oauthError) {
99
+ const isAnonymous = await checkAnonymous();
100
+ if (!isAnonymous) {
101
+ redirectToLogin(generateLoginUrl);
102
+ return;
103
+ }
104
+ }
79
105
  app.showToast({
80
106
  title: '接口无访问权限',
81
107
  icon: 'error',
@@ -83,27 +109,27 @@ setConfig({
83
109
  }
84
110
  }
85
111
  }
86
- }
87
- })
112
+ },
113
+ });
88
114
 
89
115
  App({
90
116
  _query: {},
91
117
  globaldata: {
92
- _beforeCustomLaunchPromise: null
118
+ _beforeCustomLaunchPromise: null,
93
119
  },
94
120
  async beforeCustomLaunch(query) {
95
- if(!this.globaldata?._beforeCustomLaunchPromise){
96
- if(!this.globaldata) {
97
- this.globaldata = {}
121
+ if (!this.globaldata?._beforeCustomLaunchPromise) {
122
+ if (!this.globaldata) {
123
+ this.globaldata = {};
98
124
  }
99
- this.globaldata._beforeCustomLaunchPromise = new Promise(async (resolve)=>{
125
+ this.globaldata._beforeCustomLaunchPromise = new Promise(async (resolve) => {
100
126
  try {
101
- EXTRA_API.setParams('$global', query || {})
127
+ EXTRA_API.setParams('$global', query || {});
102
128
  await createStateDataSourceVar('$global', generateParamsParser({ app, $page: {}, $w: app.__internal__?.$w }));
103
129
  } catch (e) {
104
130
  throw e;
105
131
  } finally {
106
- for (const queryId in app.dataset?.query||{}) {
132
+ for (const queryId in app.dataset?.query || {}) {
107
133
  if (app.dataset.query[queryId]?._schema?.trigger === 'auto') {
108
134
  try {
109
135
  app.dataset?.query?.[queryId]?.trigger?.();
@@ -112,44 +138,44 @@ App({
112
138
  }
113
139
  }
114
140
  }
115
- resolve()
141
+ resolve();
116
142
  }
117
- })
143
+ });
118
144
  }
119
- return this.globaldata._beforeCustomLaunchPromise
145
+ return this.globaldata._beforeCustomLaunchPromise;
120
146
  },
121
147
  async onLaunch(options) {
122
- this.app = app
123
- const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
124
- let { query = {} } = options
125
- this._query = query
148
+ this.app = app;
149
+ const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch;
150
+ let { query = {} } = options;
151
+ this._query = query;
126
152
 
127
- await this.beforeCustomLaunch(query)
128
- onLaunch && onLaunch.call(this, options)
153
+ await this.beforeCustomLaunch(query);
154
+ onLaunch && onLaunch.call(this, options);
129
155
  // 初始私有全局数据
130
156
  this.$$global = {
131
- homePageId: '<%= appConfig.homePageId %>'
132
- }
157
+ homePageId: '<%= appConfig.homePageId %>',
158
+ };
133
159
  },
134
160
  async onShow(options) {
135
- await this.beforeCustomLaunch(this._query)
136
- const fn = lifeCycle.onShow || lifeCycle.onAppShow
137
- fn && fn.call(this, options)
161
+ await this.beforeCustomLaunch(this._query);
162
+ const fn = lifeCycle.onShow || lifeCycle.onAppShow;
163
+ fn && fn.call(this, options);
138
164
  },
139
165
  onHide() {
140
- const fn = lifeCycle.onHide || lifeCycle.onAppHide
141
- fn && fn.call(this)
166
+ const fn = lifeCycle.onHide || lifeCycle.onAppHide;
167
+ fn && fn.call(this);
142
168
  },
143
169
  onError(msg) {
144
- const fn = lifeCycle.onError || lifeCycle.onAppError
145
- fn && fn.call(this, msg)
170
+ const fn = lifeCycle.onError || lifeCycle.onAppError;
171
+ fn && fn.call(this, msg);
146
172
  },
147
173
  onPageNotFound() {
148
- const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
149
- fn && fn.call(this)
174
+ const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound;
175
+ fn && fn.call(this);
150
176
  },
151
177
  onUnhandledRejection() {
152
- const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
153
- fn && fn.call(this)
178
+ const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection;
179
+ fn && fn.call(this);
154
180
  },
155
- })
181
+ });
@@ -30,6 +30,7 @@ export default {
30
30
  // setData merging
31
31
  pendingData: null,
32
32
  _settingData: false, // flag to prevent multiple setData at the same time
33
+ _flushId: null,
33
34
  flushPendingData() {
34
35
  if (!this.pendingData || this._settingData) { return }
35
36
  const patch = getDatapatch(this.data, this.pendingData)
@@ -41,6 +42,17 @@ export default {
41
42
  }
42
43
  this._settingData = true
43
44
  const lastUpdateTime = Date.now()
45
+ this._flushId = lastUpdateTime;
46
+ /**
47
+ * 兜底逻辑,当长时间 setData 没有返回时
48
+ * 直接抛弃,扭转 pending 状态
49
+ */
50
+ setTimeout(()=>{
51
+ if(this._flushId === lastUpdateTime && this._settingData) {
52
+ this._settingData = false;
53
+ this.flushPendingData()
54
+ }
55
+ }, 100)
44
56
  this.setData(patch, () => {<% if(debug) {%>
45
57
  const elapsedTime = Date.now() - lastUpdateTime;
46
58
  if(elapsedTime > 16) {
@@ -136,7 +136,7 @@ export function createEventHandlers(
136
136
  },
137
137
  dataContext,
138
138
  });
139
- let res = await l.handler.call(owner, { event, data: resolvedData });
139
+ let res = await l.handler.call(owner, { event, data: resolvedData, $w });
140
140
  nextEventHandles[0].handlerName =
141
141
  prefix && l.key ? `${prefix}$${l.key}${!isIfAction || res ? '_success' : '_fail'}` : '';
142
142
  nextEventHandles[0].event.detail = isIfAction ? event.detail : res;
@@ -283,21 +283,30 @@ export function createPage({
283
283
  app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
284
284
  });
285
285
  };
286
+ $page.setParams = (params) => {
287
+ Object.keys(params).forEach((keyPath) => {
288
+ app.utils.set($page.dataset?.params, keyPath, params[keyPath]);
289
+ });
290
+ }
286
291
 
287
292
  const { widgets, rootWidget } = createWidgets(widgetProps, dataBinds, this, $page.widgets);
288
293
  $page.widgets = widgets;
289
294
  $page._rootWidget = rootWidget;
290
295
 
291
296
  $page.invokeComponentMethod = ({ component, method, params }) => {
292
- const components = $page.widgets[component];
293
297
  let componentInstance = undefined;
294
- if (Array.isArray(components)) {
295
- if (components.length > 1) {
296
- throw new Error(`调用方法失败:id为${component}的组件拥有多个实例`);
298
+ if (typeof component === 'string') {
299
+ const components = $page.widgets[component];
300
+ if (Array.isArray(components)) {
301
+ if (components.length > 1) {
302
+ throw new Error(`调用方法失败:id为${component}的组件拥有多个实例`);
303
+ }
304
+ componentInstance = components[0];
305
+ } else {
306
+ componentInstance = components;
297
307
  }
298
- componentInstance = components[0];
299
308
  } else {
300
- componentInstance = components;
309
+ componentInstance = component
301
310
  }
302
311
 
303
312
  const currentInstanceRef = componentInstance?._getInstanceRef()?.current || {};
@@ -7,7 +7,7 @@
7
7
  } %>
8
8
  "@cloudbase/oauth": "0.1.1-alpha.5",
9
9
  "@cloudbase/weda-client": "1.0.6",
10
- "@cloudbase/weda-cloud-sdk": "1.0.43",
10
+ "@cloudbase/weda-cloud-sdk": "1.0.45",
11
11
  "mobx": "^5.15.4",
12
12
  "lodash.get": "^4.4.2",
13
13
  "lodash.set": "^4.3.2",