@cloudbase/framework-plugin-low-code 0.7.10-beta.2 → 0.7.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.
- package/lib/builder/core/generate.d.ts.map +1 -1
- package/lib/builder/core/generate.js +6 -8
- package/lib/builder/core/index.d.ts.map +1 -1
- package/lib/builder/service/builder/webpack.d.ts +1 -1
- package/lib/builder/service/builder/webpack.d.ts.map +1 -1
- package/lib/builder/service/builder/webpack.js +17 -28
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -73
- package/lib/weapps-core/utils/style.js +8 -0
- package/package.json +1 -1
- package/template/html/index.html.ejs +426 -426
- package/template/mp/app/weapps-api.js +27 -95
- package/template/mp/app.js +60 -76
- package/template/mp/common/util.js +3 -312
- package/template/mp/datasources/index.js +16 -5
- package/template/mp/package.json +2 -2
- package/template/package.json +1 -1
- package/template/src/app/global-api.js +41 -154
- package/template/src/datasources/index.js.tpl +14 -2
- package/template/src/handlers/FieldMiddleware/renderer.jsx +25 -85
- package/template/src/handlers/actionHandler/utils.js +10 -31
- package/template/src/handlers/lifecycle.js +10 -21
- package/template/src/handlers/render.jsx +6 -17
- package/template/src/handlers/utils/common.js +26 -42
- package/template/src/handlers/utils/widgets.js +8 -37
- package/template/src/index.jsx +9 -8
- package/template/src/pages/app.tpl +2 -0
- package/template/src/utils/formatEnum.js +1 -1
- package/template/src/utils/index.js +0 -14
- package/template/src/utils/ScanCodeComponent.js +0 -345
- package/template/src/utils/date.js +0 -324
- package/template/src/utils/scan-code-action.js +0 -27
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK, auth} from '@cloudbase/weda-client'
|
|
2
|
+
const {
|
|
2
3
|
setConfig,
|
|
3
4
|
initTcb,
|
|
4
|
-
CLOUD_SDK
|
|
5
|
-
|
|
5
|
+
CLOUD_SDK,
|
|
6
|
+
createDataset,
|
|
7
|
+
createStateDataSourceVar,
|
|
8
|
+
generateParamsParser,
|
|
9
|
+
EXTRA_API,
|
|
10
|
+
DS_API,
|
|
11
|
+
DS_SDK,
|
|
12
|
+
} = WEDA_CLOUD_SDK
|
|
13
|
+
const getAccessToken = auth.getAccessToken
|
|
14
|
+
|
|
6
15
|
export {
|
|
7
16
|
createDataset,
|
|
8
17
|
createStateDataSourceVar,
|
|
@@ -11,8 +20,10 @@ export {
|
|
|
11
20
|
CLOUD_SDK,
|
|
12
21
|
DS_API,
|
|
13
22
|
DS_SDK,
|
|
14
|
-
setConfig
|
|
15
|
-
|
|
23
|
+
setConfig,
|
|
24
|
+
getAccessToken,
|
|
25
|
+
initTcb,
|
|
26
|
+
}
|
|
16
27
|
|
|
17
28
|
import config from './config'
|
|
18
29
|
|
package/template/mp/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"scripts": {},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@cloudbase/weda-
|
|
7
|
-
"@cloudbase/oauth": "0.1.1-alpha.
|
|
6
|
+
"@cloudbase/weda-client": "0.2.8",
|
|
7
|
+
"@cloudbase/oauth": "0.1.1-alpha.5",
|
|
8
8
|
"mobx": "^5.15.4",
|
|
9
9
|
"lodash.get": "^4.4.2",
|
|
10
10
|
"lodash.set": "^4.3.2",
|
package/template/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import * as sdk from '@tcwd/weapps-sdk';
|
|
2
|
+
import {
|
|
3
|
+
createWebApp,
|
|
4
|
+
_ACTIONS_KEY as ACTIONS_KEY,
|
|
5
|
+
_ROUTER_KEY as ROUTER_KEY,
|
|
6
|
+
} from '@cloudbase/weda-client';
|
|
2
7
|
import { createComputed } from 'utils';
|
|
3
|
-
import {
|
|
8
|
+
import { createDataset } from '../datasources';
|
|
4
9
|
import store, { subPackageName } from '../store';
|
|
5
10
|
import computed from '../store/computed';
|
|
6
11
|
import common from './common';
|
|
7
|
-
import { formatDate } from '../utils/date';
|
|
8
12
|
import { formatEnum, enumOptions } from '../utils/formatEnum';
|
|
9
|
-
import {
|
|
13
|
+
import { _isMobile } from '../utils';
|
|
10
14
|
import actionMap from './material-actions';
|
|
11
|
-
import {
|
|
12
|
-
import { get as lodashGet } from 'lodash'
|
|
15
|
+
import { get as lodashGet } from 'lodash';
|
|
13
16
|
|
|
14
17
|
const mainAppKey = '__weappsMainApp';
|
|
15
18
|
const appGlobal = process.env.isMiniprogram ? getApp() : window;
|
|
@@ -17,98 +20,46 @@ const appGlobal = process.env.isMiniprogram ? getApp() : window;
|
|
|
17
20
|
export const app = createGlboalApi();
|
|
18
21
|
export const $page = createPageApi();
|
|
19
22
|
|
|
20
|
-
export function setCurrentPage(pageCtx) {
|
|
21
|
-
try {
|
|
22
|
-
app.__internal__.activePage = pageCtx
|
|
23
|
-
} catch(e) { }
|
|
24
|
-
Object.assign($page, pageCtx);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
23
|
function createGlboalApi() {
|
|
24
|
+
const webApp = createWebApp({
|
|
25
|
+
id: '<%= appId %>',
|
|
26
|
+
domain: '<%= domain %>',
|
|
27
|
+
appConfig: <%= appConfig %>,
|
|
28
|
+
});
|
|
28
29
|
const globalAPI = {
|
|
29
30
|
id: '<%= appId %>',
|
|
30
31
|
domain: '<%= domain %>',
|
|
31
|
-
platform: 'WEB',
|
|
32
|
-
__internal__: {
|
|
33
|
-
activePage: null,
|
|
34
|
-
getConfig: function () {
|
|
35
|
-
return <%= appConfig %>;
|
|
36
|
-
},
|
|
37
|
-
resolveStaticResourceUrl(staticUrl) {
|
|
38
|
-
if (/^\//.test(staticUrl) && !window._isPrivate) {
|
|
39
|
-
const domain = globalAPI?.__internal__?.getConfig?.()?.staticResourceDomain || globalAPI?.domain || ''
|
|
40
|
-
const url = `https://${domain}${staticUrl}`;
|
|
41
|
-
return url;
|
|
42
|
-
}
|
|
43
|
-
return staticUrl;
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
32
|
formActions: {},
|
|
47
33
|
pages: {},
|
|
48
34
|
session: {
|
|
49
|
-
configure: sdk.configure,
|
|
50
|
-
request: sdk.request,
|
|
51
|
-
getSessionId: sdk.getSessionId,
|
|
35
|
+
// configure: sdk.configure,
|
|
36
|
+
// request: sdk.request,
|
|
37
|
+
// getSessionId: sdk.getSessionId,
|
|
52
38
|
},
|
|
53
|
-
enumOptions: enumOptions,
|
|
54
39
|
state: store,
|
|
55
40
|
computed: createComputed(computed.global),
|
|
56
41
|
common,
|
|
57
|
-
dataSources: DS_SDK,
|
|
58
|
-
relaunchHome: function () {
|
|
59
|
-
const { pages = [] } = globalAPI.__internal__.getConfig();
|
|
60
|
-
if (pages[0]) {
|
|
61
|
-
globalAPI.reLaunch({
|
|
62
|
-
pageId: pages[0].id,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
42
|
invoke(params) {
|
|
67
|
-
return $page.invokeComponentMethod(params)
|
|
68
|
-
},
|
|
69
|
-
utils: {
|
|
70
|
-
formatDate,
|
|
71
|
-
formatEnum,
|
|
72
|
-
get: getter,
|
|
73
|
-
set: setter,
|
|
74
|
-
/**
|
|
75
|
-
* @deprecated
|
|
76
|
-
*/
|
|
77
|
-
_getConfig(){
|
|
78
|
-
return globalAPI.__internal__.getConfig()
|
|
79
|
-
},
|
|
80
|
-
getWXContext: function () {
|
|
81
|
-
return Promise.resolve({})
|
|
82
|
-
},
|
|
83
|
-
getCurrentPage: function () {
|
|
84
|
-
return $page
|
|
85
|
-
},
|
|
43
|
+
return $page.invokeComponentMethod(params);
|
|
86
44
|
},
|
|
45
|
+
...webApp,
|
|
46
|
+
};
|
|
87
47
|
|
|
88
|
-
|
|
89
|
-
|
|
48
|
+
globalAPI.__internal__.enumOptions = enumOptions;
|
|
49
|
+
globalAPI.utils.formatEnum = formatEnum;
|
|
50
|
+
globalAPI.utils._getConfig = () => {
|
|
51
|
+
console.warn('deprecated app.utils._getConfig');
|
|
52
|
+
return globalAPI.__internal__.getConfig();
|
|
53
|
+
}
|
|
90
54
|
|
|
91
55
|
const dataset = createDataset('$global');
|
|
92
56
|
globalAPI.dataset = dataset;
|
|
93
57
|
globalAPI.state.dataset = dataset;
|
|
94
58
|
globalAPI.setState = (userSetState) => {
|
|
95
59
|
Object.keys(userSetState).forEach((keyPath) => {
|
|
96
|
-
globalAPI.utils.set(
|
|
97
|
-
globalAPI.dataset.state,
|
|
98
|
-
keyPath,
|
|
99
|
-
userSetState[keyPath]
|
|
100
|
-
);
|
|
60
|
+
globalAPI.utils.set(globalAPI.dataset.state, keyPath, userSetState[keyPath]);
|
|
101
61
|
});
|
|
102
62
|
};
|
|
103
|
-
/**
|
|
104
|
-
* 内部通用的设置状态变量值的方法
|
|
105
|
-
* varPath 结构为 $global.<变量名> 即全局变量
|
|
106
|
-
* $page.<变量名> 即当前页面变量
|
|
107
|
-
* <pageId>.<变量名> 指定页面 pageId 的变量 (应当避免修改非当前页面的变量值)
|
|
108
|
-
*/
|
|
109
|
-
globalAPI._setStateVal = (config) => {
|
|
110
|
-
EXTRA_API.setState(config.varPath, config.val);
|
|
111
|
-
};
|
|
112
63
|
if (subPackageName) {
|
|
113
64
|
// is sub app
|
|
114
65
|
globalAPI.mainApp = appGlobal[mainAppKey];
|
|
@@ -126,9 +77,6 @@ function createGlboalApi() {
|
|
|
126
77
|
sdkModsIncluded.forEach((key) => {
|
|
127
78
|
globalAPI[key] = sdk[key];
|
|
128
79
|
});
|
|
129
|
-
// 避免被wx.cloud 覆盖
|
|
130
|
-
globalAPI.cloud = CLOUD_SDK;
|
|
131
|
-
|
|
132
80
|
return globalAPI;
|
|
133
81
|
}
|
|
134
82
|
function createPageApi() {
|
|
@@ -144,7 +92,7 @@ function createPageApi() {
|
|
|
144
92
|
$page.invokeComponentMethod = ({ component, method, params }) => {
|
|
145
93
|
const widgetData = lodashGet($page.widgets, component);
|
|
146
94
|
if (Array.isArray(widgetData)) {
|
|
147
|
-
throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
|
|
95
|
+
throw new Error('调用方法失败:id为' + component + '的组件拥有多个实例');
|
|
148
96
|
// widgetData.forEach(widget => {
|
|
149
97
|
// if(!widget._methods[method]) {
|
|
150
98
|
// throw new Error('NOT_FOUND')
|
|
@@ -153,12 +101,12 @@ function createPageApi() {
|
|
|
153
101
|
// }
|
|
154
102
|
// })
|
|
155
103
|
} else {
|
|
156
|
-
if(!widgetData._methods[method] || typeof widgetData._methods[method]!= 'function') {
|
|
157
|
-
throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
|
|
104
|
+
if (!widgetData._methods[method] || typeof widgetData._methods[method] != 'function') {
|
|
105
|
+
throw new Error('调用方法失败:未找到id为' + component + '下的方法' + method);
|
|
158
106
|
}
|
|
159
|
-
return widgetData._methods[method](params)
|
|
107
|
+
return widgetData._methods[method](params);
|
|
160
108
|
}
|
|
161
|
-
}
|
|
109
|
+
};
|
|
162
110
|
return $page;
|
|
163
111
|
}
|
|
164
112
|
|
|
@@ -166,80 +114,19 @@ function createPageApi() {
|
|
|
166
114
|
export const mountAPIs = (sdks) => {
|
|
167
115
|
Object.keys(sdks).forEach((item) => {
|
|
168
116
|
let action = sdks[item];
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
...obj,
|
|
176
|
-
image:
|
|
177
|
-
'data:image/svg+xml,%3Csvg%20width%3D%22120%22%20height%3D%22120%22%20viewBox%3D%220,0,24,24%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M12%2010.586l5.657-5.657%201.414%201.414L13.414%2012l5.657%205.657-1.414%201.414L12%2013.414l-5.657%205.657-1.414-1.414L10.586%2012%204.929%206.343%206.343%204.93%2012%2010.586z%22%20fill-rule%3D%22evenodd%22%20fill%3D%22white%22%2F%3E%3C%2Fsvg%3E',
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return sdks[item](obj);
|
|
181
|
-
};
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
case 'showModal': {
|
|
185
|
-
const OFFICIAL_COMPONENT_LIB = 'gsd-h5-react';
|
|
186
|
-
const showModal =
|
|
187
|
-
actionMap[OFFICIAL_COMPONENT_LIB] &&
|
|
188
|
-
actionMap[OFFICIAL_COMPONENT_LIB].showModal;
|
|
189
|
-
if (!_isMobile() && showModal) {
|
|
190
|
-
action = function (params) {
|
|
191
|
-
return showModal({ data: params });
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
case 'scanCode': {
|
|
197
|
-
action = (options) => {
|
|
198
|
-
if (
|
|
199
|
-
!options ||
|
|
200
|
-
(!options.success && !options.fail && !options.complete)
|
|
201
|
-
) {
|
|
202
|
-
return new Promise((resolve, reject) => {
|
|
203
|
-
scanCodeApi({
|
|
204
|
-
...options,
|
|
205
|
-
success: resolve,
|
|
206
|
-
fail: reject,
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
scanCodeApi(options);
|
|
211
|
-
};
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
case 'navigateTo':
|
|
215
|
-
case 'reLaunch':
|
|
216
|
-
case 'redirectTo': {
|
|
217
|
-
action = function (obj) {
|
|
218
|
-
if (obj.mode === 'web' && process.env.isMiniprogram) {
|
|
219
|
-
console.warn('url navigation can only be used in h5 build');
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const { url, ...restOpts } = obj;
|
|
223
|
-
if (obj.mode === 'web') {
|
|
224
|
-
if (item === 'navigateTo') {
|
|
225
|
-
window.open(url);
|
|
226
|
-
} else {
|
|
227
|
-
window.location.href = url;
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
return sdks[item]({
|
|
231
|
-
...restOpts,
|
|
232
|
-
pageId: restOpts.pageId
|
|
233
|
-
? restOpts.pageId.replace(/^(\.)?\//, '')
|
|
234
|
-
: restOpts.pageId,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
117
|
+
if(item === 'showModal') {
|
|
118
|
+
const OFFICIAL_COMPONENT_LIB = 'gsd-h5-react';
|
|
119
|
+
const showModal = actionMap[OFFICIAL_COMPONENT_LIB]?.showModal;
|
|
120
|
+
if (!_isMobile() && showModal) {
|
|
121
|
+
action = function (params) {
|
|
122
|
+
return showModal({ data: params });
|
|
237
123
|
};
|
|
238
|
-
break;
|
|
239
124
|
}
|
|
125
|
+
app[item] = action;
|
|
126
|
+
}
|
|
127
|
+
else if (!(item in ACTIONS_KEY) && !(item in ROUTER_KEY)) {
|
|
128
|
+
app[item] = action;
|
|
240
129
|
}
|
|
241
|
-
|
|
242
|
-
app[item] = action;
|
|
243
130
|
});
|
|
244
131
|
return app;
|
|
245
132
|
};
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK } from '@cloudbase/weda-client'
|
|
2
2
|
import config from './config';
|
|
3
3
|
|
|
4
|
+
const {
|
|
5
|
+
setConfig,
|
|
6
|
+
initTcb,
|
|
7
|
+
createDataset,
|
|
8
|
+
createStateDataSourceVar,
|
|
9
|
+
generateParamsParser,
|
|
10
|
+
EXTRA_API,
|
|
11
|
+
CLOUD_SDK,
|
|
12
|
+
DS_API,
|
|
13
|
+
DS_SDK
|
|
14
|
+
} = WEDA_CLOUD_SDK
|
|
15
|
+
|
|
4
16
|
export {
|
|
5
17
|
createDataset,
|
|
6
18
|
createStateDataSourceVar,
|
|
@@ -9,7 +21,7 @@ export {
|
|
|
9
21
|
CLOUD_SDK,
|
|
10
22
|
DS_API,
|
|
11
23
|
DS_SDK,
|
|
12
|
-
}
|
|
24
|
+
}
|
|
13
25
|
|
|
14
26
|
setConfig(config);
|
|
15
27
|
<% if(!isXPage){ %>
|
|
@@ -25,7 +25,7 @@ function generateSlotMap(slots, forContext = undefined) {
|
|
|
25
25
|
slotProp,
|
|
26
26
|
<ForContext.Provider value={forContext}>
|
|
27
27
|
<Element />
|
|
28
|
-
</ForContext.Provider
|
|
28
|
+
</ForContext.Provider>,
|
|
29
29
|
);
|
|
30
30
|
} else {
|
|
31
31
|
set(map, slotProp, <Element />);
|
|
@@ -49,14 +49,7 @@ function getSafeComponentProps({ style, classNameList }) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// TODO: 需要不断移除 dataBinds(style/classList)
|
|
52
|
-
function getBindData({
|
|
53
|
-
widgetData,
|
|
54
|
-
forItems,
|
|
55
|
-
scopeContext,
|
|
56
|
-
codeContext,
|
|
57
|
-
commonStyle = {},
|
|
58
|
-
classNameList = [],
|
|
59
|
-
}) {
|
|
52
|
+
function getBindData({ widgetData, forItems, scopeContext, codeContext, commonStyle = {}, classNameList = [] }) {
|
|
60
53
|
// bindData
|
|
61
54
|
if (Array.isArray(widgetData)) {
|
|
62
55
|
widgetData =
|
|
@@ -103,19 +96,13 @@ function getBindData({
|
|
|
103
96
|
|
|
104
97
|
// bindClassList
|
|
105
98
|
const bindClassList = fieldData.classList || [];
|
|
106
|
-
const finalClassNameList = getFinalClassNameList(
|
|
107
|
-
classNameList,
|
|
108
|
-
bindClassList
|
|
109
|
-
);
|
|
99
|
+
const finalClassNameList = getFinalClassNameList(classNameList, bindClassList);
|
|
110
100
|
|
|
111
101
|
// 当前在复合组件中,且当前节点为根节点
|
|
112
102
|
if (isInComposite && isRootNode) {
|
|
113
103
|
if (widgetData.ownerWidget) {
|
|
114
104
|
Object.keys(widgetData.ownerWidget).forEach((propName) => {
|
|
115
|
-
if (
|
|
116
|
-
propName === 'role' ||
|
|
117
|
-
['aria-', 'data-'].some((prefix) => propName.startsWith(prefix))
|
|
118
|
-
) {
|
|
105
|
+
if (propName === 'role' || ['aria-', 'data-'].some((prefix) => propName.startsWith(prefix))) {
|
|
119
106
|
widgetData[propName] = widgetData.ownerWidget[propName];
|
|
120
107
|
}
|
|
121
108
|
});
|
|
@@ -142,10 +129,7 @@ function getForList(compId, dataBinds, parentForItems, dataContext) {
|
|
|
142
129
|
|
|
143
130
|
try {
|
|
144
131
|
// 绑定了 for 变量,但计算值错误时,应当空数组兜底
|
|
145
|
-
forList =
|
|
146
|
-
dataBinds &&
|
|
147
|
-
dataBinds._waFor &&
|
|
148
|
-
(dataBinds._waFor(parentForItems, undefined, dataContext) || []);
|
|
132
|
+
forList = dataBinds && dataBinds._waFor && (dataBinds._waFor(parentForItems, undefined, dataContext) || []);
|
|
149
133
|
} catch (e) {
|
|
150
134
|
// 计算值出错则使用空数组兜底
|
|
151
135
|
forList = [];
|
|
@@ -176,14 +160,7 @@ function FieldWrapper({
|
|
|
176
160
|
children,
|
|
177
161
|
updateContext,
|
|
178
162
|
}) {
|
|
179
|
-
const {
|
|
180
|
-
scopeContext,
|
|
181
|
-
forContext,
|
|
182
|
-
forIndexes,
|
|
183
|
-
widgetsData,
|
|
184
|
-
codeContext,
|
|
185
|
-
dataContext,
|
|
186
|
-
} = context;
|
|
163
|
+
const { scopeContext, forContext, forIndexes, widgetsData, codeContext, dataContext } = context;
|
|
187
164
|
|
|
188
165
|
const injectContext = {};
|
|
189
166
|
const indexRef = React.useRef();
|
|
@@ -210,14 +187,7 @@ function FieldWrapper({
|
|
|
210
187
|
}
|
|
211
188
|
|
|
212
189
|
if (injectContext?.emit) {
|
|
213
|
-
return injectContext.emit(
|
|
214
|
-
trigger,
|
|
215
|
-
listeners,
|
|
216
|
-
eventData,
|
|
217
|
-
forItems,
|
|
218
|
-
domEvent,
|
|
219
|
-
scopeContext
|
|
220
|
-
);
|
|
190
|
+
return injectContext.emit(trigger, listeners, eventData, forItems, domEvent, scopeContext);
|
|
221
191
|
} else {
|
|
222
192
|
const event = {
|
|
223
193
|
detail: eventData,
|
|
@@ -240,16 +210,14 @@ function FieldWrapper({
|
|
|
240
210
|
domEvent,
|
|
241
211
|
},
|
|
242
212
|
scopeContext,
|
|
243
|
-
dataContext
|
|
213
|
+
dataContext,
|
|
244
214
|
);
|
|
245
215
|
}
|
|
246
216
|
},
|
|
247
|
-
[widgetsData]
|
|
217
|
+
[widgetsData],
|
|
248
218
|
);
|
|
249
219
|
|
|
250
|
-
const currentWidget = Array.isArray(widgetsData)
|
|
251
|
-
? get(widgetsData, forIndexes)
|
|
252
|
-
: widgetsData;
|
|
220
|
+
const currentWidget = Array.isArray(widgetsData) ? get(widgetsData, forIndexes) : widgetsData;
|
|
253
221
|
|
|
254
222
|
React.useLayoutEffect(() => {
|
|
255
223
|
return () => {
|
|
@@ -266,10 +234,7 @@ function FieldWrapper({
|
|
|
266
234
|
}
|
|
267
235
|
|
|
268
236
|
// 判断为容器组件,则增加一个onDataChange事件
|
|
269
|
-
if (
|
|
270
|
-
componentSchema?.compConfig?.isDataContainer &&
|
|
271
|
-
!events?.includes('onDataChange')
|
|
272
|
-
) {
|
|
237
|
+
if (componentSchema?.compConfig?.isDataContainer && !events?.includes('onDataChange')) {
|
|
273
238
|
events.push('onDataChange');
|
|
274
239
|
}
|
|
275
240
|
|
|
@@ -285,34 +250,23 @@ function FieldWrapper({
|
|
|
285
250
|
typeRef.current = blockKey;
|
|
286
251
|
}
|
|
287
252
|
},
|
|
288
|
-
events:
|
|
289
|
-
componentSchema?.selectableBlock?.events.map((item) => item.name) ||
|
|
290
|
-
[],
|
|
253
|
+
events: componentSchema?.selectableBlock?.events.map((item) => item.name) || [],
|
|
291
254
|
emit: (trigger, evt, domEvent) =>
|
|
292
255
|
emit(
|
|
293
256
|
trigger,
|
|
294
257
|
indexRef?.current !== undefined &&
|
|
295
258
|
typeRef?.current &&
|
|
296
|
-
data?.[typeRef.current]?.[indexRef.current]?.selectableBlock?.[
|
|
297
|
-
'x-props'
|
|
298
|
-
]?.listenerInstances,
|
|
259
|
+
data?.[typeRef.current]?.[indexRef.current]?.selectableBlock?.['x-props']?.listenerInstances,
|
|
299
260
|
evt,
|
|
300
261
|
forContext,
|
|
301
262
|
domEvent,
|
|
302
|
-
scopeContext
|
|
263
|
+
scopeContext,
|
|
303
264
|
),
|
|
304
265
|
},
|
|
305
266
|
}}
|
|
306
267
|
id={id}
|
|
307
268
|
emit={(trigger, eventData, domEvent) =>
|
|
308
|
-
emit(
|
|
309
|
-
trigger,
|
|
310
|
-
listenerInstances,
|
|
311
|
-
eventData,
|
|
312
|
-
forContext,
|
|
313
|
-
domEvent,
|
|
314
|
-
scopeContext
|
|
315
|
-
)
|
|
269
|
+
emit(trigger, listenerInstances, eventData, forContext, domEvent, scopeContext)
|
|
316
270
|
}
|
|
317
271
|
events={events}
|
|
318
272
|
compositeParent={compositeParent}
|
|
@@ -361,9 +315,7 @@ export function getComponentRenderList(props) {
|
|
|
361
315
|
|
|
362
316
|
const isInComposite = !!codeContext;
|
|
363
317
|
// 判断 widgets 是从 page 来的,还是组件来的
|
|
364
|
-
const widgetsData = !isInComposite
|
|
365
|
-
? $page.widgets[compId]
|
|
366
|
-
: codeContext.$WEAPPS_COMP.widgets[compId];
|
|
318
|
+
const widgetsData = !isInComposite ? $page.widgets[compId] : codeContext.$WEAPPS_COMP.widgets[compId];
|
|
367
319
|
|
|
368
320
|
if (!xProps) {
|
|
369
321
|
return (
|
|
@@ -386,9 +338,7 @@ export function getComponentRenderList(props) {
|
|
|
386
338
|
if (forList) {
|
|
387
339
|
return forList
|
|
388
340
|
.map((item, index) => {
|
|
389
|
-
const forItemsIndexes = (parentForItems['forIndexes'] || []).concat(
|
|
390
|
-
index
|
|
391
|
-
);
|
|
341
|
+
const forItemsIndexes = (parentForItems['forIndexes'] || []).concat(index);
|
|
392
342
|
const forItems = {
|
|
393
343
|
...parentForItems,
|
|
394
344
|
[compId]: item,
|
|
@@ -421,8 +371,8 @@ export function getComponentRenderList(props) {
|
|
|
421
371
|
},
|
|
422
372
|
{
|
|
423
373
|
renderSlot,
|
|
424
|
-
}
|
|
425
|
-
)
|
|
374
|
+
},
|
|
375
|
+
),
|
|
426
376
|
);
|
|
427
377
|
|
|
428
378
|
return (
|
|
@@ -491,8 +441,8 @@ export function getComponentRenderList(props) {
|
|
|
491
441
|
},
|
|
492
442
|
{
|
|
493
443
|
renderSlot,
|
|
494
|
-
}
|
|
495
|
-
)
|
|
444
|
+
},
|
|
445
|
+
),
|
|
496
446
|
);
|
|
497
447
|
|
|
498
448
|
return (
|
|
@@ -527,13 +477,8 @@ export function getComponentRenderList(props) {
|
|
|
527
477
|
);
|
|
528
478
|
}
|
|
529
479
|
|
|
530
|
-
export function getFinalStyle(
|
|
531
|
-
|
|
532
|
-
bindStyle = {},
|
|
533
|
-
widgetStyle = {}
|
|
534
|
-
) {
|
|
535
|
-
const remBindStyle =
|
|
536
|
-
typeof bindStyle === 'object' ? translateStyleToRem(bindStyle) : {};
|
|
480
|
+
export function getFinalStyle(commonStyle = {}, bindStyle = {}, widgetStyle = {}) {
|
|
481
|
+
const remBindStyle = typeof bindStyle === 'object' ? translateStyleToRem(bindStyle) : {};
|
|
537
482
|
|
|
538
483
|
return {
|
|
539
484
|
...(translateStyleToRem(commonStyle) || {}),
|
|
@@ -542,11 +487,7 @@ export function getFinalStyle(
|
|
|
542
487
|
};
|
|
543
488
|
}
|
|
544
489
|
|
|
545
|
-
export function getFinalClassNameList(
|
|
546
|
-
classNameList = [],
|
|
547
|
-
bindClassList = [],
|
|
548
|
-
widgetClassList = []
|
|
549
|
-
) {
|
|
490
|
+
export function getFinalClassNameList(classNameList = [], bindClassList = [], widgetClassList = []) {
|
|
550
491
|
return [].concat(classNameList, bindClassList, widgetClassList);
|
|
551
492
|
}
|
|
552
493
|
|
|
@@ -577,8 +518,7 @@ function setGetDomApi(currentWidget, props) {
|
|
|
577
518
|
currentWidget.domRef = React.createRef();
|
|
578
519
|
}
|
|
579
520
|
if (!currentWidget.getDom) {
|
|
580
|
-
currentWidget.getDom = (options) =>
|
|
581
|
-
getDom(currentWidget.domRef.current, options);
|
|
521
|
+
currentWidget.getDom = (options) => getDom(currentWidget.domRef.current, options);
|
|
582
522
|
}
|
|
583
523
|
|
|
584
524
|
if (
|
|
@@ -11,13 +11,7 @@ export function getMetaInfoBySourceKey(sourceKey) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export function emitEvent(
|
|
15
|
-
trigger,
|
|
16
|
-
listeners = [],
|
|
17
|
-
args,
|
|
18
|
-
scopeContext = {},
|
|
19
|
-
context
|
|
20
|
-
) {
|
|
14
|
+
export function emitEvent(trigger, listeners = [], args, scopeContext = {}, context) {
|
|
21
15
|
const targetListeners = listeners.filter((l) => l.trigger === trigger);
|
|
22
16
|
targetListeners.forEach(async (listener) => {
|
|
23
17
|
// 当前非捕获Event,再判断冒泡行为
|
|
@@ -26,10 +20,7 @@ export function emitEvent(
|
|
|
26
20
|
}
|
|
27
21
|
|
|
28
22
|
// 判断捕获的执行,只有执行的捕获与配置的捕获一致时。才会执行。
|
|
29
|
-
if (
|
|
30
|
-
(listener?.isCapturePhase || false) ===
|
|
31
|
-
(args?.customEventData?.isCapturePhase || false)
|
|
32
|
-
) {
|
|
23
|
+
if ((listener?.isCapturePhase || false) === (args?.customEventData?.isCapturePhase || false)) {
|
|
33
24
|
try {
|
|
34
25
|
const res = await invokeListener(listener, args, scopeContext, context);
|
|
35
26
|
const eventName = `${listener.key}.success`;
|
|
@@ -58,11 +49,11 @@ export function emitEvent(
|
|
|
58
49
|
customEventData: event,
|
|
59
50
|
},
|
|
60
51
|
scopeContext,
|
|
61
|
-
context
|
|
52
|
+
context,
|
|
62
53
|
);
|
|
63
54
|
if (res) {
|
|
64
55
|
console.warn(
|
|
65
|
-
`@deprecated 事件编排中后续事件(${eventName}) event.detail.value.xxx 已废弃,建议使用 event.detail
|
|
56
|
+
`@deprecated 事件编排中后续事件(${eventName}) event.detail.value.xxx 已废弃,建议使用 event.detail 直接访问前一动作返回值`,
|
|
66
57
|
);
|
|
67
58
|
}
|
|
68
59
|
} catch (e) {
|
|
@@ -87,10 +78,10 @@ export function emitEvent(
|
|
|
87
78
|
customEventData: event,
|
|
88
79
|
},
|
|
89
80
|
scopeContext,
|
|
90
|
-
context
|
|
81
|
+
context,
|
|
91
82
|
);
|
|
92
83
|
console.warn(
|
|
93
|
-
`@deprecated 事件编排中后续事件(${eventName}) event.detail.value.xxx 已废弃,建议使用 event.detail
|
|
84
|
+
`@deprecated 事件编排中后续事件(${eventName}) event.detail.value.xxx 已废弃,建议使用 event.detail 直接访问前一动作返回值`,
|
|
94
85
|
);
|
|
95
86
|
// 之前 invoke 内部catch 了错误,不会抛错
|
|
96
87
|
// throw e
|
|
@@ -99,12 +90,7 @@ export function emitEvent(
|
|
|
99
90
|
});
|
|
100
91
|
}
|
|
101
92
|
|
|
102
|
-
async function invokeListener(
|
|
103
|
-
{ instanceFunction, data = {}, dataBinds = {} },
|
|
104
|
-
args,
|
|
105
|
-
scopeContext,
|
|
106
|
-
context
|
|
107
|
-
) {
|
|
93
|
+
async function invokeListener({ instanceFunction, data = {}, dataBinds = {} }, args, scopeContext, context) {
|
|
108
94
|
// ToDo resolve databinds
|
|
109
95
|
const action = instanceFunction;
|
|
110
96
|
let maxTimeout = DEFAULT_MAX_TIMEOUT;
|
|
@@ -119,21 +105,14 @@ async function invokeListener(
|
|
|
119
105
|
{ event: args.event },
|
|
120
106
|
scopeContext,
|
|
121
107
|
true,
|
|
122
|
-
context
|
|
108
|
+
context,
|
|
123
109
|
);
|
|
124
110
|
|
|
125
111
|
// eslint-disable-next-line no-restricted-syntax
|
|
126
112
|
for (const key in resolvedDataBinds) {
|
|
127
|
-
if (
|
|
128
|
-
resolvedDataBinds[key] &&
|
|
129
|
-
resolvedDataBinds[key].__type === 'scopedValue'
|
|
130
|
-
) {
|
|
113
|
+
if (resolvedDataBinds[key] && resolvedDataBinds[key].__type === 'scopedValue') {
|
|
131
114
|
try {
|
|
132
|
-
lodashSet(
|
|
133
|
-
resolvedData,
|
|
134
|
-
key,
|
|
135
|
-
resolvedDataBinds[key].getValue(scopeContext)
|
|
136
|
-
);
|
|
115
|
+
lodashSet(resolvedData, key, resolvedDataBinds[key].getValue(scopeContext));
|
|
137
116
|
} catch (e) {
|
|
138
117
|
lodashSet(resolvedData, key, '');
|
|
139
118
|
}
|