@infly/libs 2.0.43 → 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
package/module/REST.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REST HTTP 客户端(Vue 2 / axios 生态)
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ 本模块是 Vue 2 生态专用 axios 封装(依赖 process.env.VUE_APP_BASE_API、
|
|
5
|
+
* window.location、TokenService),与 @infly/ts-libs 的 createHttpClient
|
|
6
|
+
* (框架无关 fetch 客户端)是并行实现,非代码重复。
|
|
7
|
+
*
|
|
8
|
+
* 新项目(React/非 Vue 生态)请使用 @infly/ts-libs createHttpClient。
|
|
9
|
+
*/
|
|
1
10
|
import axios from "axios";
|
|
2
11
|
import Uts from "./Uts.js";
|
|
3
12
|
import TokenService from "./TokenService.js";
|
|
4
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
matchesConfiguredBaseURL,
|
|
15
|
+
resolveInternalServiceURL
|
|
16
|
+
} from "./cjs/request-url-rules.cjs";
|
|
17
|
+
import {
|
|
18
|
+
normalizeErrorPayload,
|
|
19
|
+
resolveStatusErrorMessage
|
|
20
|
+
} from "./cjs/rest-error-rules.cjs";
|
|
5
21
|
|
|
6
22
|
const baseURL = process.env.VUE_APP_BASE_API;
|
|
7
23
|
const { env } = Uts.getEnv() || {};
|
|
@@ -28,7 +44,7 @@ function remapLocalhostToCurrentHost(url) {
|
|
|
28
44
|
|
|
29
45
|
parsed.hostname = window.location.hostname;
|
|
30
46
|
return parsed.toString();
|
|
31
|
-
} catch
|
|
47
|
+
} catch {
|
|
32
48
|
return normalized;
|
|
33
49
|
}
|
|
34
50
|
}
|
|
@@ -66,6 +82,7 @@ export function createNotifyDedup(fn, ttl = 500) {
|
|
|
66
82
|
* @param {Function} config.onLogout 登出回调
|
|
67
83
|
* @param {Object} config.notify Message-like 对象(如 ElementUI Message),传入后自动应用去重并构建 onNotify
|
|
68
84
|
* @param {Function} config.onNotify 自定义通知回调;若传入 Message-like 对象也可自动识别
|
|
85
|
+
* @param {String[]} config.productionBaseURLs 由应用注入的正式 API 基地址;测试环境命中时告警
|
|
69
86
|
* @returns {AxiosInstance}
|
|
70
87
|
*/
|
|
71
88
|
export function createService(config) {
|
|
@@ -78,11 +95,12 @@ export function createService(config) {
|
|
|
78
95
|
notify,
|
|
79
96
|
onNotify: rawOnNotify,
|
|
80
97
|
getTokenFunc = "getToken",
|
|
81
|
-
internalServiceURLRules = []
|
|
98
|
+
internalServiceURLRules = [],
|
|
99
|
+
productionBaseURLs = []
|
|
82
100
|
} = config || {};
|
|
83
101
|
// 统一在 REST 内部处理 baseURL,避免业务项目重复实现主机替换逻辑。
|
|
84
102
|
const resolvedBaseURL = resolveServiceBaseURL(customBaseURL);
|
|
85
|
-
const isProdAPI =
|
|
103
|
+
const isProdAPI = matchesConfiguredBaseURL(resolvedBaseURL, productionBaseURLs);
|
|
86
104
|
const service = axios.create({ baseURL: resolvedBaseURL });
|
|
87
105
|
|
|
88
106
|
// 统一处理 notify 与 onNotify:
|
|
@@ -165,27 +183,21 @@ export function createService(config) {
|
|
|
165
183
|
(error) => {
|
|
166
184
|
const { response, request } = error || {};
|
|
167
185
|
const { status, data } = response || {};
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
const errorMsg =
|
|
186
|
+
const normalizedData = Uts.transArrayBufferToObj(data);
|
|
187
|
+
const backendErrorMsg = normalizeErrorPayload(normalizedData);
|
|
188
|
+
const errorMsg = backendErrorMsg || `请求失败(${status})`;
|
|
189
|
+
|
|
190
|
+
// 让仍按 data.error 读取错误的旧调用方也能兼容 detail/message/msg 返回。
|
|
191
|
+
if (response && normalizedData !== undefined) {
|
|
192
|
+
response.data = normalizedData;
|
|
193
|
+
}
|
|
171
194
|
|
|
172
195
|
// 添加标识,表示错误已被拦截器处理
|
|
173
196
|
error.handledByInterceptor = true;
|
|
174
197
|
|
|
175
|
-
// HTTP 状态码 → 固定提示语映射(400 直接用后端返回的 errorMsg)
|
|
176
|
-
const STATUS_MESSAGES = {
|
|
177
|
-
400: errorMsg,
|
|
178
|
-
401: "登录信息已过期,请重新登录",
|
|
179
|
-
403: "您没有权限访问,请联系管理员",
|
|
180
|
-
500: errorMsg || "服务器内部错误,请联系开发人员",
|
|
181
|
-
502: "网关错误,请稍后重试或联系开发人员",
|
|
182
|
-
503: "服务暂时不可用,请稍后重试",
|
|
183
|
-
504: "网关超时,请稍后重试或联系开发人员"
|
|
184
|
-
};
|
|
185
|
-
|
|
186
198
|
// 按优先级确定最终提示语,合并为一次 handleNotify 调用
|
|
187
199
|
const notifyMsg =
|
|
188
|
-
|
|
200
|
+
resolveStatusErrorMessage(status, normalizedData) ??
|
|
189
201
|
(response ? errorMsg : null) ??
|
|
190
202
|
(request ? "网络请求失败,请检查网络连接" : null) ??
|
|
191
203
|
(error.message || "请求配置错误");
|
package/module/TokenService.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token 服务(Vue 2 / localStorage 生态)
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ 本模块是 Vue 2 生态专用(localStorage + cookie + 多 key 支持),
|
|
5
|
+
* 与 @infly/ts-libs 的 createStorageTokenStore(框架无关 Token 抽象)
|
|
6
|
+
* 是并行实现,非代码重复。
|
|
7
|
+
*
|
|
8
|
+
* 新项目(React/非 Vue 生态)请使用 @infly/ts-libs createStorageTokenStore。
|
|
9
|
+
*/
|
|
1
10
|
// TokenService.js
|
|
2
11
|
import Uts from "./Uts"; // 假设Uts工具类在同级目录或可访问路径
|
|
3
12
|
|