@base-web-kits/base-tools-web 1.0.2-alpha.1 → 1.0.2-alpha.3
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/dist/base-tools-web.umd.global.js +8 -7
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/config/index.d.ts +5 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/index.cjs +9 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/network/request.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/web/config/index.ts +2 -2
- package/src/web/network/request.ts +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/web/network/request.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAiB,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9F,cAAc,aAAa,CAAC;AAK5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/web/network/request.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAiB,iBAAiB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9F,cAAc,aAAa,CAAC;AAK5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;WAmL9D,WAAW;EAMxC"}
|
package/package.json
CHANGED
package/src/web/config/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type AppConfig = {
|
|
2
2
|
/** 全局 Toast 提示 */
|
|
3
|
-
toast?: (msg: string) => void;
|
|
3
|
+
toast?: (option: { msg: string; status: 'success' | 'fail' }) => void;
|
|
4
4
|
/** 显示全局 Loading */
|
|
5
5
|
showLoading?: () => void;
|
|
6
6
|
/** 隐藏全局 Loading */
|
|
@@ -46,6 +46,6 @@ export function getAppConfig() {
|
|
|
46
46
|
/**
|
|
47
47
|
* 初始化应用配置 (在入口文件设置)
|
|
48
48
|
*/
|
|
49
|
-
export function
|
|
49
|
+
export function setBaseToolsConfig(newConfig: AppConfig) {
|
|
50
50
|
Object.assign(appConfig, newConfig);
|
|
51
51
|
}
|
|
@@ -225,22 +225,23 @@ export function request<T, D extends RequestData = RequestData>(config: RequestC
|
|
|
225
225
|
appConfig.toLogin?.(); // 放在后面,确保reject执行后再跳转登录
|
|
226
226
|
} else {
|
|
227
227
|
// 业务错误
|
|
228
|
-
if (toastError && msg) appConfig.toast?.(msg);
|
|
228
|
+
if (toastError && msg) appConfig.toast?.({ status: 'fail', msg });
|
|
229
229
|
reject(res);
|
|
230
230
|
}
|
|
231
231
|
} catch (e) {
|
|
232
|
+
const status = 'fail';
|
|
232
233
|
const isAbortError = e instanceof DOMException && e.name === 'AbortError'; // 取消请求不视为错误
|
|
233
234
|
|
|
234
235
|
if (isAbortError && isTimeout) {
|
|
235
|
-
if (toastError) appConfig.toast?.('请求超时');
|
|
236
|
+
if (toastError) appConfig.toast?.({ status, msg: '请求超时' });
|
|
236
237
|
const timeoutError = new Error('Request Timeout');
|
|
237
|
-
logRequestInfo({ status
|
|
238
|
+
logRequestInfo({ status, config: logConfig, startTime, e: timeoutError });
|
|
238
239
|
reject(timeoutError);
|
|
239
240
|
return;
|
|
240
241
|
}
|
|
241
242
|
|
|
242
|
-
if (!isAbortError && toastError) appConfig.toast?.('网络请求失败');
|
|
243
|
-
logRequestInfo({ status
|
|
243
|
+
if (!isAbortError && toastError) appConfig.toast?.({ status, msg: '网络请求失败' });
|
|
244
|
+
logRequestInfo({ status, config: logConfig, startTime, e });
|
|
244
245
|
reject(e);
|
|
245
246
|
} finally {
|
|
246
247
|
if (timeoutId) clearTimeout(timeoutId);
|