@cloudbase/framework-plugin-low-code 0.6.67 → 0.7.0
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 +8 -3
- package/lib/builder/mp/index.d.ts.map +1 -1
- package/lib/builder/mp/index.js +11 -6
- package/lib/builder/service/builder/generate.d.ts.map +1 -1
- package/lib/builder/service/builder/generate.js +2 -0
- package/lib/generator/core/generate.d.ts.map +1 -1
- package/lib/generator/core/generate.js +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -46
- package/lib/weapps-core/types/app.d.ts +1 -0
- package/lib/weapps-core/types/app.d.ts.map +1 -1
- package/lib/weapps-core/types/web.d.ts +1 -0
- package/lib/weapps-core/types/web.d.ts.map +1 -1
- package/package.json +1 -1
- package/template/html/index.html.ejs +2 -15
- package/template/mp/app/weapps-api.js +4 -3
- package/template/mp/app.js +69 -24
- package/template/mp/common/util.js +121 -69
- package/template/mp/common/weapp-page.js +2 -15
- package/template/mp/datasources/config.js.tpl +2 -0
- package/template/mp/package.json +10 -8
- package/template/mp/page/index.js +1 -3
- package/template/package.json +2 -2
- package/template/src/app/global-api.js +3 -3
- package/template/src/datasources/config.js.tpl +2 -0
- package/template/src/handlers/FieldMiddleware/renderer.jsx +321 -411
- package/template/src/handlers/render.jsx +97 -114
- package/template/src/handlers/utils/common.js +132 -29
- package/template/src/index.jsx +45 -1
- package/template/src/pages/app.tpl +31 -31
- package/template/src/utils/formatEnum.js +0 -42
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { findForItemsOfWidget, mpCompToWidget } from './widget'
|
|
4
4
|
import lodashGet from 'lodash.get';
|
|
5
5
|
import lodashSet from 'lodash.set';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { getAccessToken } from '@cloudbase/weda-cloud-sdk'
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* Convert abcWordSnd -> abc-word-snd
|
|
10
10
|
*/
|
|
@@ -53,12 +53,12 @@ export function createEventHandlers(evtListeners, context) {
|
|
|
53
53
|
})
|
|
54
54
|
} catch (e) {
|
|
55
55
|
let eventName = l.key ? `${prefix}$${l.key}_fail` : ''
|
|
56
|
-
if(self[eventName]){
|
|
56
|
+
if (self[eventName]) {
|
|
57
57
|
await self[eventName]({
|
|
58
58
|
...event,
|
|
59
59
|
detail: e
|
|
60
60
|
})
|
|
61
|
-
}else {
|
|
61
|
+
} else {
|
|
62
62
|
throw e
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -207,8 +207,8 @@ export function set(object, path, value) {
|
|
|
207
207
|
newValue = isObject(objValue)
|
|
208
208
|
? objValue
|
|
209
209
|
: isIndex(path[index + 1])
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
? []
|
|
211
|
+
: {}
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
assignValue(nested, key, newValue)
|
|
@@ -231,37 +231,133 @@ export function setter(context, path, value = undefined) {
|
|
|
231
231
|
return lodashSet(context, path, value);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
export function findLoginPage() {
|
|
235
|
+
const { app } = getApp();
|
|
236
|
+
const { pages = [] } = app.utils._getConfig();
|
|
237
|
+
return pages.find(item => item.type === 'login');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let _AUTH_CONFIG_CACHE = null;
|
|
241
|
+
export async function getAuthConfig() {
|
|
242
|
+
const { app } = getApp();
|
|
243
|
+
if (_AUTH_CONFIG_CACHE) {
|
|
244
|
+
return _AUTH_CONFIG_CACHE;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const res = await app.cloud.callWedaApi({
|
|
248
|
+
action: "DescribeRuntimeResourceStrategy",
|
|
249
|
+
data: {
|
|
250
|
+
ResourceType: `<%= isAdminPortal? 'modelApp' : 'app'%>`,
|
|
251
|
+
ResourceId: app.id,
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
const settingData = {};
|
|
255
|
+
// 云api不支持map只能传字符串,需要转换
|
|
256
|
+
res.forEach((item) => {
|
|
257
|
+
settingData[item.Key] = ['AllowRegister', 'NeedLogin'].includes(item.Key) ? item.Value === '1' : item.Value;
|
|
258
|
+
});
|
|
259
|
+
_AUTH_CONFIG_CACHE = settingData;
|
|
260
|
+
return _AUTH_CONFIG_CACHE;
|
|
261
|
+
} catch (e) {
|
|
262
|
+
return {
|
|
263
|
+
NeedLogin: false,
|
|
264
|
+
RejectStrategy: "show_warning",
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
let _AUTH_CACHE_MAP = {}
|
|
270
|
+
async function getAccessPermission(app, appId, pageId) {
|
|
271
|
+
const cacheKey = `${appId}-${pageId}`
|
|
272
|
+
if (_AUTH_CACHE_MAP[cacheKey] !== undefined) {
|
|
273
|
+
return _AUTH_CACHE_MAP[cacheKey];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let isAccess = false;
|
|
277
|
+
try {
|
|
278
|
+
const res = await app.cloud.callWedaApi({
|
|
279
|
+
action: 'DescribeResourcesPermission',
|
|
280
|
+
data: {
|
|
281
|
+
ResourceType: `<%= isAdminPortal? 'modelApp' : 'app'%>`,
|
|
282
|
+
ResourceIdList: [cacheKey],
|
|
283
|
+
AppResourceId: appId,
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
if (Array.isArray(res) && res.length > 0) {
|
|
287
|
+
isAccess = !!res[0].IsAccess;
|
|
288
|
+
}
|
|
289
|
+
_AUTH_CACHE_MAP[cacheKey] = isAccess;
|
|
290
|
+
} catch (e) {
|
|
291
|
+
console.warn('getAccessPermission', e);
|
|
292
|
+
}
|
|
293
|
+
return isAccess
|
|
294
|
+
}
|
|
295
|
+
|
|
234
296
|
/**
|
|
235
297
|
* 检查页面权限
|
|
236
298
|
**/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return _AUTH_CACHE_MAP[cacheKey]
|
|
299
|
+
export async function checkAuth(app, appId, $page) {
|
|
300
|
+
const loginPage = findLoginPage(app);
|
|
301
|
+
if (loginPage?.id === $page.id) {
|
|
302
|
+
return true
|
|
242
303
|
}
|
|
243
304
|
app.showNavigationBarLoading();
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
ResourceIdList: [cacheKey],
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
let isLogin = false;
|
|
252
|
-
if (Array.isArray(checkAuthResult) && checkAuthResult.length > 0) {
|
|
253
|
-
isLogin = checkAuthResult[0]?.IsAccess || false;
|
|
305
|
+
const requestList = [getAccessPermission(app, appId, $page.id)];
|
|
306
|
+
// 暂时先认为有登录页则自定义登录功能开启且生效
|
|
307
|
+
if (loginPage) {
|
|
308
|
+
requestList.push(getAuthConfig(app));
|
|
254
309
|
}
|
|
310
|
+
const [isAccess, authConfig] = await Promise.all(requestList);
|
|
255
311
|
app.hideNavigationBarLoading();
|
|
256
312
|
|
|
257
|
-
if (!
|
|
313
|
+
if (!isAccess) {
|
|
314
|
+
if (loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
|
|
315
|
+
redirectToLogin($page);
|
|
316
|
+
} else {
|
|
317
|
+
app.showToast({
|
|
318
|
+
title: '页面无访问权限',
|
|
319
|
+
icon: 'error',
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
} else if (loginPage && authConfig.NeedLogin) {
|
|
323
|
+
// 此分支逻辑本不应该前端判断是否登录,历史原因后端短期内搞不定,后续后端优化后删除
|
|
324
|
+
try {
|
|
325
|
+
const { accessToken } = await getAccessToken()
|
|
326
|
+
if (!accessToken) {
|
|
327
|
+
redirectToLogin($page);
|
|
328
|
+
}
|
|
329
|
+
} catch (e) {
|
|
330
|
+
redirectToLogin($page);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return isAccess;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function redirectToLogin(currentPage) {
|
|
337
|
+
// 去登录则清空权限缓存。
|
|
338
|
+
_AUTH_CACHE_MAP = {};
|
|
339
|
+
const { app } = getApp();
|
|
340
|
+
const loginPage = findLoginPage(app);
|
|
341
|
+
if (!currentPage) {
|
|
342
|
+
currentPage = app.utils.getCurrentPage() || {};
|
|
343
|
+
}
|
|
344
|
+
if (loginPage?.id === currentPage.id) {
|
|
345
|
+
return true
|
|
346
|
+
}
|
|
347
|
+
if (loginPage) {
|
|
348
|
+
app.redirectTo({
|
|
349
|
+
pageId: loginPage.id,
|
|
350
|
+
params: {
|
|
351
|
+
sourcePageId: currentPage.id,
|
|
352
|
+
sourcePageParams: currentPage.params
|
|
353
|
+
}
|
|
354
|
+
})
|
|
355
|
+
} else {
|
|
258
356
|
app.showToast({
|
|
259
|
-
title: '
|
|
357
|
+
title: '用户未登录',
|
|
260
358
|
icon: 'error',
|
|
261
359
|
});
|
|
262
360
|
}
|
|
263
|
-
_AUTH_CACHE_MAP[cacheKey] = isLogin
|
|
264
|
-
return isLogin;
|
|
265
361
|
}
|
|
266
362
|
|
|
267
363
|
// 日期转换
|
|
@@ -550,52 +646,8 @@ class CustomDate {
|
|
|
550
646
|
|
|
551
647
|
const dataInstance = new CustomDate();
|
|
552
648
|
export const formatDate = new CustomDate().format.bind(dataInstance);
|
|
553
|
-
|
|
554
|
-
let loading = {};
|
|
555
|
-
export let enumOptions = observable({});
|
|
556
|
-
export function formatEnum(path, optionname) {
|
|
557
|
-
// 判断是单选还是多选
|
|
558
|
-
let isSingle = Array.isArray(path);
|
|
559
|
-
// 获取到options
|
|
560
|
-
let parseOptions = getEnumOptions(optionname);
|
|
561
|
-
if (parseOptions === '') {
|
|
562
|
-
return !isSingle ? path : path.join(',');
|
|
563
|
-
}
|
|
564
|
-
let multiTmp = [];
|
|
565
|
-
let value = !isSingle
|
|
566
|
-
? JSON.parse(parseOptions)?.find((item) => item?.key === path)?.value
|
|
567
|
-
: JSON.parse(parseOptions)
|
|
568
|
-
?.filter((item) => path.some((pathValue) => item?.key === pathValue))
|
|
569
|
-
.map((item) => multiTmp.push(item?.value));
|
|
570
|
-
// 对多选或者单选有不同处理
|
|
571
|
-
return !isSingle ? value : multiTmp?.join(',');
|
|
572
|
-
}
|
|
573
|
-
function getEnumOptions(optionName) {
|
|
574
|
-
if (enumOptions[optionName]) {
|
|
575
|
-
return enumOptions[optionName];
|
|
576
|
-
}
|
|
577
|
-
if (!loading[optionName]) {
|
|
578
|
-
loading[optionName] = true;
|
|
579
|
-
getGeneralOptions(optionName).then((data) => {
|
|
580
|
-
enumOptions[optionName] = data?.Items[0]?.Config;
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
return '';
|
|
584
|
-
}
|
|
585
|
-
export async function getGeneralOptions(optionName) {
|
|
586
|
-
return app.cloud.callWedaApi({
|
|
587
|
-
action: 'DescribeGeneralOptionsDetailList',
|
|
588
|
-
data: {
|
|
589
|
-
PageSize: 1,
|
|
590
|
-
PageIndex: 1,
|
|
591
|
-
LikeNameOrTitle: optionName,
|
|
592
|
-
},
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
|
|
596
649
|
export const utils = {
|
|
597
650
|
formatDate,
|
|
598
651
|
get: getter,
|
|
599
652
|
set: setter,
|
|
600
|
-
formatEnum
|
|
601
653
|
};
|
|
@@ -14,7 +14,6 @@ export function createPage(
|
|
|
14
14
|
app,
|
|
15
15
|
$page,
|
|
16
16
|
context,
|
|
17
|
-
pageAttributes
|
|
18
17
|
) {
|
|
19
18
|
const evtHandlers = createEventHandlers(evtListeners, context);
|
|
20
19
|
|
|
@@ -33,18 +32,6 @@ export function createPage(
|
|
|
33
32
|
if (res?.from === 'button' && res?.target?.dataset?.weda_share_info) {
|
|
34
33
|
return res?.target?.dataset?.weda_share_info;
|
|
35
34
|
}
|
|
36
|
-
if (res?.from === 'menu' && pageAttributes?.appShareMessage) {
|
|
37
|
-
let { enable, pageId, params, imageUrl, title } = pageAttributes.appShareMessage;
|
|
38
|
-
if (enable) {
|
|
39
|
-
pageId = pageId ? pageId.replace(/^(\.)?\//, '') : pageId;
|
|
40
|
-
let realPath = `/pages/${pageId}/index` + (params ? '?' + params.map(pair => pair.key + '=' + pair.value).join('&') : '');
|
|
41
|
-
return {
|
|
42
|
-
path: realPath,
|
|
43
|
-
imageUrl,
|
|
44
|
-
title
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
35
|
try {
|
|
49
36
|
return lifecycle?.['onShareAppMessage']?.() || {};
|
|
50
37
|
} catch (error) {
|
|
@@ -118,7 +105,7 @@ export function createPage(
|
|
|
118
105
|
hook && hook.call(this);
|
|
119
106
|
|
|
120
107
|
// 权限检查
|
|
121
|
-
if (await checkAuth(app, app.id,
|
|
108
|
+
if (await checkAuth(app, app.id, $page)) {
|
|
122
109
|
this.setData({
|
|
123
110
|
weDaHasLogin: true,
|
|
124
111
|
});
|
|
@@ -132,7 +119,7 @@ export function createPage(
|
|
|
132
119
|
},
|
|
133
120
|
|
|
134
121
|
getWeAppInst() {
|
|
135
|
-
if
|
|
122
|
+
if(!this.$WEAPPS_PAGE){
|
|
136
123
|
$page.state = observable(pageState);
|
|
137
124
|
let dataset = createDataset($page.uuid);
|
|
138
125
|
$page.dataset = dataset;
|
package/template/mp/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"@cloudbase/weda-cloud-sdk": "1.0.
|
|
2
|
+
"name": "lcap-<%= appId%>",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"scripts": {},
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@cloudbase/weda-cloud-sdk": "1.0.8-alpha.11",
|
|
7
|
+
"@cloudbase/oauth": "0.1.1-alpha.2",
|
|
7
8
|
"mobx": "^5.15.4",
|
|
8
9
|
"lodash.get": "^4.4.2",
|
|
9
10
|
"lodash.set": "^4.3.2",
|
|
10
|
-
|
|
11
|
+
"miniprogram-gesture": "^1.0.6",
|
|
11
12
|
"miniprogram-api-promise": "^1.0.4"<% Object.keys(extraDeps).map(depName => {%>,
|
|
12
|
-
|
|
13
|
+
"<%= depName%>": "<%= extraDeps[depName]%>"<%
|
|
14
|
+
})
|
|
13
15
|
%>
|
|
14
16
|
}
|
|
15
|
-
}
|
|
17
|
+
}
|
|
@@ -34,9 +34,7 @@ const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
|
34
34
|
},<%}) %>
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const pageAttributes = <%= pageAttributes?JSON.stringify(pageAttributes):'{}' %>
|
|
38
|
-
|
|
39
37
|
$page.id = '<%= pageName %>'
|
|
40
38
|
$page.uuid = '<%= pageUUID %>'
|
|
41
39
|
$page.handler = handlers
|
|
42
|
-
createPage(lifecyle, widgetProps, state, computed, evtListeners, dataBinds, app, $page, context
|
|
40
|
+
createPage(lifecyle, widgetProps, state, computed, evtListeners, dataBinds, app, $page, context)
|
package/template/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@cloudbase/js-sdk": "1.5.3-alpha.0",
|
|
9
|
-
"@cloudbase/weda-cloud-sdk": "1.0.
|
|
9
|
+
"@cloudbase/weda-cloud-sdk": "1.0.8-alpha.11",
|
|
10
10
|
"@tcwd/weapps-core": "2.2.6",
|
|
11
11
|
"@tcwd/weapps-sdk": "1.2.9",
|
|
12
12
|
"@zxing/library": "^0.18.6",
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
"webpack-cli": "^4.2.0",
|
|
61
61
|
"webpack-dev-server": "^3.11.0"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
|
@@ -5,7 +5,6 @@ import store, { subPackageName } from '../store';
|
|
|
5
5
|
import computed from '../store/computed';
|
|
6
6
|
import common from './common';
|
|
7
7
|
import { formatDate } from '../utils/date';
|
|
8
|
-
import { formatEnum, enumOptions } from '../utils/formatEnum';
|
|
9
8
|
import { getter, setter, _isMobile } from '../utils';
|
|
10
9
|
import actionMap from './material-actions';
|
|
11
10
|
import { scanCodeApi } from '../utils/scan-code-action';
|
|
@@ -32,7 +31,6 @@ function createGlboalApi() {
|
|
|
32
31
|
request: sdk.request,
|
|
33
32
|
getSessionId: sdk.getSessionId,
|
|
34
33
|
},
|
|
35
|
-
enumOptions: enumOptions,
|
|
36
34
|
state: store,
|
|
37
35
|
computed: createComputed(computed.global),
|
|
38
36
|
common,
|
|
@@ -47,7 +45,6 @@ function createGlboalApi() {
|
|
|
47
45
|
},
|
|
48
46
|
utils: {
|
|
49
47
|
formatDate,
|
|
50
|
-
formatEnum,
|
|
51
48
|
get: getter,
|
|
52
49
|
set: setter,
|
|
53
50
|
_getConfig: function () {
|
|
@@ -56,6 +53,9 @@ function createGlboalApi() {
|
|
|
56
53
|
getWXContext: function() {
|
|
57
54
|
return Promise.resolve({})
|
|
58
55
|
},
|
|
56
|
+
getCurrentPage: function(){
|
|
57
|
+
return $page
|
|
58
|
+
},
|
|
59
59
|
},
|
|
60
60
|
|
|
61
61
|
// ... other sdk apis & apis from mp
|