@kevisual/query 0.0.9 → 0.0.11
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/query-browser.d.ts +11 -4
- package/dist/query-browser.js +11 -0
- package/dist/query.d.ts +11 -4
- package/dist/query.js +11 -0
- package/package.json +1 -1
package/dist/query-browser.d.ts
CHANGED
|
@@ -83,6 +83,13 @@ type Result<S = any> = {
|
|
|
83
83
|
* 是否不返回 message
|
|
84
84
|
*/
|
|
85
85
|
noMsg?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* 显示错误, 当 handle的信息被处理的时候,如果不是success,同时自己设置了noMsg,那么就不显示错误信息了,因为被处理。
|
|
88
|
+
*
|
|
89
|
+
* 日常: fetch().then(res=>if(res.sucess){message.error('error')})的时候,比如401被处理过了,就不再提示401错误了。
|
|
90
|
+
*
|
|
91
|
+
*/
|
|
92
|
+
showError: (fn?: () => void) => void;
|
|
86
93
|
};
|
|
87
94
|
type DataOpts = Partial<QueryOpts$1> & {
|
|
88
95
|
beforeRequest?: Fn;
|
|
@@ -97,7 +104,7 @@ type DataOpts = Partial<QueryOpts$1> & {
|
|
|
97
104
|
*
|
|
98
105
|
* U是参数 V是返回值
|
|
99
106
|
*/
|
|
100
|
-
declare class Query
|
|
107
|
+
declare class Query {
|
|
101
108
|
adapter: typeof adapter;
|
|
102
109
|
url: string;
|
|
103
110
|
beforeRequest?: Fn;
|
|
@@ -113,7 +120,7 @@ declare class Query<R = any> {
|
|
|
113
120
|
* @param options 请求配置
|
|
114
121
|
* @returns 请求结果
|
|
115
122
|
*/
|
|
116
|
-
get<
|
|
123
|
+
get<R = any, P = any>(params: Data & P, options?: DataOpts): Promise<Result<R>>;
|
|
117
124
|
/**
|
|
118
125
|
* 发送 post 请求
|
|
119
126
|
* T是请求类型自定义
|
|
@@ -122,7 +129,7 @@ declare class Query<R = any> {
|
|
|
122
129
|
* @param options 请求配置
|
|
123
130
|
* @returns 请求结果
|
|
124
131
|
*/
|
|
125
|
-
post<
|
|
132
|
+
post<R = any, P = any>(body: Data & P, options?: DataOpts): Promise<Result<R>>;
|
|
126
133
|
/**
|
|
127
134
|
* 请求前处理,设置请求前处理函数
|
|
128
135
|
* @param fn 处理函数
|
|
@@ -144,7 +151,7 @@ type QueryOpts = {
|
|
|
144
151
|
/**
|
|
145
152
|
* 前端调用后端QueryRouter
|
|
146
153
|
*/
|
|
147
|
-
declare class QueryClient
|
|
154
|
+
declare class QueryClient extends Query {
|
|
148
155
|
tokenName: string;
|
|
149
156
|
storage: Storage;
|
|
150
157
|
token: string;
|
package/dist/query-browser.js
CHANGED
|
@@ -288,6 +288,7 @@ class Query {
|
|
|
288
288
|
code: 500,
|
|
289
289
|
success: false,
|
|
290
290
|
message: 'api request beforeFn error',
|
|
291
|
+
showError: () => { },
|
|
291
292
|
};
|
|
292
293
|
}
|
|
293
294
|
return adapter(req).then(async (res) => {
|
|
@@ -296,6 +297,15 @@ class Query {
|
|
|
296
297
|
if (afterResponse) {
|
|
297
298
|
return await afterResponse(res);
|
|
298
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* 显示错误
|
|
302
|
+
* @param fn 错误处理函数
|
|
303
|
+
*/
|
|
304
|
+
res.showError = (fn) => {
|
|
305
|
+
if (!res.success && !res.noResult) {
|
|
306
|
+
fn?.();
|
|
307
|
+
}
|
|
308
|
+
};
|
|
299
309
|
return res;
|
|
300
310
|
}
|
|
301
311
|
catch (e) {
|
|
@@ -304,6 +314,7 @@ class Query {
|
|
|
304
314
|
code: 500,
|
|
305
315
|
success: false,
|
|
306
316
|
message: 'api request afterFn error',
|
|
317
|
+
showError: () => { },
|
|
307
318
|
};
|
|
308
319
|
}
|
|
309
320
|
});
|
package/dist/query.d.ts
CHANGED
|
@@ -45,6 +45,13 @@ type Result<S = any> = {
|
|
|
45
45
|
* 是否不返回 message
|
|
46
46
|
*/
|
|
47
47
|
noMsg?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* 显示错误, 当 handle的信息被处理的时候,如果不是success,同时自己设置了noMsg,那么就不显示错误信息了,因为被处理。
|
|
50
|
+
*
|
|
51
|
+
* 日常: fetch().then(res=>if(res.sucess){message.error('error')})的时候,比如401被处理过了,就不再提示401错误了。
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
showError: (fn?: () => void) => void;
|
|
48
55
|
};
|
|
49
56
|
type DataOpts = Partial<QueryOpts> & {
|
|
50
57
|
beforeRequest?: Fn;
|
|
@@ -59,7 +66,7 @@ type DataOpts = Partial<QueryOpts> & {
|
|
|
59
66
|
*
|
|
60
67
|
* U是参数 V是返回值
|
|
61
68
|
*/
|
|
62
|
-
declare class Query
|
|
69
|
+
declare class Query {
|
|
63
70
|
adapter: typeof adapter;
|
|
64
71
|
url: string;
|
|
65
72
|
beforeRequest?: Fn;
|
|
@@ -75,7 +82,7 @@ declare class Query<R = any> {
|
|
|
75
82
|
* @param options 请求配置
|
|
76
83
|
* @returns 请求结果
|
|
77
84
|
*/
|
|
78
|
-
get<
|
|
85
|
+
get<R = any, P = any>(params: Data & P, options?: DataOpts): Promise<Result<R>>;
|
|
79
86
|
/**
|
|
80
87
|
* 发送 post 请求
|
|
81
88
|
* T是请求类型自定义
|
|
@@ -84,7 +91,7 @@ declare class Query<R = any> {
|
|
|
84
91
|
* @param options 请求配置
|
|
85
92
|
* @returns 请求结果
|
|
86
93
|
*/
|
|
87
|
-
post<
|
|
94
|
+
post<R = any, P = any>(body: Data & P, options?: DataOpts): Promise<Result<R>>;
|
|
88
95
|
/**
|
|
89
96
|
* 请求前处理,设置请求前处理函数
|
|
90
97
|
* @param fn 处理函数
|
|
@@ -98,4 +105,4 @@ declare class Query<R = any> {
|
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
export { Query, adapter };
|
|
101
|
-
export type { QueryOpts };
|
|
108
|
+
export type { Data, QueryOpts, Result };
|
package/dist/query.js
CHANGED
|
@@ -113,6 +113,7 @@ class Query {
|
|
|
113
113
|
code: 500,
|
|
114
114
|
success: false,
|
|
115
115
|
message: 'api request beforeFn error',
|
|
116
|
+
showError: () => { },
|
|
116
117
|
};
|
|
117
118
|
}
|
|
118
119
|
return adapter(req).then(async (res) => {
|
|
@@ -121,6 +122,15 @@ class Query {
|
|
|
121
122
|
if (afterResponse) {
|
|
122
123
|
return await afterResponse(res);
|
|
123
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* 显示错误
|
|
127
|
+
* @param fn 错误处理函数
|
|
128
|
+
*/
|
|
129
|
+
res.showError = (fn) => {
|
|
130
|
+
if (!res.success && !res.noResult) {
|
|
131
|
+
fn?.();
|
|
132
|
+
}
|
|
133
|
+
};
|
|
124
134
|
return res;
|
|
125
135
|
}
|
|
126
136
|
catch (e) {
|
|
@@ -129,6 +139,7 @@ class Query {
|
|
|
129
139
|
code: 500,
|
|
130
140
|
success: false,
|
|
131
141
|
message: 'api request afterFn error',
|
|
142
|
+
showError: () => { },
|
|
132
143
|
};
|
|
133
144
|
}
|
|
134
145
|
});
|