@wzyjs/hooks 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/useFormRef.d.ts +2 -0
- package/dist/useFormRef.js +4 -0
- package/dist/useRequestPro.d.ts +3 -3
- package/dist/useRequestPro.js +20 -6
- package/package.json +7 -10
package/dist/useRequestPro.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RequestRes } from '@wzyjs/
|
|
2
|
-
import { Options,
|
|
1
|
+
import { RequestRes } from '@wzyjs/types';
|
|
2
|
+
import { Options, Result, Service } from 'ahooks/lib/useRequest/src/types';
|
|
3
3
|
interface UserOptions<P extends any[], R> extends Options<R, P> {
|
|
4
4
|
alertErrorMessage?: false | string;
|
|
5
5
|
alertSuccessMessage?: true | string;
|
|
@@ -7,5 +7,5 @@ interface UserOptions<P extends any[], R> extends Options<R, P> {
|
|
|
7
7
|
interface IResult<R extends RequestRes, P extends any[]> extends Omit<Result<R, P>, 'data'> {
|
|
8
8
|
data?: R['data'];
|
|
9
9
|
}
|
|
10
|
-
export declare const useRequestPro: <P extends any[], R extends RequestRes<any>>(reqPromise?: Service<R, P> | undefined, userOptions?: UserOptions<P, R> | undefined) => IResult<R, P
|
|
10
|
+
export declare const useRequestPro: <P extends any[], R extends RequestRes<any>>(reqPromise?: Service<R, P> | undefined, userOptions?: UserOptions<P, R> | undefined) => IResult<R, P>;
|
|
11
11
|
export {};
|
package/dist/useRequestPro.js
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import { message } from 'antd';
|
|
2
|
-
import { omit } from '@wzyjs/utils';
|
|
3
2
|
import { useRequest } from 'ahooks';
|
|
3
|
+
import { noop, omit } from '@wzyjs/utils';
|
|
4
|
+
const defaultResult = {
|
|
5
|
+
loading: false,
|
|
6
|
+
data: undefined,
|
|
7
|
+
error: undefined,
|
|
8
|
+
params: [],
|
|
9
|
+
cancel: noop,
|
|
10
|
+
refresh: noop,
|
|
11
|
+
refreshAsync: noop,
|
|
12
|
+
run: noop,
|
|
13
|
+
runAsync: noop,
|
|
14
|
+
mutate: noop,
|
|
15
|
+
};
|
|
4
16
|
export const useRequestPro = (reqPromise, userOptions) => {
|
|
5
17
|
if (!reqPromise) {
|
|
6
|
-
return
|
|
18
|
+
return defaultResult;
|
|
7
19
|
}
|
|
8
20
|
const { alertErrorMessage = true, alertSuccessMessage = false } = userOptions || {};
|
|
9
21
|
const defaultOptions = {
|
|
22
|
+
cacheKey: String(reqPromise),
|
|
23
|
+
staleTime: 5000,
|
|
10
24
|
debounceWait: 300,
|
|
11
25
|
throttleWait: 300,
|
|
12
|
-
onError: (
|
|
26
|
+
onError: (err, params) => {
|
|
13
27
|
if (alertErrorMessage) {
|
|
14
|
-
message.error(typeof alertErrorMessage === 'string' ? alertErrorMessage :
|
|
28
|
+
message.error(typeof alertErrorMessage === 'string' ? alertErrorMessage : err.message || '请求失败');
|
|
15
29
|
}
|
|
16
|
-
userOptions?.onError?.(
|
|
30
|
+
userOptions?.onError?.(err, params);
|
|
17
31
|
},
|
|
18
32
|
onSuccess: (res, params) => {
|
|
19
33
|
// 如果失败,则还是调用 onError
|
|
@@ -32,6 +46,6 @@ export const useRequestPro = (reqPromise, userOptions) => {
|
|
|
32
46
|
const options = Object.assign(defaultOptions, omit(userOptions, ['onSuccess', 'onError']));
|
|
33
47
|
// 取出 data 里的 data
|
|
34
48
|
const state = useRequest(reqPromise, options);
|
|
35
|
-
state.data = state.data?.data
|
|
49
|
+
state.data = state.data?.data;
|
|
36
50
|
return state;
|
|
37
51
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"license": "ISC",
|
|
@@ -14,18 +14,15 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@types
|
|
18
|
-
"@wzyjs/utils": "^0.0.
|
|
17
|
+
"@wzyjs/types": "^0.0.28",
|
|
18
|
+
"@wzyjs/utils": "^0.0.28",
|
|
19
19
|
"ahooks": "^3.7.3",
|
|
20
|
-
"antd": "^5.
|
|
20
|
+
"antd": "^5.6.2",
|
|
21
21
|
"react-use": "^17.4.0"
|
|
22
22
|
},
|
|
23
|
-
"peerDependencies": {
|
|
24
|
-
"@types/react": "latest",
|
|
25
|
-
"react": "latest"
|
|
26
|
-
},
|
|
27
23
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^18.11.17"
|
|
24
|
+
"@types/node": "^18.11.17",
|
|
25
|
+
"@types/react": "latest"
|
|
29
26
|
},
|
|
30
27
|
"publishConfig": {
|
|
31
28
|
"access": "public"
|
|
@@ -34,5 +31,5 @@
|
|
|
34
31
|
"type": "git",
|
|
35
32
|
"url": "https://gitee.com/wang-zhenyu/work.git"
|
|
36
33
|
},
|
|
37
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "b27e8d285e4092485cd1be538c1f571bc29e7835"
|
|
38
35
|
}
|