@cloudbase/lowcode-builder 1.8.73 → 1.8.75
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/index.d.ts +2 -5
- package/lib/builder/config/index.js +3 -6
- package/lib/builder/core/index.d.ts +2 -1
- package/lib/builder/core/index.js +15 -24
- package/lib/builder/core/plugin.d.ts +1 -7
- package/lib/builder/core/plugin.js +0 -2
- package/lib/builder/mp/BuildContext.d.ts +8 -0
- package/lib/builder/mp/index.d.ts +2 -2
- package/lib/builder/mp/index.js +179 -124
- package/lib/builder/mp/materials.d.ts +1 -1
- package/lib/builder/mp/materials.js +11 -19
- package/lib/builder/mp/mixMode.d.ts +9 -3
- package/lib/builder/mp/mixMode.js +70 -137
- package/lib/builder/mp/mp_config.d.ts +1 -1
- package/lib/builder/mp/mp_config.js +28 -20
- package/lib/builder/mp/wxml.js +19 -2
- package/lib/builder/service/webpack.js +1 -1
- package/lib/builder/util/common.d.ts +1 -0
- package/lib/builder/util/common.js +8 -1
- package/lib/builder/util/net.d.ts +10 -1
- package/lib/builder/util/net.js +47 -8
- package/lib/builder.web.js +13 -13
- package/package.json +6 -5
- package/template/html/index.html.ejs +2 -2
- package/template/mp/app/weapps-api.js +19 -1
- package/template/mp/app.js +3 -120
- package/template/mp/common/info/index.js +5 -4
- package/template/mp/common/info/index.wxml +2 -2
- package/template/mp/common/privacyModal/index.js +3 -2
- package/template/mp/common/util.js +24 -12
- package/template/mp/common/weapp-page.js +24 -9
- package/template/mp/component/index.wxss +2 -0
- package/template/mp/datasources/index.js.tpl +122 -2
- package/template/mp/package.json +2 -2
- package/template/mp/packages/$wd_system/pages/login/components/input/index.js +40 -0
- package/template/mp/packages/$wd_system/pages/login/components/input/index.json +4 -0
- package/template/mp/packages/$wd_system/pages/login/components/input/index.wxml +11 -0
- package/template/mp/packages/$wd_system/pages/login/index.js +161 -0
- package/template/mp/packages/$wd_system/pages/login/index.json +16 -0
- package/template/mp/packages/$wd_system/pages/login/index.wxml +60 -0
- package/template/mp/packages/$wd_system/pages/login/index.wxss +60 -0
- package/template/mp/packages/$wd_system/pages/login/methods/loginByPassword.js +55 -0
- package/template/mp/packages/$wd_system/pages/login/methods/loginByWXPhone.js +68 -0
- package/template/mp/packages/$wd_system/pages/login/methods/loginSuccessCallBack.js +20 -0
- package/template/mp/page/api.js +5 -6
- package/template/mp/page/index.js +4 -1
- package/template/package.json +6 -5
- package/template/webpack/web.dev.js +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.75",
|
|
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",
|
|
@@ -32,8 +32,9 @@
|
|
|
32
32
|
"test:build": "ts-node ./__tests__/build.ts",
|
|
33
33
|
"dev:web:serve": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
|
|
34
34
|
"dev:web": "cross-env NODE_ENV=development webpack --config ./webpack/web.config.js",
|
|
35
|
-
"build:web": "yarn run set:NODE_OPTIONS cross-env NODE_ENV=production webpack --config ./webpack/web.config.js",
|
|
36
|
-
"build:template": "./scripts/
|
|
35
|
+
"build:web": "yarn build:template && yarn run set:NODE_OPTIONS cross-env NODE_ENV=production webpack --config ./webpack/web.config.js",
|
|
36
|
+
"build:template": "node ./scripts/generateTemplate.js",
|
|
37
|
+
"dev:template": "npm run build:template --watch",
|
|
37
38
|
"dev:debug": "tsc-watch --onSuccess 'npm run build-dev-web-and-push'",
|
|
38
39
|
"build-dev-web-and-push": "npm run dev:web && clear && yalc publish --push",
|
|
39
40
|
"release": "yarn npm whoami --publish && npm run build && yarn set version 1.22.19 && yarn config set version-tag-prefix '@cloudbase/lowcode-builder@' && yarn version --no-commit-hooks --message 'chore(builder): v%s' && yarn config set version-tag-prefix v && yarn set version 3.6.2 && yarn npm publish",
|
|
@@ -46,8 +47,8 @@
|
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"@babel/core": "7.21.4",
|
|
48
49
|
"@babel/preset-env": "7.21.4",
|
|
49
|
-
"@cloudbase/cals": "^1.0.
|
|
50
|
-
"@cloudbase/lowcode-generator": "^1.8.
|
|
50
|
+
"@cloudbase/cals": "^1.0.65",
|
|
51
|
+
"@cloudbase/lowcode-generator": "^1.8.25",
|
|
51
52
|
"axios": "^0.21.0",
|
|
52
53
|
"browserfs": "^1.4.3",
|
|
53
54
|
"browserify-zlib": "^0.2.0",
|
|
@@ -454,7 +454,7 @@
|
|
|
454
454
|
<script type="module" src="/src/index.jsx"></script>
|
|
455
455
|
<% } %> <% if(!isAdminPortal){ %>
|
|
456
456
|
<script src="<%= wedaPrivateConfigEndpoint ? wedaPrivateConfigEndpoint : '' %>/weda-config/weda-private.js"></script>
|
|
457
|
-
<script src="<%= cdnEndpoints.cloudbase %>/cloudbase-js-sdk/2.
|
|
457
|
+
<script src="<%= cdnEndpoints.cloudbase %>/cloudbase-js-sdk/2.5.36-beta.0/cloudbase.full.js?v=1"></script>
|
|
458
458
|
<% }%>
|
|
459
459
|
<script>
|
|
460
460
|
if (window.cloudbase && window._aegis) {
|
|
@@ -543,7 +543,7 @@
|
|
|
543
543
|
crossorigin
|
|
544
544
|
src="<%=
|
|
545
545
|
cdnEndpoints.cdngo
|
|
546
|
-
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.
|
|
546
|
+
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.6b0be6e6436fb7ead047.bundle.js"
|
|
547
547
|
></script>
|
|
548
548
|
</body>
|
|
549
549
|
</html>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { observable } from 'mobx'
|
|
2
2
|
import { createMpApp } from '@cloudbase/weda-client';
|
|
3
|
-
import { createComputed, formatEnum, enumOptions
|
|
3
|
+
import { createComputed, formatEnum, enumOptions } from '<%= subLevelPath %>../common/util'
|
|
4
|
+
import { generateDatasetQuery } from '<%= subLevelPath %>../common/query'
|
|
5
|
+
|
|
4
6
|
import appGlobal from '<%= subLevelPath %>../app/app-global'
|
|
5
7
|
import { createDataset } from '<%= subLevelPath %>../datasources/index'
|
|
6
8
|
|
|
@@ -59,6 +61,22 @@ export const $w = new Proxy(
|
|
|
59
61
|
},
|
|
60
62
|
);
|
|
61
63
|
|
|
64
|
+
globalThis.__wedaGlobal__ = new Proxy({
|
|
65
|
+
app,
|
|
66
|
+
$w
|
|
67
|
+
}, {
|
|
68
|
+
get(_, prop) {
|
|
69
|
+
switch(prop) {
|
|
70
|
+
case 'app':
|
|
71
|
+
case '$app':
|
|
72
|
+
return app
|
|
73
|
+
case '$w':
|
|
74
|
+
return $w
|
|
75
|
+
}
|
|
76
|
+
return undefined
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
62
80
|
function createGlboalApi() {
|
|
63
81
|
const mpApp = createMpApp({
|
|
64
82
|
appConfig: {
|
package/template/mp/app.js
CHANGED
|
@@ -1,128 +1,11 @@
|
|
|
1
|
-
<%= importor.lifecycle?
|
|
2
|
-
import { app, $app } from '
|
|
1
|
+
<%= importor.lifecycle? `import lifeCycle from '${wedaRootRelativePath}lowcode/lifecycle'` : "const lifeCycle = {}" %>
|
|
2
|
+
import { app, $app } from '<%= wedaRootRelativePath %>app/weapps-api';
|
|
3
3
|
// 引入数据源管理器并进行初始化
|
|
4
4
|
import {
|
|
5
|
-
setConfig,
|
|
6
|
-
getAccessToken,
|
|
7
5
|
EXTRA_API,
|
|
8
6
|
createStateDataSourceVar,
|
|
9
7
|
generateParamsParser,
|
|
10
|
-
} from '
|
|
11
|
-
import { redirectToLogin, findLoginPage, getAuthConfig, checkAnonymous } from './common/util';
|
|
12
|
-
|
|
13
|
-
// 防止报类型不匹配warning
|
|
14
|
-
const originWarn = console.warn;
|
|
15
|
-
const warningSkipRegexp = /(type-uncompatible)|(slot "[\w-]*?" is not found)/;
|
|
16
|
-
console.warn = (...args) => {
|
|
17
|
-
// 只看第一条
|
|
18
|
-
const shouldSkip = args.length > 0 && args[0][0] === '[' && args[0][1] === 'C' && warningSkipRegexp.test(args[0]);
|
|
19
|
-
if (!shouldSkip) {
|
|
20
|
-
originWarn(...args);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// 设置数据源请求的 loading 及 toast 处理
|
|
25
|
-
setConfig({
|
|
26
|
-
beforeDSRequest: (cfg) => {
|
|
27
|
-
if (!cfg.options || !cfg.options.showLoading) return;
|
|
28
|
-
app.showLoading();
|
|
29
|
-
},
|
|
30
|
-
beforeCallFunction: async (params) => {
|
|
31
|
-
try {
|
|
32
|
-
const loginPage = findLoginPage();
|
|
33
|
-
|
|
34
|
-
let skip = false;
|
|
35
|
-
switch (params?.data?.methodName) {
|
|
36
|
-
case 'callWedaApi': {
|
|
37
|
-
if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
|
|
38
|
-
skip = true;
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 后续做过滤处理
|
|
45
|
-
const endpointType = app?.__internal__?.getCloudSdkConfig('endpointType');
|
|
46
|
-
if ((params?.data?.mode === 'c' && skip) || (endpointType !== 'tcb-api' && !loginPage)) {
|
|
47
|
-
return params;
|
|
48
|
-
}
|
|
49
|
-
// await initTcb();
|
|
50
|
-
const { accessToken } = await getAccessToken();
|
|
51
|
-
if (accessToken) {
|
|
52
|
-
params.data.accessToken = accessToken;
|
|
53
|
-
}
|
|
54
|
-
} catch (e) {
|
|
55
|
-
if (app?.cloud?.currentUser?.userType === 'externalUser' && e?.error === 'unauthenticated') {
|
|
56
|
-
app.showToast({
|
|
57
|
-
title: '登录态失效',
|
|
58
|
-
icon: 'error',
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
// console.error('beforeCallFunction error', e);
|
|
62
|
-
}
|
|
63
|
-
return params;
|
|
64
|
-
},
|
|
65
|
-
afterDSRequest: (cfg, error, result) => {
|
|
66
|
-
if (!cfg.options) return;
|
|
67
|
-
if (cfg.options.showLoading) app.hideLoading();
|
|
68
|
-
if (!cfg.options.showToast) return;
|
|
69
|
-
const isSuccess = !error && result && !result.code;
|
|
70
|
-
app.showToast({ icon: isSuccess ? 'success' : 'error' });
|
|
71
|
-
},
|
|
72
|
-
async afterCallFunction(params, error, res) {
|
|
73
|
-
let oauthError =
|
|
74
|
-
error?.message?.includes?.('PERMISSION_DENIED') ||
|
|
75
|
-
error?.code === 'unauthenticated' ||
|
|
76
|
-
error?.error === 'unauthenticated' ||
|
|
77
|
-
error?.code === 'invalid_grant' ||
|
|
78
|
-
error?.error === 'invalid_grant' ||
|
|
79
|
-
error?.code === 'INVALID_ACCESS_TOKEN';
|
|
80
|
-
|
|
81
|
-
if (!oauthError) {
|
|
82
|
-
try {
|
|
83
|
-
/**
|
|
84
|
-
* js-sdk v2 实现上吞了所有错误
|
|
85
|
-
* 返回 new Error(JSON.stringify({code: "OPERATION_FAIL", msg:"[INVALID_ACCESS_TOKEN]XXX"}))
|
|
86
|
-
*/
|
|
87
|
-
let tcbErrorObj = JSON.parse(error.message);
|
|
88
|
-
if (tcbErrorObj?.code === 'OPERATION_FAIL' && /\[INVALID_ACCESS_TOKEN\]/.test(tcbErrorObj.msg)) {
|
|
89
|
-
oauthError = true;
|
|
90
|
-
}
|
|
91
|
-
} catch (e) {}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' &&
|
|
96
|
-
(['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code) ||
|
|
97
|
-
oauthError)
|
|
98
|
-
) {
|
|
99
|
-
const loginPage = findLoginPage();
|
|
100
|
-
if (loginPage) {
|
|
101
|
-
const authConfig = await getAuthConfig();
|
|
102
|
-
if (authConfig.RejectStrategy === 'to_login') {
|
|
103
|
-
if (['InnerError.AuthFailure'].includes(res?.result?.code)) {
|
|
104
|
-
const isAnonymous = await checkAnonymous();
|
|
105
|
-
if (!isAnonymous) return;
|
|
106
|
-
// 匿名用户越权去登录
|
|
107
|
-
}
|
|
108
|
-
redirectToLogin();
|
|
109
|
-
} else if (authConfig.RejectStrategy === 'show_warning') {
|
|
110
|
-
if (oauthError) {
|
|
111
|
-
const isAnonymous = await checkAnonymous();
|
|
112
|
-
if (!isAnonymous) {
|
|
113
|
-
redirectToLogin(generateLoginUrl);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
app.showToast({
|
|
118
|
-
title: '接口无访问权限',
|
|
119
|
-
icon: 'error',
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
});
|
|
8
|
+
} from '<%= wedaRootRelativePath %>datasources/index';
|
|
126
9
|
|
|
127
10
|
App({
|
|
128
11
|
_query: {},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { redirectToLogin, findStatusPage } from '../util';
|
|
2
|
+
import { getWedaAPI } from '@cloudbase/weda-client';
|
|
2
3
|
|
|
3
4
|
Component({
|
|
4
5
|
/**
|
|
@@ -36,7 +37,7 @@ Component({
|
|
|
36
37
|
if (this.data.toLogin) {
|
|
37
38
|
redirectToLogin()
|
|
38
39
|
} else {
|
|
39
|
-
|
|
40
|
+
getWedaAPI()?.app?.relaunchHome()
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
43
|
showCustomService() {
|
|
@@ -50,13 +51,13 @@ Component({
|
|
|
50
51
|
attached() {
|
|
51
52
|
if (this.data.enableCustom) {
|
|
52
53
|
const status = findStatusPage();
|
|
53
|
-
const $page = this.data.pageCodeContext ||
|
|
54
|
+
const $page = this.data.pageCodeContext || getWedaAPI()?.app?.utils.getCurrentPage();
|
|
54
55
|
const uuid = this.data.pageUUID || $page.uuid;
|
|
55
56
|
if (status && status.id !== uuid) {
|
|
56
57
|
switch (this.data.type) {
|
|
57
58
|
case 'auth': {
|
|
58
59
|
if( $page?.id){
|
|
59
|
-
|
|
60
|
+
getWedaAPI().app?.redirectTo({
|
|
60
61
|
pageId: status.id,
|
|
61
62
|
params: {
|
|
62
63
|
statusCode: "403",
|
|
@@ -69,7 +70,7 @@ Component({
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
case 'notfound': {
|
|
72
|
-
|
|
73
|
+
getWedaAPI().app?.redirectTo({
|
|
73
74
|
pageId: status.id,
|
|
74
75
|
params: {
|
|
75
76
|
statusCode: "404",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<view class="wd-status" wx:if="{{visible}}">
|
|
2
|
-
<view style="transform: translateY(-20px);">
|
|
2
|
+
<view style="transform: translateY(-20px);width: 100%;">
|
|
3
3
|
<view class="wd-status__img {{type === 'notfound'?'wd-status--notfound':''}}">
|
|
4
4
|
<view
|
|
5
5
|
class="icon"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<view class="stack">
|
|
17
17
|
<view>
|
|
18
18
|
<text style="font-weight: 600; font-size:14px;">错误信息:</text>
|
|
19
|
-
<text user-select="true">{{error.message}}</text>
|
|
19
|
+
<text style="font-size:14px;" user-select="true">{{error.message}}</text>
|
|
20
20
|
</view>
|
|
21
21
|
<!-- <view wx:if="{{error.stack}}">
|
|
22
22
|
<text style="font-weight: 600;">错误堆栈:</text>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getWedaAPI } from '@cloudbase/weda-client';
|
|
1
2
|
let privacyHandler;
|
|
2
3
|
// let privacyResolves = new Set();
|
|
3
4
|
let closeOtherPagePopUpHooks = new Set();
|
|
@@ -31,8 +32,8 @@ Component({
|
|
|
31
32
|
*/
|
|
32
33
|
data: {
|
|
33
34
|
visible: false,
|
|
34
|
-
title:
|
|
35
|
-
desc1: `在您使用 ${
|
|
35
|
+
title: getWedaAPI().app.mpAppName || '用户隐私保护提示',
|
|
36
|
+
desc1: `在您使用 ${getWedaAPI().app.mpAppName || '本小程序'} 的后续服务之前,请仔细阅读并同意`,
|
|
36
37
|
urlTitle: '《用户隐私保护指引》。',
|
|
37
38
|
desc2: '如您拒绝,则指引中提及的相关功能使用将受限。',
|
|
38
39
|
},
|
|
@@ -4,10 +4,9 @@ import { generateForContextOfWidget, generateWidgetAPIContext, getWidget } from
|
|
|
4
4
|
import { observable, untracked } from 'mobx';
|
|
5
5
|
import { getAccessToken, loginScope } from '../datasources/index';
|
|
6
6
|
import { app } from '../app/weapps-api';
|
|
7
|
-
export { generateDatasetQuery } from './query';
|
|
8
|
-
export { generateEventFlows } from './flow';
|
|
9
7
|
import lodashGet from 'lodash.get';
|
|
10
8
|
import lodashSet from 'lodash.set';
|
|
9
|
+
import { getWedaAPI } from '@cloudbase/weda-client'
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Convert abcWordSnd -> abc-word-snd
|
|
@@ -403,13 +402,21 @@ export function set(object, path, value) {
|
|
|
403
402
|
}
|
|
404
403
|
|
|
405
404
|
export function findLoginPage() {
|
|
406
|
-
const { app } =
|
|
407
|
-
const { pages = [] } = app.__internal__.getConfig();
|
|
408
|
-
|
|
405
|
+
const { app } = getWedaAPI();
|
|
406
|
+
const { pages = [], loginConfigVersion } = app.__internal__.getConfig();
|
|
407
|
+
const custom = pages.find((item) => item.type === 'login')
|
|
408
|
+
if (loginConfigVersion) {
|
|
409
|
+
return custom || {
|
|
410
|
+
id: 'login',
|
|
411
|
+
packageName: '$wd_system',
|
|
412
|
+
uuid: '$wd_system/login',
|
|
413
|
+
type: 'login'
|
|
414
|
+
}
|
|
415
|
+
}
|
|
409
416
|
}
|
|
410
417
|
|
|
411
418
|
export function findStatusPage() {
|
|
412
|
-
const { app } =
|
|
419
|
+
const { app } = getWedaAPI();
|
|
413
420
|
const { pages = [] } = app.__internal__.getConfig();
|
|
414
421
|
return pages.find((item) => item.type === 'status');
|
|
415
422
|
}
|
|
@@ -417,7 +424,7 @@ export function findStatusPage() {
|
|
|
417
424
|
let _AUTH_CONFIG_CACHE = null;
|
|
418
425
|
|
|
419
426
|
export async function getAuthConfig() {
|
|
420
|
-
const { app } =
|
|
427
|
+
const { app } = getWedaAPI();
|
|
421
428
|
if (_AUTH_CONFIG_CACHE) {
|
|
422
429
|
return _AUTH_CONFIG_CACHE;
|
|
423
430
|
}
|
|
@@ -486,7 +493,7 @@ export async function checkAnonymous() {
|
|
|
486
493
|
try {
|
|
487
494
|
const { accessToken } = await getAccessToken();
|
|
488
495
|
isAnonymous = !accessToken;
|
|
489
|
-
const { app } =
|
|
496
|
+
const { app } = getWedaAPI();
|
|
490
497
|
// 私密链路有token则不是匿名; tcb链路会匿名登录需要多验证scope === 'anonymous'
|
|
491
498
|
if (accessToken && app.__internal__.getCloudSdkConfig('endpointType') === 'tcb-api') {
|
|
492
499
|
const scope = await loginScope();
|
|
@@ -513,7 +520,9 @@ export async function checkAuth(app, appId, $page) {
|
|
|
513
520
|
<% if(skipCheckAuth){ %> return true <% } %>
|
|
514
521
|
|
|
515
522
|
const loginPage = findLoginPage(app);
|
|
516
|
-
|
|
523
|
+
const loginPageUUID = loginPage?.uuid || loginPage.id
|
|
524
|
+
const currentUUID = $page.uuid || $page.id
|
|
525
|
+
if (loginPageUUID === currentUUID) {
|
|
517
526
|
return true;
|
|
518
527
|
}
|
|
519
528
|
const status = findStatusPage(app);
|
|
@@ -571,17 +580,20 @@ export async function checkAuth(app, appId, $page) {
|
|
|
571
580
|
export function redirectToLogin(currentPage) {
|
|
572
581
|
// 去登录则清空权限缓存。
|
|
573
582
|
_AUTH_CACHE_MAP = {};
|
|
574
|
-
const { app } =
|
|
583
|
+
const { app } = getWedaAPI();
|
|
575
584
|
const loginPage = findLoginPage(app);
|
|
576
585
|
if (!currentPage) {
|
|
577
586
|
currentPage = app.utils.getCurrentPage() || {};
|
|
578
587
|
}
|
|
579
|
-
|
|
588
|
+
const loginPageUUID = loginPage?.uuid || loginPage?.id
|
|
589
|
+
const currentUUID = currentPage.uuid || currentPage.id
|
|
590
|
+
if (loginPageUUID === currentUUID) {
|
|
580
591
|
return true;
|
|
581
592
|
}
|
|
582
593
|
if (loginPage) {
|
|
583
594
|
app.redirectTo({
|
|
584
595
|
pageId: loginPage.id,
|
|
596
|
+
packageName: loginPage.packageName,
|
|
585
597
|
params: {
|
|
586
598
|
sourcePagePackageName: currentPage.__internal__.packageName || undefined,
|
|
587
599
|
sourcePageId: currentPage.id,
|
|
@@ -631,7 +643,7 @@ function getEnumOptions(optionName) {
|
|
|
631
643
|
}
|
|
632
644
|
|
|
633
645
|
async function getGeneralOptions(optionName) {
|
|
634
|
-
const { app } =
|
|
646
|
+
const { app } = getWedaAPI();
|
|
635
647
|
return app.cloud.callWedaApi({
|
|
636
648
|
action: 'DescribeGeneralOptionsDetailList',
|
|
637
649
|
data: {
|
|
@@ -4,13 +4,14 @@ import {
|
|
|
4
4
|
createEventHandlers,
|
|
5
5
|
checkAuth,
|
|
6
6
|
getMpEventHandlerName,
|
|
7
|
-
generateDatasetQuery,
|
|
8
|
-
generateEventFlows,
|
|
9
7
|
getExpiredMessage
|
|
10
8
|
} from './util';
|
|
9
|
+
import { generateDatasetQuery } from './query'
|
|
10
|
+
import { generateEventFlows } from './flow'
|
|
11
11
|
import { createWidgets, createInitData, disposeWidget, getWidget } from './widget';
|
|
12
12
|
import mergeRenderer from './merge-renderer';
|
|
13
13
|
import {
|
|
14
|
+
setDatasetProfiles,
|
|
14
15
|
createDataset,
|
|
15
16
|
EXTRA_API,
|
|
16
17
|
createStateDataSourceVar,
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
import { runWatchers } from './watch';
|
|
21
22
|
import { $w as baseAPI } from '../app/weapps-api';
|
|
22
23
|
import { Event } from './event-emitter';
|
|
23
|
-
import { generatePageUrl } from '@cloudbase/weda-client';
|
|
24
24
|
import { mergeDynamic2StaticData, patchWdigetPropsWithEvtListeners } from './util';
|
|
25
25
|
import { styleToCss } from './style';
|
|
26
26
|
|
|
@@ -57,7 +57,7 @@ function extractLifecycles(ctx, lifecycle, appShareMessage, dataBinds, resetShar
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
let { pageId, params, imageUrl, title, packageName } = mergedData.appShareMessage || {};
|
|
60
|
-
const url = generatePageUrl({
|
|
60
|
+
const url = ctx.app?.__internal__?.generatePageUrl({
|
|
61
61
|
pageId,
|
|
62
62
|
packageName,
|
|
63
63
|
params: Array.isArray(params) ? params.reduce((map, { key, value }) => {
|
|
@@ -114,7 +114,14 @@ export function createPage({
|
|
|
114
114
|
pageContext = {},
|
|
115
115
|
pageAttributes = {},
|
|
116
116
|
resetShare = true,
|
|
117
|
+
datasetProfile = undefined
|
|
117
118
|
}) {
|
|
119
|
+
/**
|
|
120
|
+
* 单次引用
|
|
121
|
+
*/
|
|
122
|
+
if (datasetProfile) {
|
|
123
|
+
setDatasetProfiles({ [pageContext.uuid || pageContext.id || id]: datasetProfile })
|
|
124
|
+
}
|
|
118
125
|
widgetProps = patchWdigetPropsWithEvtListeners(widgetProps, evtListeners)
|
|
119
126
|
|
|
120
127
|
const evtHandlers = createEventHandlers(evtListeners);
|
|
@@ -225,9 +232,10 @@ export function createPage({
|
|
|
225
232
|
...mergeRenderer,
|
|
226
233
|
async beforePageCustomLaunch(query) {
|
|
227
234
|
if (!this._beforePageCustomLaunchPromise) {
|
|
228
|
-
this._beforePageCustomLaunchPromise = new Promise(async (resolve) => {
|
|
235
|
+
this._beforePageCustomLaunchPromise = new Promise(async (resolve, reject) => {
|
|
229
236
|
await wxApp.globaldata?._beforePageCustomLaunchPromise;
|
|
230
237
|
const $page = this._getInstance();
|
|
238
|
+
let weDaHasLogin
|
|
231
239
|
if (query) {
|
|
232
240
|
EXTRA_API.setParams($page.uuid, query);
|
|
233
241
|
}
|
|
@@ -235,18 +243,21 @@ export function createPage({
|
|
|
235
243
|
this.setData({ _isCheckingAtuh: true });
|
|
236
244
|
const auth = await checkAuth(app, app.id, $page);
|
|
237
245
|
if (auth) {
|
|
246
|
+
weDaHasLogin = true
|
|
238
247
|
this.setData({
|
|
239
|
-
weDaHasLogin
|
|
248
|
+
weDaHasLogin,
|
|
240
249
|
});
|
|
241
250
|
createStateDataSourceVar($page.uuid, generateParamsParser({ app, $page, $w: $page.__internal__?.$w }));
|
|
242
251
|
} else {
|
|
252
|
+
weDaHasLogin = false
|
|
243
253
|
this.setData({
|
|
244
|
-
weDaHasLogin
|
|
254
|
+
weDaHasLogin,
|
|
245
255
|
});
|
|
246
256
|
}
|
|
247
257
|
} catch(e) {
|
|
258
|
+
weDaHasLogin = false
|
|
248
259
|
this.setData({
|
|
249
|
-
weDaHasLogin
|
|
260
|
+
weDaHasLogin,
|
|
250
261
|
loginError: { message: e.message }
|
|
251
262
|
});
|
|
252
263
|
} finally {
|
|
@@ -269,7 +280,11 @@ export function createPage({
|
|
|
269
280
|
});
|
|
270
281
|
}
|
|
271
282
|
}
|
|
272
|
-
|
|
283
|
+
if(weDaHasLogin===false) {
|
|
284
|
+
reject(new Error('permission denied') )
|
|
285
|
+
}else {
|
|
286
|
+
resolve()
|
|
287
|
+
}
|
|
273
288
|
});
|
|
274
289
|
}
|
|
275
290
|
return this._beforePageCustomLaunchPromise;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK, auth } from '@cloudbase/weda-client'
|
|
1
|
+
import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK, auth, getWedaAPI } from '@cloudbase/weda-client'
|
|
2
|
+
import { redirectToLogin, findLoginPage, getAuthConfig, checkAnonymous } from '../common/util';
|
|
3
|
+
|
|
2
4
|
const {
|
|
3
5
|
setConfig,
|
|
4
6
|
initTcb,
|
|
5
7
|
CLOUD_SDK,
|
|
6
8
|
createDataset,
|
|
9
|
+
setDatasetProfiles,
|
|
7
10
|
createStateDataSourceVar,
|
|
8
11
|
generateParamsParser,
|
|
9
12
|
EXTRA_API,
|
|
@@ -14,6 +17,7 @@ const loginScope = auth.loginScope
|
|
|
14
17
|
|
|
15
18
|
export {
|
|
16
19
|
createDataset,
|
|
20
|
+
setDatasetProfiles,
|
|
17
21
|
createStateDataSourceVar,
|
|
18
22
|
generateParamsParser,
|
|
19
23
|
EXTRA_API,
|
|
@@ -27,7 +31,112 @@ export {
|
|
|
27
31
|
|
|
28
32
|
import { default as config, AEGIS_CONFIG } from './config'
|
|
29
33
|
|
|
30
|
-
setConfig(
|
|
34
|
+
setConfig({
|
|
35
|
+
...config,
|
|
36
|
+
// 设置数据源请求的 loading 及 toast 处理
|
|
37
|
+
beforeDSRequest: (cfg) => {
|
|
38
|
+
const { app } = getWedaAPI();
|
|
39
|
+
if (!cfg.options || !cfg.options.showLoading) return;
|
|
40
|
+
app.showLoading();
|
|
41
|
+
},
|
|
42
|
+
beforeCallFunction: async (params) => {
|
|
43
|
+
const { app } = getWedaAPI();
|
|
44
|
+
try {
|
|
45
|
+
const loginPage = findLoginPage();
|
|
46
|
+
|
|
47
|
+
let skip = false;
|
|
48
|
+
switch (params?.data?.methodName) {
|
|
49
|
+
case 'callWedaApi': {
|
|
50
|
+
if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
|
|
51
|
+
skip = true;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 后续做过滤处理
|
|
58
|
+
const endpointType = app?.__internal__?.getCloudSdkConfig('endpointType');
|
|
59
|
+
if ((params?.data?.mode === 'c' && skip) || (endpointType !== 'tcb-api' && !loginPage)) {
|
|
60
|
+
return params;
|
|
61
|
+
}
|
|
62
|
+
// await initTcb();
|
|
63
|
+
const { accessToken } = await getAccessToken();
|
|
64
|
+
if (accessToken) {
|
|
65
|
+
params.data.accessToken = accessToken;
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
if (app?.cloud?.currentUser?.userType === 'externalUser' && e?.error === 'unauthenticated') {
|
|
69
|
+
app.showToast({
|
|
70
|
+
title: '登录态失效',
|
|
71
|
+
icon: 'error',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// console.error('beforeCallFunction error', e);
|
|
75
|
+
}
|
|
76
|
+
return params;
|
|
77
|
+
},
|
|
78
|
+
afterDSRequest: (cfg, error, result) => {
|
|
79
|
+
const { app } = getWedaAPI();
|
|
80
|
+
if (!cfg.options) return;
|
|
81
|
+
if (cfg.options.showLoading) app.hideLoading();
|
|
82
|
+
if (!cfg.options.showToast) return;
|
|
83
|
+
const isSuccess = !error && result && !result.code;
|
|
84
|
+
app.showToast({ icon: isSuccess ? 'success' : 'error' });
|
|
85
|
+
},
|
|
86
|
+
async afterCallFunction(params, error, res) {
|
|
87
|
+
const { app } = getWedaAPI();
|
|
88
|
+
let oauthError =
|
|
89
|
+
error?.message?.includes?.('PERMISSION_DENIED') ||
|
|
90
|
+
error?.code === 'unauthenticated' ||
|
|
91
|
+
error?.error === 'unauthenticated' ||
|
|
92
|
+
error?.code === 'invalid_grant' ||
|
|
93
|
+
error?.error === 'invalid_grant' ||
|
|
94
|
+
error?.code === 'INVALID_ACCESS_TOKEN';
|
|
95
|
+
|
|
96
|
+
if (!oauthError) {
|
|
97
|
+
try {
|
|
98
|
+
/**
|
|
99
|
+
* js-sdk v2 实现上吞了所有错误
|
|
100
|
+
* 返回 new Error(JSON.stringify({code: "OPERATION_FAIL", msg:"[INVALID_ACCESS_TOKEN]XXX"}))
|
|
101
|
+
*/
|
|
102
|
+
let tcbErrorObj = JSON.parse(error.message);
|
|
103
|
+
if (tcbErrorObj?.code === 'OPERATION_FAIL' && /\[INVALID_ACCESS_TOKEN\]/.test(tcbErrorObj.msg)) {
|
|
104
|
+
oauthError = true;
|
|
105
|
+
}
|
|
106
|
+
} catch (e) {}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' &&
|
|
111
|
+
(['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code) || oauthError)
|
|
112
|
+
) {
|
|
113
|
+
const loginPage = findLoginPage();
|
|
114
|
+
if (loginPage) {
|
|
115
|
+
const authConfig = await getAuthConfig();
|
|
116
|
+
if (authConfig.RejectStrategy === 'to_login') {
|
|
117
|
+
if (['InnerError.AuthFailure'].includes(res?.result?.code)) {
|
|
118
|
+
const isAnonymous = await checkAnonymous();
|
|
119
|
+
if (!isAnonymous) return;
|
|
120
|
+
// 匿名用户越权去登录
|
|
121
|
+
}
|
|
122
|
+
redirectToLogin();
|
|
123
|
+
} else if (authConfig.RejectStrategy === 'show_warning') {
|
|
124
|
+
if (oauthError) {
|
|
125
|
+
const isAnonymous = await checkAnonymous();
|
|
126
|
+
if (!isAnonymous) {
|
|
127
|
+
redirectToLogin();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
app.showToast({
|
|
132
|
+
title: '接口无访问权限',
|
|
133
|
+
icon: 'error',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
});
|
|
31
140
|
initTcb()
|
|
32
141
|
|
|
33
142
|
<% if(cdnEndpoints.aegis){ %>
|
|
@@ -40,3 +149,14 @@ require.async('../packages/$wd_system/index.js').then(({ Aegis }) => {
|
|
|
40
149
|
app.globalData._aegis = _aegis;
|
|
41
150
|
})
|
|
42
151
|
<% }%>
|
|
152
|
+
|
|
153
|
+
// 防止报类型不匹配warning
|
|
154
|
+
const originWarn = console.warn;
|
|
155
|
+
const warningSkipRegexp = /(type-uncompatible)|(slot "[\w-]*?" is not found)/;
|
|
156
|
+
console.warn = (...args) => {
|
|
157
|
+
// 只看第一条
|
|
158
|
+
const shouldSkip = args.length > 0 && args[0][0] === '[' && args[0][1] === 'C' && warningSkipRegexp.test(args[0]);
|
|
159
|
+
if (!shouldSkip) {
|
|
160
|
+
originWarn(...args);
|
|
161
|
+
}
|
|
162
|
+
};
|
package/template/mp/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"dependencies": {<% if(importJSSDK) {%>
|
|
6
6
|
"@cloudbase/js-sdk": "2.5.6-beta.1",<% } %>
|
|
7
7
|
"@cloudbase/oauth": "0.1.1-alpha.5",
|
|
8
|
-
"@cloudbase/weda-client": "1.0.
|
|
9
|
-
"@cloudbase/weda-cloud-sdk": "1.0.
|
|
8
|
+
"@cloudbase/weda-client": "1.0.22",
|
|
9
|
+
"@cloudbase/weda-cloud-sdk": "1.0.56",
|
|
10
10
|
"mobx": "^5.15.4",
|
|
11
11
|
"lodash.get": "^4.4.2",
|
|
12
12
|
"lodash.set": "^4.3.2",
|