@cloudbase/framework-plugin-low-code 1.0.3-beta.8 → 1.0.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 (59) hide show
  1. package/lib/builder/mp/lowcode.d.ts.map +1 -1
  2. package/lib/builder/mp/lowcode.js +3 -7
  3. package/lib/builder/service/builder/generate.d.ts.map +1 -1
  4. package/lib/builder/service/builder/generate.js +3 -0
  5. package/lib/generator/core/generate.d.ts.map +1 -1
  6. package/lib/generator/core/generate.js +11 -17
  7. package/lib/utils/dataSource.d.ts +4 -0
  8. package/lib/utils/dataSource.d.ts.map +1 -1
  9. package/lib/utils/dataSource.js +27 -12
  10. package/lib/weapps-core/utils/file.d.ts +1 -1
  11. package/package.json +3 -3
  12. package/template/src/app/common.js +0 -13
  13. package/template/src/app/global-api.js +0 -132
  14. package/template/src/app/handlers.js +0 -13
  15. package/template/src/app/material-actions.js +0 -16
  16. package/template/src/app/mountAppApis.js +0 -25
  17. package/template/src/app/mountMpApis.js +0 -4
  18. package/template/src/datasources/config.js.tpl +0 -27
  19. package/template/src/datasources/dataset-profiles.js.tpl +0 -5
  20. package/template/src/datasources/datasource-profiles.js.tpl +0 -4
  21. package/template/src/datasources/index.js.tpl +0 -27
  22. package/template/src/handlers/FieldMiddleware/renderer.jsx +0 -536
  23. package/template/src/handlers/HotAreas.js +0 -36
  24. package/template/src/handlers/PositionHandler.jsx +0 -8
  25. package/template/src/handlers/actionHandler/utils.js +0 -154
  26. package/template/src/handlers/componentEventActionEmitter.js +0 -29
  27. package/template/src/handlers/componentNodeMap.js +0 -24
  28. package/template/src/handlers/controller.js +0 -5
  29. package/template/src/handlers/emitComponentEvent.js +0 -8
  30. package/template/src/handlers/eventListener/componentEventListener.js +0 -15
  31. package/template/src/handlers/eventListener/hotAreaEventListener.js +0 -32
  32. package/template/src/handlers/eventListener/index.js +0 -29
  33. package/template/src/handlers/eventListener/pageEventListener.js +0 -11
  34. package/template/src/handlers/eventListener/types.js +0 -32
  35. package/template/src/handlers/hooks/index.js +0 -15
  36. package/template/src/handlers/initWebEnv.js +0 -4
  37. package/template/src/handlers/injectStyle.js +0 -14
  38. package/template/src/handlers/instanceMap.js +0 -39
  39. package/template/src/handlers/lifecycle.js +0 -222
  40. package/template/src/handlers/render.jsx +0 -170
  41. package/template/src/handlers/utils/common.js +0 -298
  42. package/template/src/handlers/utils/eventProxy.js +0 -64
  43. package/template/src/handlers/utils/events.js +0 -8
  44. package/template/src/handlers/utils/index.js +0 -4
  45. package/template/src/handlers/utils/widgets.js +0 -307
  46. package/template/src/index.jsx +0 -185
  47. package/template/src/index.less +0 -119
  48. package/template/src/libraries/default-lib/wx_yypt_report_v2.js +0 -441
  49. package/template/src/pages/app.tpl +0 -200
  50. package/template/src/pages/composite.tpl +0 -171
  51. package/template/src/router/index.tpl +0 -29
  52. package/template/src/store/computed.js +0 -11
  53. package/template/src/store/index.js +0 -40
  54. package/template/src/utils/formatEnum.js +0 -42
  55. package/template/src/utils/history.js +0 -66
  56. package/template/src/utils/index.js +0 -82
  57. package/template/src/utils/kbone.js +0 -18
  58. package/template/src/utils/monitor-jssdk.min.js +0 -763
  59. package/template/src/utils/request.js +0 -5
@@ -1,441 +0,0 @@
1
- /*
2
- * 使用方法
3
- const wxReportSdk = require('./components/gsd-lib/report/index.js');
4
- new wxReportSdk({
5
- reportUrl:'http://www.qq.com',
6
- })
7
- */
8
- class wxReportSdk {
9
- constructor (opt) {
10
- this.originPage = Page;
11
- this.originApp = App;
12
- this.logTimer = null;
13
- this.idxKey = '_monitor_idx';
14
- this.config = {
15
- mp_appid: '', // 填入小程序的appid
16
- appKey: '', // 填入你的应用key
17
- stopReport: false, // 停止上报
18
- isNet: true, // 是否上报网络信息(默认:true)
19
- isSys: true, // 是否上报系统信息(默认:true)
20
- isError: true, // 是否开启错误上报 (默认:false)
21
- autoReportPV: false, // 是否自动上报页面PV
22
- commonPageEId: 'MP_ALLPAGES_ONSHOW', // 统一的页面上报标志
23
- getRemoteParamsUrl: '',// 获取远程参数url
24
- reportUrl: '', // 上报url
25
- intervalTime: 3, // 间隔多久执行一次上报,默认3秒
26
- reportLogsNum: 5, // 每次合并上报记录条数,默认5次
27
- };
28
-
29
- this.reportData = {
30
- ky: '',//app key,应用的身份标识
31
- pf: 'MiniProgram',// 平台类型
32
- id: '',// 平台型相关的ID字段,如微信平台中则是open_id
33
- cui: '',// custom user id,自定义用户id,用户上报的自定义用户id,也就是app业务方统计用户的身份标识,用于多平台帐号打通。
34
- geo: '',// 地理位置
35
- scene: '', // 入口场景,小程序的场景值
36
- ev: {
37
- 'cn': '',//connect type,设备连接方式
38
- 'lg': '',//anguage,系统语言类型
39
- 'sr': '',//screen resolution,屏幕分辨率
40
- 'tz': '',//time zone,系统的时区
41
- 'os': '',//操作系统,
42
- 'ua': '-', //
43
- },
44
- ui: '',// 一个随机生成的id,因为大多数没有id,cui,所以用ui计算uv
45
- si: '',//session id,会话id,一串随机产生的数字,标识一个新的会话
46
- ts: '',//timestamp,时间戳
47
- pi: '',// page id,页面id
48
- rf: '',// refer page id,来源页面id
49
- et: '1',// eventtype,事件类型,PAGE_VIEW(1),PAGE_HIDE(3001),SESSION_ENV(2),ERROR(3),CUSTOM(1000),ADDITION(1001),MONITOR_STAT(1002);SPECIAL_CUSTON(),小程序onshow使用PAGE_VIEW,关闭或隐藏时使用PAGE_HIDE,事件使用1000
50
- ht: '',// hot tag string 屏幕的点击事件ID
51
- htx: '',// hot tag x string 点击位置的X坐标
52
- hty: '',// hot tag y string 点击位置的Y坐标
53
- ei: '',// event id,自定义事件id string 自定义事件id
54
- kv: '',// Key-Value,自定义事件Key-Value参数对 map JSON格式
55
- er: '',// error,错误、异常信息 string 错误字符串或堆栈异常信息
56
- ea: '',//error attribute uint 共有4种错误类型:USER_MSG(0)、USER_EXCEPTION(1)、AUTO_EXCEPTION(2)、NATIVE_CRASH(3)、SDK_EXCEPTION(99)
57
- ext: '',//扩展字段,不进行计算,可存储更细的用户信息
58
- region: '', // 城市码
59
- mp_appid: '', // 小程序appid
60
- adt: "", // 自定义渠道来源
61
- };
62
-
63
- this.config = Object.assign(this.config, opt || {});
64
- this.reportLogs = [];
65
- this.pagePrams = {};//存储每个页面自定义上报的数据,例如kv
66
- this.cusSid = this._getCusSid();
67
- this._init();
68
- }
69
-
70
- // 获取自定义session
71
- _getCusSid(len = 10) {
72
- const $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz123456789";
73
- const maxPos = $chars.length;
74
- let pwd = "";
75
- for (let i = 0; i < len; i++) {
76
- pwd = pwd + $chars.charAt(Math.floor(Math.random() * maxPos));
77
- }
78
- return pwd + new Date().getTime();
79
- }
80
-
81
- // 获取用户唯一标示
82
- _getUuid () {
83
- let uuidKey = "_mp_monitor_uuid_v2";
84
- let uuid = wx.getStorageSync(uuidKey);
85
- if (uuid) {
86
- return uuid;
87
- }
88
- let s = [];
89
- let hexDigits = '0123456789abcdef';
90
- for (let i = 0; i < 36; i++) {
91
- s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
92
- }
93
- s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
94
- s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
95
- s[8] = s[13] = s[18] = s[23] = '-';
96
- uuid = "mc_" + s.join('');
97
- wx.setStorageSync(uuidKey, uuid);
98
- return uuid;
99
- };
100
-
101
- startReport () {
102
- if (this.config.stopReport || !this._isAllowReport()) return;
103
- const _this = this;
104
- _this._logRequest();
105
- _this.logTimer = setInterval(function () {
106
- _this._logRequest();
107
- }, _this.config.intervalTime * 1000);
108
- }
109
-
110
- /*点击流上报
111
- * eid 事件id
112
- * kv Key-Value,自定义事件Key-Value参数对
113
- * event 事件对象
114
- * */
115
- eventClick (eid, params = {}, event) {
116
- let cookiedObj = {};
117
- // 兼容老版本事项直接传入kv值
118
- if (eid === 'MP_SHIXIANG' && !params.kv) {
119
- cookiedObj.kv = params;
120
- }
121
- else {
122
- cookiedObj = params;
123
- }
124
- this._statpid(Object.assign({
125
- et: '1000',// eventtype 事件使用1000
126
- ei: eid, // 事件id
127
- htx: event ? event.detail.x : '',
128
- hty: event ? event.detail.y : '',
129
- ht: event ? event.target.id : '',// hot tag string 屏幕的点击事件ID
130
- }, cookiedObj));
131
- }
132
-
133
- logInfo (msg, params = {}) {
134
- params.type = 'info';
135
- params.msg = msg;
136
- this._logReport(params);
137
- }
138
-
139
- logWarn (msg, params = {}) {
140
- params.type = 'warn';
141
- params.msg = msg;
142
- this._logReport(params);
143
- }
144
-
145
- logError (msg, params = {}) {
146
- params.type = 'error';
147
- params.msg = msg;
148
- this._logReport(params);
149
- }
150
-
151
- // 日志上报
152
- _logReport (params = {}) {
153
- let cookiedObj = { kv: params };
154
- this._statpid(Object.assign({
155
- et: '2000',//
156
- }, cookiedObj));
157
- }
158
-
159
- /*页面pv上报
160
- * pageId 页面标识id
161
- * params 额外参数,比如城市码
162
- * */
163
- pagePV (pageId, params = {}) {
164
- this._statpid(Object.assign({
165
- et: '3001',// eventtype,事件类型,PAGE_VIEW(1),PAGE_HIDE(3001),SESSION_ENV(2),ERROR(3),CUSTOM(1000),ADDITION(1001),MONITOR_STAT(1002);SPECIAL_CUSTON(),小程序onshow使用PAGE_VIEW,关闭或隐藏时使用PAGE_HIDE,事件使用1000å
166
- ei: pageId, // 事件id
167
- }, params));
168
- }
169
-
170
- // 设置页面参数
171
- setPagePrams (params) {
172
- let pagePath = this._getPagePath();
173
- if (pagePath && params) {
174
- this.pagePrams[pagePath] = params;
175
- }
176
- }
177
-
178
- // 是否允许上报
179
- _isAllowReport () {
180
- if (!this.config.reportUrl || !this.config.appKey) {
181
- console.error('reportUrl、appKey,存在没传的参数,不允许上报');
182
- return false;
183
- }
184
- return true;
185
- }
186
-
187
- _init () {
188
- if (this.config.stopReport || !this._isAllowReport()) return;
189
- this._spyApp();
190
- this._spyPage();
191
- if (this.config.isNet) this._network();
192
- if (this.config.isSys) this._system();
193
- }
194
-
195
- // 包装App对象
196
- _spyApp () {
197
- const _this = this;
198
- App = (app) => {
199
- const _onError = app.onError || function () { };
200
- const _onLaunch = app.onLaunch || function () { };
201
- const _onHide = app.onHide || function () { };
202
- app.onLaunch = function (opt) {
203
- _this.reportData.adt = opt.query.ysschannel || '';
204
- // _this.reportData.mp_appid = opt.referrerInfo &&
205
- // opt.referrerInfo.appId ||
206
- // '';
207
- _this.reportData.sense = opt.scene;
208
- wx.setStorageSync(_this.idxKey, 1);
209
- if (_this.config.getRemoteParamsUrl) {
210
- wx.request({
211
- url: _this.config.getRemoteParamsUrl,
212
- data: {},
213
- }).then((res) => {
214
- if (res.open) {
215
- _this.config = Object.assign(_this.config,
216
- {
217
- intervalTime: res.sec || _this.config.intervalTime,
218
- reportLogsNum: res.num || _this.config.reportLogsNum,
219
- stopReport: !!res.stop,
220
- });
221
- }
222
- });
223
- }
224
- return _onLaunch.apply(this, arguments);
225
- };
226
- if (this.config.isError) {
227
- // 错误捕获并上报
228
- app.onError = function (err) {
229
- let errspit = err.split(/\n/) || [];
230
- let src, col, line;
231
- let errs = err.match(/\(.+?\)/);
232
- if (errs && errs.length) errs = errs[0];
233
- errs = (errs || '').replace(/\w.+js/g, $1 => {
234
- src = $1;
235
- return '';
236
- });
237
- errs = errs.split(':');
238
- if (errs && errs.length > 1) line = parseInt(errs[1] || 0);
239
- col = parseInt(errs[2] || 0);
240
- _this._reportError(JSON.stringify({
241
- col: col,
242
- line: line,
243
- name: src,
244
- msg: `${errspit[0]};${errspit[1]};${errspit[2]};`,
245
- type: 'js',
246
- }));
247
- return _onError.apply(this, arguments);
248
- };
249
- }
250
- app.onHide = function () {
251
- if (_this.logTimer) {
252
- clearInterval(_this.logTimer);
253
- }
254
- _this._logRequest(true);
255
- return _onHide.apply(this, arguments);
256
- };
257
- _this.originApp(app);
258
- };
259
- }
260
-
261
- _wrapPagePV (pageOnShowTime) {
262
- const _this = this;
263
- if (_this.config.autoReportPV) {
264
- _this.pagePV(_this.config.commonPageEId,
265
- { du: Math.ceil((Date.now() - pageOnShowTime) / 1000) });
266
- }
267
- }
268
-
269
- // 包装page对象
270
- _spyPage () {
271
- const _this = this;
272
- Page = (page) => {
273
- const _onShow = page.onShow || function () { };
274
- const _onHide = page.onHide || function () { };
275
- const _onUnload = page.onUnload || function () { };
276
- let pageOnShowTime = 0;
277
- page.onShow = function () {
278
- pageOnShowTime = Date.now();
279
- if (_this.config.autoReportPV) {
280
- _this.pagePV(_this.config.commonPageEId, { et: '1' });
281
- }
282
- return _onShow.apply(this, arguments);
283
- };
284
- page.onHide = function () {
285
- _this._wrapPagePV(pageOnShowTime);
286
- return _onHide.apply(this, arguments);
287
- };
288
- page.onUnload = function () {
289
- _this._wrapPagePV(pageOnShowTime);
290
- return _onUnload.apply(this, arguments);
291
- };
292
- _this.originPage(page);
293
- };
294
- }
295
-
296
- // 集中收集 logs 方法
297
- // type = 'memory' | 'storage'
298
- _collectLogs (item) {
299
- let nData = [];
300
- let oData = this.reportLogs;
301
- Array.isArray(item) ? nData = item : nData.push(item);
302
- // 剔除掉无值的字段,减少体积
303
- nData.forEach(tempItem => {
304
- for (let tempKey in tempItem) {
305
- let tempVal = tempItem[tempKey];
306
- if (tempVal === '' ||
307
- (typeof tempVal === 'object' && Object.keys(tempVal).length === 0)) {
308
- delete tempItem[tempKey];
309
- }
310
- }
311
- });
312
- // 内存不能超过 100 条
313
- let rule = oData.length > 100;
314
- if (rule) {
315
- oData.splice(0, nData.length);
316
- }
317
- this.reportLogs = oData.concat(nData);
318
- }
319
-
320
- // 获取页面路径
321
- _getPagePath () {
322
- let currentPages = getCurrentPages();
323
- if (currentPages && currentPages.length) {
324
- const length = currentPages.length;
325
- const lastpage = currentPages[length - 1];
326
- return lastpage.__route__;
327
- }
328
- else {
329
- return '';
330
- }
331
- }
332
-
333
- // 埋点上报
334
- _statpid (opt) {
335
- let currentPages = getCurrentPages();
336
- if (currentPages && currentPages.length) {
337
- const length = currentPages.length;
338
- const lastpage = currentPages[length - 1];
339
- opt.pi = lastpage.__route__;
340
- if (length >= 2) {
341
- opt.rf = currentPages[length - 2].__route__;
342
- }
343
- opt.ext = lastpage.options || {};
344
- // 合并用户传入的自定义参数
345
- opt = Object.assign(opt, this.pagePrams[opt.pi]);
346
- }
347
- let idx = Number(wx.getStorageSync(this.idxKey) || '0') + 1;
348
- wx.setStorageSync(this.idxKey, idx);
349
- opt.idx = idx;
350
- const _statpid2 = this._getCookiedReportData(opt);
351
- this._collectLogs(_statpid2);
352
- }
353
-
354
- /*错误上报
355
- * desc 错误信息
356
- * */
357
- _reportError (desc) {
358
- this._logReport({ type: 'error', msg: desc });
359
- }
360
-
361
- _getCookiedReportData (opt) {
362
- const realUserId = wx.getStorageSync('wx-openid') || wx.getStorageSync('tif-openid') ||
363
- wx.getStorageSync('openid') || opt.openid || this._getUuid();
364
- return Object.assign({}, this.reportData, {
365
- ts: Date.now(),//timestamp,时间戳
366
- ky: this.config.appKey, // app key,应用的身份标识
367
- si: wx.getStorageSync('wx-sessionid') || wx.getStorageSync('tif-sid') || this.cusSid,
368
- id: realUserId, // 平台型相关的ID字段,如微信平台中则是open_id
369
- cui: realUserId, // custom user
370
- ui: wx.getStorageSync('tif-unionid') || realUserId, // id,自定义用户id,用户上报的自定义用户id,也就是app业务方统计用户的身份标识,用于多平台帐号打通。
371
- region: wx.getStorageSync('reportRegion') || '',
372
- mp_appid: this.config.mp_appid || '',
373
- }, opt);
374
- }
375
-
376
- /*
377
- * cycle:是否循环上报
378
- * */
379
- _logRequest (cycle = false) {
380
- // 过滤掉开发者工具、测试环境的logs
381
- let _this = this;
382
- // 停止上报
383
- if (_this.config.stopReport) return;
384
- const reportLogs = _this.reportLogs;
385
- if (reportLogs.length === 0) {
386
- return;
387
- }
388
- let data = reportLogs.splice(0, _this.config.reportLogsNum);
389
- let sessionid = wx.getStorageSync('wx-sessionid') || wx.getStorageSync('tif-sid')
390
- wx.request({
391
- url: _this.config.reportUrl,
392
- header: {
393
- 'x-tif-sid': sessionid,
394
- 'x-tif-did': wx.getStorageSync('tif-did'),
395
- 'wx-sessionid': sessionid,
396
- 'content-type': 'application/x-www-form-urlencoded',
397
- },
398
- data: {reportInfo: JSON.stringify(data)},
399
- method: 'POST',
400
- complete (res) {
401
- if (cycle && res.data && Number(res.data.errcode) === 0 &&
402
- reportLogs.length > 0) {
403
- _this._logRequest(true);
404
- }
405
- if (res.data && (Number(res.data.errcode) !== 0)) {
406
- if (data && data.length !== 0) {
407
- _this._collectLogs(data);
408
- }
409
- }
410
- },
411
- });
412
- }
413
-
414
- // 获取网络类型
415
- _network () {
416
- wx.getNetworkType({
417
- success: res => {
418
- this.reportData.ev.cn = res.networkType;//connect type,设备连接方式
419
- },
420
- });
421
- }
422
-
423
- // 获取系统信息
424
- _system () {
425
- wx.getSystemInfo({
426
- success: res => {
427
- this.reportData.ev = {
428
- 'lg': res.language,//anguage,系统语言类型
429
- 'sr': res.screenWidth + '*' + res.screenHeight,//screen resolution,屏幕分辨率
430
- 'tz': new Date().getTimezoneOffset(),//time zone,系统的时区
431
- 'os': res.system,//操作系统,
432
- 'version': res.version,//微信版本号
433
- 'SDKVersion': res.SDKVersion,//客户端基础库版本
434
- 'ua': `oa=${res.system},mp_version=${res.version},mp_sdk=${res.SDKVersion}`,
435
- };
436
- },
437
- });
438
- }
439
- }
440
-
441
- module.exports = wxReportSdk;
@@ -1,200 +0,0 @@
1
- // Import Libs and Handlers
2
- import * as React from 'react'
3
- import { observable } from 'mobx'
4
- import { AppRender } from 'handlers/render'
5
- import { initLifeCycle, pageLifeCycleMount } from 'handlers/lifecycle'
6
- import { createComputed } from 'utils'
7
- import AppLifeCycle from 'lowcode/lifecycle'
8
- import { createDataset, createStateDataSourceVar, generateParamsParser, EXTRA_API } from '../../datasources'
9
- import { $$_<%= pageName %> as handler } from '../../app/handlers'
10
- import { app as mainApp } from 'app/global-api' // 取主包app
11
- import { app, $page } from '../../app/global-api' // 取对应子包app
12
- import { createWidgets, retryDataBinds, resolveComponentProps, checkAuth, reportTime } from 'handlers/utils'
13
- import { useScrollTop } from 'handlers/hooks'
14
- import { get } from "lodash";
15
- import './index.less'
16
- <% if(pageSource){ %>
17
- import { loadMicroApp } from 'qiankun';
18
- const PageLifeCycle = {};
19
- const initPageState = {};
20
- const computed = {}
21
- <% } else { %>
22
- import PageLifeCycle from '../../lowcode/<%= pageName %>/lifecycle'
23
- import initPageState from '../../lowcode/<%= pageName %>/state'
24
- import computed from '../../lowcode/<%= pageName %>/computed'
25
- function loadMicroApp(){
26
- return new Proxy({}, {
27
- get(obj, prop) {
28
- return (...args) => {};
29
- },
30
- })
31
- }
32
- <% } %>
33
-
34
- let ReactDOMServer;
35
-
36
- if(process.env.SSR) {
37
- ReactDOMServer = require('react-dom/server');
38
- }
39
-
40
- // Import dependencies entry
41
- <%= entryImports %>
42
-
43
- // Import Components
44
- <%= componentImports %>
45
-
46
- // Import Plugins
47
- <%= pluginImports %>
48
-
49
- // Import Actions
50
- <%= actionImports %>
51
-
52
- // Actions
53
-
54
- // Plugin
55
- const pluginInstances = <%= pluginInstances %>;
56
- const virtualFields = <%= virtualFields %>;
57
- const componentSchema = <%= componentSchema %>;
58
- const pageListenerInstances = <%= pageListenerInstances %>;
59
- const widgetsContext = <%= widgets %>;
60
- const dataBinds = <%= dataBinds %>;
61
-
62
- AppLifeCycle.beforeCustomLaunch = (query)=>{
63
- EXTRA_API.setParams('$global', query || {})
64
- createStateDataSourceVar('$global',generateParamsParser({app}))
65
- };
66
- PageLifeCycle.beforePageCustomLaunch = (query) => {
67
- EXTRA_API.setParams('<%= pageName %>', query || {})
68
- createStateDataSourceVar('<%= pageName %>',generateParamsParser({app, $page}))
69
- };
70
- // lifecycle
71
- initLifeCycle({
72
- ...AppLifeCycle,
73
- ...PageLifeCycle
74
- }, app, mainApp)
75
-
76
-
77
- // Init
78
- export default function App() {
79
- // 检查权限
80
- const [weDaHasLogin, setWeDaHasLogin] = React.useState(false);
81
- const dataContextRef = React.useRef(observable({}))
82
- const context = dataContextRef.current;
83
- const containerRef = React.useRef(null);
84
- const microApp = React.useRef(null);
85
- const pureSrc = '<%= pageSource %>';
86
- const isPure = !!pureSrc;
87
-
88
- React.useEffect(() => {
89
-
90
- Object.assign($page, {
91
- id: '<%= pageName %>',
92
- state: observable(initPageState),
93
- computed: createComputed(computed),
94
- // _context: context,
95
- handler,
96
- });
97
-
98
- let dataset = createDataset('<%= pageName %>', { app, $page });
99
- $page.dataset = dataset;
100
- $page.state.dataset = dataset;
101
- $page.setState = (userSetState) => {
102
- Object.keys(userSetState).forEach((keyPath) => {
103
- app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
104
- });
105
- };
106
- app.__internal__.activePage = $page
107
-
108
- checkAuth(app, app.id, $page).then((checkAuthResult) => {
109
- setWeDaHasLogin(checkAuthResult)
110
- reportTime('FIRST_PAGE_CONTENT_RENDERED', undefined, true)
111
- });
112
-
113
- return () => {
114
- if (microApp.current) {
115
- microApp.current.unmount();
116
- }
117
- };
118
- }, []);
119
-
120
- React.useEffect(() => {
121
- $page.widgets = createWidgets(widgetsContext, dataBinds, {}, dataContextRef.current);
122
- // widgets 内的 dataBinds 可能需要关联 widgets,需要重新执行 dataBinds
123
- retryDataBinds();
124
- }, [dataContextRef.current]);
125
-
126
- // Web 环境页面级别生命周期
127
- if (!process.env.isMiniprogram) {
128
- React.useEffect(() => {
129
- document.title = "<%= title %>"
130
- }, [])
131
- pageLifeCycleMount(React.useEffect, PageLifeCycle, app, {reachBottomDistance:<%= reachBottomDistance %>})
132
- }
133
-
134
- React.useEffect(() => {
135
- if (isPure) {
136
- if (weDaHasLogin) {
137
- if (!microApp.current) {
138
- microApp.current = loadMicroApp({
139
- name: '<%= pageName %>',
140
- entry: pureSrc,
141
- container: containerRef.current,
142
- });
143
- } else {
144
- microApp.current.mount?.();
145
- }
146
- } else if (microApp.current) {
147
- microApp.current.unmount();
148
- }
149
- }
150
- }, [weDaHasLogin]);
151
-
152
- useScrollTop();
153
-
154
- return (
155
- <div className="weapps-page" ref={containerRef}>
156
- <style
157
- type="text/css"
158
- dangerouslySetInnerHTML={{
159
- __html: `<%= pageStyleText %>`,
160
- }}
161
- />
162
- {weDaHasLogin &&
163
- !isPure &&
164
- (PageLifeCycle.onPageRender ? (
165
- PageLifeCycle.onPageRender()
166
- ) : (
167
- <AppRender
168
- pageListenerInstances={pageListenerInstances}
169
- virtualFields={virtualFields}
170
- componentSchema={componentSchema}
171
- context={dataContextRef.current}
172
- /**
173
- * 更新数据容器的上下文的方法
174
- * 会传递到事件emit的地方,将从组件获取到的数据data赋值给上下文
175
- * 当组件卸载时,传过来的data为undefined即可
176
- * {
177
- * id1: [{...}],
178
- * id2: {...},
179
- * id3: undefined,
180
- * id4: null,
181
- * ...
182
- * }
183
- * @param id
184
- * @param data
185
- */
186
- updateContext={(id, data) => {
187
- if (id) {
188
- dataContextRef.current[id] = { data };
189
- // console.log('111', context[id])
190
- }
191
- }}
192
- />
193
- ))}
194
- </div>
195
- );
196
- }
197
-
198
- export function renderToString() {
199
- return ReactDOMServer.renderToString(<App />);
200
- }