@dazhicheng/utils 1.0.3 → 1.0.5

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.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * HTTP 错误处理模块
3
+ *
4
+ * 提供统一的 HTTP 请求错误处理机制
5
+ *
6
+ * ## 主要功能
7
+ *
8
+ * - 自定义 HttpError 错误类,封装错误信息、状态码、时间戳等
9
+ * - 错误拦截和转换,将 Axios 错误转换为标准的 HttpError
10
+ * - 错误消息国际化处理,根据状态码返回对应的多语言错误提示
11
+ * - 错误日志记录,便于问题追踪和调试
12
+ * - 错误和成功消息的统一展示
13
+ * - 类型守卫函数,用于判断错误类型
14
+ *
15
+ * ## 使用场景
16
+ *
17
+ * - HTTP 请求拦截器中统一处理错误
18
+ * - 业务代码中捕获和处理特定错误
19
+ * - 错误日志收集和上报
20
+ *
21
+ * @module utils/http/error
22
+ * @author Art Design Pro Team
23
+ */
24
+ import { AxiosError } from "axios";
25
+ export interface ErrorResponse {
26
+ /** 错误状态码 */
27
+ code: number;
28
+ /** 错误消息 */
29
+ msg: string;
30
+ /** 错误附加数据 */
31
+ data?: unknown;
32
+ }
33
+ export interface ErrorLogData {
34
+ /** 错误状态码 */
35
+ code: number;
36
+ /** 错误消息 */
37
+ message: string;
38
+ /** 错误附加数据 */
39
+ data?: unknown;
40
+ /** 错误发生时间戳 */
41
+ timestamp: string;
42
+ /** 请求 URL */
43
+ url?: string;
44
+ /** 请求方法 */
45
+ method?: string;
46
+ /** 错误堆栈信息 */
47
+ stack?: string;
48
+ }
49
+ export declare class HttpError extends Error {
50
+ readonly code: number;
51
+ readonly data?: unknown;
52
+ readonly timestamp: string;
53
+ readonly url?: string;
54
+ readonly method?: string;
55
+ constructor(message: string, code: number, options?: {
56
+ data?: unknown;
57
+ url?: string;
58
+ method?: string;
59
+ });
60
+ toLogData(): ErrorLogData;
61
+ }
62
+ /**
63
+ * 处理错误
64
+ * @param error 错误对象
65
+ * @returns 错误对象
66
+ */
67
+ export declare function handleError(error: AxiosError<ErrorResponse>): never;
68
+ /**
69
+ * 显示错误消息
70
+ * @param error 错误对象
71
+ * @param showMessage 是否显示错误消息
72
+ */
73
+ export declare function showError(error: HttpError, showMessage?: boolean): void;
74
+ /**
75
+ * 显示成功消息
76
+ * @param message 成功消息
77
+ * @param showMessage 是否显示消息
78
+ */
79
+ export declare function showSuccess(message: string, showMessage?: boolean): void;
80
+ /**
81
+ * 判断是否为 HttpError 类型
82
+ * @param error 错误对象
83
+ * @returns 是否为 HttpError 类型
84
+ */
85
+ export declare const isHttpError: (error: unknown) => error is HttpError;
86
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../../packages/utils/src/axios/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAKnC,MAAM,WAAW,aAAa;IAC5B,YAAY;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAGD,MAAM,WAAW,YAAY;IAC3B,YAAY;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,IAAI,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,GAAG,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAG9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAWI,SAAS,IAAI,YAAY;CAWjC;AAuBD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,aAAa,CAAC,GAAG,KAAK,CA0BnE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,GAAE,OAAc,GAAG,IAAI,CAM7E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,GAAE,OAAc,GAAG,IAAI,CAI9E;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAErD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { TtHttpReturnType } from "./type";
2
+ /** 退出登录函数 */
3
+ export declare function TtHttp(config: any): TtHttpReturnType;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/utils/src/axios/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAOxD,aAAa;AAEb,wBAAgB,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,gBAAgB,CAgQpD"}
@@ -0,0 +1,2 @@
1
+ export declare const fourDotsSpinnerSvg = "\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"40\" viewBox=\"0 0 40 40\">\n <style>\n .spinner {\n transform-origin: 20px 20px;\n animation: rotate 1.6s linear infinite;\n }\n .dot {\n fill: var(--theme-color);\n animation: fade 1.6s infinite;\n }\n .dot:nth-child(1) { animation-delay: 0s; }\n .dot:nth-child(2) { animation-delay: 0.5s; }\n .dot:nth-child(3) { animation-delay: 1s; }\n .dot:nth-child(4) { animation-delay: 1.5s; }\n @keyframes rotate {\n 100% { transform: rotate(360deg); }\n }\n @keyframes fade {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n </style>\n <g class=\"spinner\">\n <circle class=\"dot\" cx=\"20\" cy=\"8\" r=\"4\"/>\n <circle class=\"dot\" cx=\"32\" cy=\"20\" r=\"4\"/>\n <circle class=\"dot\" cx=\"20\" cy=\"32\" r=\"4\"/>\n <circle class=\"dot\" cx=\"8\" cy=\"20\" r=\"4\"/>\n </g>\n </svg>\n";
2
+ //# sourceMappingURL=loadinSvg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadinSvg.d.ts","sourceRoot":"","sources":["../../../../packages/utils/src/axios/loadinSvg.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,8+BA8B9B,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const loadingService: {
2
+ /**
3
+ * 显示 loading
4
+ * @returns 关闭 loading 的函数
5
+ */
6
+ showLoading(): () => void;
7
+ /**
8
+ * 隐藏 loading
9
+ */
10
+ hideLoading(): void;
11
+ };
12
+ //# sourceMappingURL=loading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loading.d.ts","sourceRoot":"","sources":["../../../../packages/utils/src/axios/loading.ts"],"names":[],"mappings":"AAyDA,eAAO,MAAM,cAAc;IACzB;;;OAGG;mBACY,MAAM,IAAI;IAYzB;;OAEG;mBACY,IAAI;CAMpB,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * 接口状态码
3
+ */
4
+ export declare enum ApiStatus {
5
+ success = 200,// 成功
6
+ success1 = 0,// 成功
7
+ error = 400,// 错误
8
+ unauthorized = 401,// 未授权
9
+ forbidden = 403,// 禁止访问
10
+ notFound = 404,// 未找到
11
+ methodNotAllowed = 405,// 方法不允许
12
+ requestTimeout = 408,// 请求超时
13
+ internalServerError = 500,// 服务器错误
14
+ notImplemented = 501,// 未实现
15
+ badGateway = 502,// 网关错误
16
+ serviceUnavailable = 503,// 服务不可用
17
+ gatewayTimeout = 504,// 网关超时
18
+ httpVersionNotSupported = 505,// HTTP版本不支持
19
+ NEED_REFRESH_TOKEN = 1001,// 需要刷新令牌
20
+ API_NO_AUTH = 1002,// 接口未授权
21
+ INVALID_TOKEN = 1005
22
+ }
23
+ export declare enum HttpMsg {
24
+ badGateway = "\u7F51\u5173\u9519\u8BEF\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",
25
+ forbidden = "\u7981\u6B62\u8BBF\u95EE\u8BE5\u8D44\u6E90",
26
+ gatewayTimeout = "\u7F51\u5173\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",
27
+ internalServerError = "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",
28
+ methodNotAllowed = "\u8BF7\u6C42\u65B9\u6CD5\u4E0D\u5141\u8BB8",
29
+ networkError = "\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5",
30
+ notFound = "\u8BF7\u6C42\u7684\u8D44\u6E90\u4E0D\u5B58\u5728",
31
+ requestCancelled = "\u8BF7\u6C42\u5DF2\u53D6\u6D88",
32
+ requestConfigError = "\u8BF7\u6C42\u914D\u7F6E\u9519\u8BEF",
33
+ requestFailed = "\u8BF7\u6C42\u5931\u8D25",
34
+ requestTimeout = "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",
35
+ serviceUnavailable = "\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5",
36
+ unauthorized = "\u672A\u6388\u6743\u8BBF\u95EE\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55"
37
+ }
38
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../packages/utils/src/axios/status.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,SAAS;IACnB,OAAO,MAAM,CAAE,KAAK;IACpB,QAAQ,IAAI,CAAE,KAAK;IACnB,KAAK,MAAM,CAAE,KAAK;IAClB,YAAY,MAAM,CAAE,MAAM;IAC1B,SAAS,MAAM,CAAE,OAAO;IACxB,QAAQ,MAAM,CAAE,MAAM;IACtB,gBAAgB,MAAM,CAAE,QAAQ;IAChC,cAAc,MAAM,CAAE,OAAO;IAC7B,mBAAmB,MAAM,CAAE,QAAQ;IACnC,cAAc,MAAM,CAAE,MAAM;IAC5B,UAAU,MAAM,CAAE,OAAO;IACzB,kBAAkB,MAAM,CAAE,QAAQ;IAClC,cAAc,MAAM,CAAE,OAAO;IAC7B,uBAAuB,MAAM,CAAE,YAAY;IAC3C,kBAAkB,OAAO,CAAE,SAAS;IACpC,WAAW,OAAO,CAAE,QAAQ;IAC5B,aAAa,OAAO;CACrB;AAGD,oBAAY,OAAO;IACjB,UAAU,iEAAe;IACzB,SAAS,+CAAY;IACrB,cAAc,iEAAe;IAC7B,mBAAmB,mFAAkB;IACrC,gBAAgB,+CAAY;IAC5B,YAAY,yFAAmB;IAC/B,QAAQ,qDAAa;IACrB,gBAAgB,mCAAU;IAC1B,kBAAkB,yCAAW;IAC7B,aAAa,6BAAS;IACtB,cAAc,iEAAe;IAC7B,kBAAkB,mFAAkB;IACpC,YAAY,uEAAgB;CAC7B"}
@@ -0,0 +1,24 @@
1
+ import { AxiosRequestConfig } from "axios";
2
+ /** 基础 API 响应结构 */
3
+ export interface BaseResponse<T = unknown> {
4
+ /** 状态码 */
5
+ code: number;
6
+ /** 消息 */
7
+ msg: string;
8
+ /** 数据 */
9
+ data: T;
10
+ }
11
+ export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
12
+ showErrorMessage?: boolean;
13
+ showSuccessMessage?: boolean;
14
+ hideLoading?: boolean;
15
+ }
16
+ export interface TtHttpReturnType {
17
+ get<T>(config: Omit<ExtendedAxiosRequestConfig, "method">): Promise<T>;
18
+ post<T>(config: Omit<ExtendedAxiosRequestConfig, "method">): Promise<T>;
19
+ put<T>(config: Omit<ExtendedAxiosRequestConfig, "method">): Promise<T>;
20
+ del<T>(config: Omit<ExtendedAxiosRequestConfig, "method">): Promise<T>;
21
+ request<T>(config: ExtendedAxiosRequestConfig): Promise<T>;
22
+ logOut: () => void;
23
+ }
24
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../packages/utils/src/axios/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC3C,kBAAkB;AAClB,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,UAAU;IACV,IAAI,EAAE,MAAM,CAAC;IACb,SAAS;IACT,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS;IACT,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACxE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB"}
package/dist/file.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @param res 响应 { data: Blob, ... }
3
+ * @param type 类型
4
+ */
5
+ interface HttpResponse<T> {
6
+ data: T;
7
+ headers: Record<string, string>;
8
+ status: number;
9
+ statusText: string;
10
+ }
11
+ export declare const downloadFile: (res: HttpResponse<Blob>, type: string) => void;
12
+ export {};
13
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,UAAU,YAAY,CAAC,CAAC;IACtB,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AACD,eAAO,MAAM,YAAY,GAAI,KAAK,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,MAAM,SAwBjE,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";exports.capitalize=function(t){return t.charAt(0).toUpperCase()+t.slice(1)},exports.divide=function(t,r){return t/r},exports.multiply=function(t,r){return t*r},exports.subtract=function(t,r){return t-r},exports.sum=function(t,r){return t+r},exports.trim=function(t){return t.trim()};
1
+ "use strict";var e=require("axios"),t=require("element-plus"),r=require("vue");const n=(e,t)=>{try{const r=new Blob([e.data],{type:t}),n=document.createElement("a"),o=(window.URL||window.webkitURL).createObjectURL(r);n.href=o;let a=((e.headers["content-disposition"]||"").split("=")||[]).at(-1)||"";a=a?decodeURI(a.replace(/"/g,"")):"";const s=a?.split("''");a=s.at(-1)||"",n.download=a,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),window.URL.revokeObjectURL(o)}catch(e){console.log(e)}};var o,a;!function(e){e[e.success=200]="success",e[e.success1=0]="success1",e[e.error=400]="error",e[e.unauthorized=401]="unauthorized",e[e.forbidden=403]="forbidden",e[e.notFound=404]="notFound",e[e.methodNotAllowed=405]="methodNotAllowed",e[e.requestTimeout=408]="requestTimeout",e[e.internalServerError=500]="internalServerError",e[e.notImplemented=501]="notImplemented",e[e.badGateway=502]="badGateway",e[e.serviceUnavailable=503]="serviceUnavailable",e[e.gatewayTimeout=504]="gatewayTimeout",e[e.httpVersionNotSupported=505]="httpVersionNotSupported",e[e.NEED_REFRESH_TOKEN=1001]="NEED_REFRESH_TOKEN",e[e.API_NO_AUTH=1002]="API_NO_AUTH",e[e.INVALID_TOKEN=1005]="INVALID_TOKEN"}(o||(o={})),function(e){e.badGateway="网关错误,请稍后重试",e.forbidden="禁止访问该资源",e.gatewayTimeout="网关超时,请稍后重试",e.internalServerError="服务器内部错误,请稍后重试",e.methodNotAllowed="请求方法不允许",e.networkError="网络连接异常,请检查网络连接",e.notFound="请求的资源不存在",e.requestCancelled="请求已取消",e.requestConfigError="请求配置错误",e.requestFailed="请求失败",e.requestTimeout="请求超时,请稍后重试",e.serviceUnavailable="服务暂时不可用,请稍后重试",e.unauthorized="未授权访问,请重新登录"}(a||(a={}));class s extends Error{code;data;timestamp;url;method;constructor(e,t,r){super(e),this.name="HttpError",this.code=t,this.data=r?.data,this.timestamp=(new Date).toISOString(),this.url=r?.url||"",this.method=r?.method||""}toLogData(){return{code:this.code,message:this.message,data:this.data,timestamp:this.timestamp,url:this.url||"",method:this.method||"",stack:this.stack||""}}}function i(e){if("ERR_CANCELED"===e.code)throw console.warn("Request cancelled:",e.message),new s(a.requestCancelled,o.error);const t=e.response?.status,r=e.response?.data?.msg||e.message,n=e.config;if(!e.response)throw new s(a.networkError,o.error,{url:n?.url||"",method:n?.method?.toUpperCase()||""});const i=t?(c=t,{[o.unauthorized]:a.unauthorized,[o.forbidden]:a.forbidden,[o.notFound]:a.notFound,[o.methodNotAllowed]:a.methodNotAllowed,[o.requestTimeout]:a.requestTimeout,[o.internalServerError]:a.internalServerError,[o.badGateway]:a.badGateway,[o.serviceUnavailable]:a.serviceUnavailable,[o.gatewayTimeout]:a.gatewayTimeout}[c]||a.internalServerError):r||a.requestFailed;var c;throw new s(i,t||o.error,{data:e.response.data,url:n?.url||"",method:n?.method?.toUpperCase()||""})}function c(e,r=!0){r&&t.ElMessage.error(e.message),console.error("[HTTP Error]",e.toLogData())}const d=()=>document.documentElement.classList.contains("dark")?"rgba(7, 7, 7, 0.85)":"rgba(255, 255, 255, 0.5)",u={lock:!0,get background(){return d()},svg:'\n <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40">\n <style>\n .spinner {\n transform-origin: 20px 20px;\n animation: rotate 1.6s linear infinite;\n }\n .dot {\n fill: var(--theme-color);\n animation: fade 1.6s infinite;\n }\n .dot:nth-child(1) { animation-delay: 0s; }\n .dot:nth-child(2) { animation-delay: 0.5s; }\n .dot:nth-child(3) { animation-delay: 1s; }\n .dot:nth-child(4) { animation-delay: 1.5s; }\n @keyframes rotate {\n 100% { transform: rotate(360deg); }\n }\n @keyframes fade {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n </style>\n <g class="spinner">\n <circle class="dot" cx="20" cy="8" r="4"/>\n <circle class="dot" cx="32" cy="20" r="4"/>\n <circle class="dot" cx="20" cy="32" r="4"/>\n <circle class="dot" cx="8" cy="20" r="4"/>\n </g>\n </svg>\n',svgViewBox:"0 0 40 40",customClass:"art-loading-fix"};let l=null;const m={showLoading(){if(!l){const e={...u,background:d()};l=t.ElLoading.service(e)}return()=>this.hideLoading()},hideLoading(){l&&(l.close(),l=null)}};exports.TtHttp=function(d){const{router:u,useUserStore:l,VITE_API_URL:h,VITE_WITH_CREDENTIALS:p}=d;let f=!1;const g=["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"];let w=0;function E(){setTimeout(()=>{w--,0===w&&f&&r.nextTick(()=>{m.hideLoading(),f=!1})},0)}let T=!1,y=null;const v=e.create({timeout:6e4,baseURL:"/"+h,withCredentials:"true"===p,validateStatus:e=>e>=200&&e<300,transformResponse:[(e,t)=>{const r=t["content-type"];if(r?.includes("application/json"))try{return JSON.parse(e)}catch{return e}return e}]});function b(e,t){return new s(e,t)}function x(e){const t=b(e||a.unauthorized,o.unauthorized);if(!T)throw T=!0,L(),y=setTimeout(N,3e3),c(t,!0),t;throw t}function N(){T=!1,y&&clearTimeout(y),y=null}v.interceptors.request.use(e=>{const{accessToken:t,info:r}=l();return t&&(e.headers.set("Authorization",t),e.headers.set("token",t),e.headers.set("x-userid-header",r.userId),e.headers.set("x-permission-code-header",u.currentRoute.value.meta.permissionOnlyCode)),e.hideLoading||0!==w||(f=!0,m.showLoading()),w++,!e.data||e.data instanceof FormData||e.headers["Content-Type"]||(e.headers.set("Content-Type","application/json"),e.data=JSON.stringify(e.data)),e},e=>(c(b(a.requestConfigError,o.error)),Promise.reject(e))),v.interceptors.response.use(e=>{E();const t=e.headers["content-type"];if(t?.includes("application/json")){const{code:t,msg:r}=e.data;if([o.success,o.success1].includes(t))return e;throw[o.unauthorized,o.INVALID_TOKEN].includes(t)&&x(r),b(r||a.requestFailed,t)}if(g.includes(t))return n(e,t),e},e=>(E(),e.response?.status===o.unauthorized&&x(),Promise.reject(i(e))));const L=()=>{setTimeout(()=>{l().logOut()},500)};async function S(e,r=0){try{return await async function(e){["POST","PUT"].includes(e.method?.toUpperCase()||"")&&e.params&&!e.data&&(e.data=e.params,e.params=void 0);try{const r=await v.request(e);return e.showSuccessMessage&&r.data.msg&&function(e,r=!0){r&&t.ElMessage.success(e)}(r.data.msg),r.data.data}catch(t){const r=[o.unauthorized,o.NEED_REFRESH_TOKEN].includes(t.code);if(t instanceof s&&!r){c(t,!1!==e.showErrorMessage)}return Promise.reject(t)}}(e)}catch(t){if(t instanceof s&&[o.NEED_REFRESH_TOKEN].includes(t.code)&&!e.url?.includes("/iam/user/refreshToken"))return await l().refreshTokenFunc(),await U(1e3),S(e,r-1);if(r>0&&t instanceof s&&(n=t.code,[o.requestTimeout,o.internalServerError,o.badGateway,o.serviceUnavailable,o.gatewayTimeout].includes(n)))return await U(1e3),S(e,r-1);throw t}var n}function U(e){return new Promise(t=>setTimeout(t,e))}return{...{get:e=>S({...e,method:"GET"}),post:e=>S({...e,method:"POST"}),put:e=>S({...e,method:"PUT"}),del:e=>S({...e,method:"DELETE"}),request:e=>S(e)},logOut:L}},exports.capitalize=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},exports.divide=function(e,t){return e/t},exports.downloadFile=n,exports.multiply=function(e,t){return e*t},exports.subtract=function(e,t){return e-t},exports.sum=function(e,t){return e+t},exports.trim=function(e){return e.trim()};
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/string.ts","../src/math.ts"],"sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nexport function trim(str: string): string {\n return str.trim();\n}","export function sum(a: number, b: number): number {\n return a + b;\n}\n\nexport function multiply(a: number, b: number): number {\n return a * b;\n}\n\nexport function subtract(a: number, b: number): number {\n return a - b;\n}\n\nexport function divide(a: number, b: number): number {\n return a / b;\n}"],"names":["str","charAt","toUpperCase","slice","a","b","trim"],"mappings":"gCAAM,SAAqBA,GACzB,OAAOA,EAAIC,OAAO,GAAGC,cAAgBF,EAAIG,MAAM,EACjD,iBCUM,SAAiBC,EAAWC,GAChC,OAAOD,EAAIC,CACb,mBAVM,SAAmBD,EAAWC,GAClC,OAAOD,EAAIC,CACb,mBAEM,SAAmBD,EAAWC,GAClC,OAAOD,EAAIC,CACb,cAVM,SAAcD,EAAWC,GAC7B,OAAOD,EAAIC,CACb,eDEM,SAAeL,GACnB,OAAOA,EAAIM,MACb"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/file.ts","../src/axios/status.ts","../src/axios/error.ts","../src/axios/loadinSvg.ts","../src/axios/loading.ts","../src/axios/index.ts","../src/string.ts","../src/math.ts"],"sourcesContent":["/**\r\n * @param res 响应 { data: Blob, ... }\r\n * @param type 类型\r\n */\r\n\r\ninterface HttpResponse<T> {\r\n data: T;\r\n headers: Record<string, string>;\r\n status: number;\r\n statusText: string;\r\n}\r\nexport const downloadFile = (res: HttpResponse<Blob>, type: string) => {\r\n try {\r\n // 创建blob对象,解析流数据\r\n const blob = new Blob([res.data], {\r\n type\r\n });\r\n const a = document.createElement(\"a\");\r\n const URL = window.URL || window.webkitURL;\r\n const herf = URL.createObjectURL(blob);\r\n a.href = herf;\r\n const contentDisposition: string[] = (res.headers[\"content-disposition\"] || \"\").split(\"=\") || [];\r\n let fileName = contentDisposition.at(-1) || \"\";\r\n fileName = fileName ? decodeURI(fileName.replace(/\"/g, \"\")) : \"\";\r\n const decodedParts = fileName?.split(\"''\");\r\n fileName = decodedParts.at(-1) || \"\";\r\n a.download = fileName;\r\n a.style.display = \"none\";\r\n document.body.appendChild(a);\r\n a.click();\r\n document.body.removeChild(a);\r\n window.URL.revokeObjectURL(herf);\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n};\r\n","/**\r\n * 接口状态码\r\n */\r\nexport enum ApiStatus {\r\n success = 200, // 成功\r\n success1 = 0, // 成功\r\n error = 400, // 错误\r\n unauthorized = 401, // 未授权\r\n forbidden = 403, // 禁止访问\r\n notFound = 404, // 未找到\r\n methodNotAllowed = 405, // 方法不允许\r\n requestTimeout = 408, // 请求超时\r\n internalServerError = 500, // 服务器错误\r\n notImplemented = 501, // 未实现\r\n badGateway = 502, // 网关错误\r\n serviceUnavailable = 503, // 服务不可用\r\n gatewayTimeout = 504, // 网关超时\r\n httpVersionNotSupported = 505, // HTTP版本不支持\r\n NEED_REFRESH_TOKEN = 1001, // 需要刷新令牌\r\n API_NO_AUTH = 1002, // 接口未授权\r\n INVALID_TOKEN = 1005 // 无效的token\r\n}\r\n\r\n// 错误提示\r\nexport enum HttpMsg {\r\n badGateway = \"网关错误,请稍后重试\",\r\n forbidden = \"禁止访问该资源\",\r\n gatewayTimeout = \"网关超时,请稍后重试\",\r\n internalServerError = \"服务器内部错误,请稍后重试\",\r\n methodNotAllowed = \"请求方法不允许\",\r\n networkError = \"网络连接异常,请检查网络连接\",\r\n notFound = \"请求的资源不存在\",\r\n requestCancelled = \"请求已取消\",\r\n requestConfigError = \"请求配置错误\",\r\n requestFailed = \"请求失败\",\r\n requestTimeout = \"请求超时,请稍后重试\",\r\n serviceUnavailable = \"服务暂时不可用,请稍后重试\",\r\n unauthorized = \"未授权访问,请重新登录\"\r\n}\r\n","/**\r\n * HTTP 错误处理模块\r\n *\r\n * 提供统一的 HTTP 请求错误处理机制\r\n *\r\n * ## 主要功能\r\n *\r\n * - 自定义 HttpError 错误类,封装错误信息、状态码、时间戳等\r\n * - 错误拦截和转换,将 Axios 错误转换为标准的 HttpError\r\n * - 错误消息国际化处理,根据状态码返回对应的多语言错误提示\r\n * - 错误日志记录,便于问题追踪和调试\r\n * - 错误和成功消息的统一展示\r\n * - 类型守卫函数,用于判断错误类型\r\n *\r\n * ## 使用场景\r\n *\r\n * - HTTP 请求拦截器中统一处理错误\r\n * - 业务代码中捕获和处理特定错误\r\n * - 错误日志收集和上报\r\n *\r\n * @module utils/http/error\r\n * @author Art Design Pro Team\r\n */\r\nimport { AxiosError } from \"axios\";\r\nimport { ApiStatus, HttpMsg } from \"./status\";\r\nimport { ElMessage } from \"element-plus\";\r\n\r\n// 错误响应接口\r\nexport interface ErrorResponse {\r\n /** 错误状态码 */\r\n code: number;\r\n /** 错误消息 */\r\n msg: string;\r\n /** 错误附加数据 */\r\n data?: unknown;\r\n}\r\n\r\n// 错误日志数据接口\r\nexport interface ErrorLogData {\r\n /** 错误状态码 */\r\n code: number;\r\n /** 错误消息 */\r\n message: string;\r\n /** 错误附加数据 */\r\n data?: unknown;\r\n /** 错误发生时间戳 */\r\n timestamp: string;\r\n /** 请求 URL */\r\n url?: string;\r\n /** 请求方法 */\r\n method?: string;\r\n /** 错误堆栈信息 */\r\n stack?: string;\r\n}\r\n\r\n// 自定义 HttpError 类\r\nexport class HttpError extends Error {\r\n public readonly code: number;\r\n public readonly data?: unknown;\r\n public readonly timestamp: string;\r\n public readonly url?: string;\r\n public readonly method?: string;\r\n\r\n constructor(\r\n message: string,\r\n code: number,\r\n options?: {\r\n data?: unknown;\r\n url?: string;\r\n method?: string;\r\n }\r\n ) {\r\n super(message);\r\n this.name = \"HttpError\";\r\n this.code = code;\r\n this.data = options?.data;\r\n this.timestamp = new Date().toISOString();\r\n this.url = options?.url || \"\";\r\n this.method = options?.method || \"\";\r\n }\r\n\r\n public toLogData(): ErrorLogData {\r\n return {\r\n code: this.code,\r\n message: this.message,\r\n data: this.data,\r\n timestamp: this.timestamp,\r\n url: this.url || \"\",\r\n method: this.method || \"\",\r\n stack: this.stack || \"\"\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * 获取错误消息\r\n * @param status 错误状态码\r\n * @returns 错误消息\r\n */\r\nconst getErrorMessage = (status: number): string => {\r\n const errorMap: Record<number, string> = {\r\n [ApiStatus.unauthorized]: HttpMsg.unauthorized,\r\n [ApiStatus.forbidden]: HttpMsg.forbidden,\r\n [ApiStatus.notFound]: HttpMsg.notFound,\r\n [ApiStatus.methodNotAllowed]: HttpMsg.methodNotAllowed,\r\n [ApiStatus.requestTimeout]: HttpMsg.requestTimeout,\r\n [ApiStatus.internalServerError]: HttpMsg.internalServerError,\r\n [ApiStatus.badGateway]: HttpMsg.badGateway,\r\n [ApiStatus.serviceUnavailable]: HttpMsg.serviceUnavailable,\r\n [ApiStatus.gatewayTimeout]: HttpMsg.gatewayTimeout\r\n };\r\n\r\n return errorMap[status] || HttpMsg.internalServerError;\r\n};\r\n\r\n/**\r\n * 处理错误\r\n * @param error 错误对象\r\n * @returns 错误对象\r\n */\r\nexport function handleError(error: AxiosError<ErrorResponse>): never {\r\n // 处理取消的请求\r\n if (error.code === \"ERR_CANCELED\") {\r\n console.warn(\"Request cancelled:\", error.message);\r\n throw new HttpError(HttpMsg.requestCancelled, ApiStatus.error);\r\n }\r\n\r\n const statusCode = error.response?.status;\r\n const errorMessage = error.response?.data?.msg || error.message;\r\n const requestConfig = error.config;\r\n\r\n // 处理网络错误\r\n if (!error.response) {\r\n throw new HttpError(HttpMsg.networkError, ApiStatus.error, {\r\n url: requestConfig?.url || \"\",\r\n method: requestConfig?.method?.toUpperCase() || \"\"\r\n });\r\n }\r\n\r\n // 处理 HTTP 状态码错误\r\n const message = statusCode ? getErrorMessage(statusCode) : errorMessage || HttpMsg.requestFailed;\r\n throw new HttpError(message, statusCode || ApiStatus.error, {\r\n data: error.response.data,\r\n url: requestConfig?.url || \"\",\r\n method: requestConfig?.method?.toUpperCase() || \"\"\r\n });\r\n}\r\n\r\n/**\r\n * 显示错误消息\r\n * @param error 错误对象\r\n * @param showMessage 是否显示错误消息\r\n */\r\nexport function showError(error: HttpError, showMessage: boolean = true): void {\r\n if (showMessage) {\r\n ElMessage.error(error.message);\r\n }\r\n // 记录错误日志\r\n console.error(\"[HTTP Error]\", error.toLogData());\r\n}\r\n\r\n/**\r\n * 显示成功消息\r\n * @param message 成功消息\r\n * @param showMessage 是否显示消息\r\n */\r\nexport function showSuccess(message: string, showMessage: boolean = true): void {\r\n if (showMessage) {\r\n ElMessage.success(message);\r\n }\r\n}\r\n\r\n/**\r\n * 判断是否为 HttpError 类型\r\n * @param error 错误对象\r\n * @returns 是否为 HttpError 类型\r\n */\r\nexport const isHttpError = (error: unknown): error is HttpError => {\r\n return error instanceof HttpError;\r\n};\r\n","// 自定义四点旋转SVG\r\nexport const fourDotsSpinnerSvg = `\r\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"40\" viewBox=\"0 0 40 40\">\r\n <style>\r\n .spinner {\r\n transform-origin: 20px 20px;\r\n animation: rotate 1.6s linear infinite;\r\n }\r\n .dot {\r\n fill: var(--theme-color);\r\n animation: fade 1.6s infinite;\r\n }\r\n .dot:nth-child(1) { animation-delay: 0s; }\r\n .dot:nth-child(2) { animation-delay: 0.5s; }\r\n .dot:nth-child(3) { animation-delay: 1s; }\r\n .dot:nth-child(4) { animation-delay: 1.5s; }\r\n @keyframes rotate {\r\n 100% { transform: rotate(360deg); }\r\n }\r\n @keyframes fade {\r\n 0%, 100% { opacity: 1; }\r\n 50% { opacity: 0.5; }\r\n }\r\n </style>\r\n <g class=\"spinner\">\r\n <circle class=\"dot\" cx=\"20\" cy=\"8\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"32\" cy=\"20\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"20\" cy=\"32\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"8\" cy=\"20\" r=\"4\"/>\r\n </g>\r\n </svg>\r\n`;\r\n","/**\r\n * 全局 Loading 加载管理模块\r\n *\r\n * 提供统一的全屏加载动画管理\r\n *\r\n * ## 主要功能\r\n *\r\n * - 全屏 Loading 显示和隐藏\r\n * - 自动适配明暗主题背景色\r\n * - 自定义 SVG 加载动画\r\n * - 单例模式防止重复创建\r\n * - 锁定页面交互\r\n *\r\n * ## 使用场景\r\n *\r\n * - 页面初始化加载\r\n * - 大量数据请求\r\n * - 路由切换过渡\r\n * - 异步操作等待\r\n *\r\n * ## 特性\r\n *\r\n * - 自动检测当前主题并应用对应背景色\r\n * - 使用自定义 SVG 动画(四点旋转)\r\n * - 单例模式确保同时只有一个 Loading\r\n * - 提供便捷的显示/隐藏方法\r\n *\r\n * @module utils/ui/loading\r\n * @author Art Design Pro Team\r\n */\r\nimport { fourDotsSpinnerSvg } from \"./loadinSvg\";\r\nimport { ElLoading } from \"element-plus\";\r\n/**\r\n * 获取当前主题对应的loading背景色\r\n * @returns 背景色字符串\r\n */\r\nconst getLoadingBackground = (): string => {\r\n const isDark = document.documentElement.classList.contains(\"dark\");\r\n return isDark ? \"rgba(7, 7, 7, 0.85)\" : \"rgba(255, 255, 255, 0.5)\";\r\n};\r\n\r\nconst DEFAULT_LOADING_CONFIG = {\r\n lock: true,\r\n get background() {\r\n return getLoadingBackground();\r\n },\r\n svg: fourDotsSpinnerSvg,\r\n svgViewBox: \"0 0 40 40\",\r\n customClass: \"art-loading-fix\"\r\n} as const;\r\n\r\ninterface LoadingInstance {\r\n close: () => void;\r\n}\r\n\r\nlet loadingInstance: LoadingInstance | null = null;\r\n\r\nexport const loadingService = {\r\n /**\r\n * 显示 loading\r\n * @returns 关闭 loading 的函数\r\n */\r\n showLoading(): () => void {\r\n if (!loadingInstance) {\r\n // 每次显示时获取最新的配置,确保背景色与当前主题同步\r\n const config = {\r\n ...DEFAULT_LOADING_CONFIG,\r\n background: getLoadingBackground()\r\n };\r\n loadingInstance = ElLoading.service(config);\r\n }\r\n return () => this.hideLoading();\r\n },\r\n\r\n /**\r\n * 隐藏 loading\r\n */\r\n hideLoading(): void {\r\n if (loadingInstance) {\r\n loadingInstance.close();\r\n loadingInstance = null;\r\n }\r\n }\r\n};\r\n","import axios, { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from \"axios\";\r\nimport { HttpError, handleError, showError, showSuccess } from \"./error\";\r\nimport { ApiStatus, HttpMsg } from \"./status\";\r\nimport { BaseResponse, TtHttpReturnType } from \"./type\";\r\nimport { downloadFile } from \"../file\";\r\nimport { nextTick } from \"vue\";\r\nimport { loadingService } from \"./loading\";\r\n\r\n// 需要传入\r\n// router useUserStore closeLoading startLoading VITE_API_URL VITE_WITH_CREDENTIALS\r\n/** 退出登录函数 */\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport function TtHttp(config: any): TtHttpReturnType {\r\n const { router, useUserStore, VITE_API_URL, VITE_WITH_CREDENTIALS } = config;\r\n\r\n // 跟踪是否需要关闭 loading\r\n let pendingLoading = false;\r\n function closeLoading(): void {\r\n if (pendingLoading) {\r\n nextTick(() => {\r\n loadingService.hideLoading();\r\n pendingLoading = false;\r\n });\r\n }\r\n }\r\n /** 开始 loading 效果 */\r\n function startLoading(): void {\r\n pendingLoading = true;\r\n loadingService.showLoading();\r\n }\r\n // 文件类型\r\n const FILE_TYPES = [\r\n \"image/jpeg\",\r\n \"image/png\",\r\n \"image/gif\",\r\n \"image/webp\",\r\n \"image/svg+xml\",\r\n \"application/pdf\",\r\n \"application/msword\",\r\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\r\n \"application/vnd.ms-excel\",\r\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8\"\r\n ];\r\n\r\n /** 请求配置常量 */\r\n const REQUEST_TIMEOUT = 1000 * 60;\r\n const LOGOUT_DELAY = 500;\r\n const MAX_RETRIES = 0;\r\n const RETRY_DELAY = 1000;\r\n const UNAUTHORIZED_DEBOUNCE_TIME = 3000;\r\n\r\n let activeRequests = 0;\r\n function debuncesLoading() {\r\n setTimeout(() => {\r\n activeRequests--;\r\n if (activeRequests === 0) {\r\n closeLoading();\r\n }\r\n }, 0);\r\n }\r\n\r\n /** 401防抖状态 */\r\n let isUnauthorizedErrorShown = false;\r\n let unauthorizedTimer: NodeJS.Timeout | null = null;\r\n\r\n /** 扩展 AxiosRequestConfig */\r\n interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {\r\n showErrorMessage?: boolean;\r\n showSuccessMessage?: boolean;\r\n hideLoading?: boolean;\r\n }\r\n\r\n /** Axios实例 */\r\n const axiosInstance = axios.create({\r\n timeout: REQUEST_TIMEOUT,\r\n baseURL: \"/\" + VITE_API_URL,\r\n withCredentials: VITE_WITH_CREDENTIALS === \"true\",\r\n validateStatus: status => status >= 200 && status < 300,\r\n transformResponse: [\r\n (data, headers) => {\r\n const contentType = headers[\"content-type\"];\r\n if (contentType?.includes(\"application/json\")) {\r\n try {\r\n return JSON.parse(data);\r\n } catch {\r\n return data;\r\n }\r\n }\r\n return data;\r\n }\r\n ]\r\n });\r\n\r\n /** 请求拦截器 */\r\n axiosInstance.interceptors.request.use(\r\n (request: InternalAxiosRequestConfig) => {\r\n const { accessToken, info } = useUserStore();\r\n if (accessToken) {\r\n request.headers.set(\"Authorization\", accessToken);\r\n request.headers.set(\"token\", accessToken);\r\n request.headers.set(\"x-userid-header\", info.userId);\r\n request.headers.set(\"x-permission-code-header\", router.currentRoute.value.meta.permissionOnlyCode as string);\r\n }\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n if (!(request as any).hideLoading && activeRequests === 0) {\r\n startLoading();\r\n }\r\n activeRequests++;\r\n\r\n if (request.data && !(request.data instanceof FormData) && !request.headers[\"Content-Type\"]) {\r\n request.headers.set(\"Content-Type\", \"application/json\");\r\n request.data = JSON.stringify(request.data);\r\n }\r\n\r\n return request;\r\n },\r\n error => {\r\n showError(createHttpError(HttpMsg.requestConfigError, ApiStatus.error));\r\n return Promise.reject(error);\r\n }\r\n );\r\n\r\n /** 响应拦截器 */\r\n axiosInstance.interceptors.response.use(\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n (response: AxiosResponse<BaseResponse> | any) => {\r\n debuncesLoading();\r\n const contentType = response.headers[\"content-type\"];\r\n if (contentType?.includes(\"application/json\")) {\r\n const { code, msg } = response.data;\r\n if ([ApiStatus.success, ApiStatus.success1].includes(code)) return response;\r\n if ([ApiStatus.unauthorized, ApiStatus.INVALID_TOKEN].includes(code)) handleUnauthorizedError(msg);\r\n throw createHttpError(msg || HttpMsg.requestFailed, code);\r\n } else if (FILE_TYPES.includes(contentType)) {\r\n // 文件类型 下载\r\n downloadFile(response, contentType);\r\n return response;\r\n }\r\n },\r\n error => {\r\n debuncesLoading();\r\n if (error.response?.status === ApiStatus.unauthorized) handleUnauthorizedError();\r\n return Promise.reject(handleError(error));\r\n }\r\n );\r\n\r\n /** 统一创建HttpError */\r\n function createHttpError(message: string, code: number) {\r\n return new HttpError(message, code);\r\n }\r\n\r\n /** 处理401错误(带防抖) */\r\n function handleUnauthorizedError(message?: string): never {\r\n const error = createHttpError(message || HttpMsg.unauthorized, ApiStatus.unauthorized);\r\n\r\n if (!isUnauthorizedErrorShown) {\r\n isUnauthorizedErrorShown = true;\r\n logOut();\r\n\r\n unauthorizedTimer = setTimeout(resetUnauthorizedError, UNAUTHORIZED_DEBOUNCE_TIME);\r\n\r\n showError(error, true);\r\n throw error;\r\n }\r\n\r\n throw error;\r\n }\r\n\r\n /** 重置401防抖状态 */\r\n function resetUnauthorizedError() {\r\n isUnauthorizedErrorShown = false;\r\n if (unauthorizedTimer) clearTimeout(unauthorizedTimer);\r\n unauthorizedTimer = null;\r\n }\r\n\r\n const logOut = () => {\r\n setTimeout(() => {\r\n useUserStore().logOut();\r\n }, LOGOUT_DELAY);\r\n };\r\n /** 是否需要重试 */\r\n function shouldRetry(statusCode: number) {\r\n return [\r\n ApiStatus.requestTimeout,\r\n ApiStatus.internalServerError,\r\n ApiStatus.badGateway,\r\n ApiStatus.serviceUnavailable,\r\n ApiStatus.gatewayTimeout\r\n ].includes(statusCode);\r\n }\r\n\r\n /** 请求重试逻辑 */\r\n async function retryRequest<T>(config: ExtendedAxiosRequestConfig, retries: number = MAX_RETRIES): Promise<T> {\r\n try {\r\n return await request<T>(config);\r\n } catch (error) {\r\n if (error instanceof HttpError && [ApiStatus.NEED_REFRESH_TOKEN].includes(error.code)) {\r\n if (!config.url?.includes(\"/iam/user/refreshToken\")) {\r\n // 刷新token\r\n await useUserStore().refreshTokenFunc();\r\n await delay(RETRY_DELAY);\r\n return retryRequest<T>(config, retries - 1);\r\n }\r\n }\r\n if (retries > 0 && error instanceof HttpError && shouldRetry(error.code)) {\r\n await delay(RETRY_DELAY);\r\n return retryRequest<T>(config, retries - 1);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** 延迟函数 */\r\n function delay(ms: number) {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n /** 请求函数 */\r\n async function request<T>(config: ExtendedAxiosRequestConfig): Promise<T> {\r\n // POST | PUT 参数自动填充\r\n if ([\"POST\", \"PUT\"].includes(config.method?.toUpperCase() || \"\") && config.params && !config.data) {\r\n config.data = config.params;\r\n config.params = undefined;\r\n }\r\n\r\n try {\r\n const res = await axiosInstance.request<BaseResponse<T>>(config);\r\n\r\n // 显示成功消息\r\n if (config.showSuccessMessage && res.data.msg) {\r\n showSuccess(res.data.msg);\r\n }\r\n\r\n return res.data.data as T;\r\n } catch (error) {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const excludeError = [ApiStatus.unauthorized, ApiStatus.NEED_REFRESH_TOKEN].includes((error as any).code);\r\n if (error instanceof HttpError && !excludeError) {\r\n const showMsg = config.showErrorMessage !== false;\r\n showError(error, showMsg);\r\n }\r\n return Promise.reject(error);\r\n }\r\n }\r\n\r\n /** API方法集合 */\r\n const api = {\r\n get<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"GET\" });\r\n },\r\n post<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"POST\" });\r\n },\r\n put<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"PUT\" });\r\n },\r\n del<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"DELETE\" });\r\n },\r\n request<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>(config);\r\n }\r\n };\r\n\r\n return {\r\n ...api,\r\n logOut\r\n };\r\n}\r\n","export function capitalize(str: string): string {\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n\r\nexport function trim(str: string): string {\r\n return str.trim();\r\n}","export function sum(a: number, b: number): number {\r\n return a + b;\r\n}\r\n\r\nexport function multiply(a: number, b: number): number {\r\n return a * b;\r\n}\r\n\r\nexport function subtract(a: number, b: number): number {\r\n return a - b;\r\n}\r\n\r\nexport function divide(a: number, b: number): number {\r\n return a / b;\r\n}"],"names":["downloadFile","res","type","blob","Blob","data","a","document","createElement","herf","window","URL","webkitURL","createObjectURL","href","fileName","headers","split","at","decodeURI","replace","decodedParts","download","style","display","body","appendChild","click","removeChild","revokeObjectURL","error","console","log","ApiStatus","HttpMsg","HttpError","Error","code","timestamp","url","method","constructor","message","options","super","this","name","Date","toISOString","toLogData","stack","handleError","warn","requestCancelled","statusCode","response","status","errorMessage","msg","requestConfig","config","networkError","toUpperCase","unauthorized","forbidden","notFound","methodNotAllowed","requestTimeout","internalServerError","badGateway","serviceUnavailable","gatewayTimeout","requestFailed","showError","showMessage","ElMessage","getLoadingBackground","documentElement","classList","contains","DEFAULT_LOADING_CONFIG","lock","background","svg","svgViewBox","customClass","loadingInstance","loadingService","showLoading","ElLoading","service","hideLoading","close","router","useUserStore","VITE_API_URL","VITE_WITH_CREDENTIALS","pendingLoading","FILE_TYPES","activeRequests","debuncesLoading","setTimeout","nextTick","isUnauthorizedErrorShown","unauthorizedTimer","axiosInstance","axios","create","timeout","baseURL","withCredentials","validateStatus","transformResponse","contentType","includes","JSON","parse","createHttpError","handleUnauthorizedError","logOut","resetUnauthorizedError","clearTimeout","interceptors","request","use","accessToken","info","set","userId","currentRoute","value","meta","permissionOnlyCode","FormData","stringify","requestConfigError","Promise","reject","success","success1","INVALID_TOKEN","async","retryRequest","retries","params","undefined","showSuccessMessage","showSuccess","excludeError","NEED_REFRESH_TOKEN","showErrorMessage","refreshTokenFunc","delay","ms","resolve","get","post","put","del","str","charAt","slice","b","trim"],"mappings":"qFAWaA,EAAe,CAACC,EAAyBC,KACpD,I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B2D,SAEJ,qBC5QM,SAAqBwC,GACzB,OAAOA,EAAIC,OAAO,GAAGlG,cAAgBiG,EAAIE,MAAM,EACjD,iBCUM,SAAiB3J,EAAW4J,GAChC,OAAO5J,EAAI4J,CACb,0CAVM,SAAmB5J,EAAW4J,GAClC,OAAO5J,EAAI4J,CACb,mBAEM,SAAmB5J,EAAW4J,GAClC,OAAO5J,EAAI4J,CACb,cAVM,SAAc5J,EAAW4J,GAC7B,OAAO5J,EAAI4J,CACb,eDEM,SAAeH,GACnB,OAAOA,EAAII,MACb"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from "./string";
2
2
  export * from "./math";
3
+ export * from "./file";
4
+ export * from "./axios/index";
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AAEvB,cAAc,QAAQ,CAAC;AAEvB,cAAc,eAAe,CAAC"}
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- function n(n){return n.charAt(0).toUpperCase()+n.slice(1)}function r(n){return n.trim()}function t(n,r){return n+r}function u(n,r){return n*r}function e(n,r){return n-r}function c(n,r){return n/r}export{n as capitalize,c as divide,u as multiply,e as subtract,t as sum,r as trim};
1
+ import e from"axios";import{ElMessage as t,ElLoading as r}from"element-plus";import{nextTick as n}from"vue";function o(e){return e.charAt(0).toUpperCase()+e.slice(1)}function a(e){return e.trim()}function s(e,t){return e+t}function i(e,t){return e*t}function c(e,t){return e-t}function d(e,t){return e/t}const u=(e,t)=>{try{const r=new Blob([e.data],{type:t}),n=document.createElement("a"),o=(window.URL||window.webkitURL).createObjectURL(r);n.href=o;let a=((e.headers["content-disposition"]||"").split("=")||[]).at(-1)||"";a=a?decodeURI(a.replace(/"/g,"")):"";const s=a?.split("''");a=s.at(-1)||"",n.download=a,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),window.URL.revokeObjectURL(o)}catch(e){console.log(e)}};var l,m;!function(e){e[e.success=200]="success",e[e.success1=0]="success1",e[e.error=400]="error",e[e.unauthorized=401]="unauthorized",e[e.forbidden=403]="forbidden",e[e.notFound=404]="notFound",e[e.methodNotAllowed=405]="methodNotAllowed",e[e.requestTimeout=408]="requestTimeout",e[e.internalServerError=500]="internalServerError",e[e.notImplemented=501]="notImplemented",e[e.badGateway=502]="badGateway",e[e.serviceUnavailable=503]="serviceUnavailable",e[e.gatewayTimeout=504]="gatewayTimeout",e[e.httpVersionNotSupported=505]="httpVersionNotSupported",e[e.NEED_REFRESH_TOKEN=1001]="NEED_REFRESH_TOKEN",e[e.API_NO_AUTH=1002]="API_NO_AUTH",e[e.INVALID_TOKEN=1005]="INVALID_TOKEN"}(l||(l={})),function(e){e.badGateway="网关错误,请稍后重试",e.forbidden="禁止访问该资源",e.gatewayTimeout="网关超时,请稍后重试",e.internalServerError="服务器内部错误,请稍后重试",e.methodNotAllowed="请求方法不允许",e.networkError="网络连接异常,请检查网络连接",e.notFound="请求的资源不存在",e.requestCancelled="请求已取消",e.requestConfigError="请求配置错误",e.requestFailed="请求失败",e.requestTimeout="请求超时,请稍后重试",e.serviceUnavailable="服务暂时不可用,请稍后重试",e.unauthorized="未授权访问,请重新登录"}(m||(m={}));class h extends Error{code;data;timestamp;url;method;constructor(e,t,r){super(e),this.name="HttpError",this.code=t,this.data=r?.data,this.timestamp=(new Date).toISOString(),this.url=r?.url||"",this.method=r?.method||""}toLogData(){return{code:this.code,message:this.message,data:this.data,timestamp:this.timestamp,url:this.url||"",method:this.method||"",stack:this.stack||""}}}function p(e){if("ERR_CANCELED"===e.code)throw console.warn("Request cancelled:",e.message),new h(m.requestCancelled,l.error);const t=e.response?.status,r=e.response?.data?.msg||e.message,n=e.config;if(!e.response)throw new h(m.networkError,l.error,{url:n?.url||"",method:n?.method?.toUpperCase()||""});const o=t?(a=t,{[l.unauthorized]:m.unauthorized,[l.forbidden]:m.forbidden,[l.notFound]:m.notFound,[l.methodNotAllowed]:m.methodNotAllowed,[l.requestTimeout]:m.requestTimeout,[l.internalServerError]:m.internalServerError,[l.badGateway]:m.badGateway,[l.serviceUnavailable]:m.serviceUnavailable,[l.gatewayTimeout]:m.gatewayTimeout}[a]||m.internalServerError):r||m.requestFailed;var a;throw new h(o,t||l.error,{data:e.response.data,url:n?.url||"",method:n?.method?.toUpperCase()||""})}function f(e,r=!0){r&&t.error(e.message),console.error("[HTTP Error]",e.toLogData())}const g=()=>document.documentElement.classList.contains("dark")?"rgba(7, 7, 7, 0.85)":"rgba(255, 255, 255, 0.5)",w={lock:!0,get background(){return g()},svg:'\n <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40">\n <style>\n .spinner {\n transform-origin: 20px 20px;\n animation: rotate 1.6s linear infinite;\n }\n .dot {\n fill: var(--theme-color);\n animation: fade 1.6s infinite;\n }\n .dot:nth-child(1) { animation-delay: 0s; }\n .dot:nth-child(2) { animation-delay: 0.5s; }\n .dot:nth-child(3) { animation-delay: 1s; }\n .dot:nth-child(4) { animation-delay: 1.5s; }\n @keyframes rotate {\n 100% { transform: rotate(360deg); }\n }\n @keyframes fade {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n </style>\n <g class="spinner">\n <circle class="dot" cx="20" cy="8" r="4"/>\n <circle class="dot" cx="32" cy="20" r="4"/>\n <circle class="dot" cx="20" cy="32" r="4"/>\n <circle class="dot" cx="8" cy="20" r="4"/>\n </g>\n </svg>\n',svgViewBox:"0 0 40 40",customClass:"art-loading-fix"};let E=null;const y={showLoading(){if(!E){const e={...w,background:g()};E=r.service(e)}return()=>this.hideLoading()},hideLoading(){E&&(E.close(),E=null)}};function T(r){const{router:o,useUserStore:a,VITE_API_URL:s,VITE_WITH_CREDENTIALS:i}=r;let c=!1;const d=["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"];let g=0;function w(){setTimeout(()=>{g--,0===g&&c&&n(()=>{y.hideLoading(),c=!1})},0)}let E=!1,T=null;const v=e.create({timeout:6e4,baseURL:"/"+s,withCredentials:"true"===i,validateStatus:e=>e>=200&&e<300,transformResponse:[(e,t)=>{const r=t["content-type"];if(r?.includes("application/json"))try{return JSON.parse(e)}catch{return e}return e}]});function b(e,t){return new h(e,t)}function N(e){const t=b(e||m.unauthorized,l.unauthorized);if(!E)throw E=!0,U(),T=setTimeout(S,3e3),f(t,!0),t;throw t}function S(){E=!1,T&&clearTimeout(T),T=null}v.interceptors.request.use(e=>{const{accessToken:t,info:r}=a();return t&&(e.headers.set("Authorization",t),e.headers.set("token",t),e.headers.set("x-userid-header",r.userId),e.headers.set("x-permission-code-header",o.currentRoute.value.meta.permissionOnlyCode)),e.hideLoading||0!==g||(c=!0,y.showLoading()),g++,!e.data||e.data instanceof FormData||e.headers["Content-Type"]||(e.headers.set("Content-Type","application/json"),e.data=JSON.stringify(e.data)),e},e=>(f(b(m.requestConfigError,l.error)),Promise.reject(e))),v.interceptors.response.use(e=>{w();const t=e.headers["content-type"];if(t?.includes("application/json")){const{code:t,msg:r}=e.data;if([l.success,l.success1].includes(t))return e;throw[l.unauthorized,l.INVALID_TOKEN].includes(t)&&N(r),b(r||m.requestFailed,t)}if(d.includes(t))return u(e,t),e},e=>(w(),e.response?.status===l.unauthorized&&N(),Promise.reject(p(e))));const U=()=>{setTimeout(()=>{a().logOut()},500)};async function L(e,r=0){try{return await async function(e){["POST","PUT"].includes(e.method?.toUpperCase()||"")&&e.params&&!e.data&&(e.data=e.params,e.params=void 0);try{const r=await v.request(e);return e.showSuccessMessage&&r.data.msg&&function(e,r=!0){r&&t.success(e)}(r.data.msg),r.data.data}catch(t){const r=[l.unauthorized,l.NEED_REFRESH_TOKEN].includes(t.code);if(t instanceof h&&!r){f(t,!1!==e.showErrorMessage)}return Promise.reject(t)}}(e)}catch(t){if(t instanceof h&&[l.NEED_REFRESH_TOKEN].includes(t.code)&&!e.url?.includes("/iam/user/refreshToken"))return await a().refreshTokenFunc(),await R(1e3),L(e,r-1);if(r>0&&t instanceof h&&(n=t.code,[l.requestTimeout,l.internalServerError,l.badGateway,l.serviceUnavailable,l.gatewayTimeout].includes(n)))return await R(1e3),L(e,r-1);throw t}var n}function R(e){return new Promise(t=>setTimeout(t,e))}const _={get:e=>L({...e,method:"GET"}),post:e=>L({...e,method:"POST"}),put:e=>L({...e,method:"PUT"}),del:e=>L({...e,method:"DELETE"}),request:e=>L(e)};return{..._,logOut:U}}export{T as TtHttp,o as capitalize,d as divide,u as downloadFile,i as multiply,c as subtract,s as sum,a as trim};
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/string.ts","../src/math.ts"],"sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nexport function trim(str: string): string {\n return str.trim();\n}","export function sum(a: number, b: number): number {\n return a + b;\n}\n\nexport function multiply(a: number, b: number): number {\n return a * b;\n}\n\nexport function subtract(a: number, b: number): number {\n return a - b;\n}\n\nexport function divide(a: number, b: number): number {\n return a / b;\n}"],"names":["capitalize","str","charAt","toUpperCase","slice","trim","sum","a","b","multiply","subtract","divide"],"mappings":"AAAM,SAAUA,EAAWC,GACzB,OAAOA,EAAIC,OAAO,GAAGC,cAAgBF,EAAIG,MAAM,EACjD,CAEM,SAAUC,EAAKJ,GACnB,OAAOA,EAAII,MACb,CCNM,SAAUC,EAAIC,EAAWC,GAC7B,OAAOD,EAAIC,CACb,CAEM,SAAUC,EAASF,EAAWC,GAClC,OAAOD,EAAIC,CACb,CAEM,SAAUE,EAASH,EAAWC,GAClC,OAAOD,EAAIC,CACb,CAEM,SAAUG,EAAOJ,EAAWC,GAChC,OAAOD,EAAIC,CACb"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/string.ts","../src/math.ts","../src/file.ts","../src/axios/status.ts","../src/axios/error.ts","../src/axios/loadinSvg.ts","../src/axios/loading.ts","../src/axios/index.ts"],"sourcesContent":["export function capitalize(str: string): string {\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n\r\nexport function trim(str: string): string {\r\n return str.trim();\r\n}","export function sum(a: number, b: number): number {\r\n return a + b;\r\n}\r\n\r\nexport function multiply(a: number, b: number): number {\r\n return a * b;\r\n}\r\n\r\nexport function subtract(a: number, b: number): number {\r\n return a - b;\r\n}\r\n\r\nexport function divide(a: number, b: number): number {\r\n return a / b;\r\n}","/**\r\n * @param res 响应 { data: Blob, ... }\r\n * @param type 类型\r\n */\r\n\r\ninterface HttpResponse<T> {\r\n data: T;\r\n headers: Record<string, string>;\r\n status: number;\r\n statusText: string;\r\n}\r\nexport const downloadFile = (res: HttpResponse<Blob>, type: string) => {\r\n try {\r\n // 创建blob对象,解析流数据\r\n const blob = new Blob([res.data], {\r\n type\r\n });\r\n const a = document.createElement(\"a\");\r\n const URL = window.URL || window.webkitURL;\r\n const herf = URL.createObjectURL(blob);\r\n a.href = herf;\r\n const contentDisposition: string[] = (res.headers[\"content-disposition\"] || \"\").split(\"=\") || [];\r\n let fileName = contentDisposition.at(-1) || \"\";\r\n fileName = fileName ? decodeURI(fileName.replace(/\"/g, \"\")) : \"\";\r\n const decodedParts = fileName?.split(\"''\");\r\n fileName = decodedParts.at(-1) || \"\";\r\n a.download = fileName;\r\n a.style.display = \"none\";\r\n document.body.appendChild(a);\r\n a.click();\r\n document.body.removeChild(a);\r\n window.URL.revokeObjectURL(herf);\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n};\r\n","/**\r\n * 接口状态码\r\n */\r\nexport enum ApiStatus {\r\n success = 200, // 成功\r\n success1 = 0, // 成功\r\n error = 400, // 错误\r\n unauthorized = 401, // 未授权\r\n forbidden = 403, // 禁止访问\r\n notFound = 404, // 未找到\r\n methodNotAllowed = 405, // 方法不允许\r\n requestTimeout = 408, // 请求超时\r\n internalServerError = 500, // 服务器错误\r\n notImplemented = 501, // 未实现\r\n badGateway = 502, // 网关错误\r\n serviceUnavailable = 503, // 服务不可用\r\n gatewayTimeout = 504, // 网关超时\r\n httpVersionNotSupported = 505, // HTTP版本不支持\r\n NEED_REFRESH_TOKEN = 1001, // 需要刷新令牌\r\n API_NO_AUTH = 1002, // 接口未授权\r\n INVALID_TOKEN = 1005 // 无效的token\r\n}\r\n\r\n// 错误提示\r\nexport enum HttpMsg {\r\n badGateway = \"网关错误,请稍后重试\",\r\n forbidden = \"禁止访问该资源\",\r\n gatewayTimeout = \"网关超时,请稍后重试\",\r\n internalServerError = \"服务器内部错误,请稍后重试\",\r\n methodNotAllowed = \"请求方法不允许\",\r\n networkError = \"网络连接异常,请检查网络连接\",\r\n notFound = \"请求的资源不存在\",\r\n requestCancelled = \"请求已取消\",\r\n requestConfigError = \"请求配置错误\",\r\n requestFailed = \"请求失败\",\r\n requestTimeout = \"请求超时,请稍后重试\",\r\n serviceUnavailable = \"服务暂时不可用,请稍后重试\",\r\n unauthorized = \"未授权访问,请重新登录\"\r\n}\r\n","/**\r\n * HTTP 错误处理模块\r\n *\r\n * 提供统一的 HTTP 请求错误处理机制\r\n *\r\n * ## 主要功能\r\n *\r\n * - 自定义 HttpError 错误类,封装错误信息、状态码、时间戳等\r\n * - 错误拦截和转换,将 Axios 错误转换为标准的 HttpError\r\n * - 错误消息国际化处理,根据状态码返回对应的多语言错误提示\r\n * - 错误日志记录,便于问题追踪和调试\r\n * - 错误和成功消息的统一展示\r\n * - 类型守卫函数,用于判断错误类型\r\n *\r\n * ## 使用场景\r\n *\r\n * - HTTP 请求拦截器中统一处理错误\r\n * - 业务代码中捕获和处理特定错误\r\n * - 错误日志收集和上报\r\n *\r\n * @module utils/http/error\r\n * @author Art Design Pro Team\r\n */\r\nimport { AxiosError } from \"axios\";\r\nimport { ApiStatus, HttpMsg } from \"./status\";\r\nimport { ElMessage } from \"element-plus\";\r\n\r\n// 错误响应接口\r\nexport interface ErrorResponse {\r\n /** 错误状态码 */\r\n code: number;\r\n /** 错误消息 */\r\n msg: string;\r\n /** 错误附加数据 */\r\n data?: unknown;\r\n}\r\n\r\n// 错误日志数据接口\r\nexport interface ErrorLogData {\r\n /** 错误状态码 */\r\n code: number;\r\n /** 错误消息 */\r\n message: string;\r\n /** 错误附加数据 */\r\n data?: unknown;\r\n /** 错误发生时间戳 */\r\n timestamp: string;\r\n /** 请求 URL */\r\n url?: string;\r\n /** 请求方法 */\r\n method?: string;\r\n /** 错误堆栈信息 */\r\n stack?: string;\r\n}\r\n\r\n// 自定义 HttpError 类\r\nexport class HttpError extends Error {\r\n public readonly code: number;\r\n public readonly data?: unknown;\r\n public readonly timestamp: string;\r\n public readonly url?: string;\r\n public readonly method?: string;\r\n\r\n constructor(\r\n message: string,\r\n code: number,\r\n options?: {\r\n data?: unknown;\r\n url?: string;\r\n method?: string;\r\n }\r\n ) {\r\n super(message);\r\n this.name = \"HttpError\";\r\n this.code = code;\r\n this.data = options?.data;\r\n this.timestamp = new Date().toISOString();\r\n this.url = options?.url || \"\";\r\n this.method = options?.method || \"\";\r\n }\r\n\r\n public toLogData(): ErrorLogData {\r\n return {\r\n code: this.code,\r\n message: this.message,\r\n data: this.data,\r\n timestamp: this.timestamp,\r\n url: this.url || \"\",\r\n method: this.method || \"\",\r\n stack: this.stack || \"\"\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * 获取错误消息\r\n * @param status 错误状态码\r\n * @returns 错误消息\r\n */\r\nconst getErrorMessage = (status: number): string => {\r\n const errorMap: Record<number, string> = {\r\n [ApiStatus.unauthorized]: HttpMsg.unauthorized,\r\n [ApiStatus.forbidden]: HttpMsg.forbidden,\r\n [ApiStatus.notFound]: HttpMsg.notFound,\r\n [ApiStatus.methodNotAllowed]: HttpMsg.methodNotAllowed,\r\n [ApiStatus.requestTimeout]: HttpMsg.requestTimeout,\r\n [ApiStatus.internalServerError]: HttpMsg.internalServerError,\r\n [ApiStatus.badGateway]: HttpMsg.badGateway,\r\n [ApiStatus.serviceUnavailable]: HttpMsg.serviceUnavailable,\r\n [ApiStatus.gatewayTimeout]: HttpMsg.gatewayTimeout\r\n };\r\n\r\n return errorMap[status] || HttpMsg.internalServerError;\r\n};\r\n\r\n/**\r\n * 处理错误\r\n * @param error 错误对象\r\n * @returns 错误对象\r\n */\r\nexport function handleError(error: AxiosError<ErrorResponse>): never {\r\n // 处理取消的请求\r\n if (error.code === \"ERR_CANCELED\") {\r\n console.warn(\"Request cancelled:\", error.message);\r\n throw new HttpError(HttpMsg.requestCancelled, ApiStatus.error);\r\n }\r\n\r\n const statusCode = error.response?.status;\r\n const errorMessage = error.response?.data?.msg || error.message;\r\n const requestConfig = error.config;\r\n\r\n // 处理网络错误\r\n if (!error.response) {\r\n throw new HttpError(HttpMsg.networkError, ApiStatus.error, {\r\n url: requestConfig?.url || \"\",\r\n method: requestConfig?.method?.toUpperCase() || \"\"\r\n });\r\n }\r\n\r\n // 处理 HTTP 状态码错误\r\n const message = statusCode ? getErrorMessage(statusCode) : errorMessage || HttpMsg.requestFailed;\r\n throw new HttpError(message, statusCode || ApiStatus.error, {\r\n data: error.response.data,\r\n url: requestConfig?.url || \"\",\r\n method: requestConfig?.method?.toUpperCase() || \"\"\r\n });\r\n}\r\n\r\n/**\r\n * 显示错误消息\r\n * @param error 错误对象\r\n * @param showMessage 是否显示错误消息\r\n */\r\nexport function showError(error: HttpError, showMessage: boolean = true): void {\r\n if (showMessage) {\r\n ElMessage.error(error.message);\r\n }\r\n // 记录错误日志\r\n console.error(\"[HTTP Error]\", error.toLogData());\r\n}\r\n\r\n/**\r\n * 显示成功消息\r\n * @param message 成功消息\r\n * @param showMessage 是否显示消息\r\n */\r\nexport function showSuccess(message: string, showMessage: boolean = true): void {\r\n if (showMessage) {\r\n ElMessage.success(message);\r\n }\r\n}\r\n\r\n/**\r\n * 判断是否为 HttpError 类型\r\n * @param error 错误对象\r\n * @returns 是否为 HttpError 类型\r\n */\r\nexport const isHttpError = (error: unknown): error is HttpError => {\r\n return error instanceof HttpError;\r\n};\r\n","// 自定义四点旋转SVG\r\nexport const fourDotsSpinnerSvg = `\r\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"40\" viewBox=\"0 0 40 40\">\r\n <style>\r\n .spinner {\r\n transform-origin: 20px 20px;\r\n animation: rotate 1.6s linear infinite;\r\n }\r\n .dot {\r\n fill: var(--theme-color);\r\n animation: fade 1.6s infinite;\r\n }\r\n .dot:nth-child(1) { animation-delay: 0s; }\r\n .dot:nth-child(2) { animation-delay: 0.5s; }\r\n .dot:nth-child(3) { animation-delay: 1s; }\r\n .dot:nth-child(4) { animation-delay: 1.5s; }\r\n @keyframes rotate {\r\n 100% { transform: rotate(360deg); }\r\n }\r\n @keyframes fade {\r\n 0%, 100% { opacity: 1; }\r\n 50% { opacity: 0.5; }\r\n }\r\n </style>\r\n <g class=\"spinner\">\r\n <circle class=\"dot\" cx=\"20\" cy=\"8\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"32\" cy=\"20\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"20\" cy=\"32\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"8\" cy=\"20\" r=\"4\"/>\r\n </g>\r\n </svg>\r\n`;\r\n","/**\r\n * 全局 Loading 加载管理模块\r\n *\r\n * 提供统一的全屏加载动画管理\r\n *\r\n * ## 主要功能\r\n *\r\n * - 全屏 Loading 显示和隐藏\r\n * - 自动适配明暗主题背景色\r\n * - 自定义 SVG 加载动画\r\n * - 单例模式防止重复创建\r\n * - 锁定页面交互\r\n *\r\n * ## 使用场景\r\n *\r\n * - 页面初始化加载\r\n * - 大量数据请求\r\n * - 路由切换过渡\r\n * - 异步操作等待\r\n *\r\n * ## 特性\r\n *\r\n * - 自动检测当前主题并应用对应背景色\r\n * - 使用自定义 SVG 动画(四点旋转)\r\n * - 单例模式确保同时只有一个 Loading\r\n * - 提供便捷的显示/隐藏方法\r\n *\r\n * @module utils/ui/loading\r\n * @author Art Design Pro Team\r\n */\r\nimport { fourDotsSpinnerSvg } from \"./loadinSvg\";\r\nimport { ElLoading } from \"element-plus\";\r\n/**\r\n * 获取当前主题对应的loading背景色\r\n * @returns 背景色字符串\r\n */\r\nconst getLoadingBackground = (): string => {\r\n const isDark = document.documentElement.classList.contains(\"dark\");\r\n return isDark ? \"rgba(7, 7, 7, 0.85)\" : \"rgba(255, 255, 255, 0.5)\";\r\n};\r\n\r\nconst DEFAULT_LOADING_CONFIG = {\r\n lock: true,\r\n get background() {\r\n return getLoadingBackground();\r\n },\r\n svg: fourDotsSpinnerSvg,\r\n svgViewBox: \"0 0 40 40\",\r\n customClass: \"art-loading-fix\"\r\n} as const;\r\n\r\ninterface LoadingInstance {\r\n close: () => void;\r\n}\r\n\r\nlet loadingInstance: LoadingInstance | null = null;\r\n\r\nexport const loadingService = {\r\n /**\r\n * 显示 loading\r\n * @returns 关闭 loading 的函数\r\n */\r\n showLoading(): () => void {\r\n if (!loadingInstance) {\r\n // 每次显示时获取最新的配置,确保背景色与当前主题同步\r\n const config = {\r\n ...DEFAULT_LOADING_CONFIG,\r\n background: getLoadingBackground()\r\n };\r\n loadingInstance = ElLoading.service(config);\r\n }\r\n return () => this.hideLoading();\r\n },\r\n\r\n /**\r\n * 隐藏 loading\r\n */\r\n hideLoading(): void {\r\n if (loadingInstance) {\r\n loadingInstance.close();\r\n loadingInstance = null;\r\n }\r\n }\r\n};\r\n","import axios, { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from \"axios\";\r\nimport { HttpError, handleError, showError, showSuccess } from \"./error\";\r\nimport { ApiStatus, HttpMsg } from \"./status\";\r\nimport { BaseResponse, TtHttpReturnType } from \"./type\";\r\nimport { downloadFile } from \"../file\";\r\nimport { nextTick } from \"vue\";\r\nimport { loadingService } from \"./loading\";\r\n\r\n// 需要传入\r\n// router useUserStore closeLoading startLoading VITE_API_URL VITE_WITH_CREDENTIALS\r\n/** 退出登录函数 */\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport function TtHttp(config: any): TtHttpReturnType {\r\n const { router, useUserStore, VITE_API_URL, VITE_WITH_CREDENTIALS } = config;\r\n\r\n // 跟踪是否需要关闭 loading\r\n let pendingLoading = false;\r\n function closeLoading(): void {\r\n if (pendingLoading) {\r\n nextTick(() => {\r\n loadingService.hideLoading();\r\n pendingLoading = false;\r\n });\r\n }\r\n }\r\n /** 开始 loading 效果 */\r\n function startLoading(): void {\r\n pendingLoading = true;\r\n loadingService.showLoading();\r\n }\r\n // 文件类型\r\n const FILE_TYPES = [\r\n \"image/jpeg\",\r\n \"image/png\",\r\n \"image/gif\",\r\n \"image/webp\",\r\n \"image/svg+xml\",\r\n \"application/pdf\",\r\n \"application/msword\",\r\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\r\n \"application/vnd.ms-excel\",\r\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8\"\r\n ];\r\n\r\n /** 请求配置常量 */\r\n const REQUEST_TIMEOUT = 1000 * 60;\r\n const LOGOUT_DELAY = 500;\r\n const MAX_RETRIES = 0;\r\n const RETRY_DELAY = 1000;\r\n const UNAUTHORIZED_DEBOUNCE_TIME = 3000;\r\n\r\n let activeRequests = 0;\r\n function debuncesLoading() {\r\n setTimeout(() => {\r\n activeRequests--;\r\n if (activeRequests === 0) {\r\n closeLoading();\r\n }\r\n }, 0);\r\n }\r\n\r\n /** 401防抖状态 */\r\n let isUnauthorizedErrorShown = false;\r\n let unauthorizedTimer: NodeJS.Timeout | null = null;\r\n\r\n /** 扩展 AxiosRequestConfig */\r\n interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {\r\n showErrorMessage?: boolean;\r\n showSuccessMessage?: boolean;\r\n hideLoading?: boolean;\r\n }\r\n\r\n /** Axios实例 */\r\n const axiosInstance = axios.create({\r\n timeout: REQUEST_TIMEOUT,\r\n baseURL: \"/\" + VITE_API_URL,\r\n withCredentials: VITE_WITH_CREDENTIALS === \"true\",\r\n validateStatus: status => status >= 200 && status < 300,\r\n transformResponse: [\r\n (data, headers) => {\r\n const contentType = headers[\"content-type\"];\r\n if (contentType?.includes(\"application/json\")) {\r\n try {\r\n return JSON.parse(data);\r\n } catch {\r\n return data;\r\n }\r\n }\r\n return data;\r\n }\r\n ]\r\n });\r\n\r\n /** 请求拦截器 */\r\n axiosInstance.interceptors.request.use(\r\n (request: InternalAxiosRequestConfig) => {\r\n const { accessToken, info } = useUserStore();\r\n if (accessToken) {\r\n request.headers.set(\"Authorization\", accessToken);\r\n request.headers.set(\"token\", accessToken);\r\n request.headers.set(\"x-userid-header\", info.userId);\r\n request.headers.set(\"x-permission-code-header\", router.currentRoute.value.meta.permissionOnlyCode as string);\r\n }\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n if (!(request as any).hideLoading && activeRequests === 0) {\r\n startLoading();\r\n }\r\n activeRequests++;\r\n\r\n if (request.data && !(request.data instanceof FormData) && !request.headers[\"Content-Type\"]) {\r\n request.headers.set(\"Content-Type\", \"application/json\");\r\n request.data = JSON.stringify(request.data);\r\n }\r\n\r\n return request;\r\n },\r\n error => {\r\n showError(createHttpError(HttpMsg.requestConfigError, ApiStatus.error));\r\n return Promise.reject(error);\r\n }\r\n );\r\n\r\n /** 响应拦截器 */\r\n axiosInstance.interceptors.response.use(\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n (response: AxiosResponse<BaseResponse> | any) => {\r\n debuncesLoading();\r\n const contentType = response.headers[\"content-type\"];\r\n if (contentType?.includes(\"application/json\")) {\r\n const { code, msg } = response.data;\r\n if ([ApiStatus.success, ApiStatus.success1].includes(code)) return response;\r\n if ([ApiStatus.unauthorized, ApiStatus.INVALID_TOKEN].includes(code)) handleUnauthorizedError(msg);\r\n throw createHttpError(msg || HttpMsg.requestFailed, code);\r\n } else if (FILE_TYPES.includes(contentType)) {\r\n // 文件类型 下载\r\n downloadFile(response, contentType);\r\n return response;\r\n }\r\n },\r\n error => {\r\n debuncesLoading();\r\n if (error.response?.status === ApiStatus.unauthorized) handleUnauthorizedError();\r\n return Promise.reject(handleError(error));\r\n }\r\n );\r\n\r\n /** 统一创建HttpError */\r\n function createHttpError(message: string, code: number) {\r\n return new HttpError(message, code);\r\n }\r\n\r\n /** 处理401错误(带防抖) */\r\n function handleUnauthorizedError(message?: string): never {\r\n const error = createHttpError(message || HttpMsg.unauthorized, ApiStatus.unauthorized);\r\n\r\n if (!isUnauthorizedErrorShown) {\r\n isUnauthorizedErrorShown = true;\r\n logOut();\r\n\r\n unauthorizedTimer = setTimeout(resetUnauthorizedError, UNAUTHORIZED_DEBOUNCE_TIME);\r\n\r\n showError(error, true);\r\n throw error;\r\n }\r\n\r\n throw error;\r\n }\r\n\r\n /** 重置401防抖状态 */\r\n function resetUnauthorizedError() {\r\n isUnauthorizedErrorShown = false;\r\n if (unauthorizedTimer) clearTimeout(unauthorizedTimer);\r\n unauthorizedTimer = null;\r\n }\r\n\r\n const logOut = () => {\r\n setTimeout(() => {\r\n useUserStore().logOut();\r\n }, LOGOUT_DELAY);\r\n };\r\n /** 是否需要重试 */\r\n function shouldRetry(statusCode: number) {\r\n return [\r\n ApiStatus.requestTimeout,\r\n ApiStatus.internalServerError,\r\n ApiStatus.badGateway,\r\n ApiStatus.serviceUnavailable,\r\n ApiStatus.gatewayTimeout\r\n ].includes(statusCode);\r\n }\r\n\r\n /** 请求重试逻辑 */\r\n async function retryRequest<T>(config: ExtendedAxiosRequestConfig, retries: number = MAX_RETRIES): Promise<T> {\r\n try {\r\n return await request<T>(config);\r\n } catch (error) {\r\n if (error instanceof HttpError && [ApiStatus.NEED_REFRESH_TOKEN].includes(error.code)) {\r\n if (!config.url?.includes(\"/iam/user/refreshToken\")) {\r\n // 刷新token\r\n await useUserStore().refreshTokenFunc();\r\n await delay(RETRY_DELAY);\r\n return retryRequest<T>(config, retries - 1);\r\n }\r\n }\r\n if (retries > 0 && error instanceof HttpError && shouldRetry(error.code)) {\r\n await delay(RETRY_DELAY);\r\n return retryRequest<T>(config, retries - 1);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** 延迟函数 */\r\n function delay(ms: number) {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n /** 请求函数 */\r\n async function request<T>(config: ExtendedAxiosRequestConfig): Promise<T> {\r\n // POST | PUT 参数自动填充\r\n if ([\"POST\", \"PUT\"].includes(config.method?.toUpperCase() || \"\") && config.params && !config.data) {\r\n config.data = config.params;\r\n config.params = undefined;\r\n }\r\n\r\n try {\r\n const res = await axiosInstance.request<BaseResponse<T>>(config);\r\n\r\n // 显示成功消息\r\n if (config.showSuccessMessage && res.data.msg) {\r\n showSuccess(res.data.msg);\r\n }\r\n\r\n return res.data.data as T;\r\n } catch (error) {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const excludeError = [ApiStatus.unauthorized, ApiStatus.NEED_REFRESH_TOKEN].includes((error as any).code);\r\n if (error instanceof HttpError && !excludeError) {\r\n const showMsg = config.showErrorMessage !== false;\r\n showError(error, showMsg);\r\n }\r\n return Promise.reject(error);\r\n }\r\n }\r\n\r\n /** API方法集合 */\r\n const api = {\r\n get<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"GET\" });\r\n },\r\n post<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"POST\" });\r\n },\r\n put<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"PUT\" });\r\n },\r\n del<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"DELETE\" });\r\n },\r\n request<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>(config);\r\n }\r\n };\r\n\r\n return {\r\n ...api,\r\n logOut\r\n };\r\n}\r\n"],"names":["capitalize","str","charAt","toUpperCase","slice","trim","sum","a","b","multiply","subtract","divide","downloadFile","res","type","blob","Blob","data","document","createElement","herf","window","URL","webkitURL","createObjectURL","href","fileName","headers","split","at","decodeURI","replace","decodedParts","download","style","display","body","appendChild","click","removeChild","revokeObjectURL","error","console","log","ApiStatus","HttpMsg","HttpError","Error","code","timestamp","url","method","constructor","message","options","super","this","name","Date","toISOString","toLogData","stack","handleError","warn","requestCancelled","statusCode","response","status","errorMessage","msg","requestConfig","config","networkError","unauthorized","forbidden","notFound","methodNotAllowed","requestTimeout","internalServerError","badGateway","serviceUnavailable","gatewayTimeout","requestFailed","showError","showMessage","ElMessage","getLoadingBackground","documentElement","classList","contains","DEFAULT_LOADING_CONFIG","lock","background","svg","svgViewBox","customClass","loadingInstance","loadingService","showLoading","ElLoading","service","hideLoading","close","TtHttp","router","useUserStore","VITE_API_URL","VITE_WITH_CREDENTIALS","pendingLoading","FILE_TYPES","activeRequests","debuncesLoading","setTimeout","nextTick","isUnauthorizedErrorShown","unauthorizedTimer","axiosInstance","axios","create","timeout","baseURL","withCredentials","validateStatus","transformResponse","contentType","includes","JSON","parse","createHttpError","handleUnauthorizedError","logOut","resetUnauthorizedError","clearTimeout","interceptors","request","use","accessToken","info","set","userId","currentRoute","value","meta","permissionOnlyCode","FormData","stringify","requestConfigError","Promise","reject","success","success1","INVALID_TOKEN","async","retryRequest","retries","params","undefined","showSuccessMessage","showSuccess","excludeError","NEED_REFRESH_TOKEN","showErrorMessage","refreshTokenFunc","delay","ms","resolve","api","get","post","put","del"],"mappings":"4GAAM,SAAUA,EAAWC,GACzB,OAAOA,EAAIC,OAAO,GAAGC,cAAgBF,EAAIG,MAAM,EACjD,CAEM,SAAUC,EAAKJ,GACnB,OAAOA,EAAII,MACb,CCNM,SAAUC,EAAIC,EAAWC,GAC7B,OAAOD,EAAIC,CACb,CAEM,SAAUC,EAASF,EAAWC,GAClC,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9CsH,IAAOlG,GACEkF,EAAgB,IAAKlF,EAAQpB,OAAQ,QAE9CuH,IAAOnG,GACEkF,EAAgB,IAAKlF,EAAQpB,OAAQ,WAE9CmF,QAAW/D,GACFkF,EAAgBlF,IAI3B,MAAO,IACF+F,EACHpC,SAEJ"}
@@ -1,2 +1,2 @@
1
- var TtyiMonorepoUtils=function(t){"use strict";return t.capitalize=function(t){return t.charAt(0).toUpperCase()+t.slice(1)},t.divide=function(t,n){return t/n},t.multiply=function(t,n){return t*n},t.subtract=function(t,n){return t-n},t.sum=function(t,n){return t+n},t.trim=function(t){return t.trim()},t}({});
1
+ var TtyiMonorepoUtils=function(e,t,n,r){"use strict";const o=(e,t)=>{try{const n=new Blob([e.data],{type:t}),r=document.createElement("a"),o=(window.URL||window.webkitURL).createObjectURL(n);r.href=o;let a=((e.headers["content-disposition"]||"").split("=")||[]).at(-1)||"";a=a?decodeURI(a.replace(/"/g,"")):"";const s=a?.split("''");a=s.at(-1)||"",r.download=a,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(o)}catch(e){console.log(e)}};var a,s;!function(e){e[e.success=200]="success",e[e.success1=0]="success1",e[e.error=400]="error",e[e.unauthorized=401]="unauthorized",e[e.forbidden=403]="forbidden",e[e.notFound=404]="notFound",e[e.methodNotAllowed=405]="methodNotAllowed",e[e.requestTimeout=408]="requestTimeout",e[e.internalServerError=500]="internalServerError",e[e.notImplemented=501]="notImplemented",e[e.badGateway=502]="badGateway",e[e.serviceUnavailable=503]="serviceUnavailable",e[e.gatewayTimeout=504]="gatewayTimeout",e[e.httpVersionNotSupported=505]="httpVersionNotSupported",e[e.NEED_REFRESH_TOKEN=1001]="NEED_REFRESH_TOKEN",e[e.API_NO_AUTH=1002]="API_NO_AUTH",e[e.INVALID_TOKEN=1005]="INVALID_TOKEN"}(a||(a={})),function(e){e.badGateway="网关错误,请稍后重试",e.forbidden="禁止访问该资源",e.gatewayTimeout="网关超时,请稍后重试",e.internalServerError="服务器内部错误,请稍后重试",e.methodNotAllowed="请求方法不允许",e.networkError="网络连接异常,请检查网络连接",e.notFound="请求的资源不存在",e.requestCancelled="请求已取消",e.requestConfigError="请求配置错误",e.requestFailed="请求失败",e.requestTimeout="请求超时,请稍后重试",e.serviceUnavailable="服务暂时不可用,请稍后重试",e.unauthorized="未授权访问,请重新登录"}(s||(s={}));class i extends Error{code;data;timestamp;url;method;constructor(e,t,n){super(e),this.name="HttpError",this.code=t,this.data=n?.data,this.timestamp=(new Date).toISOString(),this.url=n?.url||"",this.method=n?.method||""}toLogData(){return{code:this.code,message:this.message,data:this.data,timestamp:this.timestamp,url:this.url||"",method:this.method||"",stack:this.stack||""}}}function c(e){if("ERR_CANCELED"===e.code)throw console.warn("Request cancelled:",e.message),new i(s.requestCancelled,a.error);const t=e.response?.status,n=e.response?.data?.msg||e.message,r=e.config;if(!e.response)throw new i(s.networkError,a.error,{url:r?.url||"",method:r?.method?.toUpperCase()||""});const o=t?(c=t,{[a.unauthorized]:s.unauthorized,[a.forbidden]:s.forbidden,[a.notFound]:s.notFound,[a.methodNotAllowed]:s.methodNotAllowed,[a.requestTimeout]:s.requestTimeout,[a.internalServerError]:s.internalServerError,[a.badGateway]:s.badGateway,[a.serviceUnavailable]:s.serviceUnavailable,[a.gatewayTimeout]:s.gatewayTimeout}[c]||s.internalServerError):n||s.requestFailed;var c;throw new i(o,t||a.error,{data:e.response.data,url:r?.url||"",method:r?.method?.toUpperCase()||""})}function d(e,t=!0){t&&n.ElMessage.error(e.message),console.error("[HTTP Error]",e.toLogData())}const u=()=>document.documentElement.classList.contains("dark")?"rgba(7, 7, 7, 0.85)":"rgba(255, 255, 255, 0.5)",l={lock:!0,get background(){return u()},svg:'\n <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40">\n <style>\n .spinner {\n transform-origin: 20px 20px;\n animation: rotate 1.6s linear infinite;\n }\n .dot {\n fill: var(--theme-color);\n animation: fade 1.6s infinite;\n }\n .dot:nth-child(1) { animation-delay: 0s; }\n .dot:nth-child(2) { animation-delay: 0.5s; }\n .dot:nth-child(3) { animation-delay: 1s; }\n .dot:nth-child(4) { animation-delay: 1.5s; }\n @keyframes rotate {\n 100% { transform: rotate(360deg); }\n }\n @keyframes fade {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n </style>\n <g class="spinner">\n <circle class="dot" cx="20" cy="8" r="4"/>\n <circle class="dot" cx="32" cy="20" r="4"/>\n <circle class="dot" cx="20" cy="32" r="4"/>\n <circle class="dot" cx="8" cy="20" r="4"/>\n </g>\n </svg>\n',svgViewBox:"0 0 40 40",customClass:"art-loading-fix"};let m=null;const h={showLoading(){if(!m){const e={...l,background:u()};m=n.ElLoading.service(e)}return()=>this.hideLoading()},hideLoading(){m&&(m.close(),m=null)}};return e.TtHttp=function(e){const{router:u,useUserStore:l,VITE_API_URL:m,VITE_WITH_CREDENTIALS:p}=e;let f=!1;const g=["image/jpeg","image/png","image/gif","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"];let w=0;function E(){setTimeout(()=>{w--,0===w&&f&&r.nextTick(()=>{h.hideLoading(),f=!1})},0)}let T=!1,y=null;const v=t.create({timeout:6e4,baseURL:"/"+m,withCredentials:"true"===p,validateStatus:e=>e>=200&&e<300,transformResponse:[(e,t)=>{const n=t["content-type"];if(n?.includes("application/json"))try{return JSON.parse(e)}catch{return e}return e}]});function b(e,t){return new i(e,t)}function N(e){const t=b(e||s.unauthorized,a.unauthorized);if(!T)throw T=!0,L(),y=setTimeout(U,3e3),d(t,!0),t;throw t}function U(){T=!1,y&&clearTimeout(y),y=null}v.interceptors.request.use(e=>{const{accessToken:t,info:n}=l();return t&&(e.headers.set("Authorization",t),e.headers.set("token",t),e.headers.set("x-userid-header",n.userId),e.headers.set("x-permission-code-header",u.currentRoute.value.meta.permissionOnlyCode)),e.hideLoading||0!==w||(f=!0,h.showLoading()),w++,!e.data||e.data instanceof FormData||e.headers["Content-Type"]||(e.headers.set("Content-Type","application/json"),e.data=JSON.stringify(e.data)),e},e=>(d(b(s.requestConfigError,a.error)),Promise.reject(e))),v.interceptors.response.use(e=>{E();const t=e.headers["content-type"];if(t?.includes("application/json")){const{code:t,msg:n}=e.data;if([a.success,a.success1].includes(t))return e;throw[a.unauthorized,a.INVALID_TOKEN].includes(t)&&N(n),b(n||s.requestFailed,t)}if(g.includes(t))return o(e,t),e},e=>(E(),e.response?.status===a.unauthorized&&N(),Promise.reject(c(e))));const L=()=>{setTimeout(()=>{l().logOut()},500)};async function S(e,t=0){try{return await async function(e){["POST","PUT"].includes(e.method?.toUpperCase()||"")&&e.params&&!e.data&&(e.data=e.params,e.params=void 0);try{const t=await v.request(e);return e.showSuccessMessage&&t.data.msg&&function(e,t=!0){t&&n.ElMessage.success(e)}(t.data.msg),t.data.data}catch(t){const n=[a.unauthorized,a.NEED_REFRESH_TOKEN].includes(t.code);if(t instanceof i&&!n){d(t,!1!==e.showErrorMessage)}return Promise.reject(t)}}(e)}catch(n){if(n instanceof i&&[a.NEED_REFRESH_TOKEN].includes(n.code)&&!e.url?.includes("/iam/user/refreshToken"))return await l().refreshTokenFunc(),await R(1e3),S(e,t-1);if(t>0&&n instanceof i&&(r=n.code,[a.requestTimeout,a.internalServerError,a.badGateway,a.serviceUnavailable,a.gatewayTimeout].includes(r)))return await R(1e3),S(e,t-1);throw n}var r}function R(e){return new Promise(t=>setTimeout(t,e))}return{...{get:e=>S({...e,method:"GET"}),post:e=>S({...e,method:"POST"}),put:e=>S({...e,method:"PUT"}),del:e=>S({...e,method:"DELETE"}),request:e=>S(e)},logOut:L}},e.capitalize=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},e.divide=function(e,t){return e/t},e.downloadFile=o,e.multiply=function(e,t){return e*t},e.subtract=function(e,t){return e-t},e.sum=function(e,t){return e+t},e.trim=function(e){return e.trim()},e}({},axios,elementPlus,Vue);
2
2
  //# sourceMappingURL=index.iife.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.iife.js","sources":["../src/string.ts","../src/math.ts"],"sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nexport function trim(str: string): string {\n return str.trim();\n}","export function sum(a: number, b: number): number {\n return a + b;\n}\n\nexport function multiply(a: number, b: number): number {\n return a * b;\n}\n\nexport function subtract(a: number, b: number): number {\n return a - b;\n}\n\nexport function divide(a: number, b: number): number {\n return a / b;\n}"],"names":["str","charAt","toUpperCase","slice","a","b","trim"],"mappings":"mEAAM,SAAqBA,GACzB,OAAOA,EAAIC,OAAO,GAAGC,cAAgBF,EAAIG,MAAM,EACjD,WCUM,SAAiBC,EAAWC,GAChC,OAAOD,EAAIC,CACb,aAVM,SAAmBD,EAAWC,GAClC,OAAOD,EAAIC,CACb,aAEM,SAAmBD,EAAWC,GAClC,OAAOD,EAAIC,CACb,QAVM,SAAcD,EAAWC,GAC7B,OAAOD,EAAIC,CACb,SDEM,SAAeL,GACnB,OAAOA,EAAIM,MACb"}
1
+ {"version":3,"file":"index.iife.js","sources":["../src/file.ts","../src/axios/status.ts","../src/axios/error.ts","../src/axios/loadinSvg.ts","../src/axios/loading.ts","../src/axios/index.ts","../src/string.ts","../src/math.ts"],"sourcesContent":["/**\r\n * @param res 响应 { data: Blob, ... }\r\n * @param type 类型\r\n */\r\n\r\ninterface HttpResponse<T> {\r\n data: T;\r\n headers: Record<string, string>;\r\n status: number;\r\n statusText: string;\r\n}\r\nexport const downloadFile = (res: HttpResponse<Blob>, type: string) => {\r\n try {\r\n // 创建blob对象,解析流数据\r\n const blob = new Blob([res.data], {\r\n type\r\n });\r\n const a = document.createElement(\"a\");\r\n const URL = window.URL || window.webkitURL;\r\n const herf = URL.createObjectURL(blob);\r\n a.href = herf;\r\n const contentDisposition: string[] = (res.headers[\"content-disposition\"] || \"\").split(\"=\") || [];\r\n let fileName = contentDisposition.at(-1) || \"\";\r\n fileName = fileName ? decodeURI(fileName.replace(/\"/g, \"\")) : \"\";\r\n const decodedParts = fileName?.split(\"''\");\r\n fileName = decodedParts.at(-1) || \"\";\r\n a.download = fileName;\r\n a.style.display = \"none\";\r\n document.body.appendChild(a);\r\n a.click();\r\n document.body.removeChild(a);\r\n window.URL.revokeObjectURL(herf);\r\n } catch (error) {\r\n console.log(error);\r\n }\r\n};\r\n","/**\r\n * 接口状态码\r\n */\r\nexport enum ApiStatus {\r\n success = 200, // 成功\r\n success1 = 0, // 成功\r\n error = 400, // 错误\r\n unauthorized = 401, // 未授权\r\n forbidden = 403, // 禁止访问\r\n notFound = 404, // 未找到\r\n methodNotAllowed = 405, // 方法不允许\r\n requestTimeout = 408, // 请求超时\r\n internalServerError = 500, // 服务器错误\r\n notImplemented = 501, // 未实现\r\n badGateway = 502, // 网关错误\r\n serviceUnavailable = 503, // 服务不可用\r\n gatewayTimeout = 504, // 网关超时\r\n httpVersionNotSupported = 505, // HTTP版本不支持\r\n NEED_REFRESH_TOKEN = 1001, // 需要刷新令牌\r\n API_NO_AUTH = 1002, // 接口未授权\r\n INVALID_TOKEN = 1005 // 无效的token\r\n}\r\n\r\n// 错误提示\r\nexport enum HttpMsg {\r\n badGateway = \"网关错误,请稍后重试\",\r\n forbidden = \"禁止访问该资源\",\r\n gatewayTimeout = \"网关超时,请稍后重试\",\r\n internalServerError = \"服务器内部错误,请稍后重试\",\r\n methodNotAllowed = \"请求方法不允许\",\r\n networkError = \"网络连接异常,请检查网络连接\",\r\n notFound = \"请求的资源不存在\",\r\n requestCancelled = \"请求已取消\",\r\n requestConfigError = \"请求配置错误\",\r\n requestFailed = \"请求失败\",\r\n requestTimeout = \"请求超时,请稍后重试\",\r\n serviceUnavailable = \"服务暂时不可用,请稍后重试\",\r\n unauthorized = \"未授权访问,请重新登录\"\r\n}\r\n","/**\r\n * HTTP 错误处理模块\r\n *\r\n * 提供统一的 HTTP 请求错误处理机制\r\n *\r\n * ## 主要功能\r\n *\r\n * - 自定义 HttpError 错误类,封装错误信息、状态码、时间戳等\r\n * - 错误拦截和转换,将 Axios 错误转换为标准的 HttpError\r\n * - 错误消息国际化处理,根据状态码返回对应的多语言错误提示\r\n * - 错误日志记录,便于问题追踪和调试\r\n * - 错误和成功消息的统一展示\r\n * - 类型守卫函数,用于判断错误类型\r\n *\r\n * ## 使用场景\r\n *\r\n * - HTTP 请求拦截器中统一处理错误\r\n * - 业务代码中捕获和处理特定错误\r\n * - 错误日志收集和上报\r\n *\r\n * @module utils/http/error\r\n * @author Art Design Pro Team\r\n */\r\nimport { AxiosError } from \"axios\";\r\nimport { ApiStatus, HttpMsg } from \"./status\";\r\nimport { ElMessage } from \"element-plus\";\r\n\r\n// 错误响应接口\r\nexport interface ErrorResponse {\r\n /** 错误状态码 */\r\n code: number;\r\n /** 错误消息 */\r\n msg: string;\r\n /** 错误附加数据 */\r\n data?: unknown;\r\n}\r\n\r\n// 错误日志数据接口\r\nexport interface ErrorLogData {\r\n /** 错误状态码 */\r\n code: number;\r\n /** 错误消息 */\r\n message: string;\r\n /** 错误附加数据 */\r\n data?: unknown;\r\n /** 错误发生时间戳 */\r\n timestamp: string;\r\n /** 请求 URL */\r\n url?: string;\r\n /** 请求方法 */\r\n method?: string;\r\n /** 错误堆栈信息 */\r\n stack?: string;\r\n}\r\n\r\n// 自定义 HttpError 类\r\nexport class HttpError extends Error {\r\n public readonly code: number;\r\n public readonly data?: unknown;\r\n public readonly timestamp: string;\r\n public readonly url?: string;\r\n public readonly method?: string;\r\n\r\n constructor(\r\n message: string,\r\n code: number,\r\n options?: {\r\n data?: unknown;\r\n url?: string;\r\n method?: string;\r\n }\r\n ) {\r\n super(message);\r\n this.name = \"HttpError\";\r\n this.code = code;\r\n this.data = options?.data;\r\n this.timestamp = new Date().toISOString();\r\n this.url = options?.url || \"\";\r\n this.method = options?.method || \"\";\r\n }\r\n\r\n public toLogData(): ErrorLogData {\r\n return {\r\n code: this.code,\r\n message: this.message,\r\n data: this.data,\r\n timestamp: this.timestamp,\r\n url: this.url || \"\",\r\n method: this.method || \"\",\r\n stack: this.stack || \"\"\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * 获取错误消息\r\n * @param status 错误状态码\r\n * @returns 错误消息\r\n */\r\nconst getErrorMessage = (status: number): string => {\r\n const errorMap: Record<number, string> = {\r\n [ApiStatus.unauthorized]: HttpMsg.unauthorized,\r\n [ApiStatus.forbidden]: HttpMsg.forbidden,\r\n [ApiStatus.notFound]: HttpMsg.notFound,\r\n [ApiStatus.methodNotAllowed]: HttpMsg.methodNotAllowed,\r\n [ApiStatus.requestTimeout]: HttpMsg.requestTimeout,\r\n [ApiStatus.internalServerError]: HttpMsg.internalServerError,\r\n [ApiStatus.badGateway]: HttpMsg.badGateway,\r\n [ApiStatus.serviceUnavailable]: HttpMsg.serviceUnavailable,\r\n [ApiStatus.gatewayTimeout]: HttpMsg.gatewayTimeout\r\n };\r\n\r\n return errorMap[status] || HttpMsg.internalServerError;\r\n};\r\n\r\n/**\r\n * 处理错误\r\n * @param error 错误对象\r\n * @returns 错误对象\r\n */\r\nexport function handleError(error: AxiosError<ErrorResponse>): never {\r\n // 处理取消的请求\r\n if (error.code === \"ERR_CANCELED\") {\r\n console.warn(\"Request cancelled:\", error.message);\r\n throw new HttpError(HttpMsg.requestCancelled, ApiStatus.error);\r\n }\r\n\r\n const statusCode = error.response?.status;\r\n const errorMessage = error.response?.data?.msg || error.message;\r\n const requestConfig = error.config;\r\n\r\n // 处理网络错误\r\n if (!error.response) {\r\n throw new HttpError(HttpMsg.networkError, ApiStatus.error, {\r\n url: requestConfig?.url || \"\",\r\n method: requestConfig?.method?.toUpperCase() || \"\"\r\n });\r\n }\r\n\r\n // 处理 HTTP 状态码错误\r\n const message = statusCode ? getErrorMessage(statusCode) : errorMessage || HttpMsg.requestFailed;\r\n throw new HttpError(message, statusCode || ApiStatus.error, {\r\n data: error.response.data,\r\n url: requestConfig?.url || \"\",\r\n method: requestConfig?.method?.toUpperCase() || \"\"\r\n });\r\n}\r\n\r\n/**\r\n * 显示错误消息\r\n * @param error 错误对象\r\n * @param showMessage 是否显示错误消息\r\n */\r\nexport function showError(error: HttpError, showMessage: boolean = true): void {\r\n if (showMessage) {\r\n ElMessage.error(error.message);\r\n }\r\n // 记录错误日志\r\n console.error(\"[HTTP Error]\", error.toLogData());\r\n}\r\n\r\n/**\r\n * 显示成功消息\r\n * @param message 成功消息\r\n * @param showMessage 是否显示消息\r\n */\r\nexport function showSuccess(message: string, showMessage: boolean = true): void {\r\n if (showMessage) {\r\n ElMessage.success(message);\r\n }\r\n}\r\n\r\n/**\r\n * 判断是否为 HttpError 类型\r\n * @param error 错误对象\r\n * @returns 是否为 HttpError 类型\r\n */\r\nexport const isHttpError = (error: unknown): error is HttpError => {\r\n return error instanceof HttpError;\r\n};\r\n","// 自定义四点旋转SVG\r\nexport const fourDotsSpinnerSvg = `\r\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"40\" viewBox=\"0 0 40 40\">\r\n <style>\r\n .spinner {\r\n transform-origin: 20px 20px;\r\n animation: rotate 1.6s linear infinite;\r\n }\r\n .dot {\r\n fill: var(--theme-color);\r\n animation: fade 1.6s infinite;\r\n }\r\n .dot:nth-child(1) { animation-delay: 0s; }\r\n .dot:nth-child(2) { animation-delay: 0.5s; }\r\n .dot:nth-child(3) { animation-delay: 1s; }\r\n .dot:nth-child(4) { animation-delay: 1.5s; }\r\n @keyframes rotate {\r\n 100% { transform: rotate(360deg); }\r\n }\r\n @keyframes fade {\r\n 0%, 100% { opacity: 1; }\r\n 50% { opacity: 0.5; }\r\n }\r\n </style>\r\n <g class=\"spinner\">\r\n <circle class=\"dot\" cx=\"20\" cy=\"8\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"32\" cy=\"20\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"20\" cy=\"32\" r=\"4\"/>\r\n <circle class=\"dot\" cx=\"8\" cy=\"20\" r=\"4\"/>\r\n </g>\r\n </svg>\r\n`;\r\n","/**\r\n * 全局 Loading 加载管理模块\r\n *\r\n * 提供统一的全屏加载动画管理\r\n *\r\n * ## 主要功能\r\n *\r\n * - 全屏 Loading 显示和隐藏\r\n * - 自动适配明暗主题背景色\r\n * - 自定义 SVG 加载动画\r\n * - 单例模式防止重复创建\r\n * - 锁定页面交互\r\n *\r\n * ## 使用场景\r\n *\r\n * - 页面初始化加载\r\n * - 大量数据请求\r\n * - 路由切换过渡\r\n * - 异步操作等待\r\n *\r\n * ## 特性\r\n *\r\n * - 自动检测当前主题并应用对应背景色\r\n * - 使用自定义 SVG 动画(四点旋转)\r\n * - 单例模式确保同时只有一个 Loading\r\n * - 提供便捷的显示/隐藏方法\r\n *\r\n * @module utils/ui/loading\r\n * @author Art Design Pro Team\r\n */\r\nimport { fourDotsSpinnerSvg } from \"./loadinSvg\";\r\nimport { ElLoading } from \"element-plus\";\r\n/**\r\n * 获取当前主题对应的loading背景色\r\n * @returns 背景色字符串\r\n */\r\nconst getLoadingBackground = (): string => {\r\n const isDark = document.documentElement.classList.contains(\"dark\");\r\n return isDark ? \"rgba(7, 7, 7, 0.85)\" : \"rgba(255, 255, 255, 0.5)\";\r\n};\r\n\r\nconst DEFAULT_LOADING_CONFIG = {\r\n lock: true,\r\n get background() {\r\n return getLoadingBackground();\r\n },\r\n svg: fourDotsSpinnerSvg,\r\n svgViewBox: \"0 0 40 40\",\r\n customClass: \"art-loading-fix\"\r\n} as const;\r\n\r\ninterface LoadingInstance {\r\n close: () => void;\r\n}\r\n\r\nlet loadingInstance: LoadingInstance | null = null;\r\n\r\nexport const loadingService = {\r\n /**\r\n * 显示 loading\r\n * @returns 关闭 loading 的函数\r\n */\r\n showLoading(): () => void {\r\n if (!loadingInstance) {\r\n // 每次显示时获取最新的配置,确保背景色与当前主题同步\r\n const config = {\r\n ...DEFAULT_LOADING_CONFIG,\r\n background: getLoadingBackground()\r\n };\r\n loadingInstance = ElLoading.service(config);\r\n }\r\n return () => this.hideLoading();\r\n },\r\n\r\n /**\r\n * 隐藏 loading\r\n */\r\n hideLoading(): void {\r\n if (loadingInstance) {\r\n loadingInstance.close();\r\n loadingInstance = null;\r\n }\r\n }\r\n};\r\n","import axios, { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from \"axios\";\r\nimport { HttpError, handleError, showError, showSuccess } from \"./error\";\r\nimport { ApiStatus, HttpMsg } from \"./status\";\r\nimport { BaseResponse, TtHttpReturnType } from \"./type\";\r\nimport { downloadFile } from \"../file\";\r\nimport { nextTick } from \"vue\";\r\nimport { loadingService } from \"./loading\";\r\n\r\n// 需要传入\r\n// router useUserStore closeLoading startLoading VITE_API_URL VITE_WITH_CREDENTIALS\r\n/** 退出登录函数 */\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport function TtHttp(config: any): TtHttpReturnType {\r\n const { router, useUserStore, VITE_API_URL, VITE_WITH_CREDENTIALS } = config;\r\n\r\n // 跟踪是否需要关闭 loading\r\n let pendingLoading = false;\r\n function closeLoading(): void {\r\n if (pendingLoading) {\r\n nextTick(() => {\r\n loadingService.hideLoading();\r\n pendingLoading = false;\r\n });\r\n }\r\n }\r\n /** 开始 loading 效果 */\r\n function startLoading(): void {\r\n pendingLoading = true;\r\n loadingService.showLoading();\r\n }\r\n // 文件类型\r\n const FILE_TYPES = [\r\n \"image/jpeg\",\r\n \"image/png\",\r\n \"image/gif\",\r\n \"image/webp\",\r\n \"image/svg+xml\",\r\n \"application/pdf\",\r\n \"application/msword\",\r\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\r\n \"application/vnd.ms-excel\",\r\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8\"\r\n ];\r\n\r\n /** 请求配置常量 */\r\n const REQUEST_TIMEOUT = 1000 * 60;\r\n const LOGOUT_DELAY = 500;\r\n const MAX_RETRIES = 0;\r\n const RETRY_DELAY = 1000;\r\n const UNAUTHORIZED_DEBOUNCE_TIME = 3000;\r\n\r\n let activeRequests = 0;\r\n function debuncesLoading() {\r\n setTimeout(() => {\r\n activeRequests--;\r\n if (activeRequests === 0) {\r\n closeLoading();\r\n }\r\n }, 0);\r\n }\r\n\r\n /** 401防抖状态 */\r\n let isUnauthorizedErrorShown = false;\r\n let unauthorizedTimer: NodeJS.Timeout | null = null;\r\n\r\n /** 扩展 AxiosRequestConfig */\r\n interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {\r\n showErrorMessage?: boolean;\r\n showSuccessMessage?: boolean;\r\n hideLoading?: boolean;\r\n }\r\n\r\n /** Axios实例 */\r\n const axiosInstance = axios.create({\r\n timeout: REQUEST_TIMEOUT,\r\n baseURL: \"/\" + VITE_API_URL,\r\n withCredentials: VITE_WITH_CREDENTIALS === \"true\",\r\n validateStatus: status => status >= 200 && status < 300,\r\n transformResponse: [\r\n (data, headers) => {\r\n const contentType = headers[\"content-type\"];\r\n if (contentType?.includes(\"application/json\")) {\r\n try {\r\n return JSON.parse(data);\r\n } catch {\r\n return data;\r\n }\r\n }\r\n return data;\r\n }\r\n ]\r\n });\r\n\r\n /** 请求拦截器 */\r\n axiosInstance.interceptors.request.use(\r\n (request: InternalAxiosRequestConfig) => {\r\n const { accessToken, info } = useUserStore();\r\n if (accessToken) {\r\n request.headers.set(\"Authorization\", accessToken);\r\n request.headers.set(\"token\", accessToken);\r\n request.headers.set(\"x-userid-header\", info.userId);\r\n request.headers.set(\"x-permission-code-header\", router.currentRoute.value.meta.permissionOnlyCode as string);\r\n }\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n if (!(request as any).hideLoading && activeRequests === 0) {\r\n startLoading();\r\n }\r\n activeRequests++;\r\n\r\n if (request.data && !(request.data instanceof FormData) && !request.headers[\"Content-Type\"]) {\r\n request.headers.set(\"Content-Type\", \"application/json\");\r\n request.data = JSON.stringify(request.data);\r\n }\r\n\r\n return request;\r\n },\r\n error => {\r\n showError(createHttpError(HttpMsg.requestConfigError, ApiStatus.error));\r\n return Promise.reject(error);\r\n }\r\n );\r\n\r\n /** 响应拦截器 */\r\n axiosInstance.interceptors.response.use(\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n (response: AxiosResponse<BaseResponse> | any) => {\r\n debuncesLoading();\r\n const contentType = response.headers[\"content-type\"];\r\n if (contentType?.includes(\"application/json\")) {\r\n const { code, msg } = response.data;\r\n if ([ApiStatus.success, ApiStatus.success1].includes(code)) return response;\r\n if ([ApiStatus.unauthorized, ApiStatus.INVALID_TOKEN].includes(code)) handleUnauthorizedError(msg);\r\n throw createHttpError(msg || HttpMsg.requestFailed, code);\r\n } else if (FILE_TYPES.includes(contentType)) {\r\n // 文件类型 下载\r\n downloadFile(response, contentType);\r\n return response;\r\n }\r\n },\r\n error => {\r\n debuncesLoading();\r\n if (error.response?.status === ApiStatus.unauthorized) handleUnauthorizedError();\r\n return Promise.reject(handleError(error));\r\n }\r\n );\r\n\r\n /** 统一创建HttpError */\r\n function createHttpError(message: string, code: number) {\r\n return new HttpError(message, code);\r\n }\r\n\r\n /** 处理401错误(带防抖) */\r\n function handleUnauthorizedError(message?: string): never {\r\n const error = createHttpError(message || HttpMsg.unauthorized, ApiStatus.unauthorized);\r\n\r\n if (!isUnauthorizedErrorShown) {\r\n isUnauthorizedErrorShown = true;\r\n logOut();\r\n\r\n unauthorizedTimer = setTimeout(resetUnauthorizedError, UNAUTHORIZED_DEBOUNCE_TIME);\r\n\r\n showError(error, true);\r\n throw error;\r\n }\r\n\r\n throw error;\r\n }\r\n\r\n /** 重置401防抖状态 */\r\n function resetUnauthorizedError() {\r\n isUnauthorizedErrorShown = false;\r\n if (unauthorizedTimer) clearTimeout(unauthorizedTimer);\r\n unauthorizedTimer = null;\r\n }\r\n\r\n const logOut = () => {\r\n setTimeout(() => {\r\n useUserStore().logOut();\r\n }, LOGOUT_DELAY);\r\n };\r\n /** 是否需要重试 */\r\n function shouldRetry(statusCode: number) {\r\n return [\r\n ApiStatus.requestTimeout,\r\n ApiStatus.internalServerError,\r\n ApiStatus.badGateway,\r\n ApiStatus.serviceUnavailable,\r\n ApiStatus.gatewayTimeout\r\n ].includes(statusCode);\r\n }\r\n\r\n /** 请求重试逻辑 */\r\n async function retryRequest<T>(config: ExtendedAxiosRequestConfig, retries: number = MAX_RETRIES): Promise<T> {\r\n try {\r\n return await request<T>(config);\r\n } catch (error) {\r\n if (error instanceof HttpError && [ApiStatus.NEED_REFRESH_TOKEN].includes(error.code)) {\r\n if (!config.url?.includes(\"/iam/user/refreshToken\")) {\r\n // 刷新token\r\n await useUserStore().refreshTokenFunc();\r\n await delay(RETRY_DELAY);\r\n return retryRequest<T>(config, retries - 1);\r\n }\r\n }\r\n if (retries > 0 && error instanceof HttpError && shouldRetry(error.code)) {\r\n await delay(RETRY_DELAY);\r\n return retryRequest<T>(config, retries - 1);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** 延迟函数 */\r\n function delay(ms: number) {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n }\r\n\r\n /** 请求函数 */\r\n async function request<T>(config: ExtendedAxiosRequestConfig): Promise<T> {\r\n // POST | PUT 参数自动填充\r\n if ([\"POST\", \"PUT\"].includes(config.method?.toUpperCase() || \"\") && config.params && !config.data) {\r\n config.data = config.params;\r\n config.params = undefined;\r\n }\r\n\r\n try {\r\n const res = await axiosInstance.request<BaseResponse<T>>(config);\r\n\r\n // 显示成功消息\r\n if (config.showSuccessMessage && res.data.msg) {\r\n showSuccess(res.data.msg);\r\n }\r\n\r\n return res.data.data as T;\r\n } catch (error) {\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const excludeError = [ApiStatus.unauthorized, ApiStatus.NEED_REFRESH_TOKEN].includes((error as any).code);\r\n if (error instanceof HttpError && !excludeError) {\r\n const showMsg = config.showErrorMessage !== false;\r\n showError(error, showMsg);\r\n }\r\n return Promise.reject(error);\r\n }\r\n }\r\n\r\n /** API方法集合 */\r\n const api = {\r\n get<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"GET\" });\r\n },\r\n post<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"POST\" });\r\n },\r\n put<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"PUT\" });\r\n },\r\n del<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>({ ...config, method: \"DELETE\" });\r\n },\r\n request<T>(config: ExtendedAxiosRequestConfig) {\r\n return retryRequest<T>(config);\r\n }\r\n };\r\n\r\n return {\r\n ...api,\r\n logOut\r\n };\r\n}\r\n","export function capitalize(str: string): string {\r\n return str.charAt(0).toUpperCase() + str.slice(1);\r\n}\r\n\r\nexport function trim(str: string): string {\r\n return str.trim();\r\n}","export function sum(a: number, b: number): number {\r\n return a + b;\r\n}\r\n\r\nexport function multiply(a: number, b: number): number {\r\n return a * b;\r\n}\r\n\r\nexport function subtract(a: number, b: number): number {\r\n return a - b;\r\n}\r\n\r\nexport function divide(a: number, b: number): number {\r\n return a / b;\r\n}"],"names":["downloadFile","res","type","blob","Blob","data","a","document","createElement","herf","window","URL","webkitURL","createObjectURL","href","fileName","headers","split","at","decodeURI","replace","decodedParts","download","style","display","body","appendChild","click","removeChild","revokeObjectURL","error","console","log","ApiStatus","HttpMsg","HttpError","Error","code","timestamp","url","method","constructor","message","options","super","this","name","Date","toISOString","toLogData","stack","handleError","warn","requestCancelled","statusCode","response","status","errorMessage","msg","requestConfig","config","networkError","toUpperCase","unauthorized","forbidden","notFound","methodNotAllowed","requestTimeout","internalServerError","badGateway","serviceUnavailable","gatewayTimeout","requestFailed","showError","showMessage","ElMessage","getLoadingBackground","documentElement","classList","contains","DEFAULT_LOADING_CONFIG","lock","background","svg","svgViewBox","customClass","loadingInstance","loadingService","showLoading","ElLoading","service","hideLoading","close","router","useUserStore","VITE_API_URL","VITE_WITH_CREDENTIALS","pendingLoading","FILE_TYPES","activeRequests","debuncesLoading","setTimeout","nextTick","isUnauthorizedErrorShown","unauthorizedTimer","axiosInstance","axios","create","timeout","baseURL","withCredentials","validateStatus","transformResponse","contentType","includes","JSON","parse","createHttpError","handleUnauthorizedError","logOut","resetUnauthorizedError","clearTimeout","interceptors","request","use","accessToken","info","set","userId","currentRoute","value","meta","permissionOnlyCode","FormData","stringify","requestConfigError","Promise","reject","success","success1","INVALID_TOKEN","async","retryRequest","retries","params","undefined","showSuccessMessage","showSuccess","excludeError","NEED_REFRESH_TOKEN","showErrorMessage","refreshTokenFunc","delay","ms","resolve","get","post","put","del","str","charAt","slice","b","trim"],"mappings":"2DAWaA,EAAe,CAACC,EAAyBC,KACpD,IAEE,MAAMC,EAAO,IAAIC,KAAK,CAACH,EAAII,MAAO,CAChCH,SAEII,EAAIC,SAASC,cAAc,KAE3BC,GADMC,OAAOC,KAAOD,OAAOE,WAChBC,gBAAgBV,GACjCG,EAAEQ,KAAOL,EAET,IAAIM,IADkCd,EAAIe,QAAQ,wBAA0B,IAAIC,MAAM,MAAQ,IAC5DC,IAAI,IAAM,GAC5CH,EAAWA,EAAWI,UAAUJ,EAASK,QAAQ,KAAM,KAAO,GAC9D,MAAMC,EAAeN,GAAUE,MAAM,MACrCF,EAAWM,EAAaH,IAAI,IAAM,GAClCZ,EAAEgB,SAAWP,EACbT,EAAEiB,MAAMC,QAAU,OAClBjB,SAASkB,KAAKC,YAAYpB,GAC1BA,EAAEqB,QACFpB,SAASkB,KAAKG,YAAYtB,GAC1BI,OAAOC,IAAIkB,gBAAgBpB,EAC7B,CAAE,MAAOqB,GACPC,QAAQC,IAAIF,EACd,GC/BF,IAAYG,EAqBAC,GArBZ,SAAYD,GACVA,EAAAA,EAAA,QAAA,KAAA,UACAA,EAAAA,EAAA,SAAA,GAAA,WACAA,EAAAA,EAAA,MAAA,KAAA,QACAA,EAAAA,EAAA,aAAA,KAAA,eACAA,EAAAA,EAAA,UAAA,KAAA,YACAA,EAAAA,EAAA,SAAA,KAAA,WACAA,EAAAA,EAAA,iBAAA,KAAA,mBACAA,EAA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,CA5BF,IAAqBwB,CA6BrB,CAGA,SAASkG,EAAMC,GACb,OAAO,IAAIjB,QAAQkB,GAAWrD,WAAWqD,EAASD,GACpD,CAiDA,MAAO,IAlBK,CACVE,IAAO/F,GACEkF,EAAgB,IAAKlF,EAAQpB,OAAQ,QAE9CoH,KAAQhG,GACCkF,EAAgB,IAAKlF,EAAQpB,OAAQ,SAE9CqH,IAAOjG,GACEkF,EAAgB,IAAKlF,EAAQpB,OAAQ,QAE9CsH,IAAOlG,GACEkF,EAAgB,IAAKlF,EAAQpB,OAAQ,WAE9CmF,QAAW/D,GACFkF,EAAgBlF,IAMzB2D,SAEJ,eC5QM,SAAqBwC,GACzB,OAAOA,EAAIC,OAAO,GAAGlG,cAAgBiG,EAAIE,MAAM,EACjD,WCUM,SAAiB3J,EAAW4J,GAChC,OAAO5J,EAAI4J,CACb,8BAVM,SAAmB5J,EAAW4J,GAClC,OAAO5J,EAAI4J,CACb,aAEM,SAAmB5J,EAAW4J,GAClC,OAAO5J,EAAI4J,CACb,QAVM,SAAc5J,EAAW4J,GAC7B,OAAO5J,EAAI4J,CACb,SDEM,SAAeH,GACnB,OAAOA,EAAII,MACb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dazhicheng/utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,6 +23,12 @@
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
+ "dependencies": {
27
+ "@types/node": "^24.5.2",
28
+ "axios": "^1.13.4",
29
+ "element-plus": "^2.13.2",
30
+ "vue": "^3.5.21"
31
+ },
26
32
  "scripts": {
27
33
  "test": "echo \"Error: no test specified\" && exit 1"
28
34
  }