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