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