@whitesev/utils 1.5.3 → 1.5.5
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 +38 -8
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +38 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +38 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +38 -8
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +38 -8
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +38 -8
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +1 -1
- package/dist/src/Utils.d.ts +10 -3
- package/dist/src/VueObject.d.ts +3 -0
- package/package.json +1 -1
- package/src/Httpx.ts +18 -8
- package/src/Utils.ts +26 -0
- package/src/VueObject.ts +4 -0
package/dist/index.umd.js
CHANGED
|
@@ -1510,13 +1510,14 @@
|
|
|
1510
1510
|
},
|
|
1511
1511
|
/**
|
|
1512
1512
|
* 成功的回调
|
|
1513
|
-
* @param response
|
|
1513
|
+
* @param response 响应
|
|
1514
|
+
* @param details 请求的配置
|
|
1514
1515
|
*/
|
|
1515
|
-
successResponseCallBack(response) {
|
|
1516
|
+
successResponseCallBack(response, details) {
|
|
1516
1517
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1517
1518
|
let item = this.$config.configList[index];
|
|
1518
1519
|
if (typeof item.successFn === "function") {
|
|
1519
|
-
if (item.successFn(response) == null) {
|
|
1520
|
+
if (item.successFn(response, details) == null) {
|
|
1520
1521
|
return;
|
|
1521
1522
|
}
|
|
1522
1523
|
}
|
|
@@ -1525,7 +1526,7 @@
|
|
|
1525
1526
|
},
|
|
1526
1527
|
/**
|
|
1527
1528
|
* 失败的回调
|
|
1528
|
-
* @param
|
|
1529
|
+
* @param data 配置
|
|
1529
1530
|
*/
|
|
1530
1531
|
errorResponseCallBack(data) {
|
|
1531
1532
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
@@ -1788,6 +1789,7 @@
|
|
|
1788
1789
|
type: "onabort",
|
|
1789
1790
|
error: new TypeError("request canceled"),
|
|
1790
1791
|
response: null,
|
|
1792
|
+
details: details,
|
|
1791
1793
|
}) == null) {
|
|
1792
1794
|
return;
|
|
1793
1795
|
}
|
|
@@ -1819,6 +1821,7 @@
|
|
|
1819
1821
|
type: "onerror",
|
|
1820
1822
|
error: new TypeError("request error"),
|
|
1821
1823
|
response: response,
|
|
1824
|
+
details: details,
|
|
1822
1825
|
}) == null) {
|
|
1823
1826
|
return;
|
|
1824
1827
|
}
|
|
@@ -1847,6 +1850,7 @@
|
|
|
1847
1850
|
type: "ontimeout",
|
|
1848
1851
|
error: new TypeError("request timeout"),
|
|
1849
1852
|
response: (argumentsList || [null])[0],
|
|
1853
|
+
details: details,
|
|
1850
1854
|
}) == null) {
|
|
1851
1855
|
return;
|
|
1852
1856
|
}
|
|
@@ -1930,8 +1934,7 @@
|
|
|
1930
1934
|
}
|
|
1931
1935
|
/* 状态码2xx都是成功的 */
|
|
1932
1936
|
if (Math.floor(Response.status / 100) === 2) {
|
|
1933
|
-
if (this.context.HttpxResponseHook.successResponseCallBack(Response) ==
|
|
1934
|
-
null) {
|
|
1937
|
+
if (this.context.HttpxResponseHook.successResponseCallBack(Response, details) == null) {
|
|
1935
1938
|
return;
|
|
1936
1939
|
}
|
|
1937
1940
|
resolve({
|
|
@@ -2052,7 +2055,7 @@
|
|
|
2052
2055
|
let responseText = "";
|
|
2053
2056
|
/** 响应xml文档 */
|
|
2054
2057
|
let responseXML = "";
|
|
2055
|
-
let arrayBuffer = await resp.arrayBuffer;
|
|
2058
|
+
let arrayBuffer = await resp.arrayBuffer();
|
|
2056
2059
|
let encoding = "utf-8";
|
|
2057
2060
|
if (resp.headers.has("Content-Type")) {
|
|
2058
2061
|
let charsetMatched = resp.headers
|
|
@@ -2063,7 +2066,7 @@
|
|
|
2063
2066
|
}
|
|
2064
2067
|
}
|
|
2065
2068
|
let textDecoder = new TextDecoder(encoding);
|
|
2066
|
-
responseText = textDecoder.decode(
|
|
2069
|
+
responseText = textDecoder.decode(arrayBuffer);
|
|
2067
2070
|
response = responseText;
|
|
2068
2071
|
if (details.responseType === "arraybuffer") {
|
|
2069
2072
|
response = arrayBuffer;
|
|
@@ -6219,6 +6222,33 @@
|
|
|
6219
6222
|
});
|
|
6220
6223
|
return formData;
|
|
6221
6224
|
}
|
|
6225
|
+
/**
|
|
6226
|
+
* 将链接转为URL对象,自动补充URL的protocol或者origin
|
|
6227
|
+
* @param text 需要转换的链接字符串
|
|
6228
|
+
* @example
|
|
6229
|
+
* Utils.toUrl("//www.baidu.com/s?word=666");
|
|
6230
|
+
* Utils.toUrl("/s?word=666");
|
|
6231
|
+
*/
|
|
6232
|
+
toUrl(text) {
|
|
6233
|
+
if (typeof text !== "string") {
|
|
6234
|
+
throw new TypeError("toUrl: text must be string");
|
|
6235
|
+
}
|
|
6236
|
+
text = text.trim();
|
|
6237
|
+
if (text === "") {
|
|
6238
|
+
throw new TypeError("toUrl: text must not be empty");
|
|
6239
|
+
}
|
|
6240
|
+
if (text.startsWith("//")) {
|
|
6241
|
+
/* //www.baidu.com/xxxxxxx */
|
|
6242
|
+
/* 没有protocol,加上 */
|
|
6243
|
+
text = UtilsCore.globalThis.location.protocol + text;
|
|
6244
|
+
}
|
|
6245
|
+
else if (text.startsWith("/")) {
|
|
6246
|
+
/* /xxx/info?xxx=xxx */
|
|
6247
|
+
/* 没有Origin,加上 */
|
|
6248
|
+
text = UtilsCore.globalThis.location.origin + text;
|
|
6249
|
+
}
|
|
6250
|
+
return new URL(text);
|
|
6251
|
+
}
|
|
6222
6252
|
/**
|
|
6223
6253
|
* 生成uuid
|
|
6224
6254
|
* @example
|