@cloudbase/framework-plugin-low-code 0.6.67 → 0.6.68
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/common.js +1 -1
- package/lib/builder/config/index.js +2 -2
- package/lib/builder/config/mp.js +1 -1
- package/lib/builder/core/copy.js +3 -3
- package/lib/builder/core/generate.d.ts.map +1 -1
- package/lib/builder/core/generate.js +11 -11
- package/lib/builder/core/index.js +13 -13
- package/lib/builder/core/material.js +6 -6
- package/lib/builder/core/plugin.js +3 -3
- package/lib/builder/core/prepare.js +2 -2
- package/lib/builder/core/webpack.js +5 -5
- package/lib/builder/mp/index.js +47 -47
- package/lib/builder/mp/lowcode.js +4 -4
- package/lib/builder/mp/materials.js +16 -16
- package/lib/builder/mp/mixMode.js +12 -12
- package/lib/builder/mp/mp_config.js +11 -11
- package/lib/builder/mp/util.d.ts.map +1 -1
- package/lib/builder/mp/util.js +12 -9
- package/lib/builder/mp/wxml.d.ts.map +1 -1
- package/lib/builder/mp/wxml.js +7 -6
- package/lib/builder/service/builder/copy.js +11 -11
- package/lib/builder/service/builder/generate.js +58 -54
- package/lib/builder/service/builder/index.js +2 -2
- package/lib/builder/service/builder/plugin.js +2 -2
- package/lib/builder/service/builder/webpack.js +24 -23
- package/lib/builder/types/common.js +1 -0
- package/lib/builder/util/common.d.ts.map +1 -1
- package/lib/builder/util/common.js +8 -6
- package/lib/builder/util/console.js +1 -1
- package/lib/builder/util/generateFiles.js +2 -2
- package/lib/builder/util/index.js +1 -1
- package/lib/builder/util/junk.js +4 -2
- package/lib/builder/util/mp.js +1 -1
- package/lib/builder/util/net.js +1 -1
- package/lib/builder/util/style.js +1 -1
- package/lib/builder/util/weapp.js +1 -1
- package/lib/generate.js +2 -2
- package/lib/generator/config/index.js +2 -2
- package/lib/generator/core/generate.js +36 -34
- package/lib/generator/core/index.js +4 -4
- package/lib/generator/core/material.js +14 -14
- package/lib/generator/types/common.js +6 -3
- package/lib/generator/util/common.d.ts.map +1 -1
- package/lib/generator/util/common.js +1 -1
- package/lib/generator/util/index.js +1 -1
- package/lib/generator/util/style.js +2 -2
- package/lib/index.js +58 -53
- package/lib/utils/common.d.ts +1 -1
- package/lib/utils/common.d.ts.map +1 -1
- package/lib/utils/common.js +2 -2
- package/lib/utils/dataSource.js +2 -2
- package/lib/utils/index.js +1 -1
- package/lib/utils/postProcess.js +3 -3
- package/lib/weapps-core/config/index.js +1 -1
- package/lib/weapps-core/index.js +2 -2
- package/lib/weapps-core/types/index.js +1 -1
- package/lib/weapps-core/utils/appbuild.js +6 -3
- package/lib/weapps-core/utils/common.js +3 -2
- package/lib/weapps-core/utils/formily.js +37 -37
- package/lib/weapps-core/utils/index.js +1 -1
- package/lib/weapps-core/utils/style.js +15 -15
- package/package.json +1 -1
- package/template/mp/app/weapps-api.js +3 -0
- package/template/mp/common/weapp-component.js +26 -7
- package/template/mp/common/weapp-page.js +38 -1
- package/template/mp/common/widget.js +1 -0
- package/template/src/app/global-api.js +22 -0
- package/template/src/handlers/FieldMiddleware/renderer.jsx +12 -0
- package/template/src/handlers/actionHandler/utils.js +1 -3
- package/template/src/handlers/utils/widgets.js +16 -4
- package/template/src/pages/composite.tpl +25 -7
|
@@ -7,7 +7,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
7
7
|
o[k2] = m[k];
|
|
8
8
|
}));
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./formily"), exports);
|
|
@@ -76,9 +76,9 @@ function toCssStyle(commonStyle = {}, options = { toRem: true, ignoreSelf: false
|
|
|
76
76
|
if (radius !== undefined) {
|
|
77
77
|
setStyleValue(style, 'borderRadius', _handleStyleNumValue(radius, !!options.addPXUnit));
|
|
78
78
|
}
|
|
79
|
-
if (radiusInfo && !common_1.isEmptyObj(radiusInfo)) {
|
|
79
|
+
if (radiusInfo && !(0, common_1.isEmptyObj)(radiusInfo)) {
|
|
80
80
|
if (Object.keys(radiusInfo).length === 4) {
|
|
81
|
-
if (uniq_1.default(map_1.default(radiusInfo, (val) => val)).length === 1) {
|
|
81
|
+
if ((0, uniq_1.default)((0, map_1.default)(radiusInfo, (val) => val)).length === 1) {
|
|
82
82
|
setStyleValue(style, 'borderRadius', _handleStyleNumValue(radiusInfo.topLeft, !!options.addPXUnit));
|
|
83
83
|
}
|
|
84
84
|
else if (radiusInfo.topLeft === radiusInfo.bottomRight &&
|
|
@@ -120,7 +120,7 @@ function toCssStyle(commonStyle = {}, options = { toRem: true, ignoreSelf: false
|
|
|
120
120
|
setStyleValue(style, 'backgroundSize', _handleStyleNumValue(size, !!options.addPXUnit));
|
|
121
121
|
}
|
|
122
122
|
setStyleValue(style, 'backgroundPosition', position);
|
|
123
|
-
if (positionObj && !common_1.isEmptyObj(positionObj)) {
|
|
123
|
+
if (positionObj && !(0, common_1.isEmptyObj)(positionObj)) {
|
|
124
124
|
style.background += ` ${_handleStyleNumValue(positionObj.left, !!options.addPXUnit)} ${_handleStyleNumValue(positionObj.top, !!options.addPXUnit)}`;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -166,7 +166,7 @@ exports.toCssStyle = toCssStyle;
|
|
|
166
166
|
function removeInvalidStyleFormValue(styleForm = {}) {
|
|
167
167
|
return Object.keys(styleForm).reduce((result, key) => {
|
|
168
168
|
const propStyleFormData = styleForm[key];
|
|
169
|
-
if (common_1.isPlainObject(propStyleFormData)) {
|
|
169
|
+
if ((0, common_1.isPlainObject)(propStyleFormData)) {
|
|
170
170
|
setStyleValue(result, key, removeInvalidStyleFormValue(propStyleFormData));
|
|
171
171
|
}
|
|
172
172
|
else {
|
|
@@ -178,24 +178,24 @@ function removeInvalidStyleFormValue(styleForm = {}) {
|
|
|
178
178
|
exports.removeInvalidStyleFormValue = removeInvalidStyleFormValue;
|
|
179
179
|
function setDistanceStyle(style, distance, attr, addPXUnit) {
|
|
180
180
|
if (Object.keys(distance).length === 4) {
|
|
181
|
-
if (uniq_1.default(map_1.default(distance, (val) => val)).length === 1) {
|
|
182
|
-
setStyleValue(style, common_1.camelcase(`${attr}`), _handleStyleNumValue(distance.top, addPXUnit));
|
|
181
|
+
if ((0, uniq_1.default)((0, map_1.default)(distance, (val) => val)).length === 1) {
|
|
182
|
+
setStyleValue(style, (0, common_1.camelcase)(`${attr}`), _handleStyleNumValue(distance.top, addPXUnit));
|
|
183
183
|
}
|
|
184
184
|
else if (distance.top === distance.bottom &&
|
|
185
185
|
distance.left === distance.right) {
|
|
186
|
-
setStyleValue(style, common_1.camelcase(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)}`);
|
|
186
|
+
setStyleValue(style, (0, common_1.camelcase)(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)}`);
|
|
187
187
|
}
|
|
188
188
|
else if (distance.left === distance.right) {
|
|
189
|
-
setStyleValue(style, common_1.camelcase(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)}`);
|
|
189
|
+
setStyleValue(style, (0, common_1.camelcase)(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)}`);
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
|
-
setStyleValue(style, common_1.camelcase(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)} ${_handleStyleNumValue(distance.left, addPXUnit)}`);
|
|
192
|
+
setStyleValue(style, (0, common_1.camelcase)(`${attr}`), `${_handleStyleNumValue(distance.top, addPXUnit)} ${_handleStyleNumValue(distance.right, addPXUnit)} ${_handleStyleNumValue(distance.bottom, addPXUnit)} ${_handleStyleNumValue(distance.left, addPXUnit)}`);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
else {
|
|
196
196
|
config_1.DISTANCE_KEY_LIST.forEach((key) => {
|
|
197
197
|
if (distance[key] !== undefined)
|
|
198
|
-
setStyleValue(style, common_1.camelcase(`${attr}_${key}`), _handleStyleNumValue(distance[key], addPXUnit));
|
|
198
|
+
setStyleValue(style, (0, common_1.camelcase)(`${attr}_${key}`), _handleStyleNumValue(distance[key], addPXUnit));
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
201
|
}
|
|
@@ -227,10 +227,10 @@ function setStyleValue(object, key, value) {
|
|
|
227
227
|
if (key === 'open') {
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
|
-
if (common_1.isEmptyObj(value)) {
|
|
230
|
+
if ((0, common_1.isEmptyObj)(value)) {
|
|
231
231
|
return;
|
|
232
232
|
}
|
|
233
|
-
object[common_1.camelcase(key)] = value;
|
|
233
|
+
object[(0, common_1.camelcase)(key)] = value;
|
|
234
234
|
}
|
|
235
235
|
function calPxToREM(px) {
|
|
236
236
|
if (Number.isNaN(px / 28))
|
|
@@ -280,7 +280,7 @@ exports.toRPX = toRPX;
|
|
|
280
280
|
function removeWrapperBadEffectStyle(commonStyle = {}) {
|
|
281
281
|
return Object.keys(commonStyle).reduce((result, key) => {
|
|
282
282
|
const value = commonStyle[key];
|
|
283
|
-
const camelcaseKey = common_1.camelcase(key);
|
|
283
|
+
const camelcaseKey = (0, common_1.camelcase)(key);
|
|
284
284
|
if (config_1.WRAPPER_REMOVE_STYLE_KEY_LIST.includes(camelcaseKey)) {
|
|
285
285
|
return result;
|
|
286
286
|
}
|
|
@@ -296,7 +296,7 @@ function removeEffectTwiceStyle(commonStyle = {}) {
|
|
|
296
296
|
const style = {};
|
|
297
297
|
Object.keys(commonStyle).map((key) => {
|
|
298
298
|
const value = commonStyle[key];
|
|
299
|
-
const camelcaseKey = common_1.camelcase(key);
|
|
299
|
+
const camelcaseKey = (0, common_1.camelcase)(key);
|
|
300
300
|
if (config_1.SELF_REMOVE_STYLE_KEY_LIST.includes(camelcaseKey)) {
|
|
301
301
|
return false;
|
|
302
302
|
}
|
|
@@ -313,7 +313,7 @@ function toCssText(style, className = '.some-class-name') {
|
|
|
313
313
|
const attrText = Object.keys(style)
|
|
314
314
|
.map((key) => {
|
|
315
315
|
const value = style[key];
|
|
316
|
-
return `${common_1.kebabCase(key)}: ${value};`;
|
|
316
|
+
return `${(0, common_1.kebabCase)(key)}: ${value};`;
|
|
317
317
|
})
|
|
318
318
|
.join('\n');
|
|
319
319
|
return `${className} { ${attrText} }\n`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/framework-plugin-low-code",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.68",
|
|
4
4
|
"description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
|
|
5
5
|
"author": "yhsunshining@gmail.com",
|
|
6
6
|
"homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
|
|
@@ -3,6 +3,7 @@ import { createEventHandlers, createComputed } from './util'
|
|
|
3
3
|
import { createWidgets, mpCompToWidget, disposeWidget } from './widget'
|
|
4
4
|
import mergeRenderer from './merge-renderer'
|
|
5
5
|
import sdk from './weapp-sdk'
|
|
6
|
+
import lodashGet from 'lodash.get';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Lowcodes of all components
|
|
@@ -48,7 +49,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
|
|
|
48
49
|
},
|
|
49
50
|
attached() {
|
|
50
51
|
const $comp = this.getWeAppInst()
|
|
51
|
-
if(!$comp) return
|
|
52
|
+
if (!$comp) return
|
|
52
53
|
|
|
53
54
|
$comp.props.events = createPropEvents(events, this)
|
|
54
55
|
$comp.widgets = {}
|
|
@@ -57,6 +58,19 @@ export function createComponent(key, behaviors, properties, events, handler, dat
|
|
|
57
58
|
|
|
58
59
|
try {
|
|
59
60
|
lifeCycle.onAttached && lifeCycle.onAttached.call($comp)
|
|
61
|
+
this.__handlerAttached__ = (e) => {
|
|
62
|
+
const widget = lodashGet(widgets, e.target.id);
|
|
63
|
+
widget._methods = e.detail.methods;
|
|
64
|
+
}
|
|
65
|
+
this.__handlerDetached__ = (e) => {
|
|
66
|
+
const widget = lodashGet(widgets, e.target.id);
|
|
67
|
+
delete widget._methods;
|
|
68
|
+
}
|
|
69
|
+
if ($comp.methods) {
|
|
70
|
+
this.triggerEvent('attached', {
|
|
71
|
+
'methods': $comp.methods
|
|
72
|
+
})
|
|
73
|
+
}
|
|
60
74
|
} catch (e) {
|
|
61
75
|
console.error('Component lifecycle(attached) error', this.is, e)
|
|
62
76
|
}
|
|
@@ -69,29 +83,33 @@ export function createComponent(key, behaviors, properties, events, handler, dat
|
|
|
69
83
|
},
|
|
70
84
|
detached() {
|
|
71
85
|
const $comp = this.getWeAppInst()
|
|
72
|
-
if(!$comp) return
|
|
86
|
+
if (!$comp) return
|
|
73
87
|
|
|
74
88
|
$comp.widgets = null
|
|
75
89
|
disposeWidget(this._virtualRootWidget)
|
|
76
90
|
this._disposers.forEach(dispose => dispose())
|
|
77
91
|
lifeCycle.onDetached && lifeCycle.onDetached.call($comp)
|
|
92
|
+
|
|
93
|
+
if ($comp?.methods) {
|
|
94
|
+
this.triggerEvent('detached');
|
|
95
|
+
}
|
|
78
96
|
}
|
|
79
97
|
},
|
|
80
98
|
|
|
81
99
|
pageLifetimes: {
|
|
82
100
|
show() {
|
|
83
101
|
const $comp = this.getWeAppInst()
|
|
84
|
-
if(!$comp) return
|
|
102
|
+
if (!$comp) return
|
|
85
103
|
lifeCycle.onPageShow && lifeCycle.onPageShow.call($comp)
|
|
86
104
|
},
|
|
87
105
|
hide() {
|
|
88
106
|
const $comp = this.getWeAppInst()
|
|
89
|
-
if(!$comp) return
|
|
107
|
+
if (!$comp) return
|
|
90
108
|
lifeCycle.onPageHide && lifeCycle.onPageHide.call($comp)
|
|
91
109
|
},
|
|
92
110
|
resize(size) {
|
|
93
111
|
const $comp = this.getWeAppInst()
|
|
94
|
-
if(!$comp) return
|
|
112
|
+
if (!$comp) return
|
|
95
113
|
lifeCycle.onPageResize && lifeCycle.onPageResize.call($comp, size)
|
|
96
114
|
}
|
|
97
115
|
},
|
|
@@ -119,12 +137,12 @@ export function createComponent(key, behaviors, properties, events, handler, dat
|
|
|
119
137
|
return widget.$comp
|
|
120
138
|
},
|
|
121
139
|
_runWatch() {
|
|
122
|
-
const { watchEffects = {}} = index
|
|
140
|
+
const { watchEffects = {} } = index
|
|
123
141
|
Object.keys(watchEffects).map(name => {
|
|
124
142
|
const fn = watchEffects[name]
|
|
125
143
|
if (fn instanceof Function) {
|
|
126
144
|
const $comp = this.getWeAppInst()
|
|
127
|
-
if(!$comp) return
|
|
145
|
+
if (!$comp) return
|
|
128
146
|
this._disposers.push(autorun(fn.bind($comp)))
|
|
129
147
|
} else {
|
|
130
148
|
console.error(`WatchEffect(${name}) of ${key} is not a function.`)
|
|
@@ -155,6 +173,7 @@ export function create$comp(w) {
|
|
|
155
173
|
get classList() { return w.classList },
|
|
156
174
|
},
|
|
157
175
|
lib,
|
|
176
|
+
methods: undefined,
|
|
158
177
|
i18n: {
|
|
159
178
|
...sdk.i18n,
|
|
160
179
|
t(key, data) {
|
|
@@ -3,6 +3,8 @@ import { createComputed, createEventHandlers, checkAuth } from './util';
|
|
|
3
3
|
import { createWidgets, createInitData, disposeWidget } from './widget';
|
|
4
4
|
import mergeRenderer from './merge-renderer';
|
|
5
5
|
import { createDataset, EXTRA_API, createStateDataSourceVar, generateParamsParser, setConfig } from '../datasources/index';
|
|
6
|
+
import lodashGet from 'lodash.get';
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
export function createPage(
|
|
8
10
|
lifecycle,
|
|
@@ -67,6 +69,28 @@ export function createPage(
|
|
|
67
69
|
this._rootWidget = rootWidget;
|
|
68
70
|
this._widgets = widgets;
|
|
69
71
|
this._pageActive = true;
|
|
72
|
+
this.__handlerAttached__ = (e) => {
|
|
73
|
+
if (!$page.componentMethods) {
|
|
74
|
+
$page.componentMethods = {};
|
|
75
|
+
}
|
|
76
|
+
const [id, index = 0] = e.target.id.split('-');
|
|
77
|
+
if (!$page.componentMethods[id]) {
|
|
78
|
+
$page.componentMethods[id] = [];
|
|
79
|
+
}
|
|
80
|
+
$page.componentMethods[id][index] = e.detail.methods;
|
|
81
|
+
};
|
|
82
|
+
this.__handlerDetached__ = (e) => {
|
|
83
|
+
const [id, index = 0] = e.target.id.split('-');
|
|
84
|
+
if ($page.componentMethods) {
|
|
85
|
+
const components = $page.componentMethods[id];
|
|
86
|
+
if (components) {
|
|
87
|
+
components[index] = undefined;
|
|
88
|
+
if (components.filter(com => com !== undefined).length === 0) {
|
|
89
|
+
delete $page.componentMethods[id];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
70
94
|
this._disposers = this.initMergeRenderer(widgets);
|
|
71
95
|
},
|
|
72
96
|
detached() {
|
|
@@ -143,7 +167,20 @@ export function createPage(
|
|
|
143
167
|
app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
|
|
144
168
|
});
|
|
145
169
|
};
|
|
146
|
-
|
|
170
|
+
$page.invokeComponentMethod = ({ component, method, params }) => {
|
|
171
|
+
const components = lodashGet($page.componentMethods, component);
|
|
172
|
+
if (Array.isArray(components)) {
|
|
173
|
+
throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
|
|
174
|
+
// components.forEach(component => {
|
|
175
|
+
// component[method](params);
|
|
176
|
+
// })
|
|
177
|
+
} else {
|
|
178
|
+
if(!components?.[method] || typeof components[method]!= 'function') {
|
|
179
|
+
throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
|
|
180
|
+
}
|
|
181
|
+
return components[method](params);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
147
184
|
this.$WEAPPS_PAGE = $page;
|
|
148
185
|
}
|
|
149
186
|
return this.$WEAPPS_PAGE
|
|
@@ -9,6 +9,7 @@ import { formatEnum, enumOptions } from '../utils/formatEnum';
|
|
|
9
9
|
import { getter, setter, _isMobile } from '../utils';
|
|
10
10
|
import actionMap from './material-actions';
|
|
11
11
|
import { scanCodeApi } from '../utils/scan-code-action';
|
|
12
|
+
import { get as lodashGet } from 'lodash'
|
|
12
13
|
|
|
13
14
|
const mainAppKey = '__weappsMainApp';
|
|
14
15
|
const appGlobal = process.env.isMiniprogram ? getApp() : window;
|
|
@@ -45,6 +46,9 @@ function createGlboalApi() {
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
},
|
|
49
|
+
invoke(params) {
|
|
50
|
+
return $page.invokeComponentMethod(params)
|
|
51
|
+
},
|
|
48
52
|
utils: {
|
|
49
53
|
formatDate,
|
|
50
54
|
formatEnum,
|
|
@@ -114,6 +118,24 @@ function createPageApi() {
|
|
|
114
118
|
// 页面数据源变量存储位置
|
|
115
119
|
dataVar: {},
|
|
116
120
|
};
|
|
121
|
+
$page.invokeComponentMethod = ({ component, method, params }) => {
|
|
122
|
+
const widgetData = lodashGet($page.widgets, component);
|
|
123
|
+
if (Array.isArray(widgetData)) {
|
|
124
|
+
throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
|
|
125
|
+
// widgetData.forEach(widget => {
|
|
126
|
+
// if(!widget._methods[method]) {
|
|
127
|
+
// throw new Error('NOT_FOUND')
|
|
128
|
+
// } else {
|
|
129
|
+
// actions.push(widget._methods[method])
|
|
130
|
+
// }
|
|
131
|
+
// })
|
|
132
|
+
} else {
|
|
133
|
+
if(!widgetData._methods[method] || typeof widgetData._methods[method]!= 'function') {
|
|
134
|
+
throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
|
|
135
|
+
}
|
|
136
|
+
return widgetData._methods[method](params)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
117
139
|
return $page;
|
|
118
140
|
}
|
|
119
141
|
|
|
@@ -188,6 +188,7 @@ function FieldWrapper({
|
|
|
188
188
|
const injectContext = {};
|
|
189
189
|
const indexRef = React.useRef();
|
|
190
190
|
const typeRef = React.useRef();
|
|
191
|
+
const instanceRef = React.useRef();
|
|
191
192
|
const { 'x-props': xProps } = componentSchema;
|
|
192
193
|
let { staticResourceAttribute = [], listenerInstances = [] } = xProps;
|
|
193
194
|
|
|
@@ -250,6 +251,16 @@ function FieldWrapper({
|
|
|
250
251
|
? get(widgetsData, forIndexes)
|
|
251
252
|
: widgetsData;
|
|
252
253
|
|
|
254
|
+
React.useLayoutEffect(() => {
|
|
255
|
+
return () => {
|
|
256
|
+
instanceRef.current = undefined;
|
|
257
|
+
};
|
|
258
|
+
}, []);
|
|
259
|
+
|
|
260
|
+
React.useLayoutEffect(() => {
|
|
261
|
+
currentWidget._getInstanceRef = () => instanceRef;
|
|
262
|
+
}, [currentWidget, instanceRef]);
|
|
263
|
+
|
|
253
264
|
if (!Array.isArray(staticResourceAttribute)) {
|
|
254
265
|
staticResourceAttribute = [];
|
|
255
266
|
}
|
|
@@ -264,6 +275,7 @@ function FieldWrapper({
|
|
|
264
275
|
|
|
265
276
|
return (
|
|
266
277
|
<Field
|
|
278
|
+
ref={instanceRef}
|
|
267
279
|
data={{
|
|
268
280
|
...data,
|
|
269
281
|
_selectableBlockEvents: {
|
|
@@ -94,7 +94,12 @@ export function retryDataBinds(tryTime = 10) {
|
|
|
94
94
|
retryDataBinds(tryTime - 1);
|
|
95
95
|
}, 0);
|
|
96
96
|
}
|
|
97
|
-
export function createWidgets(
|
|
97
|
+
export function createWidgets(
|
|
98
|
+
widgetProps,
|
|
99
|
+
dataBinds,
|
|
100
|
+
scopeContext = {},
|
|
101
|
+
context = {}
|
|
102
|
+
) {
|
|
98
103
|
const nodeTree = createWidgetTree(widgetProps, dataBinds);
|
|
99
104
|
const widgets = runFor(nodeTree, {}, null, null, scopeContext, context);
|
|
100
105
|
return widgets;
|
|
@@ -115,7 +120,7 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}, context
|
|
|
115
120
|
parentLevelWidgets,
|
|
116
121
|
parentWidget,
|
|
117
122
|
scopeContext,
|
|
118
|
-
context
|
|
123
|
+
context
|
|
119
124
|
) {
|
|
120
125
|
const nodeId = curForNode.id;
|
|
121
126
|
if (!curForNode.value) {
|
|
@@ -180,6 +185,13 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}, context
|
|
|
180
185
|
includeInvisibleDescendants
|
|
181
186
|
);
|
|
182
187
|
w.getOwnerWidget = () => null; // 寻找父widget,默认返回null, 后续会覆写
|
|
188
|
+
w._getInstanceRef = () => null; // 默认初始值
|
|
189
|
+
Object.defineProperty(w, '_methods', {
|
|
190
|
+
get() {
|
|
191
|
+
const instance = w._getInstanceRef();
|
|
192
|
+
return instance?.current.methods;
|
|
193
|
+
},
|
|
194
|
+
});
|
|
183
195
|
// 提供一个给 Node 挂载 API 的方式
|
|
184
196
|
untracked(() => {
|
|
185
197
|
w.extends = (name, fnOrData) =>
|
|
@@ -213,7 +225,7 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}, context
|
|
|
213
225
|
subForItems,
|
|
214
226
|
undefined,
|
|
215
227
|
context,
|
|
216
|
-
scopeContext
|
|
228
|
+
scopeContext
|
|
217
229
|
);
|
|
218
230
|
disposeError = false;
|
|
219
231
|
} catch (e) {
|
|
@@ -251,7 +263,7 @@ export function createWidgets(widgetProps, dataBinds, scopeContext = {}, context
|
|
|
251
263
|
widgets,
|
|
252
264
|
node.parent && widgets[node.parent.id],
|
|
253
265
|
scopeContext,
|
|
254
|
-
context
|
|
266
|
+
context
|
|
255
267
|
);
|
|
256
268
|
curForNode.id && widgets[curForNode.id]._disposers.push(dispose);
|
|
257
269
|
}
|
|
@@ -51,7 +51,7 @@ class CompositeCompWrapper extends React.Component {
|
|
|
51
51
|
this.compConfig = <%= JSON.stringify(compConfig, null, 2) %>
|
|
52
52
|
this.virtualFields = Object.assign({}, props.pageVirtualFields || {}, {
|
|
53
53
|
<% useComponents.forEach(compItem => {%>
|
|
54
|
-
"<%= compItem.key %>":
|
|
54
|
+
"<%= compItem.key %>": React.forwardRef((props,ref) => <<%= compItem.var %> {...resolveComponentProps(props, <%= compItem.isPlainProps? 1:0 %>)} ref={ref}/>),
|
|
55
55
|
<%}) %>
|
|
56
56
|
});
|
|
57
57
|
this.events = (<%= emitEvents %>).reduce((obj, trigger) => {
|
|
@@ -107,6 +107,7 @@ class CompositeCompWrapper extends React.Component {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
createCompAPI(compThis) {
|
|
110
|
+
const { forwardRef, ...restProps } = compThis.props || {};
|
|
110
111
|
compThis.$WEAPPS_COMP = {
|
|
111
112
|
compConfig: compThis.compConfig,
|
|
112
113
|
widgets: compThis.widgets,
|
|
@@ -114,7 +115,7 @@ class CompositeCompWrapper extends React.Component {
|
|
|
114
115
|
handler: compThis.handler,
|
|
115
116
|
lib: { const: constObj, tools: toolsObj },
|
|
116
117
|
get props() {
|
|
117
|
-
return {...
|
|
118
|
+
return {...restProps, events: compThis.events, data: compThis.propsData }
|
|
118
119
|
},
|
|
119
120
|
get state() {
|
|
120
121
|
return compThis.state
|
|
@@ -122,16 +123,32 @@ class CompositeCompWrapper extends React.Component {
|
|
|
122
123
|
get computed() {
|
|
123
124
|
return compThis.computed
|
|
124
125
|
},
|
|
126
|
+
get _instanceRef() {
|
|
127
|
+
return forwardRef
|
|
128
|
+
},
|
|
129
|
+
get methods() {
|
|
130
|
+
return forwardRef.current?.methods
|
|
131
|
+
},
|
|
132
|
+
set methods(value) {
|
|
133
|
+
if(!forwardRef.current) {
|
|
134
|
+
forwardRef.current = {}
|
|
135
|
+
}
|
|
136
|
+
forwardRef.current.methods = value
|
|
137
|
+
return value
|
|
138
|
+
}
|
|
125
139
|
};
|
|
126
140
|
}
|
|
127
141
|
|
|
128
142
|
componentDidMount() {
|
|
129
|
-
lifecycle.onAttached && lifecycle.onAttached.bind(this)
|
|
130
|
-
|
|
143
|
+
const onAttached = lifecycle.onAttached && lifecycle.onAttached.bind(this)
|
|
144
|
+
Promise.resolve(onAttached()).then(()=>{
|
|
145
|
+
lifecycle.onReady && lifecycle.onReady.bind(this)()
|
|
146
|
+
})
|
|
131
147
|
}
|
|
132
148
|
|
|
133
149
|
componentWillUnmount() {
|
|
134
150
|
lifecycle.onDetached && lifecycle.onDetached.bind(this)()
|
|
151
|
+
this.$WEAPPS_COMP._instanceRef.current = undefined
|
|
135
152
|
}
|
|
136
153
|
|
|
137
154
|
render() {
|
|
@@ -148,6 +165,7 @@ class CompositeCompWrapper extends React.Component {
|
|
|
148
165
|
}
|
|
149
166
|
}
|
|
150
167
|
|
|
151
|
-
export default observer((props) => (
|
|
152
|
-
<CompositeCompWrapper {...props}></CompositeCompWrapper>
|
|
153
|
-
));
|
|
168
|
+
export default observer((props, _ref) => (
|
|
169
|
+
<CompositeCompWrapper {...props} forwardRef={_ref}></CompositeCompWrapper>
|
|
170
|
+
), { forwardRef: true });
|
|
171
|
+
|