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