@infly/libs 2.0.42 → 2.0.44
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/README.md +92 -67
- package/adapters/vue2/build/webpack5/inline-runtime-plugin.js +35 -0
- package/adapters/vue2/build/webpack5/remove-legacy-assets-plugin.js +84 -0
- package/adapters/vue2/build/webpack5/webpack.base.js +437 -0
- package/adapters/vue2/module/Permission.js +204 -0
- package/adapters/vue2/postinstall.js +46 -0
- package/adapters/vue2/project-preview.js +148 -0
- package/adapters/vue2/script-config.js +26 -0
- package/adapters/vue2/store/index.js +1 -0
- package/adapters/vue2/store/modules/user.js +268 -0
- package/bin/cli.js +71 -71
- package/build/build-dist/index.js +863 -863
- package/build/build-dist/script-management.js +5 -5
- package/build/docker/compose-command.js +74 -74
- package/build/docker/compose-release.js +91 -91
- package/build/webpack5/inline-runtime-plugin.js +1 -35
- package/build/webpack5/remove-legacy-assets-plugin.js +1 -84
- package/build/webpack5/webpack.base.js +1 -435
- package/compat/init.js +9 -0
- package/index.js +8 -20
- package/module/Permission.js +1 -204
- package/module/REST.js +31 -19
- package/module/TokenService.js +9 -0
- package/module/Uts.js +460 -7252
- package/module/cjs/request-url-rules.cjs +6 -0
- package/module/cjs/rest-error-rules.cjs +33 -0
- package/package.json +121 -92
- package/script/build/deps.js +1 -1
- package/script/build/webhook.js +3 -2
- package/script/git-automation/git-clone.js +3 -4
- package/script/git-automation/index.js +2 -2
- package/script/index.js +1 -26
- package/script/webhook/webhook.js +7 -2
- package/store/index.js +1 -0
- package/store/modules/user.js +1 -268
- package/tools/auto-export.js +1 -2
- package/tools/file-export.js +6 -4
- package/tools/project-command.js +194 -194
- package/tools/project-preview.js +1 -148
- package/tools/select-option.js +60 -60
- package/.prettierrc +0 -5
- package/build/build-dist/script-management.test.js +0 -16
- package/build/docker/compose-command.test.js +0 -148
- package/build/docker/compose-release.test.js +0 -101
- package/build/docker/docker-build-push.test.js +0 -124
- package/build/webpack5/webpack.base.test.js +0 -59
- package/lib/index.js +0 -6
- package/lib/server/connect.js +0 -3011
- package/lib/server/serve-static.js +0 -4848
- package/script/pts/cloud-scenes.mjs +0 -65
- package/script/pts/cloud.js +0 -151
- package/script/pts/generate-cloud-params.mjs +0 -210
- package/script/pts/generate-cloud-params.test.mjs +0 -67
- package/tools/project-command.test.js +0 -267
- package/tools/select-option.test.js +0 -52
- package/webpack.config.js +0 -38
|
@@ -16,6 +16,11 @@ function normalizePathIncludes(pathIncludes) {
|
|
|
16
16
|
return pathIncludes.filter(Boolean).map((path) => String(path));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function matchesConfiguredBaseURL(baseURL, configuredBaseURLs) {
|
|
20
|
+
const normalizedBaseURL = String(baseURL || "").trim().replace(/\/+$/, "");
|
|
21
|
+
return normalizeRuleDomains(configuredBaseURLs).includes(normalizedBaseURL);
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
function resolveInternalServiceURL(url, rules = []) {
|
|
20
25
|
if (!url || !Array.isArray(rules) || rules.length === 0) {
|
|
21
26
|
return null;
|
|
@@ -51,5 +56,6 @@ function resolveInternalServiceURL(url, rules = []) {
|
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
module.exports = {
|
|
59
|
+
matchesConfiguredBaseURL,
|
|
54
60
|
resolveInternalServiceURL
|
|
55
61
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function normalizeErrorPayload(payload) {
|
|
2
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const message = payload.error || payload.detail || payload.message || payload.msg;
|
|
7
|
+
if (message && !payload.error) {
|
|
8
|
+
payload.error = message;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function resolveStatusErrorMessage(status, payload) {
|
|
15
|
+
const backendMessage = normalizeErrorPayload(payload);
|
|
16
|
+
const fallbackMessage = `请求失败(${status})`;
|
|
17
|
+
const statusMessages = {
|
|
18
|
+
400: backendMessage || fallbackMessage,
|
|
19
|
+
401: backendMessage || "登录信息已过期,请重新登录",
|
|
20
|
+
403: "您没有权限访问,请联系管理员",
|
|
21
|
+
500: backendMessage || fallbackMessage,
|
|
22
|
+
502: "网关错误,请稍后重试或联系开发人员",
|
|
23
|
+
503: "服务暂时不可用,请稍后重试",
|
|
24
|
+
504: "网关超时,请稍后重试或联系开发人员",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return statusMessages[status];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
normalizeErrorPayload,
|
|
32
|
+
resolveStatusErrorMessage,
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,92 +1,121 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@infly/libs",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"libs"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
]
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@infly/libs",
|
|
3
|
+
"version": "2.0.44",
|
|
4
|
+
"description": "不受前端框架限制的独立工具库",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"bin/",
|
|
9
|
+
"compat/",
|
|
10
|
+
"adapters/vue2/",
|
|
11
|
+
"build/",
|
|
12
|
+
"module/",
|
|
13
|
+
"script/build/",
|
|
14
|
+
"script/git-automation/",
|
|
15
|
+
"script/index.js",
|
|
16
|
+
"script/webhook/",
|
|
17
|
+
"store/",
|
|
18
|
+
"tools/",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"!**/*.test.js",
|
|
22
|
+
"!**/*.test.cjs",
|
|
23
|
+
"!**/*.test.mjs"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "node --test --test-timeout=30000 core-entry.test.js adapters/vue2/compatibility.test.js build/build-dist/script-management.test.js build/docker/compose-command.test.js build/docker/compose-release.test.js build/docker/docker-build-push.test.js build/webpack5/webpack.base.test.js tools/project-command.test.js tools/select-option.test.js module/cjs/request-url-rules.test.cjs module/cjs/rest-error-rules.test.cjs script/build/webhook.test.js script/pts/generate-cloud-params.test.mjs",
|
|
27
|
+
"test:coverage": "node --test --test-timeout=30000 --experimental-test-coverage core-entry.test.js adapters/vue2/compatibility.test.js build/build-dist/script-management.test.js build/docker/compose-command.test.js build/docker/compose-release.test.js build/docker/docker-build-push.test.js build/webpack5/webpack.base.test.js tools/project-command.test.js tools/select-option.test.js module/cjs/request-url-rules.test.cjs module/cjs/rest-error-rules.test.cjs script/build/webhook.test.js script/pts/generate-cloud-params.test.mjs",
|
|
28
|
+
"check": "node --test --test-timeout=30000 core-entry.test.js",
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"lint:strict": "eslint . --max-warnings 0",
|
|
31
|
+
"postinstall": "node adapters/vue2/postinstall.js",
|
|
32
|
+
"publishPkg": "npm publish --access=public --registry=https://registry.npmjs.org/",
|
|
33
|
+
"preview": "infly-libs --preview",
|
|
34
|
+
"preview:no-build": "infly-libs --preview --no-build",
|
|
35
|
+
"origin:preview": "infly-libs --preview",
|
|
36
|
+
"origin:preview:no-build": "infly-libs --preview --no-build"
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"infly-libs": "bin/cli.js"
|
|
40
|
+
},
|
|
41
|
+
"exports": {
|
|
42
|
+
".": "./index.js",
|
|
43
|
+
"./adapters/vue2/*": "./adapters/vue2/*",
|
|
44
|
+
"./adapters/vue2/build/*": "./adapters/vue2/build/*",
|
|
45
|
+
"./module/*": "./module/*",
|
|
46
|
+
"./tools/*": "./tools/*",
|
|
47
|
+
"./store/*": "./store/*",
|
|
48
|
+
"./build/*": "./build/*",
|
|
49
|
+
"./script/build/*": "./script/build/*"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://gitee.com/kahal/npm-package"
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"infly",
|
|
57
|
+
"infly-libs",
|
|
58
|
+
"libs"
|
|
59
|
+
],
|
|
60
|
+
"author": "Kahal",
|
|
61
|
+
"license": "ISC",
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@infly/ts-libs": "workspace:*",
|
|
64
|
+
"connect": "^3.7.0",
|
|
65
|
+
"enquirer": "^2.4.1",
|
|
66
|
+
"path-browserify": "^1.0.1",
|
|
67
|
+
"serve-static": "^1.15.0"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@babel/core": "^7.23.3",
|
|
71
|
+
"@babel/preset-env": "^7.23.3",
|
|
72
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
73
|
+
"babel-loader": "^10.0.0",
|
|
74
|
+
"webpack": "^5.88.2",
|
|
75
|
+
"webpack-cli": "^5.1.4",
|
|
76
|
+
"webpack-node-externals": "^3.0.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"axios": "^0.27.2",
|
|
80
|
+
"html-webpack-plugin": "^5.5.3"
|
|
81
|
+
},
|
|
82
|
+
"optionalDependencies": {
|
|
83
|
+
"axios": "^0.27.2",
|
|
84
|
+
"html-webpack-plugin": "^5.5.3"
|
|
85
|
+
},
|
|
86
|
+
"infly": {
|
|
87
|
+
"buildConfigs": {
|
|
88
|
+
"buildFoldName": "[构建后目录名] 可选, 默认取值vue.config.js的outputDir, 配置化 eg: example-admin",
|
|
89
|
+
"outputPath": "[输出文件目录链接] eg: ./ ",
|
|
90
|
+
"enabled": "[是否启用压缩] eg: true",
|
|
91
|
+
"gitAuto": "[是否自动提交git] eg: true",
|
|
92
|
+
"gitAutoPushReposBranchMap": {
|
|
93
|
+
"release-eg": "develop-eg [自动提交推送项目构建分支和构建仓库推送分支对应配置,必须]"
|
|
94
|
+
},
|
|
95
|
+
"gitAutoCommitText": "[自动提交文案] eg: build: 更新版本为v{version}, 推送构建文件与zip压缩包 --build by infly-libs",
|
|
96
|
+
"enablePreview": "[是否启用项目预览] eg: true",
|
|
97
|
+
"enableClipboard": "[是否启用粘贴板粘贴git信息] eg: true",
|
|
98
|
+
"openExplorer": "[是否自动打开资源管理器] eg: true",
|
|
99
|
+
"webhookUrl": "[消息推送机器人链接配置] eg: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=",
|
|
100
|
+
"webhookAtUser": [
|
|
101
|
+
"@人手机号"
|
|
102
|
+
],
|
|
103
|
+
"webhookExtraText": "[消息推送额外文案] eg: 麻烦发下版",
|
|
104
|
+
"compressionLevel": 9
|
|
105
|
+
},
|
|
106
|
+
"versionConfig": {
|
|
107
|
+
"mainVersion": "[主版本号] 可选, 默认取值项目package version, eg: 1",
|
|
108
|
+
"links": {
|
|
109
|
+
"master": "[master分支构建文件推送地址] eg: https://example.com",
|
|
110
|
+
"release": "[release分支构建文件推送地址] eg: https://staging.example.com"
|
|
111
|
+
},
|
|
112
|
+
"platformName": "[用以split的项目平台名称] eg: 示例平台-运营端",
|
|
113
|
+
"baseName": "v{version}-{timestamp}.zip",
|
|
114
|
+
"versionList": [],
|
|
115
|
+
"disableUpdateVersionEnv": [
|
|
116
|
+
"development",
|
|
117
|
+
"staging [禁用更新版本号的环境, 比如测试环境构建不需要更新version, 不配置默认禁用stage测试环境]"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
package/script/build/deps.js
CHANGED
|
@@ -9,7 +9,7 @@ const path = require("path");
|
|
|
9
9
|
*
|
|
10
10
|
* 示例(vue.config.js):
|
|
11
11
|
* alias: {
|
|
12
|
-
* "@
|
|
12
|
+
* "@example-admin": projectResolve("../example-admin/src")
|
|
13
13
|
* }
|
|
14
14
|
*
|
|
15
15
|
* @param {string} appDir - 当前 app 目录的绝对路径
|
package/script/build/webhook.js
CHANGED
|
@@ -36,7 +36,7 @@ function getRecordContent(record, deployUrl) {
|
|
|
36
36
|
publishText,
|
|
37
37
|
`构建文件:已推送对应仓库【${repos || ""}】- 分支【${targetBranch}】`,
|
|
38
38
|
`构建人:${author || ""}`,
|
|
39
|
-
`部署系统:${deployUrl}`
|
|
39
|
+
deployUrl ? `部署系统:${deployUrl}` : ""
|
|
40
40
|
]
|
|
41
41
|
.filter(Boolean)
|
|
42
42
|
.join("\n");
|
|
@@ -77,7 +77,7 @@ async function postBatchWebhook(batchWebhookFile, extraArgs, mode) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const [firstRecord] = records;
|
|
80
|
-
const { webhookUrl, webhookAtUser = [], gitInfo = {}, deployUrl = "
|
|
80
|
+
const { webhookUrl, webhookAtUser = [], gitInfo = {}, deployUrl = "" } =
|
|
81
81
|
firstRecord.extraParams || {};
|
|
82
82
|
|
|
83
83
|
if (!webhookUrl) {
|
|
@@ -114,5 +114,6 @@ async function postBatchWebhook(batchWebhookFile, extraArgs, mode) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
module.exports = {
|
|
117
|
+
getRecordContent,
|
|
117
118
|
postBatchWebhook
|
|
118
119
|
};
|
|
@@ -25,7 +25,7 @@ function cloneRepository(url, branch, targetDir) {
|
|
|
25
25
|
* @description
|
|
26
26
|
* eg: package.json
|
|
27
27
|
* {
|
|
28
|
-
"name": "
|
|
28
|
+
"name": "example-monorepo",
|
|
29
29
|
"version": "1.0.0",
|
|
30
30
|
"private": true,
|
|
31
31
|
"projectConfig": {
|
|
@@ -34,9 +34,8 @@ function cloneRepository(url, branch, targetDir) {
|
|
|
34
34
|
"baseGitUrl": "https://gitee.com/gdinfly_1/"
|
|
35
35
|
},
|
|
36
36
|
"workspaces": [
|
|
37
|
-
"apps/
|
|
38
|
-
"apps/
|
|
39
|
-
"apps/postal-benefits-platform-level"
|
|
37
|
+
"apps/example-admin",
|
|
38
|
+
"apps/example-portal"
|
|
40
39
|
]
|
|
41
40
|
}
|
|
42
41
|
*
|
|
@@ -521,8 +521,8 @@ function checkAndUpdateRootPackages(packagesDir, targetBranch = "master") {
|
|
|
521
521
|
stdio: "inherit"
|
|
522
522
|
});
|
|
523
523
|
|
|
524
|
-
// 只同步共享内容,保留当前分支配置和子模块集合
|
|
525
|
-
const mergeScriptPath = path.join(rootDir, "script", "sync-from-branch.sh");
|
|
524
|
+
// 只同步共享内容,保留当前分支配置和子模块集合
|
|
525
|
+
const mergeScriptPath = path.join(rootDir, "script", "sync-from-branch.sh");
|
|
526
526
|
if (fs.existsSync(mergeScriptPath)) {
|
|
527
527
|
execSync(`bash "${mergeScriptPath}" ${targetBranch}`, {
|
|
528
528
|
cwd: rootDir,
|
package/script/index.js
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
module.exports =
|
|
2
|
-
previewList: [
|
|
3
|
-
{
|
|
4
|
-
key: "preview",
|
|
5
|
-
value: "infly-libs --preview"
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
key: "preview:no-build",
|
|
9
|
-
value: "infly-libs --preview --no-build"
|
|
10
|
-
}
|
|
11
|
-
],
|
|
12
|
-
buildList: [
|
|
13
|
-
{
|
|
14
|
-
key: "build:prod",
|
|
15
|
-
value: "infly-libs beforeBuild && vue-cli-service build && infly-libs afterBuild"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
key: "build:stage",
|
|
19
|
-
value: "infly-libs beforeBuild && vue-cli-service build --mode staging && infly-libs afterBuild"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
key: "build:test",
|
|
23
|
-
value: "infly-libs beforeBuild && infly-libs afterBuild"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
};
|
|
1
|
+
module.exports = require("../adapters/vue2/script-config.js");
|
|
@@ -63,7 +63,7 @@ function postVersionFileAndMsg(publishText, extraParams = {}) {
|
|
|
63
63
|
gitAutoPushRepos,
|
|
64
64
|
gitAutoPushReposBranchMap,
|
|
65
65
|
repos,
|
|
66
|
-
deployUrl = "
|
|
66
|
+
deployUrl = ""
|
|
67
67
|
} = extraParams || {};
|
|
68
68
|
const { branch, commitMsg, author } = gitInfo || {};
|
|
69
69
|
const webhookMessage = getWebhookMessage();
|
|
@@ -82,7 +82,12 @@ function postVersionFileAndMsg(publishText, extraParams = {}) {
|
|
|
82
82
|
} */
|
|
83
83
|
let content = publishText;
|
|
84
84
|
if (gitAutoPushReposBranchMap) {
|
|
85
|
-
content =
|
|
85
|
+
content = [
|
|
86
|
+
publishText,
|
|
87
|
+
`构建文件:已推送对应仓库【${repos}】- 分支【${gitAutoPushReposBranchMap[branch]}】`,
|
|
88
|
+
`构建人:${author}`,
|
|
89
|
+
deployUrl ? `部署系统:${deployUrl}` : ""
|
|
90
|
+
].filter(Boolean).join("\n");
|
|
86
91
|
} else {
|
|
87
92
|
content = `${publishText}\n构建文件下载地址:${GITPATH}\n${webhookExtraText}\n`;
|
|
88
93
|
}
|
package/store/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("../adapters/vue2/store/index.js");
|
package/store/modules/user.js
CHANGED
|
@@ -1,268 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import TokenService from "../../module/TokenService.js";
|
|
3
|
-
|
|
4
|
-
const CONFIG = {
|
|
5
|
-
router: {},
|
|
6
|
-
settings: {},
|
|
7
|
-
login: () => Promise.resolve(),
|
|
8
|
-
getInfo: () => Promise.resolve(),
|
|
9
|
-
redirectRoute: {}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
function init(config = {}) {
|
|
13
|
-
const { settings } = config || {};
|
|
14
|
-
if (Uts.notEmptyObject(settings)) {
|
|
15
|
-
TokenService.init(settings);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (Uts.notEmptyObject(config)) {
|
|
19
|
-
Uts.mergeObjectWithReference(CONFIG, config);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const getDefaultState = () => {
|
|
24
|
-
return {
|
|
25
|
-
token: TokenService.getToken(),
|
|
26
|
-
name: "",
|
|
27
|
-
avatar: "",
|
|
28
|
-
user: {
|
|
29
|
-
id: "",
|
|
30
|
-
email: "",
|
|
31
|
-
header: "",
|
|
32
|
-
level_id: "",
|
|
33
|
-
level_name: "",
|
|
34
|
-
is_active_str: "",
|
|
35
|
-
mobile: "",
|
|
36
|
-
nickname: "",
|
|
37
|
-
role: "",
|
|
38
|
-
username: "",
|
|
39
|
-
company: "",
|
|
40
|
-
affiliation: {
|
|
41
|
-
province: "",
|
|
42
|
-
city: "",
|
|
43
|
-
district: ""
|
|
44
|
-
},
|
|
45
|
-
dimensionality_choices: [],
|
|
46
|
-
merchant_set: [],
|
|
47
|
-
merchantinfo: {},
|
|
48
|
-
map_key: ""
|
|
49
|
-
},
|
|
50
|
-
chatToken: TokenService.getChatToken() // 商家端聊天管理token
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const userModule = {
|
|
55
|
-
namespaced: true,
|
|
56
|
-
state: () => getDefaultState(),
|
|
57
|
-
mutations: {
|
|
58
|
-
RESET_STATE: (state) => {
|
|
59
|
-
Uts.mergeObjectWithReference(state, getDefaultState());
|
|
60
|
-
},
|
|
61
|
-
SET_USER: (state, user) => (state.user = user),
|
|
62
|
-
SET_TOKEN: (state, token) => {
|
|
63
|
-
state.token = token;
|
|
64
|
-
TokenService.setToken(token);
|
|
65
|
-
},
|
|
66
|
-
SET_NAME: (state, name) => {
|
|
67
|
-
state.name = name;
|
|
68
|
-
},
|
|
69
|
-
SET_AVATAR: (state, avatar) => {
|
|
70
|
-
state.avatar = avatar;
|
|
71
|
-
},
|
|
72
|
-
SET_MAPKEY: (state, mapKey) => {
|
|
73
|
-
Uts.storage.set("mapKey", mapKey);
|
|
74
|
-
},
|
|
75
|
-
//邮惠权益商家端聊天管理的登录凭证
|
|
76
|
-
SET_CHAT_TOKEN: (state, token) => {
|
|
77
|
-
state.chatToken = token;
|
|
78
|
-
TokenService.setChatToken(token);
|
|
79
|
-
},
|
|
80
|
-
SET_PERMISSION_CODES: (state, codes) => {
|
|
81
|
-
state.permission_codes = codes || [];
|
|
82
|
-
Uts.storage.set(CONFIG.settings.permissionsCodeKey, codes);
|
|
83
|
-
},
|
|
84
|
-
UPDATE_ROUTES: (state, menus_permission_codes) => {
|
|
85
|
-
const constantRoutes = CONFIG?.router?.options?.routes || [];
|
|
86
|
-
updateRoutesPermission(constantRoutes, menus_permission_codes);
|
|
87
|
-
CONFIG?.router?.resetRouter?.(constantRoutes);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
actions: {
|
|
91
|
-
login({ commit }, userInfo) {
|
|
92
|
-
const { mobile, sms_code } = userInfo;
|
|
93
|
-
return new Promise((resolve, reject) => {
|
|
94
|
-
CONFIG?.login?.({
|
|
95
|
-
mobile: mobile,
|
|
96
|
-
sms_code: sms_code
|
|
97
|
-
})
|
|
98
|
-
.then((response) => {
|
|
99
|
-
commit("SET_TOKEN", response.token);
|
|
100
|
-
resolve();
|
|
101
|
-
})
|
|
102
|
-
.catch((error) => {
|
|
103
|
-
reject(error);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
getInfo({ commit, state }) {
|
|
109
|
-
return new Promise((resolve, reject) => {
|
|
110
|
-
CONFIG.getInfo(state.token)
|
|
111
|
-
.then((response) => {
|
|
112
|
-
if (!response) {
|
|
113
|
-
reject("验证失败,请重新登录。");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const {
|
|
117
|
-
name,
|
|
118
|
-
header,
|
|
119
|
-
map_key,
|
|
120
|
-
merchantinfo,
|
|
121
|
-
permission_codes = [],
|
|
122
|
-
menus,
|
|
123
|
-
menus_permission_codes = Uts.pluck(menus, "path") || []
|
|
124
|
-
} = response;
|
|
125
|
-
const { service_token } = merchantinfo || {};
|
|
126
|
-
const fullePermissionCodes = [...permission_codes, ...menus_permission_codes];
|
|
127
|
-
|
|
128
|
-
commit("SET_USER", response);
|
|
129
|
-
commit("SET_NAME", name);
|
|
130
|
-
commit("SET_AVATAR", header);
|
|
131
|
-
commit("SET_MAPKEY", map_key);
|
|
132
|
-
|
|
133
|
-
if (service_token) {
|
|
134
|
-
commit("SET_CHAT_TOKEN", service_token);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
CONFIG.settings.permissionsCodeKey &&
|
|
139
|
-
JSON.stringify(fullePermissionCodes) !==
|
|
140
|
-
JSON.stringify(Uts.storage.get(CONFIG.settings.permissionsCodeKey))
|
|
141
|
-
) {
|
|
142
|
-
commit("SET_PERMISSION_CODES", fullePermissionCodes);
|
|
143
|
-
}
|
|
144
|
-
commit("UPDATE_ROUTES", menus_permission_codes);
|
|
145
|
-
resolve({ ...response, PMRedirectPath: CONFIG.redirectRoute.redirect });
|
|
146
|
-
})
|
|
147
|
-
.catch((error) => {
|
|
148
|
-
reject(error);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
logout({ commit, state }, payload) {
|
|
154
|
-
return new Promise((resolve, reject) => {
|
|
155
|
-
TokenService.removeAllTokens();
|
|
156
|
-
commit("RESET_STATE");
|
|
157
|
-
commit("SET_MAPKEY", "");
|
|
158
|
-
commit("SET_CHAT_TOKEN", "");
|
|
159
|
-
commit("SET_PERMISSION_CODES", "");
|
|
160
|
-
|
|
161
|
-
if (payload?.redirectLogin) {
|
|
162
|
-
CONFIG?.router?.push?.("/login");
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (TokenService.getUrlToken()) {
|
|
166
|
-
TokenService.removeUrlToken();
|
|
167
|
-
}
|
|
168
|
-
resolve();
|
|
169
|
-
});
|
|
170
|
-
},
|
|
171
|
-
|
|
172
|
-
resetToken({ commit }) {
|
|
173
|
-
return new Promise((resolve) => {
|
|
174
|
-
commit("SET_TOKEN", "");
|
|
175
|
-
commit("SET_MAPKEY", "");
|
|
176
|
-
commit("RESET_STATE");
|
|
177
|
-
resolve();
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
refreshToken({ commit }, { token }) {
|
|
182
|
-
return new Promise((resolve, reject) => {
|
|
183
|
-
commit("SET_TOKEN", token);
|
|
184
|
-
resolve();
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// 递归更新路由权限
|
|
191
|
-
// 递归应用路由权限(设置 hidden)
|
|
192
|
-
const applyRoutesPermission = (routes = []) => {
|
|
193
|
-
routes.forEach((route) => {
|
|
194
|
-
if (route.meta?.permission && !route.hidden) {
|
|
195
|
-
route.hidden = !Uts.getPM(route.meta.permission);
|
|
196
|
-
}
|
|
197
|
-
if (route.children?.length) {
|
|
198
|
-
applyRoutesPermission(route.children);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// 深度优先查找第一个可访问的叶子路由完整路径
|
|
204
|
-
const getFirstAccessiblePath = (routes = [], parentPath = "") => {
|
|
205
|
-
for (const route of routes) {
|
|
206
|
-
if (route.hidden || !route.path) continue;
|
|
207
|
-
|
|
208
|
-
// 绝对路径直接用,相对路径拼接父路径
|
|
209
|
-
const fullPath = route.path.startsWith("/")
|
|
210
|
-
? route.path
|
|
211
|
-
: parentPath
|
|
212
|
-
? `${parentPath}/${route.path}`
|
|
213
|
-
: route.path;
|
|
214
|
-
|
|
215
|
-
if (route.children?.length) {
|
|
216
|
-
const childPath = getFirstAccessiblePath(route.children, fullPath);
|
|
217
|
-
if (childPath) return childPath;
|
|
218
|
-
} else {
|
|
219
|
-
return fullPath;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return "";
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// 更新路由权限并设置重定向
|
|
226
|
-
const findAccessibleRouteByPath = (routes = [], targetPath, parentPath = "") => {
|
|
227
|
-
if (!targetPath) return null;
|
|
228
|
-
|
|
229
|
-
for (const route of routes) {
|
|
230
|
-
if (route.hidden || !route.path) continue;
|
|
231
|
-
|
|
232
|
-
const fullPath = route.path.startsWith("/")
|
|
233
|
-
? route.path
|
|
234
|
-
: parentPath
|
|
235
|
-
? `${parentPath}/${route.path}`
|
|
236
|
-
: route.path;
|
|
237
|
-
|
|
238
|
-
if (fullPath === targetPath) {
|
|
239
|
-
return route;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (route.children?.length) {
|
|
243
|
-
const matched = findAccessibleRouteByPath(route.children, targetPath, fullPath);
|
|
244
|
-
if (matched) return matched;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return null;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const updateRoutesPermission = (routes = []) => {
|
|
252
|
-
applyRoutesPermission(routes);
|
|
253
|
-
|
|
254
|
-
const redirectRoute = routes.find((r) => r.path === "");
|
|
255
|
-
if (redirectRoute) {
|
|
256
|
-
const availableRoutes = routes.filter((r) => r.path !== "");
|
|
257
|
-
const initRoutePath = CONFIG.settings?.projectConfig?.initRoutePath;
|
|
258
|
-
const initRoute = findAccessibleRouteByPath(availableRoutes, initRoutePath);
|
|
259
|
-
const firstPath = getFirstAccessiblePath(availableRoutes);
|
|
260
|
-
redirectRoute.redirect = initRoute ? initRoutePath : firstPath || "*";
|
|
261
|
-
CONFIG.redirectRoute = redirectRoute;
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
export default {
|
|
266
|
-
...userModule,
|
|
267
|
-
init
|
|
268
|
-
};
|
|
1
|
+
export { default } from "../../adapters/vue2/store/modules/user.js";
|