@cloudbase/lowcode-builder 1.8.17 → 1.8.19
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/dist/builder.web.js +12 -12
- package/lib/builder/config/index.d.ts +2 -2
- package/lib/builder/config/index.js +2 -2
- package/lib/builder/h5/index.d.ts +1 -1
- package/lib/builder/h5/index.js +42 -4
- package/lib/builder/h5/webpack.js +1 -1
- package/lib/builder/mp/index.js +17 -7
- package/lib/builder/mp/util.js +11 -8
- package/lib/builder/types/common.d.ts +1 -1
- package/lib/builder/util/common.d.ts +1 -1
- package/lib/builder/util/process.js +12 -15
- package/lib/builder.web.js +12 -12
- package/lib/utils/transform.d.ts +3 -0
- package/lib/utils/transform.js +35 -0
- package/lib/weapp-page.d.ts +17 -0
- package/lib/weapp-page.js +301 -0
- package/package.json +7 -4
- package/template/.DS_Store +0 -0
- package/template/html/index.html.ejs +2 -2
- package/template/mp/.DS_Store +0 -0
- package/template/mp/app.js +1 -1
- package/template/mp/common/.DS_Store +0 -0
- package/template/mp/common/flow.js +8 -6
- package/template/mp/common/query.js +72 -55
- package/template/mp/common/util.js +12 -4
- package/template/mp/common/weapp-page.js +92 -79
- package/template/mp/package.json +2 -2
- package/template/mp/page/index.js +2 -1
- package/template/mp/common/url.js +0 -21
|
@@ -3,25 +3,32 @@ import { createEventHandlers, getMpEventHandlerName, mergeDynamic2StaticData } f
|
|
|
3
3
|
import { Event } from './event-emitter';
|
|
4
4
|
|
|
5
5
|
export class Query {
|
|
6
|
+
_schema = {}
|
|
7
|
+
#schema
|
|
8
|
+
#context = {};
|
|
9
|
+
#disposes = [];
|
|
10
|
+
#dataBinds = {};
|
|
11
|
+
#triggered = false;
|
|
12
|
+
#paramsRef = observable({ current: null });
|
|
13
|
+
#currentRequestKey = null;
|
|
14
|
+
#observableValue = observable({ data: null, error: null });
|
|
15
|
+
#eventHandlerMap = {};
|
|
16
|
+
#action = () => {};
|
|
6
17
|
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 = {};
|
|
14
18
|
const { looseError = false } = options;
|
|
15
|
-
this
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
this.#schema = schema;
|
|
20
|
+
this._schema = {
|
|
21
|
+
trigger: schema.trigger
|
|
22
|
+
}
|
|
23
|
+
this.#context = context;
|
|
24
|
+
if (this.#schema?.trigger === 'auto') {
|
|
25
|
+
this.#disposes.push(
|
|
19
26
|
autorun(
|
|
20
27
|
(r) => {
|
|
21
28
|
try {
|
|
22
|
-
const data = this
|
|
23
|
-
if (this
|
|
24
|
-
this
|
|
29
|
+
const data = this.#resolveParams();
|
|
30
|
+
if (this.#triggered) {
|
|
31
|
+
this.#debounceTrigger(data);
|
|
25
32
|
}
|
|
26
33
|
} catch (e) {
|
|
27
34
|
console.error(e);
|
|
@@ -31,18 +38,18 @@ export class Query {
|
|
|
31
38
|
),
|
|
32
39
|
);
|
|
33
40
|
}
|
|
34
|
-
this.
|
|
35
|
-
this
|
|
41
|
+
this.#paramsRef.current = this.#schema.data;
|
|
42
|
+
this.#dataBinds = Object.entries(this.#schema.dataBinds || {}).reduce((map, [prop, fn]) => {
|
|
36
43
|
if (!/[\s+\-*/!&|%]*?SERVER\./.test(prop)) {
|
|
37
44
|
map[prop] = fn;
|
|
38
45
|
}
|
|
39
46
|
return map;
|
|
40
47
|
}, {});
|
|
41
48
|
|
|
42
|
-
const { $w } = this
|
|
49
|
+
const { $w } = this.#context;
|
|
43
50
|
|
|
44
|
-
this
|
|
45
|
-
this.
|
|
51
|
+
this.#action =
|
|
52
|
+
this.#schema.type === 'sql'
|
|
46
53
|
? async function (data) {
|
|
47
54
|
const Data = await $w.cloud.callWedaApi({
|
|
48
55
|
action: 'RunPluginQuery',
|
|
@@ -96,9 +103,9 @@ export class Query {
|
|
|
96
103
|
total: Total || ExecuteResultList.length,
|
|
97
104
|
};
|
|
98
105
|
}
|
|
99
|
-
: this.
|
|
100
|
-
this
|
|
101
|
-
createEventHandlers(this.
|
|
106
|
+
: this.#schema.handler;
|
|
107
|
+
this.#eventHandlerMap = Object.entries(
|
|
108
|
+
createEventHandlers(this.#schema.eventHandlers || {}, {
|
|
102
109
|
looseError: looseError,
|
|
103
110
|
isComposite: false,
|
|
104
111
|
}),
|
|
@@ -109,84 +116,94 @@ export class Query {
|
|
|
109
116
|
return map;
|
|
110
117
|
},
|
|
111
118
|
{
|
|
112
|
-
_getInstance: () => this
|
|
119
|
+
_getInstance: () => this.#context.$page || this.#context.$app,
|
|
113
120
|
},
|
|
114
121
|
);
|
|
115
122
|
return this;
|
|
116
123
|
}
|
|
117
124
|
get id() {
|
|
118
|
-
return this
|
|
125
|
+
return this.#schema?.id || '';
|
|
119
126
|
}
|
|
120
127
|
get label() {
|
|
121
|
-
return this
|
|
128
|
+
return this.#schema?.label || '';
|
|
122
129
|
}
|
|
123
130
|
get description() {
|
|
124
|
-
return this
|
|
131
|
+
return this.#schema?.description || '';
|
|
125
132
|
}
|
|
126
133
|
get data() {
|
|
127
|
-
return this.
|
|
134
|
+
return this.#observableValue.data;
|
|
128
135
|
}
|
|
129
136
|
get error() {
|
|
130
|
-
return this.
|
|
137
|
+
return this.#observableValue.error;
|
|
131
138
|
}
|
|
132
139
|
async trigger(additionalScope, options = {}) {
|
|
133
|
-
this
|
|
134
|
-
return this
|
|
140
|
+
this.#triggered = true;
|
|
141
|
+
return this.#innerTrigger(this.#resolveParams(), additionalScope, options);
|
|
135
142
|
}
|
|
136
143
|
reset() {
|
|
137
|
-
this.
|
|
138
|
-
this.
|
|
144
|
+
this.#observableValue.data = null;
|
|
145
|
+
this.#observableValue.error = null;
|
|
146
|
+
}
|
|
147
|
+
destroy() {
|
|
148
|
+
this.#disposes.forEach((dispose) => dispose());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 用于调试
|
|
153
|
+
*/
|
|
154
|
+
_toSchema() {
|
|
155
|
+
console.warn('调试使用,结构可能发生更改,请不要用于生产环境');
|
|
156
|
+
return this.#schema;
|
|
139
157
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
|
|
159
|
+
async #innerTrigger(data, additionalScope, options = {}) {
|
|
160
|
+
this.#currentRequestKey = Date.now();
|
|
161
|
+
const key = this.#currentRequestKey;
|
|
143
162
|
try {
|
|
144
|
-
const res = await this
|
|
145
|
-
if (key === this
|
|
146
|
-
this.
|
|
147
|
-
this.
|
|
148
|
-
this
|
|
163
|
+
const res = await this.#action(data);
|
|
164
|
+
if (key === this.#currentRequestKey) {
|
|
165
|
+
this.#observableValue.data = res;
|
|
166
|
+
this.#observableValue.error = null;
|
|
167
|
+
this.#emit(`success`, res);
|
|
149
168
|
}
|
|
150
169
|
return res;
|
|
151
170
|
} catch (e) {
|
|
152
|
-
if (key === this
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
155
|
-
this
|
|
171
|
+
if (key === this.#currentRequestKey) {
|
|
172
|
+
this.#observableValue.data = null;
|
|
173
|
+
this.#observableValue.error = e;
|
|
174
|
+
this.#emit(`fail`, e);
|
|
156
175
|
}
|
|
157
176
|
throw e;
|
|
158
177
|
}
|
|
159
178
|
}
|
|
160
|
-
|
|
179
|
+
#debounceTrigger(...args) {
|
|
161
180
|
if (this._timer) {
|
|
162
181
|
clearTimeout(this._timer);
|
|
163
182
|
}
|
|
164
183
|
this._timer = setTimeout(() => {
|
|
165
|
-
this
|
|
184
|
+
this.#innerTrigger(...args);
|
|
166
185
|
}, 300);
|
|
167
186
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
_resolveParams() {
|
|
187
|
+
|
|
188
|
+
#resolveParams() {
|
|
172
189
|
/**
|
|
173
190
|
* 这里万一其中某个字段计算失败
|
|
174
191
|
* 好像会阻塞其他字段的计算
|
|
175
192
|
* 从而导致 autorun 没有添加依赖
|
|
176
193
|
*/
|
|
177
|
-
return mergeDynamic2StaticData(toJS(this.
|
|
194
|
+
return mergeDynamic2StaticData(toJS(this.#paramsRef.current), this.#dataBinds, {
|
|
178
195
|
codeContext: {
|
|
179
196
|
/**
|
|
180
197
|
* $page 或 $comp 实例
|
|
181
198
|
*/
|
|
182
|
-
instance: this
|
|
199
|
+
instance: this.#context.$page,
|
|
183
200
|
},
|
|
184
|
-
$w: this
|
|
201
|
+
$w: this.#context.$w,
|
|
185
202
|
// may be additional scope
|
|
186
203
|
});
|
|
187
204
|
}
|
|
188
|
-
async
|
|
189
|
-
return this
|
|
205
|
+
async #emit(eventName, data) {
|
|
206
|
+
return this.#eventHandlerMap[getMpEventHandlerName(this.id, eventName)]?.(
|
|
190
207
|
new Event({
|
|
191
208
|
type: eventName,
|
|
192
209
|
detail: data,
|
|
@@ -96,7 +96,9 @@ export function createEventHandlers(
|
|
|
96
96
|
* 取消判断待兼容
|
|
97
97
|
*/
|
|
98
98
|
if (pageId !== id /* || (__internal__ && !__internal__.active)*/) {
|
|
99
|
-
|
|
99
|
+
if (!name?.includes?.('onDataChange')) {
|
|
100
|
+
console.error(`Action error: [${name}] 页面生命周期结束,链式调用中断`);
|
|
101
|
+
}
|
|
100
102
|
return false;
|
|
101
103
|
}
|
|
102
104
|
}
|
|
@@ -160,7 +162,7 @@ export function createEventHandlers(
|
|
|
160
162
|
}
|
|
161
163
|
} catch (e) {
|
|
162
164
|
if (e.message) {
|
|
163
|
-
e.
|
|
165
|
+
e._target = `${currentTarget?.id || ''}[${trigger}:${l.key}]`
|
|
164
166
|
}
|
|
165
167
|
nextEventHandles[0].handlerName = l.key ? `${prefix}$${l.key}_fail` : '';
|
|
166
168
|
nextEventHandles[0].event.detail = isIfAction ? event.detail : e;
|
|
@@ -175,12 +177,12 @@ export function createEventHandlers(
|
|
|
175
177
|
const nextHandler = nextEventHandles[0];
|
|
176
178
|
|
|
177
179
|
if (!self[nextHandler.handlerName] && error) {
|
|
178
|
-
console.error(`Action error:`, error);
|
|
180
|
+
console.error(`Action error:`, generateErrorDebugMessage(error), error?.stack);
|
|
179
181
|
if (!looseError) {
|
|
180
182
|
if (app.__internal__?.env?.type !== 'production') {
|
|
181
183
|
app.showModal({
|
|
182
184
|
title: `事件响应失败`,
|
|
183
|
-
content: error
|
|
185
|
+
content: generateErrorDebugMessage(error) || error.errMsg || '',
|
|
184
186
|
showCancel: false,
|
|
185
187
|
});
|
|
186
188
|
} else {
|
|
@@ -231,6 +233,12 @@ export function createEventHandlers(
|
|
|
231
233
|
|
|
232
234
|
return evtHandlers;
|
|
233
235
|
}
|
|
236
|
+
|
|
237
|
+
function generateErrorDebugMessage(error) {
|
|
238
|
+
return `${error?._target ? `${error?._target}:` : ''}${error?.message || ''}`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
234
242
|
export function getDeep(target, key, keySeparator = '.') {
|
|
235
243
|
if (key == null) {
|
|
236
244
|
return target;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { observable } from 'mobx';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
createComputed,
|
|
4
|
+
createEventHandlers,
|
|
5
|
+
checkAuth,
|
|
6
|
+
getMpEventHandlerName,
|
|
7
|
+
generateDatasetQuery,
|
|
8
|
+
generateEventFlows,
|
|
9
|
+
} from './util';
|
|
10
|
+
import { createWidgets, createInitData, disposeWidget, getWidget } from './widget';
|
|
4
11
|
import mergeRenderer from './merge-renderer';
|
|
5
12
|
import {
|
|
6
13
|
createDataset,
|
|
@@ -10,10 +17,62 @@ import {
|
|
|
10
17
|
setConfig,
|
|
11
18
|
} from '../datasources/index';
|
|
12
19
|
import { runWatchers } from './watch';
|
|
13
|
-
import { $w as baseAPI } from '../app/weapps-api'
|
|
14
|
-
import { Event } from './event-emitter'
|
|
20
|
+
import { $w as baseAPI } from '../app/weapps-api';
|
|
21
|
+
import { Event } from './event-emitter';
|
|
22
|
+
import { generatePageUrl } from '@cloudbase/weda-client';
|
|
23
|
+
|
|
24
|
+
const wxApp = getApp();
|
|
25
|
+
|
|
26
|
+
function extractLifecycles(ctx, lifecycle, appShareMessage, resetShare = true) {
|
|
27
|
+
const result = {};
|
|
28
|
+
Object.keys(lifecycle).map((name) => {
|
|
29
|
+
result[name] = function () {
|
|
30
|
+
return lifecycle[name].apply(this._getInstance(), arguments);
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (resetShare) {
|
|
35
|
+
result['onShareAppMessage'] = (res) => {
|
|
36
|
+
if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
|
|
37
|
+
return res?.target?.dataset?.weda_share_info;
|
|
38
|
+
} else if (res?.from === 'menu' && appShareMessage?.enable) {
|
|
39
|
+
let { pageId, params, imageUrl, title, packageName } = appShareMessage || {};
|
|
40
|
+
return {
|
|
41
|
+
path: generatePageUrl({
|
|
42
|
+
pageId,
|
|
43
|
+
packageName,
|
|
44
|
+
params,
|
|
45
|
+
}),
|
|
46
|
+
imageUrl: ctx.app?.__internal__?.resolveStaticResourceUrl?.(imageUrl) || imageUrl,
|
|
47
|
+
title,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return lifecycle?.['onShareAppMessage']?.() || {};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.log(error);
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
15
58
|
|
|
16
|
-
|
|
59
|
+
// 更新设备信息 窗口信息
|
|
60
|
+
result['onResize'] = (res) => {
|
|
61
|
+
let device = baseAPI.device;
|
|
62
|
+
if (!device) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const width = res?.size?.windowWidth;
|
|
66
|
+
const height = res?.size?.windowHeight;
|
|
67
|
+
if (width !== device?.viewport?.width || height !== device?.viewport?.height) {
|
|
68
|
+
device.viewport = {
|
|
69
|
+
width,
|
|
70
|
+
height,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
17
76
|
|
|
18
77
|
export function createPage({
|
|
19
78
|
app,
|
|
@@ -30,70 +89,20 @@ export function createPage({
|
|
|
30
89
|
eventFlows = [],
|
|
31
90
|
pageContext = {},
|
|
32
91
|
pageAttributes = {},
|
|
92
|
+
resetShare = true,
|
|
33
93
|
}) {
|
|
34
94
|
const evtHandlers = createEventHandlers(evtListeners);
|
|
35
95
|
|
|
36
|
-
function extractLifecycles() {
|
|
37
|
-
const result = {};
|
|
38
|
-
Object.keys(lifecycle).map((name) => {
|
|
39
|
-
result[name] = function () {
|
|
40
|
-
return lifecycle[name].apply(this._getInstance(), arguments);
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
result['onShareAppMessage'] = (res) => {
|
|
45
|
-
if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
|
|
46
|
-
return res?.target?.dataset?.weda_share_info;
|
|
47
|
-
} else if (res?.from === 'menu' && pageAttributes?.appShareMessage) {
|
|
48
|
-
let { enable, pageId, params, imageUrl, title } = pageAttributes.appShareMessage;
|
|
49
|
-
if (enable) {
|
|
50
|
-
pageId = pageId ? pageId.replace(/^(\.)?\//, '') : pageId;
|
|
51
|
-
let realPath =
|
|
52
|
-
`/pages/${pageId}/index` +
|
|
53
|
-
(params ? '?' + params.map((pair) => pair.key + '=' + pair.value).join('&') : '');
|
|
54
|
-
return {
|
|
55
|
-
path: realPath,
|
|
56
|
-
imageUrl,
|
|
57
|
-
title,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
return lifecycle?.['onShareAppMessage']?.() || {};
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.log(error);
|
|
65
|
-
return {};
|
|
66
|
-
}
|
|
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?.viewport?.width || height !== device?.viewport?.height) {
|
|
78
|
-
device.viewport = {
|
|
79
|
-
width,
|
|
80
|
-
height
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
96
|
return Component({
|
|
88
97
|
_componentType: 'page',
|
|
89
98
|
data: {
|
|
90
99
|
...createInitData(widgetProps, dataBinds),
|
|
91
100
|
_isCheckingAtuh: false,
|
|
92
|
-
weDaHasLogin: false
|
|
101
|
+
weDaHasLogin: false,
|
|
93
102
|
},
|
|
94
103
|
lifetimes: {
|
|
95
104
|
attached() {
|
|
96
|
-
this._disposers = []
|
|
105
|
+
this._disposers = [];
|
|
97
106
|
const $page = this._getInstance();
|
|
98
107
|
this._pageActive = true;
|
|
99
108
|
/**
|
|
@@ -125,8 +134,8 @@ export function createPage({
|
|
|
125
134
|
},
|
|
126
135
|
pageLifetimes: {
|
|
127
136
|
// 组件所在页面的生命周期函数,定义下给运营平台上报用
|
|
128
|
-
show: function () {
|
|
129
|
-
hide: function () {
|
|
137
|
+
show: function () {},
|
|
138
|
+
hide: function () {},
|
|
130
139
|
},
|
|
131
140
|
methods: {
|
|
132
141
|
_pageActive: true,
|
|
@@ -135,28 +144,28 @@ export function createPage({
|
|
|
135
144
|
_disposers: [],
|
|
136
145
|
|
|
137
146
|
/** page lifecycles **/
|
|
138
|
-
...extractLifecycles(),
|
|
147
|
+
...extractLifecycles({ app }, lifecycle, pageAttributes?.appShareMessage, resetShare),
|
|
139
148
|
...evtHandlers,
|
|
140
149
|
...mergeRenderer,
|
|
141
150
|
async beforePageCustomLaunch(query) {
|
|
142
151
|
if (!this._beforePageCustomLaunchPromise) {
|
|
143
152
|
this._beforePageCustomLaunchPromise = new Promise(async (resolve) => {
|
|
144
|
-
await wxApp.globaldata?._beforePageCustomLaunchPromise
|
|
153
|
+
await wxApp.globaldata?._beforePageCustomLaunchPromise;
|
|
145
154
|
const $page = this._getInstance();
|
|
146
155
|
if (query) {
|
|
147
156
|
EXTRA_API.setParams($page.uuid, query);
|
|
148
157
|
}
|
|
149
158
|
try {
|
|
150
|
-
this.setData({ _isCheckingAtuh: true })
|
|
159
|
+
this.setData({ _isCheckingAtuh: true });
|
|
151
160
|
const auth = await checkAuth(app, app.id, $page);
|
|
152
|
-
if(auth) {
|
|
161
|
+
if (auth) {
|
|
153
162
|
this.setData({
|
|
154
163
|
weDaHasLogin: true,
|
|
155
164
|
});
|
|
156
|
-
createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page }));
|
|
165
|
+
createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page, $w: $page.__internal__?.$w }));
|
|
157
166
|
}
|
|
158
167
|
} finally {
|
|
159
|
-
this.setData({ _isCheckingAtuh: false })
|
|
168
|
+
this.setData({ _isCheckingAtuh: false });
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
// eslint-disable-next-line no-restricted-syntax
|
|
@@ -164,16 +173,16 @@ export function createPage({
|
|
|
164
173
|
if ($page.dataset.query[queryId]?._schema?.trigger === 'auto') {
|
|
165
174
|
try {
|
|
166
175
|
$page.dataset.query[queryId].trigger();
|
|
167
|
-
this._disposers.push(() => $page.dataset.query[queryId].destroy())
|
|
176
|
+
this._disposers.push(() => $page.dataset.query[queryId].destroy());
|
|
168
177
|
} catch (e) {
|
|
169
178
|
console.error(`query ${queryId} 初始化失败:`, e);
|
|
170
179
|
}
|
|
171
180
|
}
|
|
172
181
|
}
|
|
173
|
-
resolve()
|
|
174
|
-
})
|
|
182
|
+
resolve();
|
|
183
|
+
});
|
|
175
184
|
}
|
|
176
|
-
return this._beforePageCustomLaunchPromise
|
|
185
|
+
return this._beforePageCustomLaunchPromise;
|
|
177
186
|
},
|
|
178
187
|
async onLoad(options) {
|
|
179
188
|
const $page = this._getInstance();
|
|
@@ -184,7 +193,7 @@ export function createPage({
|
|
|
184
193
|
|
|
185
194
|
this._query = decodePageQuery(options || {});
|
|
186
195
|
|
|
187
|
-
await this.beforePageCustomLaunch?.(this._query)
|
|
196
|
+
await this.beforePageCustomLaunch?.(this._query);
|
|
188
197
|
|
|
189
198
|
const hook = lifecycle.onLoad || lifecycle.onPageLoad;
|
|
190
199
|
await hook?.call?.($page, this._query);
|
|
@@ -198,7 +207,7 @@ export function createPage({
|
|
|
198
207
|
const hook = lifecycle.onReady || lifecycle.onPageReady;
|
|
199
208
|
await hook?.call?.($page);
|
|
200
209
|
|
|
201
|
-
this._invokeEventHandler(
|
|
210
|
+
this._invokeEventHandler('ready');
|
|
202
211
|
},
|
|
203
212
|
onUnload() {
|
|
204
213
|
const $page = this._getInstance();
|
|
@@ -215,7 +224,7 @@ export function createPage({
|
|
|
215
224
|
$page.__internal__.active = this._pageActive;
|
|
216
225
|
app.__internal__.activePage = $page;
|
|
217
226
|
|
|
218
|
-
await this.beforePageCustomLaunch?.(this._query)
|
|
227
|
+
await this.beforePageCustomLaunch?.(this._query);
|
|
219
228
|
|
|
220
229
|
const hook = lifecycle.onShow || lifecycle.onPageShow;
|
|
221
230
|
await hook?.call?.($page);
|
|
@@ -235,9 +244,9 @@ export function createPage({
|
|
|
235
244
|
const keyName = getMpEventHandlerName(id, triggerName);
|
|
236
245
|
const event = new Event({
|
|
237
246
|
type: triggerName,
|
|
238
|
-
detail: params
|
|
239
|
-
})
|
|
240
|
-
return this[keyName]?.call?.(this, event)
|
|
247
|
+
detail: params,
|
|
248
|
+
});
|
|
249
|
+
return this[keyName]?.call?.(this, event);
|
|
241
250
|
},
|
|
242
251
|
_getInstance() {
|
|
243
252
|
let $page = this.$WEAPPS_PAGE;
|
|
@@ -253,7 +262,11 @@ export function createPage({
|
|
|
253
262
|
$page = pageContext;
|
|
254
263
|
this.$WEAPPS_PAGE = $page;
|
|
255
264
|
$page.handler = Object.keys(handlers).reduce((result, key) => {
|
|
256
|
-
|
|
265
|
+
try {
|
|
266
|
+
result[key] = handlers[key].bind($page);
|
|
267
|
+
} catch (e) {
|
|
268
|
+
console.error('添加页面handler失败', e);
|
|
269
|
+
}
|
|
257
270
|
return result;
|
|
258
271
|
}, {});
|
|
259
272
|
$page.computed = createComputed(computed, $page);
|
|
@@ -262,7 +275,7 @@ export function createPage({
|
|
|
262
275
|
$w: $page.__internal__.$w,
|
|
263
276
|
$app: app,
|
|
264
277
|
$page,
|
|
265
|
-
})
|
|
278
|
+
});
|
|
266
279
|
$page.dataset = dataset;
|
|
267
280
|
$page.state.dataset = dataset;
|
|
268
281
|
$page.setState = (userSetState) => {
|
|
@@ -272,7 +285,7 @@ export function createPage({
|
|
|
272
285
|
};
|
|
273
286
|
|
|
274
287
|
const { widgets, rootWidget } = createWidgets(widgetProps, dataBinds, this, $page.widgets);
|
|
275
|
-
$page.widgets = widgets
|
|
288
|
+
$page.widgets = widgets;
|
|
276
289
|
$page._rootWidget = rootWidget;
|
|
277
290
|
|
|
278
291
|
$page.invokeComponentMethod = ({ component, method, params }) => {
|
package/template/mp/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"@cloudbase/js-sdk": "2.5.6-beta.1",<%
|
|
7
7
|
} %>
|
|
8
8
|
"@cloudbase/oauth": "0.1.1-alpha.5",
|
|
9
|
-
"@cloudbase/weda-client": "1.0.
|
|
10
|
-
"@cloudbase/weda-cloud-sdk": "1.0.
|
|
9
|
+
"@cloudbase/weda-client": "1.0.6",
|
|
10
|
+
"@cloudbase/weda-cloud-sdk": "1.0.42",
|
|
11
11
|
"mobx": "^5.15.4",
|
|
12
12
|
"lodash.get": "^4.4.2",
|
|
13
13
|
"lodash.set": "^4.3.2",
|
|
@@ -86,5 +86,6 @@ createPage({
|
|
|
86
86
|
handlers,
|
|
87
87
|
query,
|
|
88
88
|
eventFlows,
|
|
89
|
-
pageAttributes: <%= pageAttributes? stringifyObj(pageAttributes, {depth: null}):'{}'
|
|
89
|
+
pageAttributes: <%= pageAttributes? stringifyObj(pageAttributes, {depth: null}):'{}' %>,
|
|
90
|
+
resetShare: <%= resetShare %>
|
|
90
91
|
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// 处理url链接,加入params参数
|
|
2
|
-
export function urlJoinParams(url, params) {
|
|
3
|
-
if (!url || !params || typeof params !== 'object') {
|
|
4
|
-
return url
|
|
5
|
-
}
|
|
6
|
-
const separate = url.indexOf('?') === -1 ? '?' : '&'
|
|
7
|
-
const tempStr = Object.keys(params)
|
|
8
|
-
.map(key => {
|
|
9
|
-
let value = params[key]
|
|
10
|
-
if (typeof value === 'object') {
|
|
11
|
-
value = JSON.stringify(value)
|
|
12
|
-
}
|
|
13
|
-
if (value != undefined) {
|
|
14
|
-
return `${key}=${encodeURIComponent(value)}`
|
|
15
|
-
}
|
|
16
|
-
return ''
|
|
17
|
-
})
|
|
18
|
-
.filter(value => value)
|
|
19
|
-
.join('&')
|
|
20
|
-
return `${url}${separate}${tempStr}`
|
|
21
|
-
}
|