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