@ruan-cat/utils 3.1.0 → 3.3.0
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/package.json +11 -11
- package/src/vueuse/useAxios/index.ts +10 -4
- package/src/vueuse/useAxios/v2.ts +86 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "阮喵喵工具集合。一个纯typescript库,也提供纯js文件。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -58,23 +58,23 @@
|
|
|
58
58
|
"tsconfig.json"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@vueuse/integrations": "^12.
|
|
62
|
-
"axios": "^1.
|
|
61
|
+
"@vueuse/integrations": "^12.7.0",
|
|
62
|
+
"axios": "^1.8.1",
|
|
63
63
|
"consola": "^3.4.0",
|
|
64
64
|
"lodash-es": "^4.17.21"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@antfu/utils": "^
|
|
67
|
+
"@antfu/utils": "^9.1.0",
|
|
68
68
|
"@types/lodash-es": "^4.17.12",
|
|
69
|
-
"@types/node": "^22.13.
|
|
70
|
-
"@types/qs": "^6.9.
|
|
71
|
-
"qs": "^6.
|
|
72
|
-
"tsup": "^8.
|
|
69
|
+
"@types/node": "^22.13.8",
|
|
70
|
+
"@types/qs": "^6.9.18",
|
|
71
|
+
"qs": "^6.14.0",
|
|
72
|
+
"tsup": "^8.4.0",
|
|
73
73
|
"type-plus": "^7.6.2",
|
|
74
|
-
"typedoc": "^0.27.
|
|
74
|
+
"typedoc": "^0.27.9",
|
|
75
75
|
"typedoc-plugin-frontmatter": "^1.2.1",
|
|
76
|
-
"typedoc-plugin-markdown": "^4.
|
|
77
|
-
"typescript": "5.
|
|
76
|
+
"typedoc-plugin-markdown": "^4.4.2",
|
|
77
|
+
"typescript": "^5.8.2",
|
|
78
78
|
"unplugin-vue-router": "^0.11.2",
|
|
79
79
|
"vite-plugin-autogeneration-import-file": "^3.0.0",
|
|
80
80
|
"@ruan-cat/vuepress-preset-config": "^0.1.19"
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { RequiredPick } from "type-plus";
|
|
2
2
|
import type { AxiosRequestConfig, AxiosResponse, AxiosInstance } from "axios";
|
|
3
|
-
import type { UseAxiosOptions, UseAxiosReturn } from "@vueuse/integrations/useAxios";
|
|
3
|
+
import type { UseAxiosOptions, UseAxiosOptionsBase, UseAxiosReturn } from "@vueuse/integrations/useAxios";
|
|
4
4
|
import { useAxios } from "@vueuse/integrations/useAxios";
|
|
5
5
|
|
|
6
6
|
/** 在封装函数时 需要使用该类型 */
|
|
7
|
-
export { UseAxiosOptions };
|
|
7
|
+
export { UseAxiosOptions, UseAxiosOptionsBase };
|
|
8
8
|
|
|
9
9
|
/** 拓展的类型参数 用于约束必填的字段 */
|
|
10
10
|
export type KeyAxiosRequestConfig<D = any> = keyof AxiosRequestConfig<D>;
|
|
@@ -12,7 +12,10 @@ export type KeyAxiosRequestConfig<D = any> = keyof AxiosRequestConfig<D>;
|
|
|
12
12
|
/** 填写key值的帮助类型 */
|
|
13
13
|
export type KeyHelper<K extends KeyAxiosRequestConfig> = K;
|
|
14
14
|
|
|
15
|
+
/** @deprecated 在v2版本中,我们不使用该工具来约束删减类型 */
|
|
15
16
|
export type RemoveUrl<T extends KeyAxiosRequestConfig> = Exclude<T, "url">;
|
|
17
|
+
/** @deprecated 在v2版本中,我们不使用该工具来约束删减类型 */
|
|
18
|
+
export type RemoveUrlMethod<T extends KeyAxiosRequestConfig> = Exclude<T, "url" | "method">;
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* 创建 AxiosRequestConfig 的各种变种类型
|
|
@@ -65,11 +68,11 @@ declare module "@vueuse/integrations/useAxios" {
|
|
|
65
68
|
url: string,
|
|
66
69
|
config: AxiosRequestConfig<D>,
|
|
67
70
|
instance: AxiosInstance,
|
|
68
|
-
options?:
|
|
71
|
+
options?: UseAxiosOptionsBase,
|
|
69
72
|
): StrictUseAxiosReturn<T, K, R, D> & Promise<StrictUseAxiosReturn<T, K, R, D>>;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
/** 包装器的参数 */
|
|
75
|
+
/** 包装器的参数 @version 1 */
|
|
73
76
|
export interface UseAxiosWrapperParams<
|
|
74
77
|
/**
|
|
75
78
|
* 业务数据类型
|
|
@@ -122,6 +125,7 @@ export interface UseAxiosWrapperParams<
|
|
|
122
125
|
* 其本质是对 useAxios 函数的封装,仅仅是包装了参数层
|
|
123
126
|
*
|
|
124
127
|
* 预期设计成一个万能的 通用的请求函数
|
|
128
|
+
* @version 1
|
|
125
129
|
*/
|
|
126
130
|
export function useAxiosWrapper<T, K extends KeyAxiosRequestConfig, D = any>(params: UseAxiosWrapperParams) {
|
|
127
131
|
const {
|
|
@@ -136,3 +140,5 @@ export function useAxiosWrapper<T, K extends KeyAxiosRequestConfig, D = any>(par
|
|
|
136
140
|
// 跳转到我们拓展的函数声明
|
|
137
141
|
return useAxios<T, K, AxiosResponse<T>, D>(url, config, instance, options);
|
|
138
142
|
}
|
|
143
|
+
|
|
144
|
+
export * from "./v2.ts";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 这里是第二版本的工具 目前属于测试阶段
|
|
3
|
+
* 等待完善后,会正式地替代原来的设计。
|
|
4
|
+
*/
|
|
5
|
+
import type { AxiosResponse, AxiosInstance } from "axios";
|
|
6
|
+
import type { UseAxiosOptionsBase } from "@vueuse/integrations/useAxios";
|
|
7
|
+
import { useAxios } from "@vueuse/integrations/useAxios";
|
|
8
|
+
import type { CreateAxiosRequestConfig, KeyAxiosRequestConfig } from "./index.ts";
|
|
9
|
+
|
|
10
|
+
/** 包装器的参数 @version 2 */
|
|
11
|
+
export interface UseAxiosWrapperParams2<
|
|
12
|
+
/**
|
|
13
|
+
* AxiosRequestConfig 默认必填的字段
|
|
14
|
+
* @description
|
|
15
|
+
* key是首先必填的字段 必须要约束axios请求配置的可选项值
|
|
16
|
+
*
|
|
17
|
+
* 该key值不再默认要求url是必填项 不做严格约束
|
|
18
|
+
*/
|
|
19
|
+
K extends KeyAxiosRequestConfig,
|
|
20
|
+
/**
|
|
21
|
+
* 业务数据类型
|
|
22
|
+
* @description
|
|
23
|
+
* axios的返回值类型 二版本不再默认提供any类型
|
|
24
|
+
*
|
|
25
|
+
* 下游工具必须主动传递类型
|
|
26
|
+
*/
|
|
27
|
+
T,
|
|
28
|
+
/** UseAxiosOptionsBase 的派生类型 */
|
|
29
|
+
UseAxiosOptionsLike extends UseAxiosOptionsBase = UseAxiosOptionsBase<T>,
|
|
30
|
+
/**
|
|
31
|
+
* AxiosRequestConfig 用的类型
|
|
32
|
+
* @description
|
|
33
|
+
* 通常是 axios 的输入值
|
|
34
|
+
*/
|
|
35
|
+
D = any,
|
|
36
|
+
> {
|
|
37
|
+
/**
|
|
38
|
+
* 接口的url
|
|
39
|
+
* @description
|
|
40
|
+
* 接口必须要有url地址,该url迁移到此处专门设置
|
|
41
|
+
*
|
|
42
|
+
* 不要求在 axios 配置内必传url了。
|
|
43
|
+
* @version 2
|
|
44
|
+
*/
|
|
45
|
+
url: string;
|
|
46
|
+
/**
|
|
47
|
+
* axios的配置类型
|
|
48
|
+
* @description
|
|
49
|
+
* 默认为 必填url请求地址的 config 请求配置
|
|
50
|
+
*/
|
|
51
|
+
config: CreateAxiosRequestConfig<K, D>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* axios实例
|
|
55
|
+
* @description
|
|
56
|
+
* 对于包装器函数而言 必须传递有意义的请求实例
|
|
57
|
+
*/
|
|
58
|
+
instance: AxiosInstance;
|
|
59
|
+
|
|
60
|
+
/** useAxios 的选项配置 */
|
|
61
|
+
options: UseAxiosOptionsLike;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 正在尝试重构的2 url不是非必填 多了独立的url参数 */
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* useAxios 的包装函数
|
|
69
|
+
* @description
|
|
70
|
+
* 其本质是对 useAxios 函数的封装,仅仅是包装了参数层
|
|
71
|
+
*
|
|
72
|
+
* 预期设计成一个万能的 通用的请求函数
|
|
73
|
+
*
|
|
74
|
+
* 类型必传key T UseAxiosOptionsLike
|
|
75
|
+
* @version 2
|
|
76
|
+
*/
|
|
77
|
+
export function useAxiosWrapper2<
|
|
78
|
+
K extends KeyAxiosRequestConfig,
|
|
79
|
+
T,
|
|
80
|
+
UseAxiosOptionsLike extends UseAxiosOptionsBase,
|
|
81
|
+
D = any,
|
|
82
|
+
>(params: UseAxiosWrapperParams2<K, T, UseAxiosOptionsLike, D>) {
|
|
83
|
+
const { config = {}, instance, options = {} } = params;
|
|
84
|
+
const url = params.url || "";
|
|
85
|
+
return useAxios<T, K, AxiosResponse<T>, D>(url, config, instance, options);
|
|
86
|
+
}
|