@whitesev/utils 1.8.0 → 1.9.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/dist/index.amd.js +78 -40
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +78 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +78 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +78 -40
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +78 -40
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +78 -40
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -1566,14 +1566,23 @@ var Utils = (function () {
|
|
|
1566
1566
|
* @private
|
|
1567
1567
|
*/
|
|
1568
1568
|
beforeRequestCallBack(details) {
|
|
1569
|
-
if (details.allowInterceptConfig) {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
!details.allowInterceptConfig.beforeRequest) {
|
|
1573
|
-
// 设置了禁止拦截
|
|
1569
|
+
if (typeof details.allowInterceptConfig === "boolean") {
|
|
1570
|
+
if (!details.allowInterceptConfig) {
|
|
1571
|
+
// 不允许拦截
|
|
1574
1572
|
return details;
|
|
1575
1573
|
}
|
|
1576
1574
|
}
|
|
1575
|
+
else {
|
|
1576
|
+
if (details.allowInterceptConfig != null) {
|
|
1577
|
+
// 配置存在
|
|
1578
|
+
// 细分处理是否拦截
|
|
1579
|
+
if (typeof details.allowInterceptConfig.beforeRequest === "boolean" &&
|
|
1580
|
+
!details.allowInterceptConfig.beforeRequest) {
|
|
1581
|
+
// 设置了禁止拦截
|
|
1582
|
+
return details;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1577
1586
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1578
1587
|
let item = this.$config.configList[index];
|
|
1579
1588
|
if (typeof item.fn === "function") {
|
|
@@ -1635,15 +1644,24 @@ var Utils = (function () {
|
|
|
1635
1644
|
* @param details 请求的配置
|
|
1636
1645
|
*/
|
|
1637
1646
|
successResponseCallBack(response, details) {
|
|
1638
|
-
if (details.allowInterceptConfig) {
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
"boolean" &&
|
|
1642
|
-
!details.allowInterceptConfig.afterResponseSuccess) {
|
|
1643
|
-
// 设置了禁止拦截
|
|
1647
|
+
if (typeof details.allowInterceptConfig === "boolean") {
|
|
1648
|
+
if (!details.allowInterceptConfig) {
|
|
1649
|
+
// 不允许拦截
|
|
1644
1650
|
return details;
|
|
1645
1651
|
}
|
|
1646
1652
|
}
|
|
1653
|
+
else {
|
|
1654
|
+
if (details.allowInterceptConfig != null) {
|
|
1655
|
+
// 配置存在
|
|
1656
|
+
// 细分处理是否拦截
|
|
1657
|
+
if (typeof details.allowInterceptConfig.afterResponseSuccess ===
|
|
1658
|
+
"boolean" &&
|
|
1659
|
+
!details.allowInterceptConfig.afterResponseSuccess) {
|
|
1660
|
+
// 设置了禁止拦截
|
|
1661
|
+
return details;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1647
1665
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1648
1666
|
let item = this.$config.configList[index];
|
|
1649
1667
|
if (typeof item.successFn === "function") {
|
|
@@ -1657,17 +1675,28 @@ var Utils = (function () {
|
|
|
1657
1675
|
/**
|
|
1658
1676
|
* 失败的回调
|
|
1659
1677
|
* @param data 配置
|
|
1678
|
+
* @returns
|
|
1679
|
+
* 返回null|undefined就是拦截掉了
|
|
1660
1680
|
*/
|
|
1661
1681
|
errorResponseCallBack(data) {
|
|
1662
|
-
if (data.details.allowInterceptConfig) {
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
"boolean" &&
|
|
1666
|
-
!data.details.allowInterceptConfig.afterResponseError) {
|
|
1667
|
-
// 设置了禁止拦截
|
|
1682
|
+
if (typeof data.details.allowInterceptConfig === "boolean") {
|
|
1683
|
+
if (!data.details.allowInterceptConfig) {
|
|
1684
|
+
// 不允许拦截
|
|
1668
1685
|
return data;
|
|
1669
1686
|
}
|
|
1670
1687
|
}
|
|
1688
|
+
else {
|
|
1689
|
+
if (data.details.allowInterceptConfig != null) {
|
|
1690
|
+
// 配置存在
|
|
1691
|
+
// 细分处理是否拦截
|
|
1692
|
+
if (typeof data.details.allowInterceptConfig.afterResponseError ===
|
|
1693
|
+
"boolean" &&
|
|
1694
|
+
!data.details.allowInterceptConfig.afterResponseError) {
|
|
1695
|
+
// 设置了禁止拦截
|
|
1696
|
+
return data;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1671
1700
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1672
1701
|
let item = this.$config.configList[index];
|
|
1673
1702
|
if (typeof item.errorFn === "function") {
|
|
@@ -1738,10 +1767,11 @@ var Utils = (function () {
|
|
|
1738
1767
|
/**
|
|
1739
1768
|
* 获取请求配置
|
|
1740
1769
|
* @param method 当前请求方法,默认get
|
|
1741
|
-
* @param resolve promise回调
|
|
1742
1770
|
* @param details 请求配置
|
|
1771
|
+
* @param resolve promise回调
|
|
1772
|
+
* @param reject 抛出错误回调
|
|
1743
1773
|
*/
|
|
1744
|
-
getDetails(method, resolve,
|
|
1774
|
+
getDetails(method, details, resolve, reject) {
|
|
1745
1775
|
let that = this;
|
|
1746
1776
|
let result = {
|
|
1747
1777
|
url: details.url || this.context.#defaultDetails.url,
|
|
@@ -1767,10 +1797,10 @@ var Utils = (function () {
|
|
|
1767
1797
|
user: details.user || this.context.#defaultDetails.user,
|
|
1768
1798
|
password: details.password || this.context.#defaultDetails.password,
|
|
1769
1799
|
onabort(...args) {
|
|
1770
|
-
that.context.HttpxCallBack.onAbort(details, resolve, args);
|
|
1800
|
+
that.context.HttpxCallBack.onAbort(details, resolve, reject, args);
|
|
1771
1801
|
},
|
|
1772
1802
|
onerror(...args) {
|
|
1773
|
-
that.context.HttpxCallBack.onError(details, resolve, args);
|
|
1803
|
+
that.context.HttpxCallBack.onError(details, resolve, reject, args);
|
|
1774
1804
|
},
|
|
1775
1805
|
onloadstart(...args) {
|
|
1776
1806
|
that.context.HttpxCallBack.onLoadStart(details, args);
|
|
@@ -1782,10 +1812,10 @@ var Utils = (function () {
|
|
|
1782
1812
|
that.context.HttpxCallBack.onReadyStateChange(details, args);
|
|
1783
1813
|
},
|
|
1784
1814
|
ontimeout(...args) {
|
|
1785
|
-
that.context.HttpxCallBack.onTimeout(details, resolve, args);
|
|
1815
|
+
that.context.HttpxCallBack.onTimeout(details, resolve, reject, args);
|
|
1786
1816
|
},
|
|
1787
1817
|
onload(...args) {
|
|
1788
|
-
that.context.HttpxCallBack.onLoad(details, resolve, args);
|
|
1818
|
+
that.context.HttpxCallBack.onLoad(details, resolve, reject, args);
|
|
1789
1819
|
},
|
|
1790
1820
|
};
|
|
1791
1821
|
if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
|
|
@@ -1915,9 +1945,10 @@ var Utils = (function () {
|
|
|
1915
1945
|
* onabort请求被取消-触发
|
|
1916
1946
|
* @param details 配置
|
|
1917
1947
|
* @param resolve 回调
|
|
1948
|
+
* @param reject 抛出错误
|
|
1918
1949
|
* @param argumentsList 参数列表
|
|
1919
1950
|
*/
|
|
1920
|
-
onAbort(details, resolve, argumentsList) {
|
|
1951
|
+
onAbort(details, resolve, reject, argumentsList) {
|
|
1921
1952
|
if ("onabort" in details) {
|
|
1922
1953
|
details.onabort.apply(this, argumentsList);
|
|
1923
1954
|
}
|
|
@@ -1930,6 +1961,7 @@ var Utils = (function () {
|
|
|
1930
1961
|
response: null,
|
|
1931
1962
|
details: details,
|
|
1932
1963
|
}) == null) {
|
|
1964
|
+
// reject(new TypeError("response is intercept with onabort"));
|
|
1933
1965
|
return;
|
|
1934
1966
|
}
|
|
1935
1967
|
resolve({
|
|
@@ -1943,9 +1975,10 @@ var Utils = (function () {
|
|
|
1943
1975
|
* onerror请求异常-触发
|
|
1944
1976
|
* @param details 配置
|
|
1945
1977
|
* @param resolve 回调
|
|
1978
|
+
* @param reject 抛出错误
|
|
1946
1979
|
* @param argumentsList 响应的参数列表
|
|
1947
1980
|
*/
|
|
1948
|
-
onError(details, resolve, argumentsList) {
|
|
1981
|
+
onError(details, resolve, reject, argumentsList) {
|
|
1949
1982
|
if ("onerror" in details) {
|
|
1950
1983
|
details.onerror.apply(this, argumentsList);
|
|
1951
1984
|
}
|
|
@@ -1962,6 +1995,7 @@ var Utils = (function () {
|
|
|
1962
1995
|
response: response,
|
|
1963
1996
|
details: details,
|
|
1964
1997
|
}) == null) {
|
|
1998
|
+
// reject(new TypeError("response is intercept with onerror"));
|
|
1965
1999
|
return;
|
|
1966
2000
|
}
|
|
1967
2001
|
resolve({
|
|
@@ -1976,9 +2010,10 @@ var Utils = (function () {
|
|
|
1976
2010
|
* ontimeout请求超时-触发
|
|
1977
2011
|
* @param details 配置
|
|
1978
2012
|
* @param resolve 回调
|
|
2013
|
+
* @param reject 抛出错误
|
|
1979
2014
|
* @param argumentsList 参数列表
|
|
1980
2015
|
*/
|
|
1981
|
-
onTimeout(details, resolve, argumentsList) {
|
|
2016
|
+
onTimeout(details, resolve, reject, argumentsList) {
|
|
1982
2017
|
if ("ontimeout" in details) {
|
|
1983
2018
|
details.ontimeout.apply(this, argumentsList);
|
|
1984
2019
|
}
|
|
@@ -1991,6 +2026,7 @@ var Utils = (function () {
|
|
|
1991
2026
|
response: (argumentsList || [null])[0],
|
|
1992
2027
|
details: details,
|
|
1993
2028
|
}) == null) {
|
|
2029
|
+
// reject(new TypeError("response is intercept with ontimeout"));
|
|
1994
2030
|
return;
|
|
1995
2031
|
}
|
|
1996
2032
|
resolve({
|
|
@@ -2017,9 +2053,10 @@ var Utils = (function () {
|
|
|
2017
2053
|
* onload加载完毕-触发
|
|
2018
2054
|
* @param details 请求的配置
|
|
2019
2055
|
* @param resolve 回调
|
|
2056
|
+
* @param reject 抛出错误
|
|
2020
2057
|
* @param argumentsList 参数列表
|
|
2021
2058
|
*/
|
|
2022
|
-
onLoad(details, resolve, argumentsList) {
|
|
2059
|
+
onLoad(details, resolve, reject, argumentsList) {
|
|
2023
2060
|
/* X浏览器会因为设置了responseType导致不返回responseText */
|
|
2024
2061
|
let Response = argumentsList[0];
|
|
2025
2062
|
/* responseText为空,response不为空的情况 */
|
|
@@ -2074,6 +2111,7 @@ var Utils = (function () {
|
|
|
2074
2111
|
/* 状态码2xx都是成功的 */
|
|
2075
2112
|
if (Math.floor(Response.status / 100) === 2) {
|
|
2076
2113
|
if (this.context.HttpxResponseHook.successResponseCallBack(Response, details) == null) {
|
|
2114
|
+
// reject(new TypeError("response is intercept with onloada"));
|
|
2077
2115
|
return;
|
|
2078
2116
|
}
|
|
2079
2117
|
resolve({
|
|
@@ -2085,7 +2123,7 @@ var Utils = (function () {
|
|
|
2085
2123
|
});
|
|
2086
2124
|
}
|
|
2087
2125
|
else {
|
|
2088
|
-
this.context.HttpxCallBack.onError(details, resolve, argumentsList);
|
|
2126
|
+
this.context.HttpxCallBack.onError(details, resolve, reject, argumentsList);
|
|
2089
2127
|
}
|
|
2090
2128
|
},
|
|
2091
2129
|
/**
|
|
@@ -2396,8 +2434,8 @@ var Utils = (function () {
|
|
|
2396
2434
|
async get(...args) {
|
|
2397
2435
|
let that = this;
|
|
2398
2436
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2399
|
-
return new Promise((resolve) => {
|
|
2400
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2437
|
+
return new Promise((resolve, reject) => {
|
|
2438
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
|
|
2401
2439
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2402
2440
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2403
2441
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2409,8 +2447,8 @@ var Utils = (function () {
|
|
|
2409
2447
|
async post(...args) {
|
|
2410
2448
|
let that = this;
|
|
2411
2449
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2412
|
-
return new Promise((resolve) => {
|
|
2413
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2450
|
+
return new Promise((resolve, reject) => {
|
|
2451
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
|
|
2414
2452
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2415
2453
|
that.HttpxRequest.request(requestDetails);
|
|
2416
2454
|
});
|
|
@@ -2421,8 +2459,8 @@ var Utils = (function () {
|
|
|
2421
2459
|
async head(...args) {
|
|
2422
2460
|
let that = this;
|
|
2423
2461
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2424
|
-
return new Promise((resolve) => {
|
|
2425
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2462
|
+
return new Promise((resolve, reject) => {
|
|
2463
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
|
|
2426
2464
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2427
2465
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2428
2466
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2434,8 +2472,8 @@ var Utils = (function () {
|
|
|
2434
2472
|
async options(...args) {
|
|
2435
2473
|
let that = this;
|
|
2436
2474
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2437
|
-
return new Promise((resolve) => {
|
|
2438
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2475
|
+
return new Promise((resolve, reject) => {
|
|
2476
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
|
|
2439
2477
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2440
2478
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2441
2479
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2447,8 +2485,8 @@ var Utils = (function () {
|
|
|
2447
2485
|
async delete(...args) {
|
|
2448
2486
|
let that = this;
|
|
2449
2487
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2450
|
-
return new Promise((resolve) => {
|
|
2451
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2488
|
+
return new Promise((resolve, reject) => {
|
|
2489
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
|
|
2452
2490
|
Reflect.deleteProperty(requestDetails, "onprogress");
|
|
2453
2491
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2454
2492
|
that.HttpxRequest.request(requestDetails);
|
|
@@ -2460,8 +2498,8 @@ var Utils = (function () {
|
|
|
2460
2498
|
async put(...args) {
|
|
2461
2499
|
let that = this;
|
|
2462
2500
|
let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
|
|
2463
|
-
return new Promise((resolve) => {
|
|
2464
|
-
let requestDetails = that.HttpxRequestDetails.getDetails("
|
|
2501
|
+
return new Promise((resolve, reject) => {
|
|
2502
|
+
let requestDetails = that.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
|
|
2465
2503
|
requestDetails = that.HttpxRequestDetails.handle(requestDetails);
|
|
2466
2504
|
that.HttpxRequest.request(requestDetails);
|
|
2467
2505
|
});
|