@cloudbase/lowcode-builder 1.3.12-alpha.3 → 1.3.12-alpha.4

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 (40) hide show
  1. package/lib/builder/config/index.js +1 -1
  2. package/lib/builder/core/index.d.ts +8 -0
  3. package/lib/builder/core/index.js +78 -8
  4. package/lib/builder/h5/generate.d.ts +2 -1
  5. package/lib/builder/h5/generate.js +14 -3
  6. package/lib/builder/h5/index.d.ts +4 -3
  7. package/lib/builder/h5/index.js +54 -3
  8. package/lib/builder/h5/webpack.js +1 -0
  9. package/lib/builder/mp/BuildContext.d.ts +9 -0
  10. package/lib/builder/mp/index.d.ts +8 -3
  11. package/lib/builder/mp/index.js +42 -32
  12. package/lib/builder/mp/materials.js +12 -10
  13. package/lib/builder/mp/util.js +29 -5
  14. package/lib/builder/mp/wxml.js +32 -4
  15. package/lib/builder/util/common.d.ts +1 -1
  16. package/lib/builder/util/common.js +0 -4
  17. package/lib/builder/util/generateFiles.d.ts +1 -2
  18. package/lib/builder/util/generateFiles.js +1 -13
  19. package/package.json +3 -3
  20. package/template/html/index.html.ejs +72 -4
  21. package/template/mp/app/weapps-api.js +8 -5
  22. package/template/mp/app.js +27 -4
  23. package/template/mp/app.wxss +2 -1
  24. package/template/mp/common/config.js +9 -0
  25. package/template/mp/common/config.wxs +3 -0
  26. package/template/mp/common/util.js +16 -9
  27. package/template/mp/common/utils.wxs +3 -1
  28. package/template/mp/common/weapp-page.js +57 -18
  29. package/template/mp/common/widget.js +42 -13
  30. package/template/mp/component/index.js +1 -0
  31. package/template/mp/datasources/config.js.tpl +4 -3
  32. package/template/mp/package.json +1 -1
  33. package/template/mp/page/api.js +5 -2
  34. package/template/mp/page/index.js +2 -1
  35. package/dist/builder.web.js +0 -71
  36. package/lib/.turbo/turbo-build.log +0 -0
  37. package/lib/.turbo/turbo-develop.log +0 -0
  38. package/lib/builder.web.js +0 -71
  39. package/lib/test.d.ts +0 -11
  40. package/lib/test.js +0 -717
@@ -11,10 +11,14 @@ import {
11
11
  } from '../datasources/index';
12
12
  import { runWatchers } from './watch';
13
13
  import { getMpEventHandlerName } from './util';
14
+ import { $w as baseAPI } from '../app/app-global';
15
+
16
+ const wxApp = getApp()
14
17
 
15
18
  export function createPage(
16
19
  id,
17
20
  uuid,
21
+ title,
18
22
  widgetProps,
19
23
  index = {},
20
24
  lifecycle,
@@ -61,6 +65,22 @@ export function createPage(
61
65
  return {};
62
66
  }
63
67
  };
68
+
69
+ // 更新设备信息 窗口信息
70
+ result['onResize'] = (res) => {
71
+ let device = baseAPI.device;
72
+ if(!device) {
73
+ return
74
+ }
75
+ const width = res?.size?.windowWidth;
76
+ const height = res?.size?.windowHeight;
77
+ if (width !== device?.window?.width || height !== device?.window?.height) {
78
+ device.window = {
79
+ width,
80
+ height
81
+ };
82
+ }
83
+ };
64
84
  return result;
65
85
  }
66
86
 
@@ -103,32 +123,53 @@ export function createPage(
103
123
  },
104
124
  methods: {
105
125
  _pageActive: true,
126
+ _beforePageCustomLaunchPromise: null,
127
+ _query: {},
128
+
106
129
  /** page lifecycles **/
107
130
  ...extractLifecycles(),
108
131
  ...evtHandlers,
109
132
  ...mergeRenderer,
110
- onLoad(options) {
133
+ async beforePageCustomLaunch(query) {
134
+ if(!this._beforePageCustomLaunchPromise){
135
+ this._beforePageCustomLaunchPromise = new Promise(async (resolve)=>{
136
+ await wxApp.globaldata?._beforePageCustomLaunchPromise
137
+ const $page = this._getInstance();
138
+ if(query){
139
+ EXTRA_API.setParams($page.uuid, query);
140
+ }
141
+ if(await checkAuth(app, app.id, $page)){
142
+ this.setData({
143
+ weDaHasLogin: true,
144
+ });
145
+ createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page }));
146
+ resolve()
147
+ }
148
+ })
149
+ }
150
+ return this._beforePageCustomLaunchPromise
151
+ },
152
+ async onLoad(options) {
111
153
  const $page = this._getInstance();
112
154
  setConfig({ currentPageId: $page.uuid });
113
155
  app.__internal__.activePage = $page;
114
156
  this._pageActive = true;
115
157
 
116
- let query = decodePageQuery(options || {});
117
- EXTRA_API.setParams($page.uuid, query);
118
- createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page }));
158
+ this._query = decodePageQuery(options || {});
119
159
 
120
- const hook = lifecycle.onLoad || lifecycle.onPageLoad;
121
- hook?.call?.($page, query);
160
+ await this.beforePageCustomLaunch?.(this._query)
122
161
 
123
- this.invokeEventHandler(id, 'load', { detail: { query } });
162
+ const hook = lifecycle.onLoad || lifecycle.onPageLoad;
163
+ await hook?.call?.($page, this._query);
164
+ this.invokeEventHandler(id, 'load', { detail: { query: this._query } });
124
165
  },
125
- onReady() {
166
+ async onReady() {
126
167
  const $page = this._getInstance();
127
168
 
128
169
  this._disposers.push(...runWatchers(index, this));
129
170
 
130
171
  const hook = lifecycle.onReady || lifecycle.onPageReady;
131
- hook?.call?.($page);
172
+ await hook?.call?.($page);
132
173
 
133
174
  this.invokeEventHandler(id, 'ready');
134
175
  },
@@ -146,15 +187,11 @@ export function createPage(
146
187
  app.__internal__.activePage = $page;
147
188
  this._pageActive = true;
148
189
 
149
- // 权限检查
150
- if (await checkAuth(app, app.id, $page)) {
151
- this.setData({
152
- weDaHasLogin: true,
153
- });
154
- const hook = lifecycle.onShow || lifecycle.onPageShow;
155
- hook?.call?.($page);
156
- this.invokeEventHandler(id, 'show');
157
- }
190
+ await this.beforePageCustomLaunch?.(this._query)
191
+
192
+ const hook = lifecycle.onShow || lifecycle.onPageShow;
193
+ await hook?.call?.($page);
194
+ this.invokeEventHandler(id, 'show');
158
195
  },
159
196
  onHide() {
160
197
  const $page = this._getInstance();
@@ -178,6 +215,8 @@ export function createPage(
178
215
  id,
179
216
  uuid,
180
217
  state: observable(pageState),
218
+ url: this.route,
219
+ name: title,
181
220
  widgets: {},
182
221
  });
183
222
  $page = pageContext;
@@ -651,13 +651,22 @@ function mountBuiltinWigetsAPI(widget, owner) {
651
651
 
652
652
  switch (widget.widgetType) {
653
653
  case `${REPEATER.MODULE_NAME}:${REPEATER.REPEATER_NAME}`: {
654
- const currentRef = observable({ current: undefined });
654
+ const currentRef = observable({ current: {} });
655
655
  widget._getInstanceRef = () => {
656
656
  return currentRef;
657
657
  }; // 默认初始值
658
658
  widget._disposers.push(
659
659
  autorun((r) => {
660
- currentRef.current = { data: widget.data };
660
+ currentRef.current = {
661
+ data: widget.data,
662
+ items: (widget.children || []).map((item) => {
663
+ const descendants = {};
664
+ Object.keys(item?._descendants || {}).forEach((key) => {
665
+ descendants[key] = item._descendants[key]._userWidget;
666
+ });
667
+ return descendants;
668
+ })
669
+ }
661
670
  }),
662
671
  );
663
672
  break;
@@ -707,18 +716,23 @@ class UserWidget {
707
716
  }
708
717
 
709
718
  // 优先 custom
710
- if (target.custom[prop]) {
719
+ if (prop in target.custom) {
711
720
  return target.custom[prop];
712
721
  }
713
722
 
714
723
  // 再尝试内置的方法和属性
715
- const buildinMember = target.sys[prop];
716
- if (buildinMember) return buildinMember;
724
+ if (prop in target.sys) {
725
+ return target.sys[prop];
726
+ }
717
727
 
718
728
  // 兼容原来的 widget。最后直接代理到 widget 上,主要是访问组件的属性
719
729
  // return target._widget[prop];
720
730
  return undefined;
721
731
  },
732
+ /**
733
+ * userwidget 不可写
734
+ */
735
+ set() {},
722
736
  });
723
737
  }
724
738
 
@@ -776,14 +790,29 @@ class UserWidget {
776
790
  }
777
791
 
778
792
  get custom() {
779
- const { methods = {}, ...restInstance } = this._widget._getInstanceRef?.()?.current || {};
780
-
781
- const userCustomMember = {
782
- ...this._widget._methods,
783
- ...restInstance,
784
- ...methods,
785
- };
786
-
793
+ const widget = this._widget;
794
+ const instance = widget?._getInstanceRef?.()?.current || {};
795
+ const userCustomMember = untracked(() => {
796
+ const { methods = {}, ...restInstance } = instance;
797
+ return new Proxy(
798
+ {
799
+ ...widget?._methods,
800
+ ...restInstance,
801
+ ...methods,
802
+ },
803
+ {
804
+ get(_, prop) {
805
+ if (prop in methods) {
806
+ return methods[prop];
807
+ }
808
+ if (prop !== 'methods' && prop in instance) {
809
+ return instance[prop];
810
+ }
811
+ return widget?._methods?.[prop];
812
+ },
813
+ },
814
+ );
815
+ });
787
816
  return userCustomMember;
788
817
  }
789
818
  }
@@ -18,6 +18,7 @@ const evtListeners = {<% Object.entries(eventHandlers).map(([handlerName, listen
18
18
  <%= handlerName%>: [
19
19
  <%listeners.map(l=> { %>{
20
20
  key: '<%= l.key %>',
21
+ sourceKey: '<%= l.sourceKey %>',
21
22
  handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else {%> <%= l.handler %> <%} %>,
22
23
  data: <%= stringifyObj(l.data, {depth: null}) %>,
23
24
  boundData: {<% Object.entries(l.boundData).map(([prop, bindMeta])=>{%>'<%= prop %>':($comp, lists, forItems, event, $context, $w) => {<%= bindMeta.imports %> return (
@@ -1,5 +1,6 @@
1
1
  import datasetProfiles from './dataset-profiles'
2
2
  const dataSourceProfiles = require('./datasource-profiles.js')
3
+ import config from '../common/config'
3
4
 
4
5
  /**
5
6
  * 数据源基本配置
@@ -25,14 +26,14 @@ export default {
25
26
  /**
26
27
  * 确定调用链路
27
28
  */
28
- endpointType: '<%= endpointType %>',
29
+ endpointType: config.endpointType,
29
30
  /**
30
31
  * 调用链路为 tcb-api 时有效
31
32
  * 私有化需要设置
32
33
  */
33
- tcbApiOrigin: '<%= tcbApiOrigin %>',
34
+ tcbApiOrigin: config.tcbApiOrigin,
34
35
  /**
35
36
  * 是否是处于私有化版本
36
37
  */
37
- isPrivate: <%= isPrivateMode %>
38
+ isPrivate: config.isPrivate
38
39
  }
@@ -5,7 +5,7 @@
5
5
  "dependencies": {<% if(importJSSDK) {%>
6
6
  "@cloudbase/js-sdk": "2.5.6-beta.1",<% } %>
7
7
  "@cloudbase/oauth": "0.1.1-alpha.5",
8
- "@cloudbase/weda-client": "0.2.45",
8
+ "@cloudbase/weda-client": "0.2.56-alpha.2",
9
9
  "@cloudbase/weda-cloud-sdk": "1.0.26",
10
10
  "mobx": "^5.15.4",
11
11
  "lodash.get": "^4.4.2",
@@ -8,8 +8,11 @@ export const $w = new Proxy(
8
8
  baseAPI,
9
9
  {
10
10
  get(target, prop) {
11
- if(prop === '$page'){
12
- return $page
11
+ /**
12
+ * 使用当前实例进行覆盖
13
+ */
14
+ if (prop === '$page' || prop === 'page') {
15
+ return $page;
13
16
  }
14
17
  // 尝试代理页面级别组件实例
15
18
  const pageWidget = $page.widgets?.[prop];
@@ -14,6 +14,7 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
14
14
  <%= handlerName%>: [
15
15
  <%listeners.map(l=> { %>{
16
16
  key: '<%= l.key %>',
17
+ sourceKey: '<%= l.sourceKey %>',
17
18
  handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else {%> <%= l.handler %> <%} %>,
18
19
  data: <%= stringifyObj(l.data, {depth: null}) %>,
19
20
  boundData: {<% Object.entries(l.boundData).map(([prop, bindMeta])=>{%>'<%= prop %>':($page, lists, forItems, event, $context, $w) => {<%= bindMeta.imports %> return (
@@ -32,4 +33,4 @@ const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
32
33
  },<%}) %>
33
34
  }
34
35
 
35
- createPage('<%= pageName %>', '<%= pageUUID %>', widgetProps, {}, lifecyle, state, computed, evtListeners, dataBinds, app, handlers, $page, <%= pageAttributes?JSON.stringify(pageAttributes):'{}' %>)
36
+ createPage('<%= pageName %>', '<%= pageUUID %>','<%= pageTitle %>', widgetProps, {}, lifecyle, state, computed, evtListeners, dataBinds, app, handlers, $page, <%= pageAttributes?JSON.stringify(pageAttributes):'{}' %>)