@kevisual/query 0.0.12 → 0.0.13
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 +8 -0
- package/dist/query-browser.js +26 -0
- package/dist/query.d.ts +8 -0
- package/dist/query.js +26 -0
- package/package.json +1 -1
package/dist/query-browser.d.ts
CHANGED
|
@@ -115,7 +115,15 @@ declare class Query {
|
|
|
115
115
|
afterResponse?: DataOpts['afterResponse'];
|
|
116
116
|
headers?: Record<string, string>;
|
|
117
117
|
timeout?: number;
|
|
118
|
+
/**
|
|
119
|
+
* 需要突然停止请求,比如401的时候
|
|
120
|
+
*/
|
|
121
|
+
stop?: boolean;
|
|
118
122
|
constructor(opts?: QueryOpts$1);
|
|
123
|
+
/**
|
|
124
|
+
* 突然停止请求
|
|
125
|
+
*/
|
|
126
|
+
setStop(stop: boolean): void;
|
|
119
127
|
/**
|
|
120
128
|
* 发送 get 请求,转到 post 请求
|
|
121
129
|
* T是请求类型自定义
|
package/dist/query-browser.js
CHANGED
|
@@ -255,6 +255,10 @@ class Query {
|
|
|
255
255
|
afterResponse;
|
|
256
256
|
headers;
|
|
257
257
|
timeout;
|
|
258
|
+
/**
|
|
259
|
+
* 需要突然停止请求,比如401的时候
|
|
260
|
+
*/
|
|
261
|
+
stop;
|
|
258
262
|
constructor(opts) {
|
|
259
263
|
this.adapter = opts?.adapter || adapter;
|
|
260
264
|
this.url = opts?.url || '/api/router';
|
|
@@ -263,6 +267,12 @@ class Query {
|
|
|
263
267
|
};
|
|
264
268
|
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
265
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* 突然停止请求
|
|
272
|
+
*/
|
|
273
|
+
setStop(stop) {
|
|
274
|
+
this.stop = stop;
|
|
275
|
+
}
|
|
266
276
|
/**
|
|
267
277
|
* 发送 get 请求,转到 post 请求
|
|
268
278
|
* T是请求类型自定义
|
|
@@ -309,6 +319,22 @@ class Query {
|
|
|
309
319
|
showError: () => { },
|
|
310
320
|
};
|
|
311
321
|
}
|
|
322
|
+
if (this.stop) {
|
|
323
|
+
const that = this;
|
|
324
|
+
await new Promise((resolve) => {
|
|
325
|
+
let timer = 0;
|
|
326
|
+
const detect = setInterval(() => {
|
|
327
|
+
if (!that.stop) {
|
|
328
|
+
clearInterval(detect);
|
|
329
|
+
resolve(true);
|
|
330
|
+
}
|
|
331
|
+
timer++;
|
|
332
|
+
if (timer > 30) {
|
|
333
|
+
console.error('request stop: timeout', req.url, timer);
|
|
334
|
+
}
|
|
335
|
+
}, 1000);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
312
338
|
return adapter(req).then(async (res) => {
|
|
313
339
|
try {
|
|
314
340
|
setBaseResponse(res);
|
package/dist/query.d.ts
CHANGED
|
@@ -84,7 +84,15 @@ declare class Query {
|
|
|
84
84
|
afterResponse?: DataOpts['afterResponse'];
|
|
85
85
|
headers?: Record<string, string>;
|
|
86
86
|
timeout?: number;
|
|
87
|
+
/**
|
|
88
|
+
* 需要突然停止请求,比如401的时候
|
|
89
|
+
*/
|
|
90
|
+
stop?: boolean;
|
|
87
91
|
constructor(opts?: QueryOpts);
|
|
92
|
+
/**
|
|
93
|
+
* 突然停止请求
|
|
94
|
+
*/
|
|
95
|
+
setStop(stop: boolean): void;
|
|
88
96
|
/**
|
|
89
97
|
* 发送 get 请求,转到 post 请求
|
|
90
98
|
* T是请求类型自定义
|
package/dist/query.js
CHANGED
|
@@ -80,6 +80,10 @@ class Query {
|
|
|
80
80
|
afterResponse;
|
|
81
81
|
headers;
|
|
82
82
|
timeout;
|
|
83
|
+
/**
|
|
84
|
+
* 需要突然停止请求,比如401的时候
|
|
85
|
+
*/
|
|
86
|
+
stop;
|
|
83
87
|
constructor(opts) {
|
|
84
88
|
this.adapter = opts?.adapter || adapter;
|
|
85
89
|
this.url = opts?.url || '/api/router';
|
|
@@ -88,6 +92,12 @@ class Query {
|
|
|
88
92
|
};
|
|
89
93
|
this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3
|
|
90
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* 突然停止请求
|
|
97
|
+
*/
|
|
98
|
+
setStop(stop) {
|
|
99
|
+
this.stop = stop;
|
|
100
|
+
}
|
|
91
101
|
/**
|
|
92
102
|
* 发送 get 请求,转到 post 请求
|
|
93
103
|
* T是请求类型自定义
|
|
@@ -134,6 +144,22 @@ class Query {
|
|
|
134
144
|
showError: () => { },
|
|
135
145
|
};
|
|
136
146
|
}
|
|
147
|
+
if (this.stop) {
|
|
148
|
+
const that = this;
|
|
149
|
+
await new Promise((resolve) => {
|
|
150
|
+
let timer = 0;
|
|
151
|
+
const detect = setInterval(() => {
|
|
152
|
+
if (!that.stop) {
|
|
153
|
+
clearInterval(detect);
|
|
154
|
+
resolve(true);
|
|
155
|
+
}
|
|
156
|
+
timer++;
|
|
157
|
+
if (timer > 30) {
|
|
158
|
+
console.error('request stop: timeout', req.url, timer);
|
|
159
|
+
}
|
|
160
|
+
}, 1000);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
137
163
|
return adapter(req).then(async (res) => {
|
|
138
164
|
try {
|
|
139
165
|
setBaseResponse(res);
|