@tushi11/elpis 1.0.31 → 1.0.33
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/app/pages/common/curl.js
CHANGED
|
@@ -64,9 +64,30 @@ const curl = ({
|
|
|
64
64
|
pageConfigs?.requestSetting?.proxyOption[mergedRequestOptions?.proxyIndex || 0];
|
|
65
65
|
if (tokenName && tokenKey) {
|
|
66
66
|
const data = window.localStorage.getItem(tokenKey);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (data) {
|
|
68
|
+
const { value: token } = JSON.parse(data);
|
|
69
|
+
headers[tokenName] = token;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// try {
|
|
73
|
+
// const data = window.localStorage.getItem(tokenKey);
|
|
74
|
+
// // 检查 data 是否存在且不为空
|
|
75
|
+
// if (!data) {
|
|
76
|
+
// // 可选:如果需要提示 token 不存在,可添加 feedback.msgWarning('未找到登录信息');
|
|
77
|
+
// return; // 或跳过设置 token
|
|
78
|
+
// }
|
|
79
|
+
// // 解析 JSON 并容错
|
|
80
|
+
// const parsedData = JSON.parse(data);
|
|
81
|
+
// // 检查解析后的数据是否为对象且存在 value 属性
|
|
82
|
+
// if (parsedData && typeof parsedData === 'object' && 'value' in parsedData) {
|
|
83
|
+
// headers[tokenName] = parsedData.value;
|
|
84
|
+
// } else {
|
|
85
|
+
// feedback.msgWarning('登录信息格式错误');
|
|
86
|
+
// }
|
|
87
|
+
// } catch (error) {
|
|
88
|
+
// // 捕获 JSON 解析错误或其他异常
|
|
89
|
+
// feedback.msgError(`处理登录信息失败: ${error.message}`);
|
|
90
|
+
// }
|
|
70
91
|
}
|
|
71
92
|
|
|
72
93
|
// 处理请求头
|
|
@@ -76,7 +76,11 @@ const axiosHooks = {
|
|
|
76
76
|
async responseInterceptorsHook(response) {
|
|
77
77
|
NProgress.done();
|
|
78
78
|
// 从请求配置的自定义选项中获取响应处理开关
|
|
79
|
-
const {
|
|
79
|
+
const {
|
|
80
|
+
responseType = 'dtoResponse',
|
|
81
|
+
showLoading,
|
|
82
|
+
showMsgError,
|
|
83
|
+
} = response?.config?.requestOptions;
|
|
80
84
|
|
|
81
85
|
// 关闭全局加载中
|
|
82
86
|
if (showLoading) {
|
|
@@ -141,7 +145,9 @@ const axiosHooks = {
|
|
|
141
145
|
};
|
|
142
146
|
|
|
143
147
|
const errorMsg = errorMessages[code] || errorMessages.default;
|
|
144
|
-
|
|
148
|
+
if (showMsgError) {
|
|
149
|
+
feedback.msgError(errorMsg);
|
|
150
|
+
}
|
|
145
151
|
return Promise.resolve({ success: false, code, message: errorMsg });
|
|
146
152
|
}
|
|
147
153
|
// async 函数会自动将 “非 Promise 返回值” 用 Promise.resolve() 包装,因此 return 普通对象 等价于 return Promise.resolve(普通对象) // return 普通对象 更简洁(少写冗余代码),且语义清晰
|
|
@@ -175,7 +181,7 @@ const axiosHooks = {
|
|
|
175
181
|
* 可通过请求时的自定义配置覆盖默认值
|
|
176
182
|
*/
|
|
177
183
|
const {
|
|
178
|
-
requestSetting: { timeout, proxyIndex, proxyOption = [] } = {},
|
|
184
|
+
requestSetting: { timeout, proxyIndex, proxyOption = [], showMsgError = true } = {},
|
|
179
185
|
sysSetting: { version } = {},
|
|
180
186
|
} = pageConfigs;
|
|
181
187
|
const proxyConfig = proxyOption[proxyIndex] || {};
|
|
@@ -200,6 +206,7 @@ const defaultOptions = {
|
|
|
200
206
|
retryCount: 2, // 最大重试次数(默认2次)
|
|
201
207
|
showLoading: false, // 是否显示全局的加载中(默认不显示)
|
|
202
208
|
loadingText: 'Loading...', // 加载中的提示文字
|
|
209
|
+
showMsgError, // 是否显示错误消息(默认显示)
|
|
203
210
|
},
|
|
204
211
|
};
|
|
205
212
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tushi11/elpis",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"postcss": "^8.4.41",
|
|
69
69
|
"postcss-loader": "^8.1.1",
|
|
70
70
|
"postcss-pxtorem": "^6.1.0",
|
|
71
|
+
"koa-proxy": "^1.0.0-alpha.3",
|
|
71
72
|
"sass": "^1.77.8",
|
|
72
73
|
"sass-loader": "^16.0.5",
|
|
73
74
|
"style-loader": "^0.14.1",
|
|
@@ -101,7 +102,6 @@
|
|
|
101
102
|
"eslint-plugin-import": "^2.28.1",
|
|
102
103
|
"eslint-plugin-vue": "^9.17.0",
|
|
103
104
|
"ghooks": "~1.0.3",
|
|
104
|
-
"koa-proxy": "^1.0.0-alpha.3",
|
|
105
105
|
"mocha": "^6.1.4",
|
|
106
106
|
"supertest": "^4.0.2",
|
|
107
107
|
"tailwindcss": "^3.4.10",
|