@clownlee/http 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @clownlee/request
|
|
2
2
|
|
|
3
3
|
Axios 公共通用库,提供统一的 HTTP 请求能力和自动 token 刷新功能。
|
|
4
4
|
|
|
@@ -15,13 +15,13 @@ Axios 公共通用库,提供统一的 HTTP 请求能力和自动 token 刷新
|
|
|
15
15
|
## 安装
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npm install @
|
|
18
|
+
npm install @clownlee/request
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## 使用示例
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
|
-
import { init } from '@
|
|
24
|
+
import { init } from '@clownlee/request'
|
|
25
25
|
import { useUserStore } from '@/stores/user'
|
|
26
26
|
|
|
27
27
|
const userStore = useUserStore()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosRequestConfig,
|
|
1
|
+
import { AxiosRequestConfig, CancelToken, CancelTokenSource, InternalAxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Store } from 'pinia';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -53,12 +53,14 @@ export interface HttpRequestConfig extends Omit<AxiosRequestConfig, 'cancelToken
|
|
|
53
53
|
/**
|
|
54
54
|
* HTTP 响应数据模型
|
|
55
55
|
*/
|
|
56
|
-
export interface HttpResponse<T = any>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
export interface HttpResponse<T = any> {
|
|
57
|
+
code: number;
|
|
58
|
+
message: string;
|
|
59
|
+
failure?: boolean;
|
|
60
|
+
success?: boolean;
|
|
61
|
+
data?: T;
|
|
62
|
+
timestamp?: string;
|
|
63
|
+
traceId?: string;
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
66
|
* HTTP 实例接口
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AxiosError, AxiosResponse } from 'axios';
|
|
2
|
-
import { RefreshConfig } from '../types/request.types';
|
|
2
|
+
import { HttpResponse, RefreshConfig } from '../types/request.types';
|
|
3
3
|
import { Store } from 'pinia';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 处理响应拦截器(成功响应)
|
|
7
7
|
*/
|
|
8
|
-
export declare function handleResponseInterceptor<T = any>(response: AxiosResponse<T
|
|
8
|
+
export declare function handleResponseInterceptor<T = any>(response: AxiosResponse<HttpResponse<T>>, store: Store, refreshConfig: RefreshConfig): Promise<AxiosResponse<HttpResponse<T>>>;
|
|
9
9
|
/**
|
|
10
10
|
* 处理响应错误拦截器
|
|
11
11
|
*/
|
package/dist/index.js
CHANGED
|
@@ -199,7 +199,7 @@ async function handleResponseInterceptor(response, store, refreshConfig) {
|
|
|
199
199
|
} else if (code > 0) {
|
|
200
200
|
throw new Error(responseData == null ? void 0 : responseData.message);
|
|
201
201
|
}
|
|
202
|
-
return
|
|
202
|
+
return response;
|
|
203
203
|
}
|
|
204
204
|
async function handleResponseError(error) {
|
|
205
205
|
throw error;
|
|
@@ -289,7 +289,7 @@ class RequestServiceClass {
|
|
|
289
289
|
cancelToken: config.cancelToken && "token" in config.cancelToken ? config.cancelToken.token : config.cancelToken
|
|
290
290
|
};
|
|
291
291
|
const response = await instance.request(axiosConfig);
|
|
292
|
-
return response;
|
|
292
|
+
return response.data;
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
295
|
* GET 请求
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clownlee/http",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "公共 HTTP 请求库,提供统一的 HTTP 请求能力和自动 token 刷新功能",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "vite build",
|
|
20
|
+
"build:test": "vite build",
|
|
20
21
|
"dev": "vite build --watch",
|
|
21
22
|
"type-check": "vue-tsc --noEmit"
|
|
22
23
|
},
|