@cloudbase/lowcode-builder 1.6.4 → 1.6.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
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",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@cloudbase/cals": "^1.0.3",
42
- "@cloudbase/lowcode-generator": "^1.6.4",
42
+ "@cloudbase/lowcode-generator": "^1.6.5",
43
43
  "axios": "^0.21.0",
44
44
  "browserfs": "^1.4.3",
45
45
  "browserify-zlib": "^0.2.0",
@@ -523,6 +523,10 @@
523
523
  cdnEndpoints.cdngo
524
524
  %>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.29/dist/h5.browser.js"
525
525
  ></script>
526
+ <script
527
+ crossorigin
528
+ src="<%= cdnEndpoints.cdngo %>/lcap/lcap-resource-cdngo/-/release/_npm/acorn@8.0.4/dist/acorn.js"
529
+ ></script>
526
530
  <script>
527
531
  // zxing polifill
528
532
  if (!this.globalThis) {
@@ -543,7 +547,7 @@
543
547
  crossorigin
544
548
  src="<%=
545
549
  cdnEndpoints.cdngo
546
- %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.413fc7788ab27e709449.bundle.js"
550
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.b13197aa3e72385a9cc9.bundle.js"
547
551
  ></script>
548
552
  </body>
549
553
  </html>
@@ -68,8 +68,12 @@ setConfig({
68
68
  const loginPage = findLoginPage();
69
69
  if (loginPage) {
70
70
  const authConfig = await getAuthConfig();
71
- const isAnonymous = await checkAnonymous();
72
- if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
71
+ if (authConfig.RejectStrategy == 'to_login') {
72
+ if (['InnerError.AuthFailure'].includes(res?.result?.code)) {
73
+ const isAnonymous = await checkAnonymous();
74
+ if (!isAnonymous) return;
75
+ // 匿名用户越权去登录
76
+ }
73
77
  redirectToLogin();
74
78
  } else if (authConfig.RejectStrategy == 'show_warning') {
75
79
  app.showToast({
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-restricted-syntax */
1
2
  'use strict';
2
3
  import { generateForContextOfWidget, generateWidgetAPIContext, getWidget } from './widget';
3
4
  import { observable, untracked } from 'mobx';
@@ -33,7 +34,7 @@ export function generateDataContext(widget) {
33
34
  while (widget?._scope) {
34
35
  const current = widget;
35
36
  // 此处采用代理的方式,是为了可以获取到最新的 _scope.dataContext 防止 dataContext 引用被重新赋值
36
- if(current?._scope?.id){
37
+ if (current?._scope?.id) {
37
38
  Object.defineProperty(dataContext, current._scope.id, {
38
39
  get() {
39
40
  return current?._scope?.dataContext;
@@ -53,9 +54,10 @@ export function createEventHandlers(
53
54
  evtListeners,
54
55
  options = {
55
56
  looseError: false,
57
+ isComposite: false,
56
58
  },
57
59
  ) {
58
- const { looseError = false } = options;
60
+ const { looseError = false, isComposite = false } = options;
59
61
  const evtHandlers = {};
60
62
  for (const name in evtListeners) {
61
63
  const listeners = evtListeners[name];
@@ -73,41 +75,103 @@ export function createEventHandlers(
73
75
  const dataContext = untracked(() => generateDataContext(currentTarget));
74
76
  const $w = untracked(() => generateWidgetAPIContext(owner?.__internal__?.$w, currentTarget, forContext));
75
77
 
76
- const currentPageId = app.__internal__?.activePage?.id
78
+ function checkPageActive(pageId, currentPageContext, listener) {
79
+ /**
80
+ * 复合组件自身不中断校验
81
+ */
82
+ if (isComposite) {
83
+ return true;
84
+ }
85
+ const { id, __internal__ } = currentPageContext || {};
86
+ if (pageId && id) {
87
+ if (pageId !== id || (__internal__ && !__internal__.active)) {
88
+ console.error(`Action error: [${listener.trigger}:${listener.key}] 页面生命周期结束,链式调用中断`);
89
+ return false;
90
+ }
91
+ }
92
+ return true;
93
+ }
94
+
77
95
  listeners.forEach(async (l) => {
78
- if(currentPageId && owner.id && currentPageId !== owner.id) {
79
- console.error(`Action error: [${trigger}:${l.key}] 页面生命周期结束,链式调用中断`);
80
- return ;
96
+ /**
97
+ * 调用前置校验
98
+ * 是否仍可调用方法
99
+ */
100
+ if (!checkPageActive(owner.id, app.__internal__?.activePage, l)) {
101
+ return;
81
102
  }
103
+
82
104
  let { data = {}, boundData = {} } = l;
83
105
  data = { ...data };
106
+ const nextEventHandles = [
107
+ {
108
+ handlerName: '',
109
+ event: {
110
+ ...event,
111
+ },
112
+ },
113
+ ];
114
+ let error = false;
115
+ const isIfAction = l.sourceKey === 'platform:utils.If';
116
+ const isShowModalAction = l.sourceKey === 'platform:showModal';
84
117
  try {
85
118
  for (const k in boundData) {
86
119
  set(data, k, boundData[k].call(owner, owner, lists, forItems, event, dataContext, $w));
87
120
  }
88
121
  let res = await l.handler.call(owner, { event, data });
89
- let eventName = prefix && l.key ? `${prefix}$${l.key}${(l.sourceKey !== 'platform:utils.If') ? '_success' : (res ? '_success' : '_fail')}` : '';
90
- self[eventName] &&
91
- self[eventName]({
92
- ...event,
93
- detail: l.sourceKey === 'platform:utils.If' ? event.detail : res,
94
- });
122
+ nextEventHandles[0].handlerName =
123
+ prefix && l.key ? `${prefix}$${l.key}${!isIfAction || res ? '_success' : '_fail'}` : '';
124
+ nextEventHandles[0].event.detail = isIfAction ? event.detail : res;
125
+ if (isShowModalAction) {
126
+ let handlerName = '';
127
+
128
+ if (res.cancel) {
129
+ handlerName = `${prefix}$${l.key}_cancel`;
130
+ } else if (res.confirm) {
131
+ handlerName = `${prefix}$${l.key}_confirm`;
132
+ }
133
+
134
+ if (handlerName) {
135
+ nextEventHandles.push({
136
+ handlerName,
137
+ event: {
138
+ ...event,
139
+ detail: res,
140
+ },
141
+ });
142
+ }
143
+ }
95
144
  } catch (e) {
96
- let eventName = l.key ? `${prefix}$${l.key}_fail` : '';
97
- if (self[eventName]) {
98
- await self[eventName]({
99
- ...event,
100
- detail: e,
101
- });
102
- } else {
103
- console.error(`Action error: [${trigger}:${l.key}]`, e);
145
+ nextEventHandles[0].handlerName = l.key ? `${prefix}$${l.key}_fail` : '';
146
+ nextEventHandles[0].event.detail = isIfAction ? event.detail : e;
147
+ error = e;
148
+ }
149
+
150
+ /**
151
+ * 调用后置校验
152
+ * 是否触发后置事件
153
+ */
154
+ if (checkPageActive(owner.id, app.__internal__?.activePage, l)) {
155
+ const nextHandler = nextEventHandles[0];
156
+
157
+ if (!self[nextHandler.handlerName] && error) {
158
+ console.error(`Action error: [${trigger}:${l.key}]`, error);
104
159
  if (!looseError) {
105
160
  app.showToast({
106
161
  icon: 'error',
107
162
  title: `事件响应失败`,
108
163
  });
109
164
  }
110
- throw e;
165
+ throw error;
166
+ } else {
167
+ await Promise.all(
168
+ nextEventHandles.map(async (nextHandler) => {
169
+ if (self[nextHandler.handlerName]) {
170
+ return self[nextHandler.handlerName](nextHandler.event);
171
+ }
172
+ return null;
173
+ }),
174
+ );
111
175
  }
112
176
  }
113
177
  });
@@ -313,7 +377,11 @@ async function getAccessPermission(app, appId, pageId) {
313
377
  const resourceInfo = res.find((i) => i.ResourceId === cacheKey);
314
378
  const isAccess = !!resourceInfo?.IsAccess;
315
379
  _AUTH_CACHE_MAP[cacheKey] = isAccess;
316
- return isAccess;
380
+
381
+ return {
382
+ isAccess,
383
+ roleId: resourceInfo?.RoleId,
384
+ };
317
385
  } else {
318
386
  throw new Error(`鉴权接口返回参数不正确 - ${JSON.stringify(res)}`);
319
387
  }
@@ -330,7 +398,7 @@ export async function checkAnonymous() {
330
398
  const scope = await loginScope();
331
399
  isAnonymous = scope === 'anonymous';
332
400
  }
333
- } catch (e) { }
401
+ } catch (e) {}
334
402
  return isAnonymous;
335
403
  }
336
404
 
@@ -359,17 +427,17 @@ export async function checkAuth(app, appId, $page) {
359
427
  requestList.push(getAuthConfig(app));
360
428
  }
361
429
  try {
362
- const [isAccess, authConfig] = await Promise.all(requestList);
430
+ const [accessData, authConfig] = await Promise.all(requestList);
363
431
  app.hideNavigationBarLoading();
364
432
 
365
433
  const isAnonymousUser = await checkAnonymous();
366
434
 
367
- if (!isAccess) {
435
+ if (!accessData?.isAccess) {
368
436
  if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
369
437
  redirectToLogin($page);
370
438
  } else {
371
439
  app.showToast({
372
- title: '页面无访问权限',
440
+ title: ['-2', '-4'].includes(accessData?.roleId) ? '默认访客无权限' : '页面无访问权限',
373
441
  icon: 'error',
374
442
  });
375
443
  }
@@ -378,14 +446,14 @@ export async function checkAuth(app, appId, $page) {
378
446
  try {
379
447
  if (isAnonymousUser) {
380
448
  redirectToLogin($page);
381
- return false
449
+ return false;
382
450
  }
383
451
  } catch (e) {
384
452
  redirectToLogin($page);
385
- return false
453
+ return false;
386
454
  }
387
455
  }
388
- return isAccess;
456
+ return accessData?.isAccess;
389
457
  } catch (e) {
390
458
  app.showModal({
391
459
  title: '页面鉴权失败',
@@ -471,8 +539,9 @@ async function getGeneralOptions(optionName) {
471
539
 
472
540
  export function getMpEventHandlerName(widgetId, evtName, modifier = {}) {
473
541
  // Only builtin events have will bubble
474
- return `on${widgetId}$${evtName.replace(/\./g, '_')}${modifier.isCapturePhase ? '$cap' : ''}${modifier.noPropagation ? '$cat' : ''
475
- }`;
542
+ return `on${widgetId}$${evtName.replace(/\./g, '_')}${modifier.isCapturePhase ? '$cap' : ''}${
543
+ modifier.noPropagation ? '$cat' : ''
544
+ }`;
476
545
  }
477
546
 
478
547
  function isPlainObject(src) {
@@ -56,6 +56,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
56
56
  attached() {
57
57
  const $comp = this._getInstance()
58
58
  if(!$comp) return
59
+ $comp.__internal__.active = this._pageActive
59
60
 
60
61
  $comp.props.events = createPropEvents(events, this)
61
62
  const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, this, $comp.widgets)
@@ -92,6 +93,8 @@ export function createComponent(key, behaviors, properties, events, handler, dat
92
93
  detached() {
93
94
  const $comp = this._getInstance()
94
95
  if(!$comp) return
96
+ this._pageActive = false
97
+ $comp.__internal__.active = this._pageActive
95
98
 
96
99
  $comp.widgets = null
97
100
  $comp.node._eventListeners.clear();
@@ -123,7 +126,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
123
126
  },
124
127
 
125
128
  methods: {
126
- ...createEventHandlers(evtListeners, { looseError: true }),
129
+ ...createEventHandlers(evtListeners, { looseError: true, isComposite: true }),
127
130
  ...mergeRenderer,
128
131
  _getInstance() {
129
132
  if(!this.$WEAPPS_COMP){
@@ -112,6 +112,8 @@ export function createPage(
112
112
  detached() {
113
113
  const $page = this._getInstance();
114
114
  this._pageActive = false;
115
+ $page.__internal__.active = this._pageActive;
116
+
115
117
  disposeWidget($page._rootWidget);
116
118
  this._disposers.forEach((dispose) => dispose());
117
119
  },
@@ -152,8 +154,9 @@ export function createPage(
152
154
  async onLoad(options) {
153
155
  const $page = this._getInstance();
154
156
  setConfig({ currentPageId: $page.uuid });
155
- app.__internal__.activePage = $page;
156
157
  this._pageActive = true;
158
+ $page.__internal__.active = this._pageActive;
159
+ app.__internal__.activePage = $page;
157
160
 
158
161
  this._query = decodePageQuery(options || {});
159
162
 
@@ -184,8 +187,9 @@ export function createPage(
184
187
  async onShow() {
185
188
  const $page = this._getInstance();
186
189
  setConfig({ currentPageId: $page.uuid });
187
- app.__internal__.activePage = $page;
188
190
  this._pageActive = true;
191
+ $page.__internal__.active = this._pageActive;
192
+ app.__internal__.activePage = $page;
189
193
 
190
194
  await this.beforePageCustomLaunch?.(this._query)
191
195
 
@@ -198,6 +202,7 @@ export function createPage(
198
202
  const hook = lifecycle.onHide || lifecycle.onPageHide;
199
203
  hook?.call?.($page);
200
204
  this._pageActive = false;
205
+ $page.__internal__.active = this._pageActive;
201
206
 
202
207
  // 触发页面节点事件
203
208
  this.invokeEventHandler(id, 'hide');
@@ -1,7 +1,9 @@
1
1
  import { $w as baseAPI } from '<%= subLevelPath %>../../app/weapps-api'
2
2
 
3
3
  export const $page = {
4
- __internal__: {}
4
+ __internal__: {
5
+ active: false
6
+ }
5
7
  };
6
8
 
7
9
  export const $w = new Proxy(
@@ -180,7 +180,8 @@ module.exports = function (options) {
180
180
  },
181
181
  {
182
182
  test: /\.(js|jsx)$/,
183
- exclude: /node_modules\/(?!(@cloudbase\/weda-ui)|(@tcwd\/vuera)|(@tcwd\/weapps-core))|gsd-kbone-react/,
183
+ exclude:
184
+ /node_modules\/(?!(@cloudbase\/weda-ui)|(@tcwd\/vuera)|(@tcwd\/weapps-core)|(@react-spring))|gsd-kbone-react/,
184
185
  use: ['happypack/loader?id=babel'],
185
186
  },
186
187
  {