@whitesev/utils 1.4.7 → 1.4.9
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/index.amd.js +50 -16
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +50 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +50 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +50 -16
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +50 -16
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +50 -16
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +13 -1
- package/package.json +1 -1
- package/src/Httpx.ts +71 -21
package/dist/index.system.js
CHANGED
|
@@ -1466,7 +1466,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1466
1466
|
/**
|
|
1467
1467
|
* 添加请求前的回调处理配置
|
|
1468
1468
|
*/
|
|
1469
|
-
|
|
1469
|
+
add(fn) {
|
|
1470
1470
|
if (typeof fn === "function") {
|
|
1471
1471
|
let uuid = GenerateUUID();
|
|
1472
1472
|
this.$config.configList.push({
|
|
@@ -1483,7 +1483,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1483
1483
|
* 删除请求前的回调处理配置
|
|
1484
1484
|
* @param id
|
|
1485
1485
|
*/
|
|
1486
|
-
|
|
1486
|
+
delete(id) {
|
|
1487
1487
|
if (typeof id === "string") {
|
|
1488
1488
|
let findIndex = this.$config.configList.findIndex((item) => item.id === id);
|
|
1489
1489
|
if (findIndex !== -1) {
|
|
@@ -1496,7 +1496,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1496
1496
|
/**
|
|
1497
1497
|
* 清空设置的请求前的回调处理配置
|
|
1498
1498
|
*/
|
|
1499
|
-
|
|
1499
|
+
clearAll() {
|
|
1500
1500
|
this.$config.configList = [];
|
|
1501
1501
|
},
|
|
1502
1502
|
};
|
|
@@ -1526,21 +1526,21 @@ System.register('Utils', [], (function (exports) {
|
|
|
1526
1526
|
* 失败的回调
|
|
1527
1527
|
* @param response
|
|
1528
1528
|
*/
|
|
1529
|
-
errorResponseCallBack(
|
|
1529
|
+
errorResponseCallBack(data) {
|
|
1530
1530
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1531
1531
|
let item = this.$config.configList[index];
|
|
1532
1532
|
if (typeof item.errorFn === "function") {
|
|
1533
|
-
if (item.errorFn(
|
|
1533
|
+
if (item.errorFn(data) == null) {
|
|
1534
1534
|
return;
|
|
1535
1535
|
}
|
|
1536
1536
|
}
|
|
1537
1537
|
}
|
|
1538
|
-
return
|
|
1538
|
+
return data;
|
|
1539
1539
|
},
|
|
1540
1540
|
/**
|
|
1541
1541
|
* 添加请求前的回调处理配置
|
|
1542
1542
|
*/
|
|
1543
|
-
|
|
1543
|
+
add(successFn, errorFn) {
|
|
1544
1544
|
let id = GenerateUUID();
|
|
1545
1545
|
this.$config.configList.push({
|
|
1546
1546
|
id: id,
|
|
@@ -1553,7 +1553,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1553
1553
|
* 删除请求前的回调处理配置
|
|
1554
1554
|
* @param id
|
|
1555
1555
|
*/
|
|
1556
|
-
|
|
1556
|
+
delete(id) {
|
|
1557
1557
|
if (typeof id === "string") {
|
|
1558
1558
|
let findIndex = this.$config.configList.findIndex((item) => item.id === id);
|
|
1559
1559
|
if (findIndex !== -1) {
|
|
@@ -1566,7 +1566,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1566
1566
|
/**
|
|
1567
1567
|
* 清空设置的请求前的回调处理配置
|
|
1568
1568
|
*/
|
|
1569
|
-
|
|
1569
|
+
clearAll() {
|
|
1570
1570
|
this.$config.configList = [];
|
|
1571
1571
|
},
|
|
1572
1572
|
};
|
|
@@ -1807,6 +1807,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
1807
1807
|
if (response.length) {
|
|
1808
1808
|
response = response[0];
|
|
1809
1809
|
}
|
|
1810
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1811
|
+
type: "onerror",
|
|
1812
|
+
error: new TypeError("request error"),
|
|
1813
|
+
response: response,
|
|
1814
|
+
}) == null) {
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1810
1817
|
resolve({
|
|
1811
1818
|
status: false,
|
|
1812
1819
|
data: response,
|
|
@@ -1828,6 +1835,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
1828
1835
|
else if ("ontimeout" in this.context.#defaultDetails) {
|
|
1829
1836
|
this.context.#defaultDetails.ontimeout.apply(this, argumentsList);
|
|
1830
1837
|
}
|
|
1838
|
+
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1839
|
+
type: "ontimeout",
|
|
1840
|
+
error: new TypeError("request timeout"),
|
|
1841
|
+
response: (argumentsList || [null])[0],
|
|
1842
|
+
}) == null) {
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1831
1845
|
resolve({
|
|
1832
1846
|
status: false,
|
|
1833
1847
|
data: [...argumentsList],
|
|
@@ -1908,6 +1922,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
1908
1922
|
}
|
|
1909
1923
|
/* 状态码2xx都是成功的 */
|
|
1910
1924
|
if (Math.floor(Response.status / 100) === 2) {
|
|
1925
|
+
if (this.context.HttpxResponseHook.successResponseCallBack(Response) ==
|
|
1926
|
+
null) {
|
|
1927
|
+
return;
|
|
1928
|
+
}
|
|
1911
1929
|
resolve({
|
|
1912
1930
|
status: true,
|
|
1913
1931
|
data: Response,
|
|
@@ -2128,8 +2146,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
2128
2146
|
if (typeof __xmlHttpRequest__ !== "function") {
|
|
2129
2147
|
console.warn("Httpx未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,强制使用window.fetch");
|
|
2130
2148
|
}
|
|
2131
|
-
this.interceptors.request = this;
|
|
2132
|
-
this.interceptors.response = this;
|
|
2149
|
+
this.interceptors.request.context = this;
|
|
2150
|
+
this.interceptors.response.context = this;
|
|
2133
2151
|
this.GM_Api.xmlHttpRequest = __xmlHttpRequest__;
|
|
2134
2152
|
}
|
|
2135
2153
|
/**
|
|
@@ -2156,14 +2174,24 @@ System.register('Utils', [], (function (exports) {
|
|
|
2156
2174
|
* @param fn 设置的请求前回调函数,如果返回配置,则使用返回的配置,如果返回null|undefined,则阻止请求
|
|
2157
2175
|
*/
|
|
2158
2176
|
use(fn) {
|
|
2159
|
-
|
|
2177
|
+
if (typeof fn !== "function") {
|
|
2178
|
+
console.warn("[Httpx-interceptors-request] 请传入拦截器函数");
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
return this.context.HttpxRequestHook.add(fn);
|
|
2160
2182
|
},
|
|
2161
2183
|
/**
|
|
2162
2184
|
* 移除拦截器
|
|
2163
2185
|
* @param id 通过use返回的id
|
|
2164
2186
|
*/
|
|
2165
2187
|
eject(id) {
|
|
2166
|
-
return this.context.HttpxRequestHook.
|
|
2188
|
+
return this.context.HttpxRequestHook.delete(id);
|
|
2189
|
+
},
|
|
2190
|
+
/**
|
|
2191
|
+
* 移除所有拦截器
|
|
2192
|
+
*/
|
|
2193
|
+
ejectAll() {
|
|
2194
|
+
this.context.HttpxRequestHook.clearAll();
|
|
2167
2195
|
},
|
|
2168
2196
|
},
|
|
2169
2197
|
/**
|
|
@@ -2180,17 +2208,23 @@ System.register('Utils', [], (function (exports) {
|
|
|
2180
2208
|
*/
|
|
2181
2209
|
use(successFn, errorFn) {
|
|
2182
2210
|
if (typeof successFn !== "function" && typeof errorFn !== "function") {
|
|
2183
|
-
console.warn("[Httpx] 请传入拦截器函数");
|
|
2211
|
+
console.warn("[Httpx-interceptors-response] 请传入拦截器函数");
|
|
2184
2212
|
return;
|
|
2185
2213
|
}
|
|
2186
|
-
return this.context.HttpxResponseHook.
|
|
2214
|
+
return this.context.HttpxResponseHook.add(successFn, errorFn);
|
|
2187
2215
|
},
|
|
2188
2216
|
/**
|
|
2189
2217
|
* 移除拦截器
|
|
2190
2218
|
* @param id 通过use返回的id
|
|
2191
2219
|
*/
|
|
2192
2220
|
eject(id) {
|
|
2193
|
-
return this.context.HttpxResponseHook.
|
|
2221
|
+
return this.context.HttpxResponseHook.delete(id);
|
|
2222
|
+
},
|
|
2223
|
+
/**
|
|
2224
|
+
* 移除所有拦截器
|
|
2225
|
+
*/
|
|
2226
|
+
ejectAll() {
|
|
2227
|
+
this.context.HttpxResponseHook.clearAll();
|
|
2194
2228
|
},
|
|
2195
2229
|
},
|
|
2196
2230
|
};
|