@cloudbase/lowcode-builder 0.1.12 → 0.1.15

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/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
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",
@@ -26,7 +26,7 @@
26
26
  "dev": "tsc -w",
27
27
  "develop": "tsc -w",
28
28
  "clean": "rm -rf lib && rm -rf dist",
29
- "build": "tsc",
29
+ "build": "tsc && npm run build:web",
30
30
  "test": "jest",
31
31
  "test:build": "ts-node ./__tests__/build.ts",
32
32
  "dev:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
@@ -36,8 +36,8 @@
36
36
  "url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@cloudbase/cals": "^0.3.28",
40
- "@cloudbase/lowcode-generator": "0.6.17-mpbeta.1",
39
+ "@cloudbase/cals": "^0.3.29",
40
+ "@cloudbase/lowcode-generator": "^0.6.21",
41
41
  "axios": "^0.21.0",
42
42
  "browserfs": "^1.4.3",
43
43
  "browserify-zlib": "^0.2.0",
@@ -84,4 +84,4 @@
84
84
  "webpack-dev-server": "^4.7.3",
85
85
  "worker-loader": "^3.0.8"
86
86
  }
87
- }
87
+ }
@@ -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
+ })
@@ -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
  }
@@ -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",