@cloudbase/lowcode-builder 1.8.9 → 1.8.11

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 (36) hide show
  1. package/lib/builder/config/index.d.ts +2 -2
  2. package/lib/builder/config/index.js +2 -2
  3. package/lib/builder/core/index.d.ts +1 -1
  4. package/lib/builder/core/index.js +24 -20
  5. package/lib/builder/h5/generate.d.ts +7 -1
  6. package/lib/builder/h5/generate.js +16 -8
  7. package/lib/builder/h5/webpack.js +3 -1
  8. package/lib/builder/mp/BuildContext.d.ts +4 -0
  9. package/lib/builder/mp/index.js +4 -3
  10. package/lib/builder/mp/materials.js +1 -0
  11. package/lib/builder/mp/wxml.js +10 -0
  12. package/lib/builder/util/generateFiles.d.ts +1 -1
  13. package/lib/builder/util/generateFiles.js +13 -8
  14. package/package.json +3 -3
  15. package/template/html/index.html.ejs +5 -3
  16. package/template/mp/common/{event-emitter.ts → event-emitter.js} +25 -21
  17. package/template/mp/common/{flow.ts → flow.js} +11 -50
  18. package/template/mp/common/loading/index.js +30 -0
  19. package/template/mp/common/loading/index.json +4 -0
  20. package/template/mp/common/loading/index.wxml +8 -0
  21. package/template/mp/common/loading/index.wxss +44 -0
  22. package/template/mp/common/{query.ts → query.js} +21 -85
  23. package/template/mp/common/util.js +17 -9
  24. package/template/mp/common/weapp-page.js +20 -9
  25. package/dist/builder.web.js +0 -71
  26. package/lib/.turbo/turbo-build.log +0 -0
  27. package/lib/.turbo/turbo-develop.log +0 -0
  28. package/lib/builder.web.js +0 -71
  29. package/lib/event-emitter.d.ts +0 -32
  30. package/lib/event-emitter.js +0 -88
  31. package/lib/flow.d.ts +0 -32
  32. package/lib/flow.js +0 -60
  33. package/lib/query.d.ts +0 -48
  34. package/lib/query.js +0 -171
  35. package/lib/test.d.ts +0 -11
  36. package/lib/test.js +0 -717
@@ -1,59 +1,20 @@
1
- import { observable, IReactionDisposer, autorun, toJS } from 'mobx';
1
+ import { observable, autorun, toJS } from 'mobx';
2
2
  import { createEventHandlers, getMpEventHandlerName, mergeDynamic2StaticData } from './util';
3
3
  import { Event } from './event-emitter';
4
4
 
5
- interface IMPDataSourceQuery {
6
- id: string;
7
- label?: string;
8
- description?: string;
9
- trigger: 'auto' | 'manual';
10
- type: 'model' | 'apis' | 'sql';
11
- dataSourceName: string;
12
- methodName: string;
13
- data: object;
14
- dataBinds: Record<string, Function>;
15
- /**
16
- * 预处理后 event handler listeners
17
- */
18
- eventHandlers?: Record<string, any>;
19
- }
20
- interface IQueryContext {
21
- $w: any,
22
- $app?: any,
23
- $page?: any
24
- };
25
- type IDataBind = any;
26
- interface IGenerateOptions {
27
- looseError: boolean
28
- };
29
-
30
5
  export class Query {
31
- private _schema: IMPDataSourceQuery;
32
- private _context: IQueryContext;
33
- private _disposes: IReactionDisposer[] = [];
34
- private _dataBinds: Record<string, IDataBind> = {};
35
- private _triggered = false;
36
- private _action: any;
37
- private _paramsRef: { current: any } = observable({ current: null });
38
- private _currentRequestKey: any = null;
39
- private _observableValue: { data: any; error: Error | null } = observable({ data: null, error: null });
40
- private _eventHandlerMap: Record<string, Function> = {};
41
- private _timer: any;
42
-
43
- constructor({
44
- schema,
45
- context,
46
- options = {},
47
- }: {
48
- schema: IMPDataSourceQuery;
49
- context: IQueryContext;
50
- options?: IGenerateOptions;
51
- }) {
6
+ constructor({ schema, context, options = {} }) {
7
+ this._disposes = [];
8
+ this._dataBinds = {};
9
+ this._triggered = false;
10
+ this._paramsRef = observable({ current: null });
11
+ this._currentRequestKey = null;
12
+ this._observableValue = observable({ data: null, error: null });
13
+ this._eventHandlerMap = {};
52
14
  const { looseError = false } = options;
53
15
  const { $w } = context;
54
16
  this._schema = schema;
55
17
  this._context = context;
56
-
57
18
  if (this._schema?.trigger === 'auto') {
58
19
  this._disposes.push(
59
20
  autorun(
@@ -71,38 +32,29 @@ export class Query {
71
32
  ),
72
33
  );
73
34
  }
74
-
75
- const baseParam: {
76
- dataSourceName: string;
77
- sqlTemplateId?: string;
78
- methodName?: string;
79
- } = {
35
+ const baseParam = {
80
36
  dataSourceName: this._schema.dataSourceName,
81
37
  };
82
-
83
38
  if (this._schema?.type === 'sql') {
84
39
  baseParam.sqlTemplateId = this._schema.methodName;
85
40
  } else {
86
41
  baseParam.methodName = this._schema.methodName;
87
42
  }
88
-
89
43
  this._paramsRef.current = this._schema.data;
90
44
  this._dataBinds = this._schema.dataBinds;
91
-
92
45
  this._action = async (data) => {
93
46
  return $w.cloud.callDataSource({
94
47
  ...baseParam,
95
48
  params: data,
96
49
  });
97
50
  };
98
-
99
51
  this._eventHandlerMap = Object.entries(
100
52
  createEventHandlers(this._schema.eventHandlers || {}, {
101
53
  looseError: looseError,
102
54
  isComposite: false,
103
55
  }),
104
56
  ).reduce(
105
- (map, [key, fn]: [string, any]) => {
57
+ (map, [key, fn]) => {
106
58
  // map[key] = fn.bind(this);
107
59
  map[key] = fn;
108
60
  return map;
@@ -111,7 +63,6 @@ export class Query {
111
63
  _getInstance: () => this._context.$page || this._context.$app,
112
64
  },
113
65
  );
114
-
115
66
  // this._emit = async (trigger, eventData, originalEvent?) =>
116
67
  // generateEmit($w)(
117
68
  // trigger,
@@ -131,41 +82,32 @@ export class Query {
131
82
  // $w.page.id,
132
83
  // true,
133
84
  // );
134
-
135
85
  return this;
136
86
  }
137
-
138
- get id(): string {
87
+ get id() {
139
88
  return this._schema?.id || '';
140
89
  }
141
-
142
- get label(): string {
90
+ get label() {
143
91
  return this._schema?.label || '';
144
92
  }
145
-
146
- get description(): string {
93
+ get description() {
147
94
  return this._schema?.description || '';
148
95
  }
149
-
150
96
  get data() {
151
97
  return this._observableValue.data;
152
98
  }
153
-
154
99
  get error() {
155
100
  return this._observableValue.error;
156
101
  }
157
-
158
- async trigger(additionalScope?, options = {}) {
102
+ async trigger(additionalScope, options = {}) {
159
103
  this._triggered = true;
160
104
  return this._innerTrigger(this._resolveParams(), additionalScope, options);
161
105
  }
162
-
163
106
  reset() {
164
107
  this._observableValue.data = null;
165
108
  this._observableValue.error = null;
166
109
  }
167
-
168
- async _innerTrigger(data, additionalScope?, options = {}) {
110
+ async _innerTrigger(data, additionalScope, options = {}) {
169
111
  this._currentRequestKey = Date.now();
170
112
  const key = this._currentRequestKey;
171
113
  try {
@@ -179,14 +121,13 @@ export class Query {
179
121
  } catch (e) {
180
122
  if (key === this._currentRequestKey) {
181
123
  this._observableValue.data = null;
182
- this._observableValue.error = e as any;
124
+ this._observableValue.error = e;
183
125
  this._emit(`fail`, e);
184
126
  }
185
127
  throw e;
186
128
  }
187
129
  }
188
-
189
- private _debounceTrigger(...args) {
130
+ _debounceTrigger(...args) {
190
131
  if (this._timer) {
191
132
  clearTimeout(this._timer);
192
133
  }
@@ -194,12 +135,10 @@ export class Query {
194
135
  this._innerTrigger(...args);
195
136
  }, 300);
196
137
  }
197
-
198
138
  destroy() {
199
139
  this._disposes.forEach((dispose) => dispose());
200
140
  }
201
-
202
- private _resolveParams() {
141
+ _resolveParams() {
203
142
  /**
204
143
  * 这里万一其中某个字段计算失败
205
144
  * 好像会阻塞其他字段的计算
@@ -216,8 +155,7 @@ export class Query {
216
155
  // may be additional scope
217
156
  })?.params;
218
157
  }
219
-
220
- private async _emit(eventName: string, data?: any) {
158
+ async _emit(eventName, data) {
221
159
  return this._eventHandlerMap[getMpEventHandlerName(this.id, eventName)]?.(
222
160
  new Event({
223
161
  type: eventName,
@@ -228,10 +166,8 @@ export class Query {
228
166
  );
229
167
  }
230
168
  }
231
-
232
- export function generateDatasetQuery(schema, context: IQueryContext, options: IGenerateOptions) {
169
+ export function generateDatasetQuery(schema, context, options) {
233
170
  const result = {};
234
-
235
171
  for (const key in schema) {
236
172
  result[key] = new Query({ schema: schema[key], context, options });
237
173
  }
@@ -6,7 +6,6 @@ import { getAccessToken, loginScope } from '../datasources/index';
6
6
  import { app } from '../app/weapps-api';
7
7
  export { generateDatasetQuery } from './query';
8
8
  export { generateEventFlows } from './flow';
9
- import { Event } from './event-emitter';
10
9
 
11
10
  /**
12
11
  * Convert abcWordSnd -> abc-word-snd
@@ -157,6 +156,9 @@ export function createEventHandlers(
157
156
  }
158
157
  }
159
158
  } catch (e) {
159
+ if (e.message) {
160
+ e.message = `${currentTarget?.id || ''}[${trigger}:${l.key}]: ${e.message}`;
161
+ }
160
162
  nextEventHandles[0].handlerName = l.key ? `${prefix}$${l.key}_fail` : '';
161
163
  nextEventHandles[0].event.detail = isIfAction ? event.detail : e;
162
164
  error = e;
@@ -170,12 +172,20 @@ export function createEventHandlers(
170
172
  const nextHandler = nextEventHandles[0];
171
173
 
172
174
  if (!self[nextHandler.handlerName] && error) {
173
- console.error(`Action error: [${trigger}:${l.key}]`, error);
175
+ console.error(`Action error:`, error);
174
176
  if (!looseError) {
175
- app.showToast({
176
- icon: 'error',
177
- title: `事件响应失败`,
178
- });
177
+ if (app.__internal__?.env?.type !== 'production') {
178
+ app.showModal({
179
+ title: `事件响应失败`,
180
+ content: error.message || '',
181
+ showCancel: false,
182
+ });
183
+ } else {
184
+ app.showToast({
185
+ icon: 'error',
186
+ title: `事件响应失败`,
187
+ });
188
+ }
179
189
  }
180
190
  throw error;
181
191
  } else {
@@ -213,7 +223,6 @@ export function createEventHandlers(
213
223
  return res.length ? res[0] : event.detail;
214
224
  });
215
225
  }
216
-
217
226
  };
218
227
  }
219
228
 
@@ -456,7 +465,6 @@ export function formatErrorMsg(e) {
456
465
  * 检查页面权限
457
466
  **/
458
467
  export async function checkAuth(app, appId, $page) {
459
- return true;
460
468
  const loginPage = findLoginPage(app);
461
469
  if (loginPage?.id === $page.id) {
462
470
  return true;
@@ -521,7 +529,7 @@ export function redirectToLogin(currentPage) {
521
529
  pageId: loginPage.id,
522
530
  params: {
523
531
  sourcePageId: currentPage.id,
524
- sourcePageParams: currentPage.params,
532
+ sourcePageParams: currentPage.params || currentPage.dataset?.params,
525
533
  },
526
534
  });
527
535
  } else {
@@ -86,7 +86,11 @@ export function createPage({
86
86
 
87
87
  return Component({
88
88
  _componentType: 'page',
89
- data: createInitData(widgetProps, dataBinds),
89
+ data: {
90
+ ...createInitData(widgetProps, dataBinds),
91
+ _isCheckingAtuh: false,
92
+ weDaHasLogin: false
93
+ },
90
94
  lifetimes: {
91
95
  attached() {
92
96
  this._disposers = []
@@ -108,7 +112,7 @@ export function createPage({
108
112
  const widget = getWidget($page.widgets, e.target.id);
109
113
  widget._methods = {};
110
114
  };
111
- this._disposers.push( ...this.initMergeRenderer($page.widgets));
115
+ this._disposers.push(...this.initMergeRenderer($page.widgets));
112
116
  },
113
117
  detached() {
114
118
  const $page = this._getInstance();
@@ -142,18 +146,25 @@ export function createPage({
142
146
  if (query) {
143
147
  EXTRA_API.setParams($page.uuid, query);
144
148
  }
145
- if (await checkAuth(app, app.id, $page)) {
146
- this.setData({
147
- weDaHasLogin: true,
148
- });
149
- createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page }));
149
+ try {
150
+ this.setData({ _isCheckingAtuh: true })
151
+ const auth = await checkAuth(app, app.id, $page);
152
+ if(auth) {
153
+ this.setData({
154
+ weDaHasLogin: true,
155
+ });
156
+ createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page }));
157
+ }
158
+ } finally {
159
+ this.setData({ _isCheckingAtuh: false })
150
160
  }
161
+
151
162
  // eslint-disable-next-line no-restricted-syntax
152
- for (const queryId in $page.dataset?.query||{}) {
163
+ for (const queryId in $page.dataset?.query || {}) {
153
164
  if ($page.dataset.query[queryId]?._schema?.trigger === 'auto') {
154
165
  try {
155
166
  $page.dataset.query[queryId].trigger();
156
- this._disposers.push(()=> $page.dataset.query[queryId].destroy())
167
+ this._disposers.push(() => $page.dataset.query[queryId].destroy())
157
168
  } catch (e) {
158
169
  console.error(`query ${queryId} 初始化失败:`, e);
159
170
  }