@cloudbase/lowcode-builder 0.1.8 → 0.1.11
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.js +1 -5
- package/lib/builder/h5/copy.js +1 -5
- package/lib/builder/h5/material.js +1 -5
- package/lib/builder/mp/index.js +19 -7
- package/lib/builder/mp/materials.js +1 -5
- package/lib/builder/mp/mixMode.js +1 -5
- package/lib/builder/mp/mp_config.js +3 -7
- package/lib/builder/mp/plugin.js +1 -5
- package/lib/builder/util/generateFiles.js +1 -5
- package/lib/builder/util/index.js +1 -5
- package/lib/builder/util/mp.js +1 -5
- package/lib/builder/util/net.js +1 -5
- package/lib/index.js +1 -5
- package/package.json +7 -5
- package/template/mp/app/weapps-api.js +6 -5
- package/template/mp/app.js +58 -1
- package/template/mp/common/jwt.js +106 -0
- package/template/mp/common/util.js +119 -16
- package/template/mp/common/weapp-page.js +6 -6
- package/template/mp/datasources/config.js.tpl +2 -0
- package/template/mp/datasources/index.js +6 -3
- package/template/mp/package.json +3 -2
- package/template/package.json +3 -3
- package/template/src/app/global-api.js +1 -1
- package/template/src/datasources/config.js.tpl +2 -0
- package/template/src/datasources/index.js +6 -3
- package/lib/builder.web.js +0 -79
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/h5/copy.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -56,6 +52,7 @@ const templateDir = config_1.appTemplateDir + '/mp/';
|
|
|
56
52
|
const em = chalk_1.default.blue.bold;
|
|
57
53
|
const error = chalk_1.default.redBright;
|
|
58
54
|
async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, }) {
|
|
55
|
+
var _a;
|
|
59
56
|
const operationLabel = em('Wexin MiniProgram Generated');
|
|
60
57
|
console.time(operationLabel);
|
|
61
58
|
console.log('Generating ' + em('Wexin MiniProgram') + ' to ' + projDir);
|
|
@@ -199,6 +196,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
199
196
|
appID: appId,
|
|
200
197
|
resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
|
|
201
198
|
isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
|
|
199
|
+
clientID: (_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.clientId,
|
|
202
200
|
},
|
|
203
201
|
'datasources/datasource-profiles.js.tpl': {
|
|
204
202
|
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(weapps.reduce((datasources, app) => {
|
|
@@ -238,14 +236,16 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
238
|
}));
|
|
241
|
-
if (!isBrowserMpBuilder &&
|
|
239
|
+
if (!isBrowserMpBuilder &&
|
|
240
|
+
fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
|
|
242
241
|
await (0, webpack_1.installDependencies)(miniprogramRoot);
|
|
243
242
|
}
|
|
244
243
|
await handleMpPlugins();
|
|
245
244
|
console.timeEnd(operationLabel);
|
|
246
245
|
// web端的builder不需要清除
|
|
247
246
|
!isBrowserMpBuilder && cleanProj(weapps, miniprogramRoot);
|
|
248
|
-
!isBrowserMpBuilder &&
|
|
247
|
+
!isBrowserMpBuilder &&
|
|
248
|
+
cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
|
|
249
249
|
return { miniprogramRoot };
|
|
250
250
|
function resolveNpmDeps() {
|
|
251
251
|
var _a;
|
|
@@ -370,6 +370,7 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
370
370
|
subPackageName: '',
|
|
371
371
|
isBare: true,
|
|
372
372
|
domain: ctx.domain || '',
|
|
373
|
+
appConfig: JSON.stringify({}),
|
|
373
374
|
},
|
|
374
375
|
};
|
|
375
376
|
}
|
|
@@ -399,6 +400,17 @@ async function generateFramework(appData, outDir, ctx) {
|
|
|
399
400
|
: '',
|
|
400
401
|
subPackageName: appData.rootPath || '',
|
|
401
402
|
isBare: false,
|
|
403
|
+
appConfig: (0, util_3.JsonToStringWithVariableName)({
|
|
404
|
+
id: ctx.appId,
|
|
405
|
+
envId: appData.envId,
|
|
406
|
+
staticResourceDomain: ctx.domain || '',
|
|
407
|
+
envVersion: (ctx === null || ctx === void 0 ? void 0 : ctx.isProduction) ? 'production' : 'preview',
|
|
408
|
+
pages: appData.pageInstanceList
|
|
409
|
+
.sort((item) => (item.isHome ? -1 : 1))
|
|
410
|
+
.map((item) => ({
|
|
411
|
+
id: item.id,
|
|
412
|
+
})),
|
|
413
|
+
}),
|
|
402
414
|
},
|
|
403
415
|
'app/common.js': {
|
|
404
416
|
mods: appData.lowCodes
|
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -106,8 +102,8 @@ function generateMpConfig(weapps, ctx) {
|
|
|
106
102
|
appConfig.plugins = plugins;
|
|
107
103
|
}
|
|
108
104
|
miniprogramPlugins.forEach((plugin) => {
|
|
109
|
-
var _a;
|
|
110
|
-
if (!((_a = appConfig === null ||
|
|
105
|
+
var _a, _b;
|
|
106
|
+
if (!((_b = (_a = appConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b[plugin.name])) {
|
|
111
107
|
(0, lodash_1.set)(appConfig, `plugins.${plugin.name}`, {
|
|
112
108
|
version: plugin.version,
|
|
113
109
|
provider: plugin.pluginAppId,
|
package/lib/builder/mp/plugin.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/util/mp.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/util/net.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
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",
|
|
@@ -25,9 +25,10 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"dev": "tsc -w",
|
|
27
27
|
"develop": "tsc -w",
|
|
28
|
-
"
|
|
28
|
+
"clean": "rm -rf lib && rm -rf dist",
|
|
29
|
+
"build": "tsc",
|
|
29
30
|
"test": "jest",
|
|
30
|
-
"test:build": "ts-node ./
|
|
31
|
+
"test:build": "ts-node ./__tests__/build.ts",
|
|
31
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",
|
|
32
33
|
"build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js"
|
|
33
34
|
},
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@cloudbase/cals": "^0.3.
|
|
39
|
+
"@cloudbase/cals": "^0.3.28",
|
|
39
40
|
"@cloudbase/lowcode-generator": "0.6.17-mpbeta.1",
|
|
40
41
|
"axios": "^0.21.0",
|
|
41
42
|
"browserfs": "^1.4.3",
|
|
@@ -72,6 +73,7 @@
|
|
|
72
73
|
"@types/react": "^16.9.49",
|
|
73
74
|
"@types/webpack": "^4.41.22",
|
|
74
75
|
"@types/weixin-app": "^2.9.0",
|
|
76
|
+
"cross-env": "^7.0.3",
|
|
75
77
|
"csstype": "^2.6.10",
|
|
76
78
|
"jest": "^26.0.1",
|
|
77
79
|
"ts-loader": "^8.3.0",
|
|
@@ -82,4 +84,4 @@
|
|
|
82
84
|
"webpack-dev-server": "^4.7.3",
|
|
83
85
|
"worker-loader": "^3.0.8"
|
|
84
86
|
}
|
|
85
|
-
}
|
|
87
|
+
}
|
|
@@ -11,9 +11,9 @@ import state from '../lowcode/state'
|
|
|
11
11
|
import common from './common'
|
|
12
12
|
<%} else {%>
|
|
13
13
|
const state = {}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const computed = {}
|
|
15
|
+
const common = {}
|
|
16
|
+
<%}%>
|
|
17
17
|
|
|
18
18
|
const mainAppKey = '__weappsMainApp'
|
|
19
19
|
|
|
@@ -21,11 +21,12 @@ export const app = createGlboalApi()
|
|
|
21
21
|
export { process }
|
|
22
22
|
|
|
23
23
|
function createGlboalApi() {
|
|
24
|
-
const mpApp = createMpApp(
|
|
24
|
+
const mpApp = createMpApp({
|
|
25
|
+
appConfig: <%= appConfig %>
|
|
26
|
+
});
|
|
25
27
|
const globalAPI = {
|
|
26
28
|
id: '<%= appId %>',
|
|
27
29
|
domain: '<%= domain %>',
|
|
28
|
-
activePage: null,
|
|
29
30
|
pages: {},
|
|
30
31
|
session: {
|
|
31
32
|
//configure: sdk.configure,
|
package/template/mp/app.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { setConfig } from './datasources/index'
|
|
1
|
+
import { setConfig, getAccessToken, initTcb } from './datasources/index'
|
|
2
2
|
import lifeCycle from './lowcode/lifecycle'
|
|
3
3
|
import { app } from './app/weapps-api'
|
|
4
4
|
import WxReportV2 from './common/wx_yypt_report_v2'
|
|
5
5
|
// 引入数据源管理器并进行初始化
|
|
6
6
|
import { EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
|
|
7
|
+
import { redirectToLogin, findLoginPage, getAuthConfig } from './common/util'
|
|
8
|
+
|
|
7
9
|
const $app = app;
|
|
8
10
|
<% if (yyptConfig.yyptAppKey) { %>
|
|
9
11
|
const wxReport = new WxReportV2({
|
|
@@ -24,12 +26,67 @@ const wxReport = new WxReportV2({
|
|
|
24
26
|
if (!cfg.options || !cfg.options.showLoading) return
|
|
25
27
|
app.showLoading()
|
|
26
28
|
},
|
|
29
|
+
beforeCallFunction: async (params) => {
|
|
30
|
+
try {
|
|
31
|
+
const loginPage = findLoginPage();
|
|
32
|
+
|
|
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;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
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') {
|
|
54
|
+
app.showToast({
|
|
55
|
+
title: '登录态失效',
|
|
56
|
+
icon: 'error',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
console.error('beforeCallFunction error', e);
|
|
60
|
+
}
|
|
61
|
+
return params;
|
|
62
|
+
},
|
|
27
63
|
afterDSRequest: (cfg, error, result) => {
|
|
28
64
|
if (!cfg.options) return
|
|
29
65
|
if (cfg.options.showLoading) app.hideLoading()
|
|
30
66
|
if (!cfg.options.showToast) return
|
|
31
67
|
const isSuccess = !error && result && !result.code
|
|
32
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
|
+
}
|
|
33
90
|
}
|
|
34
91
|
})
|
|
35
92
|
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
4
|
+
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
5
|
+
exports.weBtoa = function (string) {
|
|
6
|
+
string = String(string);
|
|
7
|
+
var bitmap,
|
|
8
|
+
a,
|
|
9
|
+
b,
|
|
10
|
+
c,
|
|
11
|
+
result = "",
|
|
12
|
+
i = 0,
|
|
13
|
+
rest = string.length % 3;
|
|
14
|
+
for (; i < string.length; ) {
|
|
15
|
+
if (
|
|
16
|
+
(a = string.charCodeAt(i++)) > 255 ||
|
|
17
|
+
(b = string.charCodeAt(i++)) > 255 ||
|
|
18
|
+
(c = string.charCodeAt(i++)) > 255
|
|
19
|
+
)
|
|
20
|
+
throw new TypeError(
|
|
21
|
+
"Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."
|
|
22
|
+
);
|
|
23
|
+
bitmap = (a << 16) | (b << 8) | c;
|
|
24
|
+
result +=
|
|
25
|
+
b64.charAt((bitmap >> 18) & 63) +
|
|
26
|
+
b64.charAt((bitmap >> 12) & 63) +
|
|
27
|
+
b64.charAt((bitmap >> 6) & 63) +
|
|
28
|
+
b64.charAt(bitmap & 63);
|
|
29
|
+
}
|
|
30
|
+
return rest ? result.slice(0, rest - 3) + "===".substring(rest) : result;
|
|
31
|
+
};
|
|
32
|
+
exports.weAtob = function (string) {
|
|
33
|
+
string = String(string).replace(/[\t\n\f\r ]+/g, "");
|
|
34
|
+
if (!b64re.test(string))
|
|
35
|
+
throw new TypeError(
|
|
36
|
+
"Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."
|
|
37
|
+
);
|
|
38
|
+
string += "==".slice(2 - (string.length & 3));
|
|
39
|
+
var bitmap,
|
|
40
|
+
result = "",
|
|
41
|
+
r1,
|
|
42
|
+
r2,
|
|
43
|
+
i = 0;
|
|
44
|
+
for (; i < string.length; ) {
|
|
45
|
+
bitmap =
|
|
46
|
+
(b64.indexOf(string.charAt(i++)) << 18) |
|
|
47
|
+
(b64.indexOf(string.charAt(i++)) << 12) |
|
|
48
|
+
((r1 = b64.indexOf(string.charAt(i++))) << 6) |
|
|
49
|
+
(r2 = b64.indexOf(string.charAt(i++)));
|
|
50
|
+
result +=
|
|
51
|
+
r1 === 64
|
|
52
|
+
? String.fromCharCode((bitmap >> 16) & 255)
|
|
53
|
+
: r2 === 64
|
|
54
|
+
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
|
55
|
+
: String.fromCharCode(
|
|
56
|
+
(bitmap >> 16) & 255,
|
|
57
|
+
(bitmap >> 8) & 255,
|
|
58
|
+
bitmap & 255
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
function b64DecodeUnicode(str) {
|
|
64
|
+
return decodeURIComponent(
|
|
65
|
+
exports.weAtob(str).replace(/(.)/g, function (p) {
|
|
66
|
+
var code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
67
|
+
if (code.length < 2) {
|
|
68
|
+
code = "0" + code;
|
|
69
|
+
}
|
|
70
|
+
return "%" + code;
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function base64_url_decode(str) {
|
|
75
|
+
var output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
76
|
+
switch (output.length % 4) {
|
|
77
|
+
case 0:
|
|
78
|
+
break;
|
|
79
|
+
case 2:
|
|
80
|
+
output += "==";
|
|
81
|
+
break;
|
|
82
|
+
case 3:
|
|
83
|
+
output += "=";
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
throw "Illegal base64url string!";
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return b64DecodeUnicode(output);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
return exports.weAtob(output);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function weappJwtDecode(token, options) {
|
|
95
|
+
if (typeof token !== "string") {
|
|
96
|
+
throw "Invalid token specified";
|
|
97
|
+
}
|
|
98
|
+
options = options || {};
|
|
99
|
+
var pos = options.header === true ? 0 : 1;
|
|
100
|
+
try {
|
|
101
|
+
return JSON.parse(base64_url_decode(token.split(".")[pos]));
|
|
102
|
+
} catch (e) {
|
|
103
|
+
throw "Invalid token specified: " + e.message;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.default = weappJwtDecode;
|
|
@@ -55,7 +55,7 @@ export function createEventHandlers(evtListeners, context) {
|
|
|
55
55
|
detail: res
|
|
56
56
|
})
|
|
57
57
|
} catch (e) {
|
|
58
|
-
let eventName = l.key ? `${l.key}_fail` : ''
|
|
58
|
+
let eventName = l.key ? `${prefix}$${l.key}_fail` : ''
|
|
59
59
|
if (self[eventName]) {
|
|
60
60
|
await self[eventName]({
|
|
61
61
|
...event,
|
|
@@ -233,32 +233,135 @@ export function setter(context, path, value = undefined) {
|
|
|
233
233
|
return lodashSet(context, path, value);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
export function findLoginPage() {
|
|
237
|
+
const { app } = getApp();
|
|
238
|
+
const { pages = [] } = app.__internal__.getConfig();
|
|
239
|
+
return pages.find(item => item.type === 'login');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let _AUTH_CONFIG_CACHE = null;
|
|
243
|
+
export async function getAuthConfig() {
|
|
244
|
+
const { app } = getApp();
|
|
245
|
+
if (_AUTH_CONFIG_CACHE) {
|
|
246
|
+
return _AUTH_CONFIG_CACHE;
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const res = await app.cloud.callWedaApi({
|
|
250
|
+
action: "DescribeRuntimeResourceStrategy",
|
|
251
|
+
data: {
|
|
252
|
+
ResourceType: `<%= isAdminPortal? 'modelApp' : 'app'%>`,
|
|
253
|
+
ResourceId: app.id,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
const settingData = {};
|
|
257
|
+
// 云api不支持map只能传字符串,需要转换
|
|
258
|
+
res.forEach((item) => {
|
|
259
|
+
settingData[item.Key] = ['AllowRegister', 'NeedLogin'].includes(item.Key) ? item.Value === '1' : item.Value;
|
|
260
|
+
});
|
|
261
|
+
_AUTH_CONFIG_CACHE = settingData;
|
|
262
|
+
return _AUTH_CONFIG_CACHE;
|
|
263
|
+
} catch (e) {
|
|
264
|
+
return {
|
|
265
|
+
NeedLogin: false,
|
|
266
|
+
RejectStrategy: "show_warning",
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let _AUTH_CACHE_MAP = {}
|
|
272
|
+
async function getAccessPermission(app, appId, pageId) {
|
|
273
|
+
const cacheKey = `${appId}-${pageId}`
|
|
274
|
+
if (_AUTH_CACHE_MAP[cacheKey] !== undefined) {
|
|
275
|
+
return _AUTH_CACHE_MAP[cacheKey];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
let isAccess = false;
|
|
279
|
+
try {
|
|
280
|
+
const res = await app.cloud.callWedaApi({
|
|
281
|
+
action: 'DescribeResourcesPermission',
|
|
282
|
+
data: {
|
|
283
|
+
ResourceType: `<%= isAdminPortal? 'modelApp' : 'app'%>`,
|
|
284
|
+
ResourceIdList: [cacheKey],
|
|
285
|
+
AppResourceId: appId,
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
if (Array.isArray(res) && res.length > 0) {
|
|
289
|
+
isAccess = !!res[0].IsAccess;
|
|
290
|
+
}
|
|
291
|
+
_AUTH_CACHE_MAP[cacheKey] = isAccess;
|
|
292
|
+
} catch (e) {
|
|
293
|
+
console.warn('getAccessPermission', e);
|
|
294
|
+
}
|
|
295
|
+
return isAccess
|
|
296
|
+
}
|
|
297
|
+
|
|
236
298
|
/**
|
|
237
299
|
* 检查页面权限
|
|
238
300
|
**/
|
|
239
|
-
export async function checkAuth(app, appId,
|
|
240
|
-
|
|
301
|
+
export async function checkAuth(app, appId, $page) {
|
|
302
|
+
const loginPage = findLoginPage(app);
|
|
303
|
+
if (loginPage?.id === $page.id) {
|
|
304
|
+
return true
|
|
305
|
+
}
|
|
241
306
|
app.showNavigationBarLoading();
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
ResourceIdList: [`${appId}-${pageId}`],
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
let isLogin = false;
|
|
250
|
-
if (Array.isArray(checkAuthResult) && checkAuthResult.length > 0) {
|
|
251
|
-
isLogin = checkAuthResult[0]?.IsAccess || false;
|
|
307
|
+
const requestList = [getAccessPermission(app, appId, $page.id)];
|
|
308
|
+
// 暂时先认为有登录页则自定义登录功能开启且生效
|
|
309
|
+
if (loginPage) {
|
|
310
|
+
requestList.push(getAuthConfig(app));
|
|
252
311
|
}
|
|
312
|
+
const [isAccess, authConfig] = await Promise.all(requestList);
|
|
253
313
|
app.hideNavigationBarLoading();
|
|
254
314
|
|
|
255
|
-
|
|
315
|
+
const { accessToken } = await getAccessToken()
|
|
316
|
+
const isAnonymousUser = !accessToken
|
|
317
|
+
|
|
318
|
+
if (!isAccess) {
|
|
319
|
+
if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
|
|
320
|
+
redirectToLogin($page);
|
|
321
|
+
} else {
|
|
322
|
+
app.showToast({
|
|
323
|
+
title: '页面无访问权限',
|
|
324
|
+
icon: 'error',
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
} else if (loginPage && authConfig.NeedLogin) {
|
|
328
|
+
// 此分支逻辑本不应该前端判断是否登录,历史原因后端短期内搞不定,后续后端优化后删除
|
|
329
|
+
try {
|
|
330
|
+
if (isAnonymousUser) {
|
|
331
|
+
redirectToLogin($page);
|
|
332
|
+
}
|
|
333
|
+
} catch (e) {
|
|
334
|
+
redirectToLogin($page);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return isAccess;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function redirectToLogin(currentPage) {
|
|
341
|
+
// 去登录则清空权限缓存。
|
|
342
|
+
_AUTH_CACHE_MAP = {};
|
|
343
|
+
const { app } = getApp();
|
|
344
|
+
const loginPage = findLoginPage(app);
|
|
345
|
+
if (!currentPage) {
|
|
346
|
+
currentPage = app.utils.getCurrentPage() || {};
|
|
347
|
+
}
|
|
348
|
+
if (loginPage?.id === currentPage.id) {
|
|
349
|
+
return true
|
|
350
|
+
}
|
|
351
|
+
if (loginPage) {
|
|
352
|
+
app.redirectTo({
|
|
353
|
+
pageId: loginPage.id,
|
|
354
|
+
params: {
|
|
355
|
+
sourcePageId: currentPage.id,
|
|
356
|
+
sourcePageParams: currentPage.params
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
} else {
|
|
256
360
|
app.showToast({
|
|
257
|
-
title: '
|
|
361
|
+
title: '用户未登录',
|
|
258
362
|
icon: 'error',
|
|
259
363
|
});
|
|
260
364
|
}
|
|
261
|
-
return isLogin;
|
|
262
365
|
}
|
|
263
366
|
|
|
264
367
|
// 日期转换
|