@cloudbase/framework-plugin-low-code 0.7.2-beta.1 → 0.7.2
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.js +3 -3
- package/lib/builder/mp/util.d.ts.map +1 -1
- package/lib/builder/mp/util.js +6 -3
- package/lib/builder/mp/wxml.d.ts.map +1 -1
- package/lib/builder/mp/wxml.js +3 -2
- package/lib/builder/service/builder/generate.js +2 -2
- package/lib/utils/dataSource.d.ts.map +1 -1
- package/lib/utils/dataSource.js +2 -9
- package/package.json +1 -1
- package/template/mp/app/weapps-api.js +3 -0
- package/template/mp/common/util.js +5 -2
- package/template/mp/common/weapp-component.js +26 -7
- package/template/mp/common/weapp-page.js +43 -0
- package/template/mp/common/widget.js +1 -0
- package/template/mp/package.json +1 -1
- package/template/package.json +2 -2
- 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
|
@@ -61,7 +61,7 @@ function runGenerateCore(appBuildDir, appData, subAppDataList = [], dependencies
|
|
|
61
61
|
const tplStr = yield fs_extra_1.default.readFile(path_1.default.join(config_1.appTemplateDir, 'src/app/global-api.js'), {
|
|
62
62
|
encoding: 'utf8',
|
|
63
63
|
});
|
|
64
|
-
const globalApiContent = (0, lodash_template_1.default)(tplStr)({
|
|
64
|
+
const globalApiContent = (0, lodash_template_1.default)(tplStr, { interpolate: /<%=([\s\S]+?)%>/g })({
|
|
65
65
|
appId: appKey,
|
|
66
66
|
subPackageName: rootPath,
|
|
67
67
|
domain: domain,
|
|
@@ -74,10 +74,10 @@ function runGenerateCore(appBuildDir, appData, subAppDataList = [], dependencies
|
|
|
74
74
|
.sort((item) => (item.isHome ? -1 : 1))
|
|
75
75
|
.map((item) => {
|
|
76
76
|
var _a;
|
|
77
|
-
return {
|
|
77
|
+
return ({
|
|
78
78
|
id: item.id,
|
|
79
79
|
type: ((_a = item.data) === null || _a === void 0 ? void 0 : _a.isCustomLoginPage) ? 'login' : '',
|
|
80
|
-
};
|
|
80
|
+
});
|
|
81
81
|
}),
|
|
82
82
|
}),
|
|
83
83
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,uBAAuB,EAKxB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI/C,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,OAanD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE;;;EAa1E;AAGD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,UAsDnD;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,GAAG,EAAE,aAAa,MA4BnB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,uBAAuB,EAKxB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI/C,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,OAanD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE;;;EAa1E;AAGD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,UAsDnD;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,GAAG,EAAE,aAAa,MA4BnB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,aAAa,MAsGnB;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,GAAG,EAAE,aAAa,MAuDnB"}
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -153,7 +153,8 @@ function createEventHanlders(widgets, componentApi, ctx) {
|
|
|
153
153
|
let handler = (_a = l.handler) === null || _a === void 0 ? void 0 : _a.name;
|
|
154
154
|
switch (l.type) {
|
|
155
155
|
case weapps_core_1.ActionType.Platform: {
|
|
156
|
-
|
|
156
|
+
let method = (_b = l.handler) === null || _b === void 0 ? void 0 : _b.name;
|
|
157
|
+
handler = `function({data}){ return app.${method}(data)}`;
|
|
157
158
|
break;
|
|
158
159
|
}
|
|
159
160
|
case weapps_core_1.ActionType.DataSource: {
|
|
@@ -176,7 +177,8 @@ function createEventHanlders(widgets, componentApi, ctx) {
|
|
|
176
177
|
});
|
|
177
178
|
if ((_c = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _c === void 0 ? void 0 : _c.isDataContainer) {
|
|
178
179
|
const customName = (0, wxml_1.getMpEventHanlderName)(id, 'onDataChange', {});
|
|
179
|
-
eventHanlders[customName] = [
|
|
180
|
+
eventHanlders[customName] = [
|
|
181
|
+
{
|
|
180
182
|
key: `wa${Date.now().toString().slice(-8)}`,
|
|
181
183
|
handler: `({event}) => {
|
|
182
184
|
app.utils.set(context, '${id}.data', event?.detail?.data);
|
|
@@ -184,7 +186,8 @@ function createEventHanlders(widgets, componentApi, ctx) {
|
|
|
184
186
|
handlerModule: weapps_core_1.ActionType.Platform,
|
|
185
187
|
data: {},
|
|
186
188
|
boundData: {},
|
|
187
|
-
}
|
|
189
|
+
},
|
|
190
|
+
];
|
|
188
191
|
}
|
|
189
192
|
});
|
|
190
193
|
return eventHanlders;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wxml.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/wxml.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,uBAAuB,EAEvB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAU3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAkB/C,wBAAgB,YAAY,CAC1B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,MAAM,EAAE,MAAM,EACd,cAAc,KAAA,EACd,GAAG,EAAE,aAAa,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,EACxC,eAAe,KAAA,EACf,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,uBAAuB,EAAE,IAAI,KAAA,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"wxml.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/wxml.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,uBAAuB,EAEvB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAU3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAkB/C,wBAAgB,YAAY,CAC1B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,MAAM,EAAE,MAAM,EACd,cAAc,KAAA,EACd,GAAG,EAAE,aAAa,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,EACxC,eAAe,KAAA,EACf,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,uBAAuB,EAAE,IAAI,KAAA,KAAK,IAAI,UA+V7D;AA4BD,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,eAAoB,UAS/B;AAuBD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CAAE,EACnD,QAAQ,GAAE;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;CAAO;;EAYlD"}
|
package/lib/builder/mp/wxml.js
CHANGED
|
@@ -141,6 +141,8 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, nod
|
|
|
141
141
|
name: tagName,
|
|
142
142
|
attributes: {
|
|
143
143
|
id: idAttr,
|
|
144
|
+
'bind:attached': '__handlerAttached__',
|
|
145
|
+
'bind:detached': '__handlerDetached__',
|
|
144
146
|
style: `{{${attrPrefix}style}}`,
|
|
145
147
|
[(0, mp_1.getClassAttrName)(tagName)]: `{{${attrPrefix}className}}`,
|
|
146
148
|
},
|
|
@@ -194,8 +196,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, nod
|
|
|
194
196
|
listeners.forEach((l) => {
|
|
195
197
|
const evtName = getMpEventName(l.trigger);
|
|
196
198
|
const modifiers = l;
|
|
197
|
-
node.attributes[getMpEventAttr(evtName, modifiers, tagName)] =
|
|
198
|
-
getMpEventHanlderName(id, evtName, modifiers);
|
|
199
|
+
node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHanlderName(id, evtName, modifiers);
|
|
199
200
|
});
|
|
200
201
|
const compConfig = componentProto.compConfig;
|
|
201
202
|
if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.isDataContainer) {
|
|
@@ -235,9 +235,9 @@ exports.pullComponentToListByInstance = pullComponentToListByInstance;
|
|
|
235
235
|
function getVirtualFieldsString(components) {
|
|
236
236
|
const fields = components.reduce((result, component) => {
|
|
237
237
|
const { name, materialName, variableName, isPlainProps } = component;
|
|
238
|
-
result[`${materialName}:${name}`] = `%%%(props) => <${lodash_1.default.upperFirst(variableName)} ${isPlainProps
|
|
238
|
+
result[`${materialName}:${name}`] = `%%%React.forwardRef((props, ref) => <${lodash_1.default.upperFirst(variableName)} ${isPlainProps
|
|
239
239
|
? '{...resolveComponentProps(props, 1)}'
|
|
240
|
-
: '{...resolveComponentProps(props, 0)}'} pageVirtualFields={virtualFields}
|
|
240
|
+
: '{...resolveComponentProps(props, 0)}'} ref={ref} pageVirtualFields={virtualFields}/>)%%%`;
|
|
241
241
|
return result;
|
|
242
242
|
}, {});
|
|
243
243
|
return JSON.stringify(fields, null, 2).replace(/"%%%(.*?)%%%"/g, function (match, expression) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataSource.d.ts","sourceRoot":"","sources":["../../src/utils/dataSource.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAiB,MAAM,iBAAiB,CAAC;AAMpE,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AACpD,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAC7C,eAAO,MAAM,aAAa,aAAa,CAAC;AAMxC,wBAAgB,yBAAyB,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,UAGzD;AAED,wBAAgB,4BAA4B,CAAC,KAAK,KAAA,EAAE,UAAU,KAAA,EAAE,IAAI,KAAA,UAGnE;AAMD,wBAAgB,yBAAyB,CAAC,QAAQ,KAAA,EAAE,IAAI,KAAA,iBAIvD;AAMD,wBAAgB,iBAAiB,CAAC,GAAG,IAAI,OAAA,MAexC;AAmBD,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,GAAG,CAU1D;AAOD,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,GAAG,OA6C5C;AAOD,wBAAgB,qBAAqB,CAAC,WAAW,KAAA,
|
|
1
|
+
{"version":3,"file":"dataSource.d.ts","sourceRoot":"","sources":["../../src/utils/dataSource.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAiB,MAAM,iBAAiB,CAAC;AAMpE,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AACpD,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAC7C,eAAO,MAAM,aAAa,aAAa,CAAC;AAMxC,wBAAgB,yBAAyB,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA,UAGzD;AAED,wBAAgB,4BAA4B,CAAC,KAAK,KAAA,EAAE,UAAU,KAAA,EAAE,IAAI,KAAA,UAGnE;AAMD,wBAAgB,yBAAyB,CAAC,QAAQ,KAAA,EAAE,IAAI,KAAA,iBAIvD;AAMD,wBAAgB,iBAAiB,CAAC,GAAG,IAAI,OAAA,MAexC;AAmBD,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,GAAG,CAU1D;AAOD,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,GAAG,OA6C5C;AAOD,wBAAgB,qBAAqB,CAAC,WAAW,KAAA,OAehD;AAOD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB;;EAU7D;AAiCD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE;IACX,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;CACxC,EACD,IAAI,CAAC,EAAE;IACL,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;CACxC,EAAE,MAiBJ"}
|
package/lib/utils/dataSource.js
CHANGED
|
@@ -108,13 +108,7 @@ function getDatasourceProfiles(datasources) {
|
|
|
108
108
|
type: ds.type,
|
|
109
109
|
childDataSourceNames: ds.childDataSourceNames,
|
|
110
110
|
schema: ds.schema,
|
|
111
|
-
methods: ds.methods
|
|
112
|
-
ds.methods.map((method) => {
|
|
113
|
-
return {
|
|
114
|
-
name: method.name,
|
|
115
|
-
type: method.type,
|
|
116
|
-
};
|
|
117
|
-
}),
|
|
111
|
+
methods: ds.methods,
|
|
118
112
|
};
|
|
119
113
|
})) || []);
|
|
120
114
|
}
|
|
@@ -168,8 +162,7 @@ function getDatasetProfiles(mainAppData, apps) {
|
|
|
168
162
|
(_a = app.pageInstanceList) === null || _a === void 0 ? void 0 : _a.forEach((pageInstance) => {
|
|
169
163
|
let p = pageInstance;
|
|
170
164
|
if (p.dataset) {
|
|
171
|
-
result[app.rootPath ? `${app.rootPath}/${p.id}` : p.id] =
|
|
172
|
-
_generateDynamicDataset(p.dataset);
|
|
165
|
+
result[app.rootPath ? `${app.rootPath}/${p.id}` : p.id] = _generateDynamicDataset(p.dataset);
|
|
173
166
|
}
|
|
174
167
|
});
|
|
175
168
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/framework-plugin-low-code",
|
|
3
|
-
"version": "0.7.2
|
|
3
|
+
"version": "0.7.2",
|
|
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",
|
|
@@ -312,8 +312,11 @@ export async function checkAuth(app, appId, $page) {
|
|
|
312
312
|
const [isAccess, authConfig] = await Promise.all(requestList);
|
|
313
313
|
app.hideNavigationBarLoading();
|
|
314
314
|
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
let isAnonymousUser = true;
|
|
316
|
+
try {
|
|
317
|
+
const { accessToken } = await getAccessToken();
|
|
318
|
+
isAnonymousUser = !accessToken;
|
|
319
|
+
} catch (e) { }
|
|
317
320
|
|
|
318
321
|
if (!isAccess) {
|
|
319
322
|
if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
|
|
@@ -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,26 @@ export function createPage(
|
|
|
143
167
|
app.utils.set($page.dataset.state, keyPath, userSetState[keyPath]);
|
|
144
168
|
});
|
|
145
169
|
};
|
|
170
|
+
$page.invokeComponentMethod = ({ component, method, params }) => {
|
|
171
|
+
const components = lodashGet($page.componentMethods, component);
|
|
172
|
+
let componentInstance = undefined
|
|
173
|
+
if (Array.isArray(components)) {
|
|
174
|
+
if(components.length > 1){
|
|
175
|
+
throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
|
|
176
|
+
}
|
|
177
|
+
componentInstance = components[0]
|
|
178
|
+
// components.forEach(component => {
|
|
179
|
+
// component[method](params);
|
|
180
|
+
// })
|
|
181
|
+
} else {
|
|
182
|
+
componentInstance = components
|
|
183
|
+
}
|
|
146
184
|
|
|
185
|
+
if(!componentInstance?.[method] || typeof componentInstance[method]!= 'function') {
|
|
186
|
+
throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
|
|
187
|
+
}
|
|
188
|
+
return componentInstance[method](params);
|
|
189
|
+
};
|
|
147
190
|
this.$WEAPPS_PAGE = $page;
|
|
148
191
|
}
|
|
149
192
|
return this.$WEAPPS_PAGE
|
package/template/mp/package.json
CHANGED
package/template/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"build-web": "webpack --config ./webpack/webpack.web.prod.js"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@cloudbase/js-sdk": "
|
|
9
|
-
"@cloudbase/weda-cloud-sdk": "1.0.8
|
|
8
|
+
"@cloudbase/js-sdk": "2.4.0-alpha.0",
|
|
9
|
+
"@cloudbase/weda-cloud-sdk": "1.0.8",
|
|
10
10
|
"@tcwd/weapps-core": "2.2.6",
|
|
11
11
|
"@tcwd/weapps-sdk": "1.2.9",
|
|
12
12
|
"@zxing/library": "^0.18.6",
|
|
@@ -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;
|
|
@@ -54,6 +55,9 @@ function createGlboalApi() {
|
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
},
|
|
58
|
+
invoke(params) {
|
|
59
|
+
return $page.invokeComponentMethod(params)
|
|
60
|
+
},
|
|
57
61
|
utils: {
|
|
58
62
|
formatDate,
|
|
59
63
|
formatEnum,
|
|
@@ -129,6 +133,24 @@ function createPageApi() {
|
|
|
129
133
|
// 页面数据源变量存储位置
|
|
130
134
|
dataVar: {},
|
|
131
135
|
};
|
|
136
|
+
$page.invokeComponentMethod = ({ component, method, params }) => {
|
|
137
|
+
const widgetData = lodashGet($page.widgets, component);
|
|
138
|
+
if (Array.isArray(widgetData)) {
|
|
139
|
+
throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
|
|
140
|
+
// widgetData.forEach(widget => {
|
|
141
|
+
// if(!widget._methods[method]) {
|
|
142
|
+
// throw new Error('NOT_FOUND')
|
|
143
|
+
// } else {
|
|
144
|
+
// actions.push(widget._methods[method])
|
|
145
|
+
// }
|
|
146
|
+
// })
|
|
147
|
+
} else {
|
|
148
|
+
if(!widgetData._methods[method] || typeof widgetData._methods[method]!= 'function') {
|
|
149
|
+
throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
|
|
150
|
+
}
|
|
151
|
+
return widgetData._methods[method](params)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
132
154
|
return $page;
|
|
133
155
|
}
|
|
134
156
|
|
|
@@ -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 = this._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
|
+
|