@cloudbase/lowcode-builder 0.1.11 → 0.1.14

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.
@@ -409,6 +409,7 @@ async function generateFramework(appData, outDir, ctx) {
409
409
  .sort((item) => (item.isHome ? -1 : 1))
410
410
  .map((item) => ({
411
411
  id: item.id,
412
+ type: item.data.isCustomLoginPage ? 'login' : '',
412
413
  })),
413
414
  }),
414
415
  },
@@ -55,7 +55,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
55
55
  ];
56
56
  }
57
57
  function createXml(widgets, parent = null, parentForNodes = []) {
58
- var _a;
58
+ var _a, _b, _c, _d, _e;
59
59
  const elements = [];
60
60
  for (const id in widgets) {
61
61
  const { xComponent, xProps, properties, xIndex, genericComp } = widgets[id];
@@ -77,7 +77,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
77
77
  }
78
78
  continue;
79
79
  }
80
- const componentKey = xComponent.moduleName + ':' + xComponent.name;
80
+ const componentKey = `${xComponent.moduleName}:${xComponent.name}`;
81
81
  const helpMsg = `Please check component(${id}) in component tree of ${docTag}.`;
82
82
  const materialLib = ctx.materialLibs.find((lib) => lib.name === xComponent.moduleName);
83
83
  const miniprogramPlugin = (_a = ctx.miniprogramPlugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => plugin.name === xComponent.moduleName);
@@ -94,7 +94,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
94
94
  }
95
95
  // eslint-disable-next-line prefer-const
96
96
  let { tagName, path } = (0, materials_1.getWxmlTag)(xComponent, ctx, nameMangler);
97
- if (genericComp && genericComp.propName) {
97
+ if (genericComp === null || genericComp === void 0 ? void 0 : genericComp.propName) {
98
98
  tagName = getGenericCompTagName(genericComp.propName);
99
99
  componentGenerics[tagName] = { default: path || tagName };
100
100
  }
@@ -102,7 +102,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
102
102
  usingComponents[tagName] = path;
103
103
  }
104
104
  let curForNodes = parentForNodes;
105
- if (directives.waFor && directives.waFor.value) {
105
+ if ((_b = directives.waFor) === null || _b === void 0 ? void 0 : _b.value) {
106
106
  curForNodes = [...curForNodes, id];
107
107
  }
108
108
  const attrPrefix = `${wxmlDataPrefix.widgetProp}${id}${curForNodes
@@ -126,7 +126,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
126
126
  _order: xIndex || 0,
127
127
  _parent: null,
128
128
  };
129
- if (directives.waIf && directives.waIf.value) {
129
+ if ((_c = directives.waIf) === null || _c === void 0 ? void 0 : _c.value) {
130
130
  slotNode.attributes['wx:if'] = getAttrBind(directives.waIf, `${attrPrefix}._waIf`);
131
131
  }
132
132
  elements.push(slotNode);
@@ -137,6 +137,8 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
137
137
  name: tagName,
138
138
  attributes: {
139
139
  id: idAttr,
140
+ bindattached: '__handlerAttached__',
141
+ binddetached: '__handlerDetached__',
140
142
  style: `{{${attrPrefix}.style}}`,
141
143
  [(0, mp_1.getClassAttrName)(tagName)]: `{{${attrPrefix}.className}}`,
142
144
  },
@@ -148,10 +150,10 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
148
150
  if (mustEmptyStyle) {
149
151
  delete node.attributes.style;
150
152
  }
151
- if (directives.waIf && directives.waIf.value) {
153
+ if ((_d = directives.waIf) === null || _d === void 0 ? void 0 : _d.value) {
152
154
  node.attributes['wx:if'] = getAttrBind(directives.waIf, `${attrPrefix}._waIf`);
153
155
  }
154
- if (directives.waFor && directives.waFor.value) {
156
+ if ((_e = directives.waFor) === null || _e === void 0 ? void 0 : _e.value) {
155
157
  node.attributes['wx:for'] = getAttrBind(directives.waFor, `${wxmlDataPrefix.widgetProp}${id}${parentForNodes
156
158
  .map((forNodeId) => `[${wxmlDataPrefix.forIndex}${forNodeId}]`)
157
159
  .join('')}`);
@@ -159,7 +161,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
159
161
  node.attributes['wx:key'] = 'id';
160
162
  }
161
163
  const compSchema = componentProto.dataForm;
162
- for (const prop in data) {
164
+ for (const prop of Object.keys(data)) {
163
165
  if (compSchema) {
164
166
  const fieldDef = compSchema[prop];
165
167
  if (!fieldDef && !isGlobalAttr(prop)) {
@@ -167,7 +169,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
167
169
  continue;
168
170
  }
169
171
  if (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.readOnly) {
170
- if (fieldDef.hasOwnProperty('default')) {
172
+ if (Object.prototype.hasOwnProperty.call(fieldDef, 'default')) {
171
173
  node.attributes[prop] = fieldDef.default;
172
174
  }
173
175
  else {
@@ -180,7 +182,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
180
182
  const passedComp = data[prop].value;
181
183
  const [libName, compName] = passedComp.split(':');
182
184
  const { tagName, path } = (0, materials_1.getWxmlTag)({ moduleName: libName, name: compName }, ctx, nameMangler);
183
- node.attributes['generic:' + getGenericCompTagName(prop)] = tagName;
185
+ node.attributes[`generic:${getGenericCompTagName(prop)}`] = tagName;
184
186
  usingComponents[tagName] = path;
185
187
  continue;
186
188
  }
@@ -213,7 +215,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
213
215
  if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.isDataContainer) {
214
216
  node.attributes['bind:onDataChange'] = getMpEventHanlderName(id, 'onDataChange');
215
217
  }
216
- if (compConfig && compConfig.pluginConfig) {
218
+ if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.pluginConfig) {
217
219
  if (compConfig.pluginConfig.attributes) {
218
220
  Object.assign(node.attributes, compConfig.pluginConfig.attributes);
219
221
  }
@@ -274,7 +276,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
274
276
  }
275
277
  });
276
278
  }
277
- nodeTransform && nodeTransform(widgets[id], node);
279
+ nodeTransform === null || nodeTransform === void 0 ? void 0 : nodeTransform(widgets[id], node);
278
280
  elements.push(node);
279
281
  }
280
282
  return elements.sort((a, b) => a._order - b._order);
@@ -292,7 +294,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
292
294
  exports.generateWxml = generateWxml;
293
295
  function xmlJsonSetCustomAttr(node, prop, value, comp) {
294
296
  if (mp_1.builtinWigetProps.indexOf(prop) > -1) {
295
- console.error(error('Builtin prop(' + prop + ') is not allowed for custom component'), comp);
297
+ console.error(error(`Builtin prop(${prop}) is not allowed for custom component`), comp);
296
298
  return;
297
299
  }
298
300
  node.attributes[prop] = value;
@@ -302,7 +304,6 @@ function xmlJsonSetCustomAttr(node, prop, value, comp) {
302
304
  }
303
305
  }
304
306
  const evtNameMap = {
305
- // eslint-disable-next-line @typescript-eslint/camelcase
306
307
  __weapps_action_trigger_click: 'tap',
307
308
  };
308
309
  function getMpEventName(originalName) {
@@ -366,7 +367,7 @@ function getAttrBind(dVale, widgetBind, isStaticResource) {
366
367
  : `{{${attrVal}}}`;
367
368
  }
368
369
  function getGenericCompTagName(propName) {
369
- return 'g--' + propName;
370
+ return `g--${propName}`;
370
371
  }
371
372
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#list_of_global_attributes
372
373
  function isGlobalAttr(prop = '') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "0.1.11",
3
+ "version": "0.1.14",
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",
@@ -36,7 +36,7 @@
36
36
  "url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@cloudbase/cals": "^0.3.28",
39
+ "@cloudbase/cals": "^0.3.29",
40
40
  "@cloudbase/lowcode-generator": "0.6.17-mpbeta.1",
41
41
  "axios": "^0.21.0",
42
42
  "browserfs": "^1.4.3",
@@ -36,7 +36,10 @@ function createGlboalApi() {
36
36
  state: observable(state),
37
37
  computed: createComputed(computed),
38
38
  common,
39
- ...mpApp
39
+ ...mpApp,
40
+ invoke(params) {
41
+ return globalAPI.__internal__.activePage.invokeComponentMethod(params)
42
+ },
40
43
  // ... other sdk apis & apis from mp
41
44
  } // The global api exposed to lowcode
42
45
 
@@ -1,136 +1,121 @@
1
1
  import { setConfig, getAccessToken, initTcb } from './datasources/index'
2
2
  import lifeCycle from './lowcode/lifecycle'
3
3
  import { app } from './app/weapps-api'
4
- import WxReportV2 from './common/wx_yypt_report_v2'
5
4
  // 引入数据源管理器并进行初始化
6
5
  import { EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
7
6
  import { redirectToLogin, findLoginPage, getAuthConfig } from './common/util'
8
7
 
9
8
  const $app = app;
10
- <% if (yyptConfig.yyptAppKey) { %>
11
- const wxReport = new WxReportV2({
12
- appKey: '<%= yyptConfig.yyptAppKey %>', // 填入你申请的运营平台的应用key(必填)
13
- reportUrl: '<%= yyptConfig.reportUrl %><%= yyptConfig.yyptAppKey %>', // 上报url(把后端上报接口需要先挂网关,该url填写网关地址)
14
- autoReportPV: true, // 是否自动上报页面PV
15
- // getRemoteParamsUrl获取远程参数url,主要用于获取intervalTime、reportLogsNum和stopReport参数,
16
- // 返回格式{stopReport:true,intervalTime:3,reportLogsNum:5}
17
- getRemoteParamsUrl: '',
18
- stopReport: <%= yyptConfig.stopReport %>, // 停止上报
19
- intervalTime: 3, // 间隔多久执行一次上报,默认3秒
20
- reportLogsNum: 5, // 每次合并上报记录条数,默认5次
21
- });
22
-
23
- // 设置数据源请求的 loading 及 toast 处理
24
- setConfig({
25
- beforeDSRequest: (cfg) => {
26
- if (!cfg.options || !cfg.options.showLoading) return
27
- app.showLoading()
28
- },
29
- beforeCallFunction: async (params) => {
30
- try {
31
- const loginPage = findLoginPage();
9
+ // 设置数据源请求的 loading toast 处理
10
+ setConfig({
11
+ beforeDSRequest: (cfg) => {
12
+ if (!cfg.options || !cfg.options.showLoading) return
13
+ app.showLoading()
14
+ },
15
+ beforeCallFunction: async (params) => {
16
+ try {
17
+ const loginPage = findLoginPage();
32
18
 
33
- let skip = false;
34
- switch (params?.data?.methodName) {
35
- case 'callWedaApi': {
36
- if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
37
- skip = true;
38
- }
39
- break;
19
+ let skip = false;
20
+ switch (params?.data?.methodName) {
21
+ case 'callWedaApi': {
22
+ if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
23
+ skip = true;
40
24
  }
25
+ break;
41
26
  }
27
+ }
42
28
 
43
- // 后续做过滤处理
44
- if (!loginPage || (params?.data?.mode === 'c' && skip)) {
45
- return params;
46
- }
47
- // await initTcb();
48
- const { accessToken } = await getAccessToken();
49
- if (accessToken) {
50
- params.data.accessToken = accessToken;
51
- }
52
- } catch (e) {
53
- if (app?.cloud?.currentUser?.userType === "externalUser" && e?.error === 'unauthenticated') {
29
+ // 后续做过滤处理
30
+ if (!loginPage || (params?.data?.mode === 'c' && skip)) {
31
+ return params;
32
+ }
33
+ // await initTcb();
34
+ const { accessToken } = await getAccessToken();
35
+ if (accessToken) {
36
+ params.data.accessToken = accessToken;
37
+ }
38
+ } catch (e) {
39
+ if (app?.cloud?.currentUser?.userType === "externalUser" && e?.error === 'unauthenticated') {
40
+ app.showToast({
41
+ title: '登录态失效',
42
+ icon: 'error',
43
+ });
44
+ }
45
+ console.error('beforeCallFunction error', e);
46
+ }
47
+ return params;
48
+ },
49
+ afterDSRequest: (cfg, error, result) => {
50
+ if (!cfg.options) return
51
+ if (cfg.options.showLoading) app.hideLoading()
52
+ if (!cfg.options.showToast) return
53
+ const isSuccess = !error && result && !result.code
54
+ app.showToast({ icon: isSuccess ? 'success' : 'error' })
55
+ },
56
+ async afterCallFunction(params, error, res) {
57
+ if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
58
+ const loginPage = findLoginPage();
59
+ if (loginPage) {
60
+ const authConfig = await getAuthConfig();
61
+ let isAnonymous = true;
62
+ try {
63
+ const { accessToken } = await getAccessToken();
64
+ isAnonymous = !accessToken;
65
+ } catch (e) { }
66
+ if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
67
+ redirectToLogin();
68
+ } else if (authConfig.RejectStrategy == 'show_warning') {
54
69
  app.showToast({
55
- title: '登录态失效',
70
+ title: '接口无访问权限',
56
71
  icon: 'error',
57
72
  });
58
73
  }
59
- console.error('beforeCallFunction error', e);
60
- }
61
- return params;
62
- },
63
- afterDSRequest: (cfg, error, result) => {
64
- if (!cfg.options) return
65
- if (cfg.options.showLoading) app.hideLoading()
66
- if (!cfg.options.showToast) return
67
- const isSuccess = !error && result && !result.code
68
- app.showToast({ icon: isSuccess ? 'success' : 'error' })
69
- },
70
- async afterCallFunction(params, error, res) {
71
- if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
72
- const loginPage = findLoginPage();
73
- if (loginPage) {
74
- const authConfig = await getAuthConfig();
75
- let isAnonymous = true;
76
- try {
77
- const { accessToken } = await getAccessToken();
78
- isAnonymous = !accessToken;
79
- } catch (e) { }
80
- if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
81
- redirectToLogin();
82
- } else if (authConfig.RejectStrategy == 'show_warning') {
83
- app.showToast({
84
- title: '接口无访问权限',
85
- icon: 'error',
86
- });
87
- }
88
- }
89
74
  }
90
75
  }
91
- })
76
+ }
77
+ })
92
78
 
93
- <% }%>
94
- App({
95
- onLaunch(options) {
96
- this.app = app
97
- const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
98
- let { query = {} } = options
99
- EXTRA_API.setParams('$global', query)
100
- createStateDataSourceVar('$global', generateParamsParser({ app }))
79
+ App({
80
+ onLaunch(options) {
81
+ this.app = app
82
+ const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
83
+ let { query = {} } = options
84
+ EXTRA_API.setParams('$global', query)
85
+ createStateDataSourceVar('$global', generateParamsParser({ app }))
101
86
 
102
- onLaunch && onLaunch.call(this, options)
103
- <% if (yyptConfig.yyptAppKey) { %>
104
- // 挂运营平台上报对象到app里
105
- app.yyptReport = wxReport
106
- <% }%>
87
+ onLaunch && onLaunch.call(this, options)
88
+ <% if (yyptConfig.yyptAppKey) { %>
89
+ // 挂运营平台上报对象到app里
90
+ app.yyptReport = wxReport
91
+ <% }%>
107
92
 
108
- // 初始私有全局数据
109
- this.$$global = {
110
- homePageId: '<%= appConfig.homePageId %>'
111
- }
112
- },
113
- onShow(options) {
114
- const fn = lifeCycle.onShow || lifeCycle.onAppShow
115
- fn && fn.call(this, options)
116
- <% if (yyptConfig.yyptAppKey) { %>
117
- wxReport.startReport()
118
- <% }%>
93
+ // 初始私有全局数据
94
+ this.$$global = {
95
+ homePageId: '<%= appConfig.homePageId %>'
96
+ }
97
+ },
98
+ onShow(options) {
99
+ const fn = lifeCycle.onShow || lifeCycle.onAppShow
100
+ fn && fn.call(this, options)
101
+ <% if (yyptConfig.yyptAppKey) { %>
102
+ wxReport.startReport()
103
+ <% }%>
104
+ },
105
+ onHide() {
106
+ const fn = lifeCycle.onHide || lifeCycle.onAppHide
107
+ fn && fn.call(this)
108
+ },
109
+ onError(msg) {
110
+ const fn = lifeCycle.onError || lifeCycle.onAppError
111
+ fn && fn.call(this, msg)
112
+ },
113
+ onPageNotFound() {
114
+ const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
115
+ fn && fn.call(this)
116
+ },
117
+ onUnhandledRejection() {
118
+ const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
119
+ fn && fn.call(this)
119
120
  },
120
- onHide() {
121
- const fn = lifeCycle.onHide || lifeCycle.onAppHide
122
- fn && fn.call(this)
123
- },
124
- onError(msg) {
125
- const fn = lifeCycle.onError || lifeCycle.onAppError
126
- fn && fn.call(this, msg)
127
- },
128
- onPageNotFound() {
129
- const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
130
- fn && fn.call(this)
131
- },
132
- onUnhandledRejection() {
133
- const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
134
- fn && fn.call(this)
135
- },
136
- })
121
+ })
@@ -2,6 +2,7 @@
2
2
  import { findForItemsOfWidget, getWidget } from './widget'
3
3
  import lodashGet from 'lodash.get';
4
4
  import lodashSet from 'lodash.set';
5
+ import { getAccessToken } from '../datasources/index'
5
6
 
6
7
  /**
7
8
  * Convert abcWordSnd -> abc-word-snd
@@ -312,8 +313,11 @@ export async function checkAuth(app, appId, $page) {
312
313
  const [isAccess, authConfig] = await Promise.all(requestList);
313
314
  app.hideNavigationBarLoading();
314
315
 
315
- const { accessToken } = await getAccessToken()
316
- const isAnonymousUser = !accessToken
316
+ let isAnonymousUser = true;
317
+ try {
318
+ const { accessToken } = await getAccessToken();
319
+ isAnonymousUser = !accessToken;
320
+ } catch (e) { }
317
321
 
318
322
  if (!isAccess) {
319
323
  if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
@@ -4,6 +4,8 @@ import { createWidgets, getWidget, disposeWidget } from './widget'
4
4
  import mergeRenderer from './merge-renderer'
5
5
  import { runWatchers } from './watch'
6
6
  import sdk from './weapp-sdk'
7
+ import lodashGet from 'lodash.get';
8
+
7
9
 
8
10
  /**
9
11
  * Lowcodes of all components
@@ -61,6 +63,19 @@ export function createComponent(key, behaviors, properties, events, handler, dat
61
63
 
62
64
  try {
63
65
  lifeCycle.onAttached && lifeCycle.onAttached.call($comp)
66
+ this.__handlerAttached__ = (e) => {
67
+ const widget = lodashGet(widgets, e.target.id);
68
+ widget._methods = e.detail.methods;
69
+ }
70
+ this.__handlerDetached__ = (e) => {
71
+ const widget = lodashGet(widgets, e.target.id);
72
+ delete widget._methods;
73
+ }
74
+ if ($comp.methods) {
75
+ this.triggerEvent('attached', {
76
+ 'methods': $comp.methods
77
+ })
78
+ }
64
79
  } catch (e) {
65
80
  console.error('Component lifecycle(attached) error', this.is, e)
66
81
  }
@@ -82,6 +97,9 @@ export function createComponent(key, behaviors, properties, events, handler, dat
82
97
  disposeWidget(this._virtualRootWidget)
83
98
  this._disposers.forEach(dispose => dispose())
84
99
  lifeCycle.onDetached && lifeCycle.onDetached.call($comp)
100
+ if ($comp?.methods) {
101
+ this.triggerEvent('detached');
102
+ }
85
103
  }
86
104
  },
87
105
 
@@ -4,6 +4,7 @@ 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
6
  import { runWatchers } from './watch'
7
+ import lodashGet from 'lodash.get';
7
8
 
8
9
  export function createPage(
9
10
  id,
@@ -48,6 +49,28 @@ export function createPage(
48
49
  attached() {
49
50
  const $page = this.getWeAppInst()
50
51
  this._pageActive = true;
52
+ this.__handlerAttached__ = (e) => {
53
+ if (!$page.componentMethods) {
54
+ $page.componentMethods = {};
55
+ }
56
+ const [id, index = 0] = e.target.id.split('-');
57
+ if (!$page.componentMethods[id]) {
58
+ $page.componentMethods[id] = [];
59
+ }
60
+ $page.componentMethods[id][index] = e.detail.methods;
61
+ };
62
+ this.__handlerDetached__ = (e) => {
63
+ const [id, index = 0] = e.target.id.split('-');
64
+ if ($page.componentMethods) {
65
+ const components = $page.componentMethods[id];
66
+ if (components) {
67
+ components[index] = undefined;
68
+ if (components.filter(com => com !== undefined).length === 0) {
69
+ delete $page.componentMethods[id];
70
+ }
71
+ }
72
+ }
73
+ }
51
74
  this._disposers = this.initMergeRenderer($page.widgets);
52
75
  },
53
76
  detached() {
@@ -148,6 +171,27 @@ export function createPage(
148
171
  const { rootWidget } = createWidgets(widgetProps, dataBinds, $page.widgets, context, this)
149
172
  $page._rootWidget = rootWidget
150
173
 
174
+ $page.invokeComponentMethod = ({ component, method, params }) => {
175
+ const components = lodashGet($page.componentMethods, component);
176
+ let componentInstance = undefined
177
+ if (Array.isArray(components)) {
178
+ if(components.length > 1){
179
+ throw new Error('调用方法失败:id为'+component+'的组件拥有多个实例')
180
+ }
181
+ componentInstance = components[0]
182
+ // components.forEach(component => {
183
+ // component[method](params);
184
+ // })
185
+ } else {
186
+ componentInstance = components
187
+ }
188
+
189
+ if(!componentInstance?.[method] || typeof componentInstance[method]!= 'function') {
190
+ throw new Error('调用方法失败:未找到id为'+component+'下的方法'+method)
191
+ }
192
+ return componentInstance[method](params);
193
+ };
194
+
151
195
  return $page
152
196
  },
153
197
  },
@@ -392,4 +392,5 @@ function mountBuiltinWigetsAPI(widget, owner) {
392
392
  })
393
393
  }
394
394
 
395
+ widget._methods = {}
395
396
  }
@@ -1,4 +1,4 @@
1
- import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK } from '@cloudbase/weda-client'
1
+ import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK, auth} from '@cloudbase/weda-client'
2
2
  const {
3
3
  setConfig,
4
4
  initTcb,
@@ -9,8 +9,8 @@ const {
9
9
  EXTRA_API,
10
10
  DS_API,
11
11
  DS_SDK,
12
- getAccessToken,
13
12
  } = WEDA_CLOUD_SDK
13
+ const getAccessToken = auth.getAccessToken
14
14
 
15
15
  export {
16
16
  createDataset,
@@ -3,7 +3,7 @@
3
3
  "version": "1.0.8",
4
4
  "scripts": {},
5
5
  "dependencies": {
6
- "@cloudbase/weda-client": "0.2.0",
6
+ "@cloudbase/weda-client": "0.2.1",
7
7
  "@cloudbase/oauth": "0.1.1-alpha.2",
8
8
  "mobx": "^5.15.4",
9
9
  "lodash.get": "^4.4.2",