@whitesev/utils 2.3.8 → 2.4.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 +379 -268
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +379 -268
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +379 -268
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +379 -268
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +379 -268
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +379 -268
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +25 -1178
- package/dist/types/src/Log.d.ts +1 -19
- package/dist/types/src/Progress.d.ts +1 -20
- package/dist/types/src/TryCatch.d.ts +2 -11
- package/dist/types/src/Utils.d.ts +8 -32
- package/dist/types/src/UtilsGMCookie.d.ts +1 -51
- package/dist/types/src/UtilsGMMenu.d.ts +1 -50
- package/dist/types/src/WindowApi.d.ts +3 -11
- package/dist/types/src/types/Httpx.d.ts +1316 -0
- package/dist/types/src/types/Log.d.ts +19 -0
- package/dist/types/src/types/Progress.d.ts +20 -0
- package/dist/types/src/types/TryCatch.d.ts +9 -0
- package/dist/types/src/types/UtilsGMCookie.d.ts +55 -0
- package/dist/types/src/types/UtilsGMMenu.d.ts +77 -0
- package/{src/VueObject.ts → dist/types/src/types/Vue2.d.ts} +28 -15
- package/dist/types/src/types/Vue3.d.ts +0 -0
- package/dist/types/src/types/WindowApi.d.ts +10 -0
- package/dist/types/src/types/global.d.ts +24 -1
- package/package.json +1 -1
- package/src/GBKEncoder.ts +1 -1
- package/src/Httpx.ts +535 -1627
- package/src/Log.ts +1 -19
- package/src/Progress.ts +1 -20
- package/src/TryCatch.ts +2 -12
- package/src/Utils.ts +15 -38
- package/src/UtilsGMCookie.ts +7 -56
- package/src/UtilsGMMenu.ts +5 -78
- package/src/WindowApi.ts +4 -11
- package/src/types/Event.d.ts +189 -0
- package/src/types/Httpx.d.ts +1316 -0
- package/src/types/Log.d.ts +19 -0
- package/src/types/Progress.d.ts +20 -0
- package/src/types/TryCatch.d.ts +9 -0
- package/src/types/UtilsGMCookie.d.ts +55 -0
- package/src/types/UtilsGMMenu.d.ts +77 -0
- package/src/types/Vue2.d.ts +154 -0
- package/src/types/Vue3.d.ts +0 -0
- package/src/types/WindowApi.d.ts +10 -0
- package/{dist/types/src/AjaxHookerType.d.ts → src/types/ajaxHooker.d.ts} +155 -147
- package/src/types/global.d.ts +24 -1
- package/dist/types/src/Event.d.ts +0 -156
- package/dist/types/src/VueObject.d.ts +0 -123
- /package/{src/Event.ts → dist/types/src/types/Event.d.ts} +0 -0
- /package/{src/AjaxHookerType.ts → dist/types/src/types/ajaxHooker.d.ts} +0 -0
package/dist/index.amd.js
CHANGED
|
@@ -1717,55 +1717,57 @@ define((function () { 'use strict';
|
|
|
1717
1717
|
/**
|
|
1718
1718
|
* 根据传入的参数处理获取details配置
|
|
1719
1719
|
*/
|
|
1720
|
-
|
|
1721
|
-
let
|
|
1720
|
+
handleBeforeRequestOption(...args) {
|
|
1721
|
+
let option = {};
|
|
1722
1722
|
if (typeof args[0] === "string") {
|
|
1723
1723
|
/* 传入的是url,details? */
|
|
1724
1724
|
let url = args[0];
|
|
1725
|
-
|
|
1725
|
+
option.url = url;
|
|
1726
1726
|
if (typeof args[1] === "object") {
|
|
1727
1727
|
/* 处理第二个参数details */
|
|
1728
1728
|
let details = args[1];
|
|
1729
|
-
|
|
1730
|
-
|
|
1729
|
+
option = details;
|
|
1730
|
+
option.url = url;
|
|
1731
1731
|
}
|
|
1732
1732
|
}
|
|
1733
1733
|
else {
|
|
1734
1734
|
/* 传入的是details */
|
|
1735
|
-
|
|
1735
|
+
option = args[0];
|
|
1736
1736
|
}
|
|
1737
|
-
return
|
|
1737
|
+
return option;
|
|
1738
1738
|
},
|
|
1739
1739
|
/**
|
|
1740
1740
|
* 获取请求配置
|
|
1741
1741
|
* @param method 当前请求方法,默认get
|
|
1742
|
-
* @param
|
|
1742
|
+
* @param userRequestOption 用户的请求配置
|
|
1743
1743
|
* @param resolve promise回调
|
|
1744
1744
|
* @param reject 抛出错误回调
|
|
1745
1745
|
*/
|
|
1746
|
-
|
|
1746
|
+
getRequestOption(method, userRequestOption, resolve, reject) {
|
|
1747
1747
|
let that = this;
|
|
1748
|
-
let
|
|
1749
|
-
url:
|
|
1748
|
+
let requestOption = {
|
|
1749
|
+
url: userRequestOption.url || this.context.#defaultDetails.url,
|
|
1750
1750
|
method: (method || "GET").toString().toUpperCase(),
|
|
1751
|
-
timeout:
|
|
1752
|
-
responseType:
|
|
1751
|
+
timeout: userRequestOption.timeout || this.context.#defaultDetails.timeout,
|
|
1752
|
+
responseType: userRequestOption.responseType ||
|
|
1753
|
+
this.context.#defaultDetails.responseType,
|
|
1753
1754
|
/* 对象使用深拷贝 */
|
|
1754
1755
|
headers: utils.deepClone(this.context.#defaultDetails.headers),
|
|
1755
|
-
data:
|
|
1756
|
-
redirect:
|
|
1757
|
-
cookie:
|
|
1758
|
-
cookiePartition:
|
|
1756
|
+
data: userRequestOption.data || this.context.#defaultDetails.data,
|
|
1757
|
+
redirect: userRequestOption.redirect || this.context.#defaultDetails.redirect,
|
|
1758
|
+
cookie: userRequestOption.cookie || this.context.#defaultDetails.cookie,
|
|
1759
|
+
cookiePartition: userRequestOption.cookiePartition ||
|
|
1759
1760
|
this.context.#defaultDetails.cookiePartition,
|
|
1760
|
-
binary:
|
|
1761
|
-
nocache:
|
|
1762
|
-
revalidate:
|
|
1761
|
+
binary: userRequestOption.binary || this.context.#defaultDetails.binary,
|
|
1762
|
+
nocache: userRequestOption.nocache || this.context.#defaultDetails.nocache,
|
|
1763
|
+
revalidate: userRequestOption.revalidate ||
|
|
1764
|
+
this.context.#defaultDetails.revalidate,
|
|
1763
1765
|
/* 对象使用深拷贝 */
|
|
1764
|
-
context: utils.deepClone(
|
|
1765
|
-
overrideMimeType:
|
|
1766
|
+
context: utils.deepClone(userRequestOption.context || this.context.#defaultDetails.context),
|
|
1767
|
+
overrideMimeType: userRequestOption.overrideMimeType ||
|
|
1766
1768
|
this.context.#defaultDetails.overrideMimeType,
|
|
1767
|
-
anonymous:
|
|
1768
|
-
fetch:
|
|
1769
|
+
anonymous: userRequestOption.anonymous || this.context.#defaultDetails.anonymous,
|
|
1770
|
+
fetch: userRequestOption.fetch || this.context.#defaultDetails.fetch,
|
|
1769
1771
|
/* 对象使用深拷贝 */
|
|
1770
1772
|
fetchInit: utils.deepClone(this.context.#defaultDetails.fetchInit),
|
|
1771
1773
|
allowInterceptConfig: {
|
|
@@ -1776,153 +1778,243 @@ define((function () { 'use strict';
|
|
|
1776
1778
|
afterResponseError: this.context.#defaultDetails
|
|
1777
1779
|
.allowInterceptConfig.afterResponseError,
|
|
1778
1780
|
},
|
|
1779
|
-
user:
|
|
1780
|
-
password:
|
|
1781
|
+
user: userRequestOption.user || this.context.#defaultDetails.user,
|
|
1782
|
+
password: userRequestOption.password || this.context.#defaultDetails.password,
|
|
1781
1783
|
onabort(...args) {
|
|
1782
|
-
that.context.HttpxCallBack.onAbort(
|
|
1784
|
+
that.context.HttpxCallBack.onAbort(userRequestOption, resolve, reject, args);
|
|
1783
1785
|
},
|
|
1784
1786
|
onerror(...args) {
|
|
1785
|
-
that.context.HttpxCallBack.onError(
|
|
1787
|
+
that.context.HttpxCallBack.onError(userRequestOption, resolve, reject, args);
|
|
1786
1788
|
},
|
|
1787
1789
|
onloadstart(...args) {
|
|
1788
|
-
that.context.HttpxCallBack.onLoadStart(
|
|
1790
|
+
that.context.HttpxCallBack.onLoadStart(userRequestOption, args);
|
|
1789
1791
|
},
|
|
1790
1792
|
onprogress(...args) {
|
|
1791
|
-
that.context.HttpxCallBack.onProgress(
|
|
1793
|
+
that.context.HttpxCallBack.onProgress(userRequestOption, args);
|
|
1792
1794
|
},
|
|
1793
1795
|
onreadystatechange(...args) {
|
|
1794
|
-
that.context.HttpxCallBack.onReadyStateChange(
|
|
1796
|
+
that.context.HttpxCallBack.onReadyStateChange(userRequestOption, args);
|
|
1795
1797
|
},
|
|
1796
1798
|
ontimeout(...args) {
|
|
1797
|
-
that.context.HttpxCallBack.onTimeout(
|
|
1799
|
+
that.context.HttpxCallBack.onTimeout(userRequestOption, resolve, reject, args);
|
|
1798
1800
|
},
|
|
1799
1801
|
onload(...args) {
|
|
1800
|
-
that.context.HttpxCallBack.onLoad(
|
|
1802
|
+
that.context.HttpxCallBack.onLoad(userRequestOption, resolve, reject, args);
|
|
1801
1803
|
},
|
|
1802
1804
|
};
|
|
1803
1805
|
// 补全allowInterceptConfig参数
|
|
1804
|
-
if (typeof
|
|
1805
|
-
Object.keys(
|
|
1806
|
-
|
|
1807
|
-
details.allowInterceptConfig;
|
|
1806
|
+
if (typeof userRequestOption.allowInterceptConfig === "boolean") {
|
|
1807
|
+
Object.keys(requestOption.allowInterceptConfig).forEach((keyName) => {
|
|
1808
|
+
Reflect.set(requestOption.allowInterceptConfig, keyName, userRequestOption.allowInterceptConfig);
|
|
1808
1809
|
});
|
|
1809
1810
|
}
|
|
1810
1811
|
else {
|
|
1811
|
-
if (typeof
|
|
1812
|
-
|
|
1813
|
-
Object.keys(
|
|
1814
|
-
let value =
|
|
1815
|
-
if (
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
result.allowInterceptConfig[keyName] = value;
|
|
1812
|
+
if (typeof userRequestOption.allowInterceptConfig === "object" &&
|
|
1813
|
+
userRequestOption.allowInterceptConfig != null) {
|
|
1814
|
+
Object.keys(userRequestOption.allowInterceptConfig).forEach((keyName) => {
|
|
1815
|
+
let value = Reflect.get(userRequestOption.allowInterceptConfig, keyName);
|
|
1816
|
+
if (typeof value === "boolean" &&
|
|
1817
|
+
Reflect.has(requestOption.allowInterceptConfig, keyName)) {
|
|
1818
|
+
Reflect.set(requestOption.allowInterceptConfig, keyName, value);
|
|
1819
1819
|
}
|
|
1820
1820
|
});
|
|
1821
1821
|
}
|
|
1822
1822
|
}
|
|
1823
1823
|
if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1824
|
+
// GM函数不存在,强制使用fetch
|
|
1825
|
+
requestOption.fetch = true;
|
|
1826
|
+
}
|
|
1827
|
+
if (typeof requestOption.headers === "object") {
|
|
1828
|
+
if (typeof userRequestOption.headers === "object") {
|
|
1829
|
+
Object.keys(userRequestOption.headers).forEach((keyName, index) => {
|
|
1830
|
+
if (keyName in requestOption.headers &&
|
|
1831
|
+
userRequestOption.headers?.[keyName] == null) {
|
|
1831
1832
|
/* 在默认的header中存在,且设置它新的值为空,那么就是默认的值 */
|
|
1832
|
-
Reflect.deleteProperty(
|
|
1833
|
+
Reflect.deleteProperty(requestOption.headers, keyName);
|
|
1833
1834
|
}
|
|
1834
1835
|
else {
|
|
1835
|
-
|
|
1836
|
+
requestOption.headers[keyName] =
|
|
1837
|
+
userRequestOption?.headers?.[keyName];
|
|
1836
1838
|
}
|
|
1837
1839
|
});
|
|
1838
1840
|
}
|
|
1839
1841
|
}
|
|
1840
1842
|
else {
|
|
1841
|
-
|
|
1843
|
+
/* 默认的headers不是对象,那么就直接使用新的 */
|
|
1844
|
+
Reflect.set(requestOption, "headers", userRequestOption.headers);
|
|
1842
1845
|
}
|
|
1843
|
-
if (typeof
|
|
1846
|
+
if (typeof requestOption.fetchInit === "object") {
|
|
1844
1847
|
/* 使用assign替换且添加 */
|
|
1845
|
-
if (typeof
|
|
1846
|
-
Object.keys(
|
|
1847
|
-
if (keyName in
|
|
1848
|
-
|
|
1848
|
+
if (typeof userRequestOption.fetchInit === "object") {
|
|
1849
|
+
Object.keys(userRequestOption.fetchInit).forEach((keyName, index) => {
|
|
1850
|
+
if (keyName in requestOption.fetchInit &&
|
|
1851
|
+
userRequestOption.fetchInit[keyName] == null) {
|
|
1849
1852
|
/* 在默认的fetchInit中存在,且设置它新的值为空,那么就是默认的值 */
|
|
1850
|
-
Reflect.deleteProperty(
|
|
1853
|
+
Reflect.deleteProperty(requestOption.fetchInit, keyName);
|
|
1851
1854
|
}
|
|
1852
1855
|
else {
|
|
1853
|
-
|
|
1856
|
+
Reflect.set(requestOption.fetchInit, keyName, Reflect.get(userRequestOption.fetchInit, keyName));
|
|
1854
1857
|
}
|
|
1855
1858
|
});
|
|
1856
1859
|
}
|
|
1857
1860
|
}
|
|
1858
1861
|
else {
|
|
1859
|
-
|
|
1862
|
+
Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
|
|
1860
1863
|
}
|
|
1861
1864
|
// 处理新的cookiePartition
|
|
1862
|
-
if (typeof
|
|
1863
|
-
|
|
1864
|
-
if (Reflect.has(
|
|
1865
|
-
typeof
|
|
1865
|
+
if (typeof requestOption.cookiePartition === "object" &&
|
|
1866
|
+
requestOption.cookiePartition != null) {
|
|
1867
|
+
if (Reflect.has(requestOption.cookiePartition, "topLevelSite") &&
|
|
1868
|
+
typeof requestOption.cookiePartition.topLevelSite !== "string") {
|
|
1866
1869
|
// topLevelSite必须是字符串
|
|
1867
|
-
Reflect.deleteProperty(
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
return result;
|
|
1871
|
-
},
|
|
1872
|
-
/**
|
|
1873
|
-
* 处理发送请求的details,去除值为undefined、空function的值
|
|
1874
|
-
* @param details
|
|
1875
|
-
*/
|
|
1876
|
-
handle(details) {
|
|
1877
|
-
Object.keys(details).forEach((keyName) => {
|
|
1878
|
-
if (details[keyName] == null ||
|
|
1879
|
-
(details[keyName] instanceof Function &&
|
|
1880
|
-
utils.isNull(details[keyName]))) {
|
|
1881
|
-
Reflect.deleteProperty(details, keyName);
|
|
1882
|
-
return;
|
|
1870
|
+
Reflect.deleteProperty(requestOption.cookiePartition, "topLevelSite");
|
|
1883
1871
|
}
|
|
1884
|
-
});
|
|
1885
|
-
if (utils.isNull(details.url)) {
|
|
1886
|
-
throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${details.url}`);
|
|
1887
1872
|
}
|
|
1888
|
-
/*
|
|
1889
|
-
details.method = details.method.toUpperCase();
|
|
1890
|
-
/* 判断是否是以http开头,否则主动加上origin */
|
|
1873
|
+
/* 完善请求的url */
|
|
1891
1874
|
try {
|
|
1892
|
-
new URL(
|
|
1875
|
+
new URL(requestOption.url);
|
|
1893
1876
|
}
|
|
1894
1877
|
catch (error) {
|
|
1895
|
-
if (
|
|
1896
|
-
|
|
1878
|
+
if (requestOption.url.startsWith("//")) {
|
|
1879
|
+
// 补充https:
|
|
1880
|
+
requestOption.url = globalThis.location.protocol + requestOption.url;
|
|
1897
1881
|
}
|
|
1898
|
-
else if (
|
|
1899
|
-
|
|
1882
|
+
else if (requestOption.url.startsWith("/")) {
|
|
1883
|
+
// 补充origin
|
|
1884
|
+
requestOption.url = globalThis.location.origin + requestOption.url;
|
|
1900
1885
|
}
|
|
1901
1886
|
else {
|
|
1902
|
-
|
|
1887
|
+
// 补充origin+/
|
|
1888
|
+
requestOption.url =
|
|
1889
|
+
globalThis.location.origin + "/" + requestOption.url;
|
|
1903
1890
|
}
|
|
1904
1891
|
}
|
|
1905
|
-
|
|
1892
|
+
if (requestOption.fetchInit && !requestOption.fetch) {
|
|
1893
|
+
// 清空fetchInit
|
|
1894
|
+
Reflect.deleteProperty(requestOption, "fetchInit");
|
|
1895
|
+
}
|
|
1896
|
+
// 转换data类型
|
|
1897
|
+
try {
|
|
1898
|
+
/** 是否对数据进行处理 */
|
|
1899
|
+
let processData = userRequestOption.processData ?? true;
|
|
1900
|
+
if (requestOption.data != null && processData) {
|
|
1901
|
+
let method = requestOption.method;
|
|
1902
|
+
if (method === "GET" || method === "HEAD") {
|
|
1903
|
+
// GET类型,data如果有,那么需要转为searchParams
|
|
1904
|
+
let urlObj = new URL(requestOption.url);
|
|
1905
|
+
let urlSearch = "";
|
|
1906
|
+
if (typeof requestOption.data === "string") {
|
|
1907
|
+
urlSearch = requestOption.data;
|
|
1908
|
+
}
|
|
1909
|
+
else if (typeof requestOption.data === "object") {
|
|
1910
|
+
// URLSearchParams参数可以转普通的string:string,包括FormData
|
|
1911
|
+
// @ts-ignore
|
|
1912
|
+
let searchParams = new URLSearchParams(requestOption.data);
|
|
1913
|
+
urlSearch = searchParams.toString();
|
|
1914
|
+
}
|
|
1915
|
+
if (urlSearch != "") {
|
|
1916
|
+
if (urlObj.search === "") {
|
|
1917
|
+
// url没有search参数,直接覆盖
|
|
1918
|
+
urlObj.search = urlSearch;
|
|
1919
|
+
}
|
|
1920
|
+
else {
|
|
1921
|
+
// 有search参数
|
|
1922
|
+
if (urlObj.search.endsWith("&")) {
|
|
1923
|
+
// xxx=xxx&
|
|
1924
|
+
urlObj.search = urlObj.search + urlSearch;
|
|
1925
|
+
}
|
|
1926
|
+
else {
|
|
1927
|
+
// xxx=xxx&xxx=
|
|
1928
|
+
urlObj.search = urlObj.search + "&" + urlSearch;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
requestOption.url = urlObj.toString();
|
|
1933
|
+
}
|
|
1934
|
+
else if (method === "POST" && requestOption.headers != null) {
|
|
1935
|
+
// POST类型,data如果是FormData,那么需要转为string
|
|
1936
|
+
let headersKeyList = Object.keys(requestOption.headers);
|
|
1937
|
+
let ContentTypeIndex = headersKeyList.findIndex((headerKey) => {
|
|
1938
|
+
return (headerKey.trim().toLowerCase() === "content-type" &&
|
|
1939
|
+
typeof requestOption.headers[headerKey] === "string");
|
|
1940
|
+
});
|
|
1941
|
+
if (ContentTypeIndex !== -1) {
|
|
1942
|
+
let ContentTypeKey = headersKeyList[ContentTypeIndex];
|
|
1943
|
+
// 设置了Content-Type
|
|
1944
|
+
let ContentType = requestOption.headers[ContentTypeIndex].toLowerCase();
|
|
1945
|
+
if (ContentType.includes("application/json")) {
|
|
1946
|
+
// application/json
|
|
1947
|
+
if (requestOption.data instanceof FormData) {
|
|
1948
|
+
const entries = {};
|
|
1949
|
+
requestOption.data.forEach((value, key) => {
|
|
1950
|
+
entries[key] = value;
|
|
1951
|
+
});
|
|
1952
|
+
requestOption.data = JSON.stringify(entries);
|
|
1953
|
+
}
|
|
1954
|
+
else if (typeof requestOption.data === "object") {
|
|
1955
|
+
requestOption.data = JSON.stringify(requestOption.data);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
else if (ContentType.includes("application/x-www-form-urlencoded")) {
|
|
1959
|
+
// application/x-www-form-urlencoded
|
|
1960
|
+
if (typeof requestOption.data === "object") {
|
|
1961
|
+
requestOption.data = new URLSearchParams(
|
|
1962
|
+
// @ts-ignore
|
|
1963
|
+
requestOption.data).toString();
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
else if (ContentType.includes("multipart/form-data")) {
|
|
1967
|
+
// multipart/form-data
|
|
1968
|
+
if (requestOption.data instanceof FormData) {
|
|
1969
|
+
Reflect.deleteProperty(requestOption.headers, ContentTypeKey);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
catch (error) {
|
|
1977
|
+
console.warn("Httpx ==> 转换data参数错误", error);
|
|
1978
|
+
}
|
|
1979
|
+
return requestOption;
|
|
1980
|
+
},
|
|
1981
|
+
/**
|
|
1982
|
+
* 处理发送请求的配置,去除值为undefined、空function的值
|
|
1983
|
+
* @param option
|
|
1984
|
+
*/
|
|
1985
|
+
removeRequestNullOption(option) {
|
|
1986
|
+
Object.keys(option).forEach((keyName) => {
|
|
1987
|
+
if (option[keyName] == null ||
|
|
1988
|
+
(option[keyName] instanceof Function &&
|
|
1989
|
+
utils.isNull(option[keyName]))) {
|
|
1990
|
+
Reflect.deleteProperty(option, keyName);
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1993
|
+
});
|
|
1994
|
+
if (utils.isNull(option.url)) {
|
|
1995
|
+
throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
|
|
1996
|
+
}
|
|
1997
|
+
return option;
|
|
1906
1998
|
},
|
|
1907
1999
|
/**
|
|
1908
2000
|
* 处理fetch的配置
|
|
1909
|
-
* @param
|
|
2001
|
+
* @param option
|
|
1910
2002
|
*/
|
|
1911
|
-
|
|
2003
|
+
handleFetchOption(option) {
|
|
1912
2004
|
/**
|
|
1913
2005
|
* fetch的请求配置
|
|
1914
2006
|
**/
|
|
1915
|
-
let
|
|
1916
|
-
if ((
|
|
1917
|
-
|
|
2007
|
+
let fetchRequestOption = {};
|
|
2008
|
+
if ((option.method === "GET" || option.method === "HEAD") &&
|
|
2009
|
+
option.data != null) {
|
|
1918
2010
|
/* GET 或 HEAD 方法的请求不能包含 body 信息 */
|
|
1919
|
-
Reflect.deleteProperty(
|
|
2011
|
+
Reflect.deleteProperty(option, "data");
|
|
1920
2012
|
}
|
|
1921
2013
|
/* 中止信号控制器 */
|
|
1922
2014
|
let abortController = new AbortController();
|
|
1923
2015
|
let signal = abortController.signal;
|
|
1924
2016
|
signal.onabort = () => {
|
|
1925
|
-
|
|
2017
|
+
option.onabort({
|
|
1926
2018
|
isFetch: true,
|
|
1927
2019
|
responseText: "",
|
|
1928
2020
|
response: null,
|
|
@@ -1933,19 +2025,28 @@ define((function () { 'use strict';
|
|
|
1933
2025
|
error: "aborted",
|
|
1934
2026
|
});
|
|
1935
2027
|
};
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
2028
|
+
// 设置请求
|
|
2029
|
+
fetchRequestOption.method = option.method ?? "GET";
|
|
2030
|
+
// 设置请求头
|
|
2031
|
+
fetchRequestOption.headers = option.headers;
|
|
2032
|
+
// 设置请求体
|
|
2033
|
+
fetchRequestOption.body = option.data;
|
|
2034
|
+
// 设置跨域
|
|
2035
|
+
fetchRequestOption.mode = "cors";
|
|
2036
|
+
// 设置包含
|
|
2037
|
+
fetchRequestOption.credentials = "include";
|
|
2038
|
+
// 设置不缓存
|
|
2039
|
+
fetchRequestOption.cache = "no-cache";
|
|
2040
|
+
// 设置始终重定向
|
|
2041
|
+
fetchRequestOption.redirect = "follow";
|
|
2042
|
+
// 设置referer跨域
|
|
2043
|
+
fetchRequestOption.referrerPolicy = "origin-when-cross-origin";
|
|
2044
|
+
// 设置信号中断
|
|
2045
|
+
fetchRequestOption.signal = signal;
|
|
2046
|
+
Object.assign(fetchRequestOption, option.fetchInit || {});
|
|
1946
2047
|
return {
|
|
1947
|
-
|
|
1948
|
-
|
|
2048
|
+
fetchOption: option,
|
|
2049
|
+
fetchRequestOption: fetchRequestOption,
|
|
1949
2050
|
abortController: abortController,
|
|
1950
2051
|
};
|
|
1951
2052
|
},
|
|
@@ -1957,14 +2058,19 @@ define((function () { 'use strict';
|
|
|
1957
2058
|
* @param details 配置
|
|
1958
2059
|
* @param resolve 回调
|
|
1959
2060
|
* @param reject 抛出错误
|
|
1960
|
-
* @param
|
|
2061
|
+
* @param argsResult 返回的参数列表
|
|
1961
2062
|
*/
|
|
1962
|
-
onAbort(details, resolve, reject,
|
|
2063
|
+
onAbort(details, resolve, reject, argsResult) {
|
|
2064
|
+
// console.log(argsResult);
|
|
1963
2065
|
if ("onabort" in details) {
|
|
1964
|
-
details.onabort.apply(this,
|
|
2066
|
+
details.onabort.apply(this, argsResult);
|
|
1965
2067
|
}
|
|
1966
2068
|
else if ("onabort" in this.context.#defaultDetails) {
|
|
1967
|
-
this.context.#defaultDetails.onabort.apply(this,
|
|
2069
|
+
this.context.#defaultDetails.onabort.apply(this, argsResult);
|
|
2070
|
+
}
|
|
2071
|
+
let response = argsResult;
|
|
2072
|
+
if (response.length) {
|
|
2073
|
+
response = response[0];
|
|
1968
2074
|
}
|
|
1969
2075
|
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
1970
2076
|
type: "onabort",
|
|
@@ -1976,9 +2082,11 @@ define((function () { 'use strict';
|
|
|
1976
2082
|
return;
|
|
1977
2083
|
}
|
|
1978
2084
|
resolve({
|
|
1979
|
-
|
|
1980
|
-
|
|
2085
|
+
data: response,
|
|
2086
|
+
details: details,
|
|
1981
2087
|
msg: "请求被取消",
|
|
2088
|
+
status: false,
|
|
2089
|
+
statusCode: -1,
|
|
1982
2090
|
type: "onabort",
|
|
1983
2091
|
});
|
|
1984
2092
|
},
|
|
@@ -1987,16 +2095,17 @@ define((function () { 'use strict';
|
|
|
1987
2095
|
* @param details 配置
|
|
1988
2096
|
* @param resolve 回调
|
|
1989
2097
|
* @param reject 抛出错误
|
|
1990
|
-
* @param
|
|
2098
|
+
* @param argsResult 返回的参数列表
|
|
1991
2099
|
*/
|
|
1992
|
-
onError(details, resolve, reject,
|
|
2100
|
+
onError(details, resolve, reject, argsResult) {
|
|
2101
|
+
// console.log(argsResult);
|
|
1993
2102
|
if ("onerror" in details) {
|
|
1994
|
-
details.onerror.apply(this,
|
|
2103
|
+
details.onerror.apply(this, argsResult);
|
|
1995
2104
|
}
|
|
1996
2105
|
else if ("onerror" in this.context.#defaultDetails) {
|
|
1997
|
-
this.context.#defaultDetails.onerror.apply(this,
|
|
2106
|
+
this.context.#defaultDetails.onerror.apply(this, argsResult);
|
|
1998
2107
|
}
|
|
1999
|
-
let response =
|
|
2108
|
+
let response = argsResult;
|
|
2000
2109
|
if (response.length) {
|
|
2001
2110
|
response = response[0];
|
|
2002
2111
|
}
|
|
@@ -2010,10 +2119,11 @@ define((function () { 'use strict';
|
|
|
2010
2119
|
return;
|
|
2011
2120
|
}
|
|
2012
2121
|
resolve({
|
|
2013
|
-
status: false,
|
|
2014
2122
|
data: response,
|
|
2015
2123
|
details: details,
|
|
2016
2124
|
msg: "请求异常",
|
|
2125
|
+
status: false,
|
|
2126
|
+
statusCode: response["status"],
|
|
2017
2127
|
type: "onerror",
|
|
2018
2128
|
});
|
|
2019
2129
|
},
|
|
@@ -2022,42 +2132,50 @@ define((function () { 'use strict';
|
|
|
2022
2132
|
* @param details 配置
|
|
2023
2133
|
* @param resolve 回调
|
|
2024
2134
|
* @param reject 抛出错误
|
|
2025
|
-
* @param
|
|
2135
|
+
* @param argsResult 返回的参数列表
|
|
2026
2136
|
*/
|
|
2027
|
-
onTimeout(details, resolve, reject,
|
|
2137
|
+
onTimeout(details, resolve, reject, argsResult) {
|
|
2138
|
+
// console.log(argsResult);
|
|
2028
2139
|
if ("ontimeout" in details) {
|
|
2029
|
-
details.ontimeout.apply(this,
|
|
2140
|
+
details.ontimeout.apply(this, argsResult);
|
|
2030
2141
|
}
|
|
2031
2142
|
else if ("ontimeout" in this.context.#defaultDetails) {
|
|
2032
|
-
this.context.#defaultDetails.ontimeout.apply(this,
|
|
2143
|
+
this.context.#defaultDetails.ontimeout.apply(this, argsResult);
|
|
2144
|
+
}
|
|
2145
|
+
let response = argsResult;
|
|
2146
|
+
if (response.length) {
|
|
2147
|
+
response = response[0];
|
|
2033
2148
|
}
|
|
2034
2149
|
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2035
2150
|
type: "ontimeout",
|
|
2036
2151
|
error: new TypeError("request timeout"),
|
|
2037
|
-
response: (
|
|
2152
|
+
response: (argsResult || [null])[0],
|
|
2038
2153
|
details: details,
|
|
2039
2154
|
}) == null) {
|
|
2040
2155
|
// reject(new TypeError("response is intercept with ontimeout"));
|
|
2041
2156
|
return;
|
|
2042
2157
|
}
|
|
2043
2158
|
resolve({
|
|
2044
|
-
|
|
2045
|
-
|
|
2159
|
+
data: response,
|
|
2160
|
+
details: details,
|
|
2046
2161
|
msg: "请求超时",
|
|
2162
|
+
status: false,
|
|
2163
|
+
statusCode: 0,
|
|
2047
2164
|
type: "ontimeout",
|
|
2048
2165
|
});
|
|
2049
2166
|
},
|
|
2050
2167
|
/**
|
|
2051
2168
|
* onloadstart请求开始-触发
|
|
2052
2169
|
* @param details 配置
|
|
2053
|
-
* @param
|
|
2170
|
+
* @param argsResult 返回的参数列表
|
|
2054
2171
|
*/
|
|
2055
|
-
onLoadStart(details,
|
|
2172
|
+
onLoadStart(details, argsResult) {
|
|
2173
|
+
// console.log(argsResult);
|
|
2056
2174
|
if ("onloadstart" in details) {
|
|
2057
|
-
details.onloadstart.apply(this,
|
|
2175
|
+
details.onloadstart.apply(this, argsResult);
|
|
2058
2176
|
}
|
|
2059
2177
|
else if ("onloadstart" in this.context.#defaultDetails) {
|
|
2060
|
-
this.context.#defaultDetails.onloadstart.apply(this,
|
|
2178
|
+
this.context.#defaultDetails.onloadstart.apply(this, argsResult);
|
|
2061
2179
|
}
|
|
2062
2180
|
},
|
|
2063
2181
|
/**
|
|
@@ -2065,11 +2183,12 @@ define((function () { 'use strict';
|
|
|
2065
2183
|
* @param details 请求的配置
|
|
2066
2184
|
* @param resolve 回调
|
|
2067
2185
|
* @param reject 抛出错误
|
|
2068
|
-
* @param
|
|
2186
|
+
* @param argsResult 返回的参数列表
|
|
2069
2187
|
*/
|
|
2070
|
-
onLoad(details, resolve, reject,
|
|
2188
|
+
onLoad(details, resolve, reject, argsResult) {
|
|
2189
|
+
// console.log(argsResult);
|
|
2071
2190
|
/* X浏览器会因为设置了responseType导致不返回responseText */
|
|
2072
|
-
let originResponse =
|
|
2191
|
+
let originResponse = argsResult[0];
|
|
2073
2192
|
/* responseText为空,response不为空的情况 */
|
|
2074
2193
|
if (utils.isNull(originResponse["responseText"]) &&
|
|
2075
2194
|
utils.isNotNull(originResponse["response"])) {
|
|
@@ -2142,41 +2261,44 @@ define((function () { 'use strict';
|
|
|
2142
2261
|
return;
|
|
2143
2262
|
}
|
|
2144
2263
|
resolve({
|
|
2145
|
-
status: true,
|
|
2146
2264
|
data: originResponse,
|
|
2147
2265
|
details: details,
|
|
2148
|
-
msg: "
|
|
2266
|
+
msg: "请求成功",
|
|
2267
|
+
status: true,
|
|
2268
|
+
statusCode: originResponse.status,
|
|
2149
2269
|
type: "onload",
|
|
2150
2270
|
});
|
|
2151
2271
|
}
|
|
2152
2272
|
else {
|
|
2153
|
-
this.context.HttpxCallBack.onError(details, resolve, reject,
|
|
2273
|
+
this.context.HttpxCallBack.onError(details, resolve, reject, argsResult);
|
|
2154
2274
|
}
|
|
2155
2275
|
},
|
|
2156
2276
|
/**
|
|
2157
2277
|
* onprogress上传进度-触发
|
|
2158
2278
|
* @param details 配置
|
|
2159
|
-
* @param
|
|
2279
|
+
* @param argsResult 返回的参数列表
|
|
2160
2280
|
*/
|
|
2161
|
-
onProgress(details,
|
|
2281
|
+
onProgress(details, argsResult) {
|
|
2282
|
+
// console.log(argsResult);
|
|
2162
2283
|
if ("onprogress" in details) {
|
|
2163
|
-
details.onprogress.apply(this,
|
|
2284
|
+
details.onprogress.apply(this, argsResult);
|
|
2164
2285
|
}
|
|
2165
2286
|
else if ("onprogress" in this.context.#defaultDetails) {
|
|
2166
|
-
this.context.#defaultDetails.onprogress.apply(this,
|
|
2287
|
+
this.context.#defaultDetails.onprogress.apply(this, argsResult);
|
|
2167
2288
|
}
|
|
2168
2289
|
},
|
|
2169
2290
|
/**
|
|
2170
2291
|
* onreadystatechange准备状态改变-触发
|
|
2171
2292
|
* @param details 配置
|
|
2172
|
-
* @param
|
|
2293
|
+
* @param argsResult 返回的参数列表
|
|
2173
2294
|
*/
|
|
2174
|
-
onReadyStateChange(details,
|
|
2295
|
+
onReadyStateChange(details, argsResult) {
|
|
2296
|
+
// console.log(argsResult);
|
|
2175
2297
|
if ("onreadystatechange" in details) {
|
|
2176
|
-
details.onreadystatechange.apply(this,
|
|
2298
|
+
details.onreadystatechange.apply(this, argsResult);
|
|
2177
2299
|
}
|
|
2178
2300
|
else if ("onreadystatechange" in this.context.#defaultDetails) {
|
|
2179
|
-
this.context.#defaultDetails.onreadystatechange.apply(this,
|
|
2301
|
+
this.context.#defaultDetails.onreadystatechange.apply(this, argsResult);
|
|
2180
2302
|
}
|
|
2181
2303
|
},
|
|
2182
2304
|
};
|
|
@@ -2198,11 +2320,12 @@ define((function () { 'use strict';
|
|
|
2198
2320
|
}
|
|
2199
2321
|
}
|
|
2200
2322
|
if (details.fetch) {
|
|
2201
|
-
|
|
2202
|
-
|
|
2323
|
+
// 使用fetch请求
|
|
2324
|
+
const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.HttpxRequestDetails.handleFetchOption(details);
|
|
2325
|
+
return this.fetch(fetchOption, fetchRequestOption, abortController);
|
|
2203
2326
|
}
|
|
2204
2327
|
else {
|
|
2205
|
-
|
|
2328
|
+
// 使用GM_xmlHttpRequest请求
|
|
2206
2329
|
return this.xmlHttpRequest(details);
|
|
2207
2330
|
}
|
|
2208
2331
|
},
|
|
@@ -2215,12 +2338,12 @@ define((function () { 'use strict';
|
|
|
2215
2338
|
},
|
|
2216
2339
|
/**
|
|
2217
2340
|
* 使用fetch发送请求
|
|
2218
|
-
* @param
|
|
2219
|
-
* @param
|
|
2341
|
+
* @param option
|
|
2342
|
+
* @param fetchRequestOption
|
|
2220
2343
|
* @param abortController
|
|
2221
2344
|
*/
|
|
2222
|
-
fetch(
|
|
2223
|
-
fetch(
|
|
2345
|
+
fetch(option, fetchRequestOption, abortController) {
|
|
2346
|
+
fetch(option.url, fetchRequestOption)
|
|
2224
2347
|
.then(async (fetchResponse) => {
|
|
2225
2348
|
/** 自定义的response */
|
|
2226
2349
|
let httpxResponse = {
|
|
@@ -2230,15 +2353,16 @@ define((function () { 'use strict';
|
|
|
2230
2353
|
// @ts-ignore
|
|
2231
2354
|
status: fetchResponse.status,
|
|
2232
2355
|
statusText: fetchResponse.statusText,
|
|
2356
|
+
// @ts-ignore
|
|
2233
2357
|
response: void 0,
|
|
2234
2358
|
responseFetchHeaders: fetchResponse.headers,
|
|
2235
2359
|
responseHeaders: "",
|
|
2236
2360
|
// @ts-ignore
|
|
2237
2361
|
responseText: void 0,
|
|
2238
|
-
responseType:
|
|
2362
|
+
responseType: option.responseType,
|
|
2239
2363
|
responseXML: void 0,
|
|
2240
2364
|
};
|
|
2241
|
-
Object.assign(httpxResponse,
|
|
2365
|
+
Object.assign(httpxResponse, option.context || {});
|
|
2242
2366
|
// 把headers转为字符串
|
|
2243
2367
|
for (const [key, value] of fetchResponse.headers.entries()) {
|
|
2244
2368
|
httpxResponse.responseHeaders += `${key}: ${value}\n`;
|
|
@@ -2246,7 +2370,7 @@ define((function () { 'use strict';
|
|
|
2246
2370
|
/** 请求返回的类型 */
|
|
2247
2371
|
const fetchResponseType = fetchResponse.headers.get("Content-Type");
|
|
2248
2372
|
/* 如果需要stream,且获取到的是stream,那直接返回 */
|
|
2249
|
-
if (
|
|
2373
|
+
if (option.responseType === "stream" ||
|
|
2250
2374
|
(fetchResponse.headers.has("Content-Type") &&
|
|
2251
2375
|
fetchResponse.headers
|
|
2252
2376
|
.get("Content-Type")
|
|
@@ -2255,7 +2379,7 @@ define((function () { 'use strict';
|
|
|
2255
2379
|
Reflect.set(httpxResponse, "response", fetchResponse.body);
|
|
2256
2380
|
Reflect.deleteProperty(httpxResponse, "responseText");
|
|
2257
2381
|
Reflect.deleteProperty(httpxResponse, "responseXML");
|
|
2258
|
-
|
|
2382
|
+
option.onload(httpxResponse);
|
|
2259
2383
|
return;
|
|
2260
2384
|
}
|
|
2261
2385
|
/** 响应 */
|
|
@@ -2284,22 +2408,22 @@ define((function () { 'use strict';
|
|
|
2284
2408
|
let textDecoder = new TextDecoder(encoding);
|
|
2285
2409
|
responseText = textDecoder.decode(arrayBuffer);
|
|
2286
2410
|
response = responseText;
|
|
2287
|
-
if (
|
|
2411
|
+
if (option.responseType === "arraybuffer") {
|
|
2288
2412
|
// response返回格式是二进制流
|
|
2289
2413
|
response = arrayBuffer;
|
|
2290
2414
|
}
|
|
2291
|
-
else if (
|
|
2415
|
+
else if (option.responseType === "blob") {
|
|
2292
2416
|
// response返回格式是blob
|
|
2293
2417
|
response = new Blob([arrayBuffer]);
|
|
2294
2418
|
}
|
|
2295
|
-
else if (
|
|
2419
|
+
else if (option.responseType === "json" ||
|
|
2296
2420
|
(typeof fetchResponseType === "string" &&
|
|
2297
2421
|
fetchResponseType.includes("application/json"))) {
|
|
2298
2422
|
// response返回格式是JSON格式
|
|
2299
2423
|
response = utils.toJSON(responseText);
|
|
2300
2424
|
}
|
|
2301
|
-
else if (
|
|
2302
|
-
|
|
2425
|
+
else if (option.responseType === "document" ||
|
|
2426
|
+
option.responseType == null) {
|
|
2303
2427
|
// response返回格式是文档格式
|
|
2304
2428
|
let parser = new DOMParser();
|
|
2305
2429
|
response = parser.parseFromString(responseText, "text/html");
|
|
@@ -2311,15 +2435,15 @@ define((function () { 'use strict';
|
|
|
2311
2435
|
Reflect.set(httpxResponse, "responseText", responseText);
|
|
2312
2436
|
Reflect.set(httpxResponse, "responseXML", responseXML);
|
|
2313
2437
|
// 执行回调
|
|
2314
|
-
|
|
2438
|
+
option.onload(httpxResponse);
|
|
2315
2439
|
})
|
|
2316
2440
|
.catch((error) => {
|
|
2317
2441
|
if (error.name === "AbortError") {
|
|
2318
2442
|
return;
|
|
2319
2443
|
}
|
|
2320
|
-
|
|
2444
|
+
option.onerror({
|
|
2321
2445
|
isFetch: true,
|
|
2322
|
-
finalUrl:
|
|
2446
|
+
finalUrl: option.url,
|
|
2323
2447
|
readyState: 4,
|
|
2324
2448
|
status: 0,
|
|
2325
2449
|
statusText: "",
|
|
@@ -2328,9 +2452,9 @@ define((function () { 'use strict';
|
|
|
2328
2452
|
error: error,
|
|
2329
2453
|
});
|
|
2330
2454
|
});
|
|
2331
|
-
|
|
2455
|
+
option.onloadstart({
|
|
2332
2456
|
isFetch: true,
|
|
2333
|
-
finalUrl:
|
|
2457
|
+
finalUrl: option.url,
|
|
2334
2458
|
readyState: 1,
|
|
2335
2459
|
responseHeaders: "",
|
|
2336
2460
|
responseText: "",
|
|
@@ -2385,15 +2509,15 @@ define((function () { 'use strict';
|
|
|
2385
2509
|
#LOG_DETAILS = false;
|
|
2386
2510
|
/**
|
|
2387
2511
|
* 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
|
|
2388
|
-
* @param
|
|
2512
|
+
* @param xmlHttpRequest
|
|
2389
2513
|
*/
|
|
2390
|
-
constructor(
|
|
2391
|
-
if (typeof
|
|
2514
|
+
constructor(xmlHttpRequest) {
|
|
2515
|
+
if (typeof xmlHttpRequest !== "function") {
|
|
2392
2516
|
console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
|
|
2393
2517
|
}
|
|
2394
2518
|
this.interceptors.request.context = this;
|
|
2395
2519
|
this.interceptors.response.context = this;
|
|
2396
|
-
this.GM_Api.xmlHttpRequest =
|
|
2520
|
+
this.GM_Api.xmlHttpRequest = xmlHttpRequest;
|
|
2397
2521
|
}
|
|
2398
2522
|
/**
|
|
2399
2523
|
* 覆盖当前配置
|
|
@@ -2487,28 +2611,24 @@ define((function () { 'use strict';
|
|
|
2487
2611
|
*/
|
|
2488
2612
|
async get(...args // @ts-ignore
|
|
2489
2613
|
) {
|
|
2490
|
-
let
|
|
2614
|
+
let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
|
|
2491
2615
|
let abortFn = null;
|
|
2492
|
-
|
|
2493
|
-
let
|
|
2494
|
-
Reflect.deleteProperty(
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
const requestResult = this.HttpxRequest.request(requestDetails);
|
|
2616
|
+
let promise = new globalThis.Promise((resolve, reject) => {
|
|
2617
|
+
let requestOption = this.HttpxRequestDetails.getRequestOption("GET", userRequestOption, resolve, reject);
|
|
2618
|
+
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2619
|
+
this.HttpxRequestDetails.removeRequestNullOption(requestOption);
|
|
2620
|
+
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2498
2621
|
if (requestResult != null &&
|
|
2499
2622
|
typeof requestResult.abort === "function") {
|
|
2500
2623
|
abortFn = requestResult.abort;
|
|
2501
2624
|
}
|
|
2502
2625
|
});
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
};
|
|
2510
|
-
},
|
|
2511
|
-
});
|
|
2626
|
+
// @ts-ignore
|
|
2627
|
+
promise.abort = () => {
|
|
2628
|
+
if (typeof abortFn === "function") {
|
|
2629
|
+
abortFn();
|
|
2630
|
+
}
|
|
2631
|
+
};
|
|
2512
2632
|
return promise;
|
|
2513
2633
|
}
|
|
2514
2634
|
/**
|
|
@@ -2516,27 +2636,25 @@ define((function () { 'use strict';
|
|
|
2516
2636
|
*/
|
|
2517
2637
|
async post(...args // @ts-ignore
|
|
2518
2638
|
) {
|
|
2519
|
-
let
|
|
2639
|
+
let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
|
|
2520
2640
|
let abortFn = null;
|
|
2521
|
-
|
|
2522
|
-
let
|
|
2641
|
+
let promise = new Promise((resolve, reject) => {
|
|
2642
|
+
let requestOption = this.HttpxRequestDetails.getRequestOption("POST", userRequestOption, resolve, reject);
|
|
2523
2643
|
// @ts-ignore
|
|
2524
|
-
|
|
2525
|
-
|
|
2644
|
+
requestOption =
|
|
2645
|
+
this.HttpxRequestDetails.removeRequestNullOption(requestOption);
|
|
2646
|
+
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2526
2647
|
if (requestResult != null &&
|
|
2527
2648
|
typeof requestResult.abort === "function") {
|
|
2528
2649
|
abortFn = requestResult.abort;
|
|
2529
2650
|
}
|
|
2530
2651
|
});
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
};
|
|
2538
|
-
},
|
|
2539
|
-
});
|
|
2652
|
+
// @ts-ignore
|
|
2653
|
+
promise.abort = () => {
|
|
2654
|
+
if (typeof abortFn === "function") {
|
|
2655
|
+
abortFn();
|
|
2656
|
+
}
|
|
2657
|
+
};
|
|
2540
2658
|
return promise;
|
|
2541
2659
|
}
|
|
2542
2660
|
/**
|
|
@@ -2544,28 +2662,26 @@ define((function () { 'use strict';
|
|
|
2544
2662
|
*/
|
|
2545
2663
|
async head(...args // @ts-ignore
|
|
2546
2664
|
) {
|
|
2547
|
-
let
|
|
2665
|
+
let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
|
|
2548
2666
|
let abortFn = null;
|
|
2549
|
-
|
|
2550
|
-
let
|
|
2551
|
-
Reflect.deleteProperty(
|
|
2667
|
+
let promise = new Promise((resolve, reject) => {
|
|
2668
|
+
let requestOption = this.HttpxRequestDetails.getRequestOption("HEAD", userRequestOption, resolve, reject);
|
|
2669
|
+
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2552
2670
|
// @ts-ignore
|
|
2553
|
-
|
|
2554
|
-
|
|
2671
|
+
requestOption =
|
|
2672
|
+
this.HttpxRequestDetails.removeRequestNullOption(requestOption);
|
|
2673
|
+
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2555
2674
|
if (requestResult != null &&
|
|
2556
2675
|
typeof requestResult.abort === "function") {
|
|
2557
2676
|
abortFn = requestResult.abort;
|
|
2558
2677
|
}
|
|
2559
2678
|
});
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
};
|
|
2567
|
-
},
|
|
2568
|
-
});
|
|
2679
|
+
// @ts-ignore
|
|
2680
|
+
promise.abort = () => {
|
|
2681
|
+
if (typeof abortFn === "function") {
|
|
2682
|
+
abortFn();
|
|
2683
|
+
}
|
|
2684
|
+
};
|
|
2569
2685
|
return promise;
|
|
2570
2686
|
}
|
|
2571
2687
|
/**
|
|
@@ -2573,28 +2689,26 @@ define((function () { 'use strict';
|
|
|
2573
2689
|
*/
|
|
2574
2690
|
async options(...args // @ts-ignore
|
|
2575
2691
|
) {
|
|
2576
|
-
let
|
|
2692
|
+
let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
|
|
2577
2693
|
let abortFn = null;
|
|
2578
|
-
|
|
2579
|
-
let
|
|
2580
|
-
Reflect.deleteProperty(
|
|
2694
|
+
let promise = new Promise((resolve, reject) => {
|
|
2695
|
+
let requestOption = this.HttpxRequestDetails.getRequestOption("OPTIONS", userRequestOption, resolve, reject);
|
|
2696
|
+
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2581
2697
|
// @ts-ignore
|
|
2582
|
-
|
|
2583
|
-
|
|
2698
|
+
requestOption =
|
|
2699
|
+
this.HttpxRequestDetails.removeRequestNullOption(requestOption);
|
|
2700
|
+
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2584
2701
|
if (requestResult != null &&
|
|
2585
2702
|
typeof requestResult.abort === "function") {
|
|
2586
2703
|
abortFn = requestResult.abort;
|
|
2587
2704
|
}
|
|
2588
2705
|
});
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
};
|
|
2596
|
-
},
|
|
2597
|
-
});
|
|
2706
|
+
// @ts-ignore
|
|
2707
|
+
promise.abort = () => {
|
|
2708
|
+
if (typeof abortFn === "function") {
|
|
2709
|
+
abortFn();
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2598
2712
|
return promise;
|
|
2599
2713
|
}
|
|
2600
2714
|
/**
|
|
@@ -2602,28 +2716,26 @@ define((function () { 'use strict';
|
|
|
2602
2716
|
*/
|
|
2603
2717
|
async delete(...args // @ts-ignore
|
|
2604
2718
|
) {
|
|
2605
|
-
let
|
|
2719
|
+
let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
|
|
2606
2720
|
let abortFn = null;
|
|
2607
|
-
|
|
2608
|
-
let
|
|
2609
|
-
Reflect.deleteProperty(
|
|
2721
|
+
let promise = new Promise((resolve, reject) => {
|
|
2722
|
+
let requestOption = this.HttpxRequestDetails.getRequestOption("DELETE", userRequestOption, resolve, reject);
|
|
2723
|
+
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2610
2724
|
// @ts-ignore
|
|
2611
|
-
|
|
2612
|
-
|
|
2725
|
+
requestOption =
|
|
2726
|
+
this.HttpxRequestDetails.removeRequestNullOption(requestOption);
|
|
2727
|
+
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2613
2728
|
if (requestResult != null &&
|
|
2614
2729
|
typeof requestResult.abort === "function") {
|
|
2615
2730
|
abortFn = requestResult.abort;
|
|
2616
2731
|
}
|
|
2617
2732
|
});
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
};
|
|
2625
|
-
},
|
|
2626
|
-
});
|
|
2733
|
+
// @ts-ignore
|
|
2734
|
+
promise.abort = () => {
|
|
2735
|
+
if (typeof abortFn === "function") {
|
|
2736
|
+
abortFn();
|
|
2737
|
+
}
|
|
2738
|
+
};
|
|
2627
2739
|
return promise;
|
|
2628
2740
|
}
|
|
2629
2741
|
/**
|
|
@@ -2631,27 +2743,25 @@ define((function () { 'use strict';
|
|
|
2631
2743
|
*/
|
|
2632
2744
|
async put(...args // @ts-ignore
|
|
2633
2745
|
) {
|
|
2634
|
-
let
|
|
2746
|
+
let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
|
|
2635
2747
|
let abortFn = null;
|
|
2636
|
-
|
|
2637
|
-
let
|
|
2748
|
+
let promise = new Promise((resolve, reject) => {
|
|
2749
|
+
let requestOption = this.HttpxRequestDetails.getRequestOption("PUT", userRequestOption, resolve, reject);
|
|
2638
2750
|
// @ts-ignore
|
|
2639
|
-
|
|
2640
|
-
|
|
2751
|
+
requestOption =
|
|
2752
|
+
this.HttpxRequestDetails.removeRequestNullOption(requestOption);
|
|
2753
|
+
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2641
2754
|
if (requestResult != null &&
|
|
2642
2755
|
typeof requestResult.abort === "function") {
|
|
2643
2756
|
abortFn = requestResult.abort;
|
|
2644
2757
|
}
|
|
2645
2758
|
});
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
};
|
|
2653
|
-
},
|
|
2654
|
-
});
|
|
2759
|
+
// @ts-ignore
|
|
2760
|
+
promise.abort = () => {
|
|
2761
|
+
if (typeof abortFn === "function") {
|
|
2762
|
+
abortFn();
|
|
2763
|
+
}
|
|
2764
|
+
};
|
|
2655
2765
|
return promise;
|
|
2656
2766
|
}
|
|
2657
2767
|
}
|
|
@@ -3956,7 +4066,7 @@ define((function () { 'use strict';
|
|
|
3956
4066
|
this.windowApi = new WindowApi(option);
|
|
3957
4067
|
}
|
|
3958
4068
|
/** 版本号 */
|
|
3959
|
-
version = "2024.10.
|
|
4069
|
+
version = "2024.10.28";
|
|
3960
4070
|
addStyle(cssText) {
|
|
3961
4071
|
if (typeof cssText !== "string") {
|
|
3962
4072
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -6187,7 +6297,8 @@ define((function () { 'use strict';
|
|
|
6187
6297
|
dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
|
|
6188
6298
|
let UtilsContext = this;
|
|
6189
6299
|
function initMouseEvent(eventName, offSetX, offSetY) {
|
|
6190
|
-
|
|
6300
|
+
// @ts-ignore
|
|
6301
|
+
let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
6191
6302
|
let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
6192
6303
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
6193
6304
|
return mouseEvent;
|