@cloudbase/lowcode-builder 1.8.106 → 1.8.108
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/lib/builder/config/dependencies.d.ts +10 -0
- package/lib/builder/config/dependencies.js +46 -0
- package/lib/builder/config/index.d.ts +1 -0
- package/lib/builder/config/index.js +5 -3
- package/lib/builder/core/index.d.ts +1 -1
- package/lib/builder/core/index.js +13 -13
- package/lib/builder/h5/generate.js +1 -0
- package/lib/builder/mp/BuildContext.d.ts +1 -0
- package/lib/builder/mp/index.d.ts +1 -2
- package/lib/builder/mp/index.js +13 -38
- package/lib/builder/mp/lowcode.js +5 -1
- package/lib/builder/mp/materials.d.ts +2 -3
- package/lib/builder/mp/materials.js +28 -26
- package/lib/builder/mp/mp_config.js +2 -1
- package/lib/builder/mp/util.d.ts +5 -2
- package/lib/builder/mp/util.js +14 -6
- package/lib/builder/mp/wxml.d.ts +3 -1
- package/lib/builder/mp/wxml.js +20 -7
- package/lib/builder.web.js +8 -8
- package/package.json +4 -4
- package/template/html/index.html.ejs +4 -2
- package/template/mp/app/common.js +0 -2
- package/template/mp/app/weapps-api.js +1 -20
- package/template/mp/common/info/index.js +4 -2
- package/template/mp/common/util.js +33 -774
- package/template/mp/common/weapp-page.js +12 -514
- package/template/mp/component/index.js +52 -19
- package/template/mp/component/index.json +1 -1
- package/template/mp/datasources/index.js.tpl +3 -99
- package/template/mp/package.json +4 -15
- package/template/mp/packages/$wd_system/pages/login/index.json +1 -1
- package/template/mp/packages/$wd_system/pages/login/methods/loginByWXPhone.js +6 -3
- package/template/mp/page/index.js +1 -2
- package/template/mp/common/constant.js +0 -1
- package/template/mp/common/data-patch-test.js +0 -60
- package/template/mp/common/data-patch.js +0 -66
- package/template/mp/common/event-emitter.js +0 -124
- package/template/mp/common/flow.js +0 -65
- package/template/mp/common/merge-renderer.js +0 -75
- package/template/mp/common/placeholder/index.js +0 -1
- package/template/mp/common/placeholder/index.json +0 -4
- package/template/mp/common/placeholder/index.wxml +0 -1
- package/template/mp/common/placeholder/index.wxss +0 -1
- package/template/mp/common/query.js +0 -300
- package/template/mp/common/style.js +0 -34
- package/template/mp/common/watch.js +0 -70
- package/template/mp/common/weapp-component.js +0 -289
- package/template/mp/common/widget.js +0 -872
|
@@ -1,516 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import mergeRenderer from './merge-renderer';
|
|
13
|
-
import {
|
|
14
|
-
setDatasetProfiles,
|
|
15
|
-
createDataset,
|
|
16
|
-
EXTRA_API,
|
|
17
|
-
createStateDataSourceVar,
|
|
18
|
-
generateParamsParser,
|
|
19
|
-
setConfig,
|
|
20
|
-
} from './cloud-sdk';
|
|
21
|
-
import { runWatchers, watchAndSyncDatasetState2Local } from './watch';
|
|
22
|
-
import { getWedaAPI, urlJoinParams } from '@cloudbase/weda-client';
|
|
23
|
-
import { Event } from './event-emitter';
|
|
24
|
-
import { mergeDynamic2StaticData, patchWdigetPropsWithEvtListeners } from './util';
|
|
25
|
-
import { styleToCss } from './style';
|
|
26
|
-
|
|
27
|
-
export const PAGE_ROOT_SYMBOL = Symbol('@@page_route@@')
|
|
28
|
-
|
|
29
|
-
const wxApp = getApp();
|
|
30
|
-
|
|
31
|
-
function resolveParticialPageData(ctx, key, data = {}, dataBinds = {}) {
|
|
32
|
-
const reg = new RegExp(`^${key}`)
|
|
33
|
-
let merge = { [key]: data[key] }
|
|
34
|
-
const pickedDataBinds = {}
|
|
35
|
-
for (const key in dataBinds) {
|
|
36
|
-
if (reg.test(key)) {
|
|
37
|
-
pickedDataBinds[key] = dataBinds[key]
|
|
1
|
+
import { createPage as baseCreatePage } from '@cloudbase/weda-client';
|
|
2
|
+
import { checkAuth, getExpiredMessage } from './util'
|
|
3
|
+
|
|
4
|
+
export { PAGE_ROOT_SYMBOL } from '@cloudbase/weda-client';
|
|
5
|
+
export function createPage(props) {
|
|
6
|
+
return baseCreatePage({
|
|
7
|
+
...props,
|
|
8
|
+
style: <%= pageStyle || '{}' %>,
|
|
9
|
+
checkAuth,
|
|
10
|
+
getExpiredMessage: function () {
|
|
11
|
+
return getExpiredMessage(<%= expirationStartTimesnap %>)
|
|
38
12
|
}
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
merge = mergeDynamic2StaticData(merge, pickedDataBinds, {
|
|
42
|
-
codeContext: {
|
|
43
|
-
/**
|
|
44
|
-
* $page 或 $comp 实例
|
|
45
|
-
*/
|
|
46
|
-
instance: ctx.app?.__internal__?.activePage,
|
|
47
|
-
},
|
|
48
|
-
$w: ctx.app?.__internal__?.activePage?.__internal__?.$w,
|
|
49
|
-
})
|
|
50
|
-
} catch (e) {
|
|
51
|
-
console.warn('分享设置绑定计算错误:', e)
|
|
52
|
-
}
|
|
53
|
-
return merge
|
|
13
|
+
})
|
|
54
14
|
}
|
|
55
|
-
|
|
56
|
-
function extractLifecycles(ctx, lifecycle, appShareMessage, shareTimeline, dataBinds, resetShare = true) {
|
|
57
|
-
const result = {};
|
|
58
|
-
Object.keys(lifecycle).map((name) => {
|
|
59
|
-
result[name] = function () {
|
|
60
|
-
return lifecycle[name].apply(this._getInstance(), arguments);
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (resetShare) {
|
|
65
|
-
result['onShareAppMessage'] = (res) => {
|
|
66
|
-
if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
|
|
67
|
-
return res?.target?.dataset?.weda_share_info;
|
|
68
|
-
} else if (res?.from === 'menu' && appShareMessage?.enable) {
|
|
69
|
-
let mergedData = resolveParticialPageData(ctx, 'appShareMessage', { appShareMessage }, dataBinds);
|
|
70
|
-
|
|
71
|
-
let { pageId, params, imageUrl, title, packageName } = mergedData.appShareMessage || {};
|
|
72
|
-
const url = ctx.app?.__internal__?.generatePageUrl({
|
|
73
|
-
pageId,
|
|
74
|
-
packageName,
|
|
75
|
-
params: Array.isArray(params) ? params.reduce((map, { key, value }) => {
|
|
76
|
-
map[key] = value
|
|
77
|
-
return map
|
|
78
|
-
}, {}) : params,
|
|
79
|
-
})
|
|
80
|
-
return {
|
|
81
|
-
path: url,
|
|
82
|
-
imageUrl: ctx.app?.__internal__?.resolveStaticResourceUrl?.(imageUrl) || imageUrl,
|
|
83
|
-
title,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
return lifecycle?.['onShareAppMessage']?.() || {};
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.log(error);
|
|
90
|
-
return {};
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (shareTimeline?.enable || lifecycle?.['onShareTimeline']) {
|
|
96
|
-
result['onShareTimeline'] = () => {
|
|
97
|
-
if (shareTimeline?.enable) {
|
|
98
|
-
let mergedData = resolveParticialPageData(ctx, 'shareTimeline', { shareTimeline }, dataBinds);
|
|
99
|
-
|
|
100
|
-
let { params, imageUrl, title } = mergedData.shareTimeline || {};
|
|
101
|
-
const query = urlJoinParams('/fake', Array.isArray(params) ? params.reduce((map, { key, value }) => {
|
|
102
|
-
map[key] = value
|
|
103
|
-
return map
|
|
104
|
-
}, {}) : params).replace(/^\/fake\?/, '')
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
query,
|
|
108
|
-
imageUrl: ctx.app?.__internal__?.resolveStaticResourceUrl?.(imageUrl) || imageUrl,
|
|
109
|
-
title,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
return lifecycle?.['onShareTimeline']?.() || {};
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.log(error);
|
|
116
|
-
return {};
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 更新设备信息 窗口信息
|
|
122
|
-
result['onResize'] = (res) => {
|
|
123
|
-
const { $w } = getWedaAPI()
|
|
124
|
-
let device = $w.device;
|
|
125
|
-
if (!device) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const width = res?.size?.windowWidth;
|
|
129
|
-
const height = res?.size?.windowHeight;
|
|
130
|
-
if (width !== device?.viewport?.width || height !== device?.viewport?.height) {
|
|
131
|
-
device.viewport = {
|
|
132
|
-
width,
|
|
133
|
-
height,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function createPage({
|
|
141
|
-
app,
|
|
142
|
-
id,
|
|
143
|
-
widgetProps,
|
|
144
|
-
index = {},
|
|
145
|
-
lifecycle,
|
|
146
|
-
state,
|
|
147
|
-
computed,
|
|
148
|
-
evtListeners,
|
|
149
|
-
dataBinds = {},
|
|
150
|
-
handlers,
|
|
151
|
-
query: datasetQuery = {},
|
|
152
|
-
eventFlows = [],
|
|
153
|
-
pageContext = {},
|
|
154
|
-
pageAttributes = {},
|
|
155
|
-
resetShare = true,
|
|
156
|
-
datasetProfile = undefined
|
|
157
|
-
}) {
|
|
158
|
-
/**
|
|
159
|
-
* 单次引用
|
|
160
|
-
*/
|
|
161
|
-
if (datasetProfile) {
|
|
162
|
-
setDatasetProfiles({ [pageContext.uuid || pageContext.id || id]: datasetProfile })
|
|
163
|
-
}
|
|
164
|
-
widgetProps = patchWdigetPropsWithEvtListeners(widgetProps, evtListeners)
|
|
165
|
-
|
|
166
|
-
const evtHandlers = createEventHandlers(evtListeners);
|
|
167
|
-
const {[PAGE_ROOT_SYMBOL]: pageRootDataBinds, ...componentDataBinds} = dataBinds
|
|
168
|
-
const staticPageStyle = <%= pageStyle || '{}' %>
|
|
169
|
-
|
|
170
|
-
return Component({
|
|
171
|
-
_componentType: 'page',
|
|
172
|
-
data: {
|
|
173
|
-
...createInitData(widgetProps, componentDataBinds),
|
|
174
|
-
_isCheckingAtuh: false,
|
|
175
|
-
_expiredMessage: '',
|
|
176
|
-
weDaHasLogin: null,
|
|
177
|
-
loginError: null,
|
|
178
|
-
pageStyle: styleToCss(staticPageStyle)
|
|
179
|
-
},
|
|
180
|
-
lifetimes: {
|
|
181
|
-
attached() {
|
|
182
|
-
this._disposers = [];
|
|
183
|
-
const $page = this._getInstance();
|
|
184
|
-
const instance = $page.__internal__.mpInstance?.(true)
|
|
185
|
-
if( instance !== this ){
|
|
186
|
-
const currentMpInstance = this
|
|
187
|
-
$page.__internal__.mpInstance = (disableLog) => {
|
|
188
|
-
if (!disableLog) {
|
|
189
|
-
console.warn('debug 获取当前 mp page 实例,禁止在生产环境使用');
|
|
190
|
-
}
|
|
191
|
-
return currentMpInstance
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
this._pageActive = true;
|
|
195
|
-
/**
|
|
196
|
-
* @deprecated
|
|
197
|
-
* 使用 behavior 的方式挂载methods
|
|
198
|
-
*/
|
|
199
|
-
this.__mnt__ = (e) => {
|
|
200
|
-
const widget = getWidget($page.widgets, e.target.id);
|
|
201
|
-
widget._methods = e.detail.methods;
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* @deprecated
|
|
205
|
-
* 使用 behavior 的方式挂载methods
|
|
206
|
-
*/
|
|
207
|
-
this.__unmnt__ = (e) => {
|
|
208
|
-
const widget = getWidget($page.widgets, e.target.id);
|
|
209
|
-
widget._methods = {};
|
|
210
|
-
};
|
|
211
|
-
this._disposers.push(...this.initMergeRenderer($page.widgets, {
|
|
212
|
-
pageStyle: () => {
|
|
213
|
-
let pageStyle = { ...staticPageStyle }
|
|
214
|
-
try {
|
|
215
|
-
if ( pageRootDataBinds.style ) {
|
|
216
|
-
const { style } = mergeDynamic2StaticData({}, {
|
|
217
|
-
style: pageRootDataBinds.style
|
|
218
|
-
}, {
|
|
219
|
-
codeContext: {
|
|
220
|
-
/**
|
|
221
|
-
* $page 或 $comp 实例
|
|
222
|
-
*/
|
|
223
|
-
instance: $page,
|
|
224
|
-
},
|
|
225
|
-
$w: $page?.__internal__?.$w,
|
|
226
|
-
})
|
|
227
|
-
pageStyle = {
|
|
228
|
-
...pageStyle,
|
|
229
|
-
...style
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} catch(e) {
|
|
233
|
-
console.warn('页面动态style绑定计算失败:', e)
|
|
234
|
-
}
|
|
235
|
-
return styleToCss(pageStyle)
|
|
236
|
-
}
|
|
237
|
-
}));
|
|
238
|
-
getExpiredMessage(<%= expirationStartTimesnap %>).then(message => {
|
|
239
|
-
if (message) {
|
|
240
|
-
this.setData({
|
|
241
|
-
_expiredMessage: message
|
|
242
|
-
})
|
|
243
|
-
}
|
|
244
|
-
})
|
|
245
|
-
},
|
|
246
|
-
detached() {
|
|
247
|
-
const $page = this._getInstance();
|
|
248
|
-
const instance = $page.__internal__.mpInstance?.(true)
|
|
249
|
-
if( instance === this ){
|
|
250
|
-
$page.__internal__.mpInstance = () => null
|
|
251
|
-
}
|
|
252
|
-
this._pageActive = false;
|
|
253
|
-
$page.__internal__.active = this._pageActive;
|
|
254
|
-
|
|
255
|
-
disposeWidget($page._rootWidget);
|
|
256
|
-
this._disposers.forEach((dispose) => dispose());
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
pageLifetimes: {
|
|
260
|
-
// 组件所在页面的生命周期函数,定义下给运营平台上报用
|
|
261
|
-
show: function () {},
|
|
262
|
-
hide: function () {},
|
|
263
|
-
},
|
|
264
|
-
methods: {
|
|
265
|
-
_pageActive: true,
|
|
266
|
-
_beforePageCustomLaunchPromise: null,
|
|
267
|
-
_query: {},
|
|
268
|
-
_disposers: [],
|
|
269
|
-
|
|
270
|
-
/** page lifecycles **/
|
|
271
|
-
...extractLifecycles({ app }, lifecycle, pageAttributes?.appShareMessage, pageAttributes?.shareTimeline, pageRootDataBinds, resetShare),
|
|
272
|
-
...evtHandlers,
|
|
273
|
-
...mergeRenderer,
|
|
274
|
-
async beforePageCustomLaunch(query) {
|
|
275
|
-
if (!this._beforePageCustomLaunchPromise) {
|
|
276
|
-
this._beforePageCustomLaunchPromise = new Promise(async (resolve, reject) => {
|
|
277
|
-
await wxApp.globaldata?._beforePageCustomLaunchPromise;
|
|
278
|
-
const $page = this._getInstance();
|
|
279
|
-
let weDaHasLogin
|
|
280
|
-
if (query) {
|
|
281
|
-
EXTRA_API.setParams($page.uuid, query);
|
|
282
|
-
}
|
|
283
|
-
try {
|
|
284
|
-
this.setData({ _isCheckingAtuh: true });
|
|
285
|
-
const auth = await checkAuth(app, app.id, $page);
|
|
286
|
-
if (auth) {
|
|
287
|
-
weDaHasLogin = true
|
|
288
|
-
this.setData({
|
|
289
|
-
weDaHasLogin,
|
|
290
|
-
});
|
|
291
|
-
createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page, $w: $page.__internal__?.$w }));
|
|
292
|
-
} else {
|
|
293
|
-
weDaHasLogin = false
|
|
294
|
-
this.setData({
|
|
295
|
-
weDaHasLogin,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
} catch(e) {
|
|
299
|
-
weDaHasLogin = false
|
|
300
|
-
this.setData({
|
|
301
|
-
weDaHasLogin,
|
|
302
|
-
loginError: { message: e.message }
|
|
303
|
-
});
|
|
304
|
-
} finally {
|
|
305
|
-
this.setData({ _isCheckingAtuh: false });
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
309
|
-
for (const queryId in $page.dataset?.query || {}) {
|
|
310
|
-
if ($page.dataset.query[queryId]?._schema?.trigger === 'auto') {
|
|
311
|
-
/**
|
|
312
|
-
* query 初始化不阻塞生命周期
|
|
313
|
-
*/
|
|
314
|
-
Promise.resolve()
|
|
315
|
-
.then(async () => {
|
|
316
|
-
await $page.dataset.query[queryId]?.initPromise;
|
|
317
|
-
return $page.dataset.query[queryId].trigger();
|
|
318
|
-
})
|
|
319
|
-
.catch((e) => {
|
|
320
|
-
console.error(`query ${queryId} 初始化失败:`, e);
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
if(weDaHasLogin===false) {
|
|
325
|
-
reject(new Error('permission denied') )
|
|
326
|
-
}else {
|
|
327
|
-
resolve()
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
return this._beforePageCustomLaunchPromise;
|
|
332
|
-
},
|
|
333
|
-
async onLoad(options) {
|
|
334
|
-
const $page = this._getInstance();
|
|
335
|
-
setConfig({ currentPageId: $page.uuid });
|
|
336
|
-
this._pageActive = true;
|
|
337
|
-
$page.__internal__.active = this._pageActive;
|
|
338
|
-
app.__internal__.activePage = $page;
|
|
339
|
-
|
|
340
|
-
this._query = decodePageQuery(options || {});
|
|
341
|
-
|
|
342
|
-
await this.beforePageCustomLaunch?.(this._query);
|
|
343
|
-
|
|
344
|
-
const hook = lifecycle.onLoad || lifecycle.onPageLoad;
|
|
345
|
-
await hook?.call?.($page, this._query);
|
|
346
|
-
this._invokeEventHandler('load', { query: this._query });
|
|
347
|
-
},
|
|
348
|
-
async onReady() {
|
|
349
|
-
const $page = this._getInstance();
|
|
350
|
-
|
|
351
|
-
this._disposers.push(...runWatchers(index, this));
|
|
352
|
-
|
|
353
|
-
await this.beforePageCustomLaunch?.(this._query);
|
|
354
|
-
setTimeout(async () => {
|
|
355
|
-
const hook = lifecycle.onReady || lifecycle.onPageReady;
|
|
356
|
-
await hook?.call?.($page);
|
|
357
|
-
|
|
358
|
-
this._invokeEventHandler('ready');
|
|
359
|
-
}, 100);
|
|
360
|
-
},
|
|
361
|
-
onUnload() {
|
|
362
|
-
const $page = this._getInstance();
|
|
363
|
-
|
|
364
|
-
const hook = lifecycle.onUnload || lifecycle.onPageUnload;
|
|
365
|
-
hook?.call?.($page);
|
|
366
|
-
|
|
367
|
-
this._invokeEventHandler('unload');
|
|
368
|
-
},
|
|
369
|
-
async onShow() {
|
|
370
|
-
const $page = this._getInstance();
|
|
371
|
-
setConfig({ currentPageId: $page.uuid });
|
|
372
|
-
this._pageActive = true;
|
|
373
|
-
$page.__internal__.active = this._pageActive;
|
|
374
|
-
app.__internal__.activePage = $page;
|
|
375
|
-
|
|
376
|
-
await this.beforePageCustomLaunch?.(this._query);
|
|
377
|
-
|
|
378
|
-
const hook = lifecycle.onShow || lifecycle.onPageShow;
|
|
379
|
-
await hook?.call?.($page);
|
|
380
|
-
this._invokeEventHandler('show');
|
|
381
|
-
},
|
|
382
|
-
onHide() {
|
|
383
|
-
const $page = this._getInstance();
|
|
384
|
-
const hook = lifecycle.onHide || lifecycle.onPageHide;
|
|
385
|
-
hook?.call?.($page);
|
|
386
|
-
this._pageActive = false;
|
|
387
|
-
|
|
388
|
-
// 触发页面节点事件
|
|
389
|
-
this._invokeEventHandler('hide');
|
|
390
|
-
$page.__internal__.active = this._pageActive;
|
|
391
|
-
},
|
|
392
|
-
_invokeEventHandler(triggerName, params = {}) {
|
|
393
|
-
const keyName = getMpEventHandlerName(id, triggerName);
|
|
394
|
-
const event = new Event({
|
|
395
|
-
type: triggerName,
|
|
396
|
-
detail: params,
|
|
397
|
-
});
|
|
398
|
-
return this[keyName]?.call?.(this, event);
|
|
399
|
-
},
|
|
400
|
-
_getInstance() {
|
|
401
|
-
let $page = this.$WEAPPS_PAGE;
|
|
402
|
-
if ($page) {
|
|
403
|
-
return $page;
|
|
404
|
-
}
|
|
405
|
-
Object.assign(pageContext, {
|
|
406
|
-
id,
|
|
407
|
-
state: observable(state),
|
|
408
|
-
path: this.route,
|
|
409
|
-
widgets: {},
|
|
410
|
-
});
|
|
411
|
-
$page = pageContext;
|
|
412
|
-
this.$WEAPPS_PAGE = $page;
|
|
413
|
-
$page.handler = Object.keys(handlers).reduce((result, key) => {
|
|
414
|
-
try {
|
|
415
|
-
result[key] = handlers[key].bind($page);
|
|
416
|
-
} catch (e) {
|
|
417
|
-
console.error('添加页面handler失败', e);
|
|
418
|
-
}
|
|
419
|
-
return result;
|
|
420
|
-
}, {});
|
|
421
|
-
$page.computed = createComputed(computed, $page);
|
|
422
|
-
let dataset = createDataset($page.uuid, undefined, {
|
|
423
|
-
appId: app.id
|
|
424
|
-
});
|
|
425
|
-
dataset.query = generateDatasetQuery(datasetQuery, {
|
|
426
|
-
$w: $page.__internal__.$w,
|
|
427
|
-
$app: app,
|
|
428
|
-
$page,
|
|
429
|
-
});
|
|
430
|
-
this._disposers.push(...Object.values(dataset.query).map(query=>{
|
|
431
|
-
return function dispose() {
|
|
432
|
-
try {
|
|
433
|
-
query?.destroy?.()
|
|
434
|
-
} catch(e) {}
|
|
435
|
-
}
|
|
436
|
-
}))
|
|
437
|
-
$page.dataset = dataset;
|
|
438
|
-
this._disposers.push(...watchAndSyncDatasetState2Local(app.id, $page.uuid, $page.dataset.state))
|
|
439
|
-
$page.state.dataset = dataset;
|
|
440
|
-
$page.setState = (userSetState) => {
|
|
441
|
-
Object.keys(userSetState).forEach((keyPath) => {
|
|
442
|
-
app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
|
|
443
|
-
});
|
|
444
|
-
};
|
|
445
|
-
$page.setParams = (_params) => {
|
|
446
|
-
const params = Array.isArray(_params)
|
|
447
|
-
? _params.reduce((map, meta) => {
|
|
448
|
-
let { key, value } = meta;
|
|
449
|
-
if (key?.startsWith?.('$page.')) {
|
|
450
|
-
key = key.replace(/^\$page\./, '');
|
|
451
|
-
}
|
|
452
|
-
if(key?.trim?.()){
|
|
453
|
-
map[key?.trim?.()] = value;
|
|
454
|
-
}
|
|
455
|
-
return map;
|
|
456
|
-
}, {})
|
|
457
|
-
: _params;
|
|
458
|
-
|
|
459
|
-
Object.keys(params).forEach((keyPath) => {
|
|
460
|
-
app.utils.set($page.dataset?.params, keyPath, params[keyPath]);
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
const { widgets, rootWidget } = createWidgets(widgetProps, componentDataBinds, this, $page.widgets);
|
|
465
|
-
$page.widgets = widgets;
|
|
466
|
-
$page._rootWidget = rootWidget;
|
|
467
|
-
|
|
468
|
-
$page.invokeComponentMethod = ({ component, method, params }) => {
|
|
469
|
-
let componentInstance = undefined;
|
|
470
|
-
if (typeof component === 'string') {
|
|
471
|
-
const components = $page.widgets[component];
|
|
472
|
-
if (Array.isArray(components)) {
|
|
473
|
-
if (components.length > 1) {
|
|
474
|
-
throw new Error(`调用方法失败:id为${component}的组件拥有多个实例`);
|
|
475
|
-
}
|
|
476
|
-
componentInstance = components[0];
|
|
477
|
-
} else {
|
|
478
|
-
componentInstance = components;
|
|
479
|
-
}
|
|
480
|
-
} else {
|
|
481
|
-
componentInstance = component
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
const currentInstanceRef = componentInstance?._getInstanceRef()?.current || {};
|
|
485
|
-
const { methods = {}, ...restInstanceRef } = currentInstanceRef;
|
|
486
|
-
|
|
487
|
-
const readonlyMap = {
|
|
488
|
-
...componentInstance?._methods,
|
|
489
|
-
...restInstanceRef,
|
|
490
|
-
...methods,
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
if (typeof readonlyMap[method] !== 'function') {
|
|
494
|
-
throw new Error(`调用方法失败:未找到id为${componentInstance?.id}下的方法${method}`);
|
|
495
|
-
}
|
|
496
|
-
return readonlyMap[method](params);
|
|
497
|
-
};
|
|
498
|
-
$page.__internal__.eventFlows = generateEventFlows(eventFlows, {
|
|
499
|
-
$w: $page.__internal__.$w,
|
|
500
|
-
$app: app,
|
|
501
|
-
$page,
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
return $page;
|
|
505
|
-
},
|
|
506
|
-
},
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
function decodePageQuery(query) {
|
|
511
|
-
return Object.keys(query).reduce((decoded, key) => {
|
|
512
|
-
decoded[key] = decodeURIComponent(query[key]);
|
|
513
|
-
return decoded;
|
|
514
|
-
}, {});
|
|
515
|
-
}
|
|
516
|
-
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createComponent } from '<%= relativeWedaRoot %>/common/weapp-component'
|
|
3
|
-
import { concatClassList, px2rpx } from '<%= relativeWedaRoot %>/common/style'
|
|
4
|
-
import { getWedaAPI } from '@cloudbase/weda-client'
|
|
1
|
+
import { getWedaAPI, createComponent, concatClassList, px2rpx } from '@cloudbase/weda-client'
|
|
5
2
|
<%= importor.lifecycle? "import lifeCycle from './lowcode/lifecycle'" : "const lifeCycle = {}" %>
|
|
6
3
|
<%= importor.state? "import stateFn from './lowcode/state'" : "const stateFn = {}" %>
|
|
7
4
|
<%= importor.computed? "import computedFuncs from './lowcode/computed'" : "const computedFuncs = {}" %>
|
|
@@ -15,8 +12,6 @@ const handlers = {<% handlers.forEach(h => {%>
|
|
|
15
12
|
<%= h %>: _hanlder<%= h %>, <%}) %>
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
const libCode = '<%= materialName %>'
|
|
19
|
-
|
|
20
15
|
const widgetProps = <%= JSON.stringify(widgetProps, undefined, 2) %>
|
|
21
16
|
|
|
22
17
|
<% function printBoundData(boundData={}) {
|
|
@@ -30,17 +25,23 @@ const widgetProps = <%= JSON.stringify(widgetProps, undefined, 2) %>
|
|
|
30
25
|
return list.join(',')
|
|
31
26
|
}%>
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
28
|
+
<% function printEventHandler(eventHandlers) {
|
|
29
|
+
Object.entries(eventHandlers).map(([handlerName, listeners])=>{
|
|
30
|
+
print(`"${handlerName}": [
|
|
31
|
+
${listeners.map(l=>{
|
|
32
|
+
return `{
|
|
33
|
+
key: '${l.key||''}',
|
|
34
|
+
sourceKey: '${ l.sourceKey||"" }',
|
|
35
|
+
handler: ${l.generateHandler('../') || 'undefined'},
|
|
36
|
+
args: ${JSON.stringify(l.args||{}, undefined, 2)},
|
|
37
|
+
argsBinds: {${printBoundData(l.argsBinds)}}
|
|
38
|
+
}`
|
|
39
|
+
}).join(',')}
|
|
40
|
+
],`)
|
|
41
|
+
})
|
|
42
|
+
}%>
|
|
43
|
+
|
|
44
|
+
const evtListeners = {<% printEventHandler(eventHandlers) %>}
|
|
44
45
|
|
|
45
46
|
const behaviors = [<% if(formEvents) { %>'wx://form-field'<% } %>]
|
|
46
47
|
|
|
@@ -65,7 +66,39 @@ const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
|
65
66
|
},<%}) %>
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
const query = {<% Object.entries(query).map(([id, item])=>{%>
|
|
70
|
+
<%= id %>: { <% const {dataBinds={}, eventHandlers, handler, ...rest } = item %>
|
|
71
|
+
...(<%= JSON.stringify(rest, undefined, 2) %>),
|
|
72
|
+
handler: <%= handler %>,
|
|
73
|
+
dataBinds: {<%= printBoundData(dataBinds) %>},
|
|
74
|
+
eventHandlers: {<% printEventHandler(eventHandlers) %>}
|
|
75
|
+
},<%}) %>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const eventFlows = [<% eventFlows.map(flow => {%> { <% const { eventHandlers, ...rest } = flow %>
|
|
79
|
+
...(<%= JSON.stringify(rest, undefined, 2) %>),
|
|
80
|
+
eventHandlers: {<% printEventHandler(eventHandlers) %>}
|
|
81
|
+
},<%}) %>
|
|
82
|
+
]
|
|
83
|
+
|
|
68
84
|
const config = <%= JSON.stringify(config || {})%>
|
|
85
|
+
const datasetProfile = <%= datasetProfile %>;
|
|
69
86
|
|
|
70
|
-
createComponent(
|
|
71
|
-
|
|
87
|
+
createComponent({
|
|
88
|
+
key: '<%= key %>',
|
|
89
|
+
behaviors,
|
|
90
|
+
properties,
|
|
91
|
+
events,
|
|
92
|
+
handler: handlers,
|
|
93
|
+
dataBinds,
|
|
94
|
+
evtListeners,
|
|
95
|
+
widgetProps,
|
|
96
|
+
lifeCycle,
|
|
97
|
+
stateFn,
|
|
98
|
+
computedFuncs,
|
|
99
|
+
config,
|
|
100
|
+
datasetProfile,
|
|
101
|
+
query,
|
|
102
|
+
eventFlows,
|
|
103
|
+
nativeMode: !!<%= nativeMode %>,
|
|
104
|
+
})
|