@ruan-cat/utils 4.6.0 → 4.7.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "阮喵喵工具集合。默认提供js文件,也直接提供ts文件。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"tsconfig.json"
|
|
61
61
|
],
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@vueuse/integrations": "^
|
|
63
|
+
"@vueuse/integrations": "^13.3.0",
|
|
64
64
|
"axios": "^1.8.1",
|
|
65
65
|
"consola": "^3.4.0",
|
|
66
66
|
"lodash-es": "^4.17.21"
|
|
@@ -43,6 +43,7 @@ export interface StrictUseAxiosReturn<
|
|
|
43
43
|
K extends KeyAxiosRequestConfig<D>,
|
|
44
44
|
R,
|
|
45
45
|
D,
|
|
46
|
+
O extends UseAxiosOptions = UseAxiosOptions<T>,
|
|
46
47
|
> extends UseAxiosReturn<T, R, D> {
|
|
47
48
|
/**
|
|
48
49
|
* Manually call the axios request
|
|
@@ -50,7 +51,7 @@ export interface StrictUseAxiosReturn<
|
|
|
50
51
|
execute: (
|
|
51
52
|
url?: string | CreateAxiosRequestConfig<K, D>,
|
|
52
53
|
config?: CreateAxiosRequestConfig<K, D>,
|
|
53
|
-
) => Promise<StrictUseAxiosReturn<T, K, R, D>>;
|
|
54
|
+
) => Promise<StrictUseAxiosReturn<T, K, R, D, O>>;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
declare module "@vueuse/integrations/useAxios" {
|
|
@@ -65,12 +66,13 @@ declare module "@vueuse/integrations/useAxios" {
|
|
|
65
66
|
K extends KeyAxiosRequestConfig<D> = "url",
|
|
66
67
|
R = AxiosResponse<T>,
|
|
67
68
|
D = any,
|
|
69
|
+
O extends UseAxiosOptionsBase<T> = UseAxiosOptionsBase<T>,
|
|
68
70
|
>(
|
|
69
71
|
url: string,
|
|
70
72
|
config: AxiosRequestConfig<D>,
|
|
71
73
|
instance: AxiosInstance,
|
|
72
|
-
options
|
|
73
|
-
): StrictUseAxiosReturn<T, K, R, D> & Promise<StrictUseAxiosReturn<T, K, R, D>>;
|
|
74
|
+
options: O,
|
|
75
|
+
): StrictUseAxiosReturn<T, K, R, D, O> & Promise<StrictUseAxiosReturn<T, K, R, D, O>>;
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
/** 包装器的参数 @version 2 */
|
|
@@ -142,10 +144,11 @@ export function useAxiosWrapper<
|
|
|
142
144
|
T,
|
|
143
145
|
UseAxiosOptionsLike extends UseAxiosOptionsBase,
|
|
144
146
|
D = any,
|
|
147
|
+
O extends UseAxiosOptionsBase<T> = UseAxiosOptionsBase<T>,
|
|
145
148
|
>(params: UseAxiosWrapperParams<K, T, UseAxiosOptionsLike, D>) {
|
|
146
|
-
const { config = {}, instance, options = {} } = params;
|
|
149
|
+
const { config = {}, instance, options = {} as O } = params;
|
|
147
150
|
const url = params.url || "";
|
|
148
|
-
return useAxios<T, K, AxiosResponse<T>, D>(url, config, instance, options);
|
|
151
|
+
return useAxios<T, K, AxiosResponse<T>, D, O>(url, config, instance, options as O);
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
export * from "./v1.js";
|
|
@@ -8,13 +8,7 @@ import axios from "axios";
|
|
|
8
8
|
import type { JsonVO } from "./types/JsonVO";
|
|
9
9
|
|
|
10
10
|
import type { AxiosRequestConfigBaseKey, HttpParamWay } from "./tools.ts";
|
|
11
|
-
import {
|
|
12
|
-
createDefaultUseAxiosOptions,
|
|
13
|
-
setHeaders,
|
|
14
|
-
UpType,
|
|
15
|
-
setDefaultUseAxiosOptions,
|
|
16
|
-
setDataByHttpParamWay,
|
|
17
|
-
} from "./tools";
|
|
11
|
+
import { createDefaultUseAxiosOptions, setHeaders, UpType, setDefaultUseAxiosOptions } from "./tools";
|
|
18
12
|
|
|
19
13
|
/**
|
|
20
14
|
* 内部用的 axios 实例
|
|
@@ -34,7 +28,7 @@ export function defineAxiosInstance(axiosInstance: AxiosInstance) {
|
|
|
34
28
|
}
|
|
35
29
|
|
|
36
30
|
export type ParamsPathKey = AxiosRequestConfigBaseKey | "url";
|
|
37
|
-
export type ParamsQueryKey = AxiosRequestConfigBaseKey | "
|
|
31
|
+
export type ParamsQueryKey = AxiosRequestConfigBaseKey | "params";
|
|
38
32
|
export type ParamsBodyKey = AxiosRequestConfigBaseKey | "data";
|
|
39
33
|
|
|
40
34
|
type UseAxiosWrapperUseKey<T extends HttpParamWay, K extends KeyAxiosRequestConfig> =
|
|
@@ -61,6 +55,7 @@ export function useRequestIn01s<
|
|
|
61
55
|
T = any,
|
|
62
56
|
D = any,
|
|
63
57
|
HttpParamWayTemp extends HttpParamWay = Params<K>["httpParamWay"],
|
|
58
|
+
O extends UseAxiosOptionsBase<JsonVO<T>> = UseAxiosOptionsBase<JsonVO<T>>,
|
|
64
59
|
>(
|
|
65
60
|
params: Params<
|
|
66
61
|
//
|
|
@@ -79,16 +74,15 @@ export function useRequestIn01s<
|
|
|
79
74
|
} = params;
|
|
80
75
|
setHeaders(config, upType);
|
|
81
76
|
setDefaultUseAxiosOptions(options);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
config,
|
|
85
|
-
});
|
|
77
|
+
|
|
78
|
+
// console.log(" 最后请求前,看一下数据? ", config);
|
|
86
79
|
// console.log(" instance ?", instance.defaults.baseURL);
|
|
87
80
|
return useAxiosWrapper<
|
|
88
81
|
//
|
|
89
82
|
UseAxiosWrapperUseKey<HttpParamWayTemp, K>,
|
|
90
83
|
JsonVO<T>,
|
|
91
84
|
UseAxiosOptionsBase<JsonVO<T>>,
|
|
92
|
-
D
|
|
85
|
+
D,
|
|
86
|
+
O
|
|
93
87
|
>({ config, instance, options, url });
|
|
94
88
|
}
|
|
@@ -12,6 +12,15 @@ import { isConditionsSome } from "../../index";
|
|
|
12
12
|
* @description
|
|
13
13
|
* 用于控制接口请求时的参数传递方式
|
|
14
14
|
* @see https://www.cnblogs.com/jinyuanya/p/13934722.html
|
|
15
|
+
*
|
|
16
|
+
* @description
|
|
17
|
+
* 警告 该配置目前失去意义
|
|
18
|
+
*
|
|
19
|
+
* 该配置目前不再被使用了 不会被任何函数使用 配置起来属于无意义内容
|
|
20
|
+
*
|
|
21
|
+
* 未来会被删除 并重新整理对应的接口生成成果
|
|
22
|
+
*
|
|
23
|
+
* TODO: 准备删除该工具
|
|
15
24
|
*/
|
|
16
25
|
export type HttpParamWay =
|
|
17
26
|
// 路径传参
|
|
@@ -203,12 +212,29 @@ export function setDefaultUseAxiosOptions<T>(options: UseAxiosOptionsBase<T>) {
|
|
|
203
212
|
options.immediate = options?.immediate ?? _options.immediate;
|
|
204
213
|
}
|
|
205
214
|
|
|
206
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* @private
|
|
217
|
+
* @deprecated
|
|
218
|
+
* 废弃该功能
|
|
219
|
+
*
|
|
220
|
+
* 该函数没意义 重设请求前的参数 没有意义
|
|
221
|
+
*
|
|
222
|
+
* 重新设置的参数 没办法及时传递到真正执行接口请求的函数内
|
|
223
|
+
*/
|
|
207
224
|
interface SetDataByHttpParamWayParams {
|
|
208
225
|
httpParamWay: HttpParamWay;
|
|
209
226
|
config: AxiosRequestConfig;
|
|
210
227
|
}
|
|
211
|
-
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @deprecated
|
|
231
|
+
* 废弃该功能
|
|
232
|
+
*
|
|
233
|
+
* 该函数没意义 重设请求前的参数 没有意义
|
|
234
|
+
*
|
|
235
|
+
* 重新设置的参数 没办法及时传递到真正执行接口请求的函数内
|
|
236
|
+
*/
|
|
237
|
+
function setDataByHttpParamWay(params: SetDataByHttpParamWayParams) {
|
|
212
238
|
const { httpParamWay, config } = params;
|
|
213
239
|
if (
|
|
214
240
|
isConditionsSome([
|