@whitesev/utils 2.3.7 → 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.
Files changed (57) hide show
  1. package/dist/index.amd.js +415 -289
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +415 -289
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +415 -289
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +415 -289
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +415 -289
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +415 -289
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Httpx.d.ts +25 -1178
  14. package/dist/types/src/Log.d.ts +1 -19
  15. package/dist/types/src/Progress.d.ts +1 -20
  16. package/dist/types/src/TryCatch.d.ts +2 -11
  17. package/dist/types/src/Utils.d.ts +8 -32
  18. package/dist/types/src/UtilsGMCookie.d.ts +1 -51
  19. package/dist/types/src/UtilsGMMenu.d.ts +1 -50
  20. package/dist/types/src/WindowApi.d.ts +3 -11
  21. package/dist/types/src/types/Httpx.d.ts +1316 -0
  22. package/dist/types/src/types/Log.d.ts +19 -0
  23. package/dist/types/src/types/Progress.d.ts +20 -0
  24. package/dist/types/src/types/TryCatch.d.ts +9 -0
  25. package/dist/types/src/types/UtilsGMCookie.d.ts +55 -0
  26. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -0
  27. package/{src/VueObject.ts → dist/types/src/types/Vue2.d.ts} +28 -15
  28. package/dist/types/src/types/Vue3.d.ts +0 -0
  29. package/dist/types/src/types/WindowApi.d.ts +10 -0
  30. package/dist/types/src/types/global.d.ts +24 -1
  31. package/package.json +1 -1
  32. package/src/GBKEncoder.ts +1 -1
  33. package/src/Httpx.ts +535 -1627
  34. package/src/Log.ts +1 -19
  35. package/src/Progress.ts +1 -20
  36. package/src/TryCatch.ts +2 -12
  37. package/src/Utils.ts +44 -66
  38. package/src/UtilsGMCookie.ts +7 -56
  39. package/src/UtilsGMMenu.ts +5 -78
  40. package/src/WindowApi.ts +4 -11
  41. package/src/indexedDB.ts +12 -10
  42. package/src/types/Event.d.ts +189 -0
  43. package/src/types/Httpx.d.ts +1316 -0
  44. package/src/types/Log.d.ts +19 -0
  45. package/src/types/Progress.d.ts +20 -0
  46. package/src/types/TryCatch.d.ts +9 -0
  47. package/src/types/UtilsGMCookie.d.ts +55 -0
  48. package/src/types/UtilsGMMenu.d.ts +77 -0
  49. package/src/types/Vue2.d.ts +154 -0
  50. package/src/types/Vue3.d.ts +0 -0
  51. package/src/types/WindowApi.d.ts +10 -0
  52. package/{dist/types/src/AjaxHookerType.d.ts → src/types/ajaxHooker.d.ts} +155 -147
  53. package/src/types/global.d.ts +24 -1
  54. package/dist/types/src/Event.d.ts +0 -156
  55. package/dist/types/src/VueObject.d.ts +0 -123
  56. /package/{src/Event.ts → dist/types/src/types/Event.d.ts} +0 -0
  57. /package/{src/AjaxHookerType.ts → dist/types/src/types/ajaxHooker.d.ts} +0 -0
@@ -1720,55 +1720,57 @@ System.register('Utils', [], (function (exports) {
1720
1720
  /**
1721
1721
  * 根据传入的参数处理获取details配置
1722
1722
  */
1723
- handleBeforeRequestDetails(...args) {
1724
- let result = {};
1723
+ handleBeforeRequestOption(...args) {
1724
+ let option = {};
1725
1725
  if (typeof args[0] === "string") {
1726
1726
  /* 传入的是url,details? */
1727
1727
  let url = args[0];
1728
- result.url = url;
1728
+ option.url = url;
1729
1729
  if (typeof args[1] === "object") {
1730
1730
  /* 处理第二个参数details */
1731
1731
  let details = args[1];
1732
- result = details;
1733
- result.url = url;
1732
+ option = details;
1733
+ option.url = url;
1734
1734
  }
1735
1735
  }
1736
1736
  else {
1737
1737
  /* 传入的是details */
1738
- result = args[0];
1738
+ option = args[0];
1739
1739
  }
1740
- return result;
1740
+ return option;
1741
1741
  },
1742
1742
  /**
1743
1743
  * 获取请求配置
1744
1744
  * @param method 当前请求方法,默认get
1745
- * @param details 请求配置
1745
+ * @param userRequestOption 用户的请求配置
1746
1746
  * @param resolve promise回调
1747
1747
  * @param reject 抛出错误回调
1748
1748
  */
1749
- getDetails(method, details, resolve, reject) {
1749
+ getRequestOption(method, userRequestOption, resolve, reject) {
1750
1750
  let that = this;
1751
- let result = {
1752
- url: details.url || this.context.#defaultDetails.url,
1751
+ let requestOption = {
1752
+ url: userRequestOption.url || this.context.#defaultDetails.url,
1753
1753
  method: (method || "GET").toString().toUpperCase(),
1754
- timeout: details.timeout || this.context.#defaultDetails.timeout,
1755
- responseType: details.responseType || this.context.#defaultDetails.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: details.data || this.context.#defaultDetails.data,
1759
- redirect: details.redirect || this.context.#defaultDetails.redirect,
1760
- cookie: details.cookie || this.context.#defaultDetails.cookie,
1761
- cookiePartition: details.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: details.binary || this.context.#defaultDetails.binary,
1764
- nocache: details.nocache || this.context.#defaultDetails.nocache,
1765
- revalidate: details.revalidate || this.context.#defaultDetails.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(details.context || this.context.#defaultDetails.context),
1768
- overrideMimeType: details.overrideMimeType ||
1769
+ context: utils.deepClone(userRequestOption.context || this.context.#defaultDetails.context),
1770
+ overrideMimeType: userRequestOption.overrideMimeType ||
1769
1771
  this.context.#defaultDetails.overrideMimeType,
1770
- anonymous: details.anonymous || this.context.#defaultDetails.anonymous,
1771
- fetch: details.fetch || this.context.#defaultDetails.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: details.user || this.context.#defaultDetails.user,
1783
- password: details.password || this.context.#defaultDetails.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(details, resolve, reject, args);
1787
+ that.context.HttpxCallBack.onAbort(userRequestOption, resolve, reject, args);
1786
1788
  },
1787
1789
  onerror(...args) {
1788
- that.context.HttpxCallBack.onError(details, resolve, reject, args);
1790
+ that.context.HttpxCallBack.onError(userRequestOption, resolve, reject, args);
1789
1791
  },
1790
1792
  onloadstart(...args) {
1791
- that.context.HttpxCallBack.onLoadStart(details, args);
1793
+ that.context.HttpxCallBack.onLoadStart(userRequestOption, args);
1792
1794
  },
1793
1795
  onprogress(...args) {
1794
- that.context.HttpxCallBack.onProgress(details, args);
1796
+ that.context.HttpxCallBack.onProgress(userRequestOption, args);
1795
1797
  },
1796
1798
  onreadystatechange(...args) {
1797
- that.context.HttpxCallBack.onReadyStateChange(details, args);
1799
+ that.context.HttpxCallBack.onReadyStateChange(userRequestOption, args);
1798
1800
  },
1799
1801
  ontimeout(...args) {
1800
- that.context.HttpxCallBack.onTimeout(details, resolve, reject, args);
1802
+ that.context.HttpxCallBack.onTimeout(userRequestOption, resolve, reject, args);
1801
1803
  },
1802
1804
  onload(...args) {
1803
- that.context.HttpxCallBack.onLoad(details, resolve, reject, args);
1805
+ that.context.HttpxCallBack.onLoad(userRequestOption, resolve, reject, args);
1804
1806
  },
1805
1807
  };
1806
1808
  // 补全allowInterceptConfig参数
1807
- if (typeof details.allowInterceptConfig === "boolean") {
1808
- Object.keys(result.allowInterceptConfig).forEach((keyName) => {
1809
- result.allowInterceptConfig[keyName] =
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 details.allowInterceptConfig === "object" &&
1815
- details.allowInterceptConfig != null) {
1816
- Object.keys(details.allowInterceptConfig).forEach((keyName) => {
1817
- let value = details.allowInterceptConfig[keyName];
1818
- if (keyName in
1819
- result.allowInterceptConfig &&
1820
- typeof value === "boolean") {
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
- result.fetch = true;
1828
- }
1829
- if (typeof result.headers === "object") {
1830
- if (typeof details.headers === "object") {
1831
- Object.keys(details.headers).forEach((keyName, index) => {
1832
- if (keyName in result.headers &&
1833
- details.headers?.[keyName] == null) {
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(result.headers, keyName);
1836
+ Reflect.deleteProperty(requestOption.headers, keyName);
1836
1837
  }
1837
1838
  else {
1838
- result.headers[keyName] = details?.headers?.[keyName];
1839
+ requestOption.headers[keyName] =
1840
+ userRequestOption?.headers?.[keyName];
1839
1841
  }
1840
1842
  });
1841
1843
  }
1842
1844
  }
1843
1845
  else {
1844
- result.headers = details.headers;
1846
+ /* 默认的headers不是对象,那么就直接使用新的 */
1847
+ Reflect.set(requestOption, "headers", userRequestOption.headers);
1845
1848
  }
1846
- if (typeof result.fetchInit === "object") {
1849
+ if (typeof requestOption.fetchInit === "object") {
1847
1850
  /* 使用assign替换且添加 */
1848
- if (typeof details.fetchInit === "object") {
1849
- Object.keys(details.fetchInit).forEach((keyName, index) => {
1850
- if (keyName in result.fetchInit &&
1851
- details.fetchInit[keyName] == null) {
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(result.fetchInit, keyName);
1856
+ Reflect.deleteProperty(requestOption.fetchInit, keyName);
1854
1857
  }
1855
1858
  else {
1856
- result.fetchInit[keyName] = details.fetchInit[keyName];
1859
+ Reflect.set(requestOption.fetchInit, keyName, Reflect.get(userRequestOption.fetchInit, keyName));
1857
1860
  }
1858
1861
  });
1859
1862
  }
1860
1863
  }
1861
1864
  else {
1862
- result.fetchInit = details.fetchInit;
1865
+ Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
1863
1866
  }
1864
1867
  // 处理新的cookiePartition
1865
- if (typeof result.cookiePartition === "object" &&
1866
- result.cookiePartition != null) {
1867
- if (Reflect.has(result.cookiePartition, "topLevelSite") &&
1868
- typeof result.cookiePartition.topLevelSite !== "string") {
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(result.cookiePartition, "topLevelSite");
1873
+ Reflect.deleteProperty(requestOption.cookiePartition, "topLevelSite");
1871
1874
  }
1872
1875
  }
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;
1886
- }
1887
- });
1888
- if (utils.isNull(details.url)) {
1889
- throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${details.url}`);
1890
- }
1891
- /* method值统一大写,兼容Via */
1892
- details.method = details.method.toUpperCase();
1893
- /* 判断是否是以http开头,否则主动加上origin */
1876
+ /* 完善请求的url */
1894
1877
  try {
1895
- new URL(details.url);
1878
+ new URL(requestOption.url);
1896
1879
  }
1897
1880
  catch (error) {
1898
- if (details.url.startsWith("//")) {
1899
- details.url = window.location.protocol + details.url;
1881
+ if (requestOption.url.startsWith("//")) {
1882
+ // 补充https:
1883
+ requestOption.url = globalThis.location.protocol + requestOption.url;
1900
1884
  }
1901
- else if (details.url.startsWith("/")) {
1902
- details.url = window.location.origin + details.url;
1885
+ else if (requestOption.url.startsWith("/")) {
1886
+ // 补充origin
1887
+ requestOption.url = globalThis.location.origin + requestOption.url;
1903
1888
  }
1904
1889
  else {
1905
- details.url = window.location.origin + "/" + details.url;
1890
+ // 补充origin+/
1891
+ requestOption.url =
1892
+ globalThis.location.origin + "/" + requestOption.url;
1906
1893
  }
1907
1894
  }
1908
- return details;
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 details
2004
+ * @param option
1913
2005
  */
1914
- handleFetchDetail(details) {
2006
+ handleFetchOption(option) {
1915
2007
  /**
1916
2008
  * fetch的请求配置
1917
2009
  **/
1918
- let fetchRequestInit = {};
1919
- if ((details.method === "GET" || details.method === "HEAD") &&
1920
- details.data != null) {
2010
+ let fetchRequestOption = {};
2011
+ if ((option.method === "GET" || option.method === "HEAD") &&
2012
+ option.data != null) {
1921
2013
  /* GET 或 HEAD 方法的请求不能包含 body 信息 */
1922
- Reflect.deleteProperty(details, "data");
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
- details.onabort({
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
- fetchRequestInit.method = details.method ?? "GET";
1940
- fetchRequestInit.headers = details.headers;
1941
- fetchRequestInit.body = details.data;
1942
- fetchRequestInit.mode = "cors";
1943
- fetchRequestInit.credentials = "include";
1944
- fetchRequestInit.cache = "no-cache";
1945
- fetchRequestInit.redirect = "follow";
1946
- fetchRequestInit.referrerPolicy = "origin-when-cross-origin";
1947
- fetchRequestInit.signal = signal;
1948
- Object.assign(fetchRequestInit, details.fetchInit || {});
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
- fetchDetails: details,
1951
- fetchRequestInit: fetchRequestInit,
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 argumentsList 参数列表
2064
+ * @param argsResult 返回的参数列表
1964
2065
  */
1965
- onAbort(details, resolve, reject, argumentsList) {
2066
+ onAbort(details, resolve, reject, argsResult) {
2067
+ // console.log(argsResult);
1966
2068
  if ("onabort" in details) {
1967
- details.onabort.apply(this, argumentsList);
2069
+ details.onabort.apply(this, argsResult);
1968
2070
  }
1969
2071
  else if ("onabort" in this.context.#defaultDetails) {
1970
- this.context.#defaultDetails.onabort.apply(this, argumentsList);
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
- status: false,
1983
- data: [...argumentsList],
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 argumentsList 响应的参数列表
2101
+ * @param argsResult 返回的参数列表
1994
2102
  */
1995
- onError(details, resolve, reject, argumentsList) {
2103
+ onError(details, resolve, reject, argsResult) {
2104
+ // console.log(argsResult);
1996
2105
  if ("onerror" in details) {
1997
- details.onerror.apply(this, argumentsList);
2106
+ details.onerror.apply(this, argsResult);
1998
2107
  }
1999
2108
  else if ("onerror" in this.context.#defaultDetails) {
2000
- this.context.#defaultDetails.onerror.apply(this, argumentsList);
2109
+ this.context.#defaultDetails.onerror.apply(this, argsResult);
2001
2110
  }
2002
- let response = argumentsList;
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 argumentsList 参数列表
2138
+ * @param argsResult 返回的参数列表
2029
2139
  */
2030
- onTimeout(details, resolve, reject, argumentsList) {
2140
+ onTimeout(details, resolve, reject, argsResult) {
2141
+ // console.log(argsResult);
2031
2142
  if ("ontimeout" in details) {
2032
- details.ontimeout.apply(this, argumentsList);
2143
+ details.ontimeout.apply(this, argsResult);
2033
2144
  }
2034
2145
  else if ("ontimeout" in this.context.#defaultDetails) {
2035
- this.context.#defaultDetails.ontimeout.apply(this, argumentsList);
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: (argumentsList || [null])[0],
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
- status: false,
2048
- data: [...argumentsList],
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 argumentsList 参数列表
2173
+ * @param argsResult 返回的参数列表
2057
2174
  */
2058
- onLoadStart(details, argumentsList) {
2175
+ onLoadStart(details, argsResult) {
2176
+ // console.log(argsResult);
2059
2177
  if ("onloadstart" in details) {
2060
- details.onloadstart.apply(this, argumentsList);
2178
+ details.onloadstart.apply(this, argsResult);
2061
2179
  }
2062
2180
  else if ("onloadstart" in this.context.#defaultDetails) {
2063
- this.context.#defaultDetails.onloadstart.apply(this, argumentsList);
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 argumentsList 参数列表
2189
+ * @param argsResult 返回的参数列表
2072
2190
  */
2073
- onLoad(details, resolve, reject, argumentsList) {
2191
+ onLoad(details, resolve, reject, argsResult) {
2192
+ // console.log(argsResult);
2074
2193
  /* X浏览器会因为设置了responseType导致不返回responseText */
2075
- let originResponse = argumentsList[0];
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, argumentsList);
2276
+ this.context.HttpxCallBack.onError(details, resolve, reject, argsResult);
2157
2277
  }
2158
2278
  },
2159
2279
  /**
2160
2280
  * onprogress上传进度-触发
2161
2281
  * @param details 配置
2162
- * @param argumentsList 参数列表
2282
+ * @param argsResult 返回的参数列表
2163
2283
  */
2164
- onProgress(details, argumentsList) {
2284
+ onProgress(details, argsResult) {
2285
+ // console.log(argsResult);
2165
2286
  if ("onprogress" in details) {
2166
- details.onprogress.apply(this, argumentsList);
2287
+ details.onprogress.apply(this, argsResult);
2167
2288
  }
2168
2289
  else if ("onprogress" in this.context.#defaultDetails) {
2169
- this.context.#defaultDetails.onprogress.apply(this, argumentsList);
2290
+ this.context.#defaultDetails.onprogress.apply(this, argsResult);
2170
2291
  }
2171
2292
  },
2172
2293
  /**
2173
2294
  * onreadystatechange准备状态改变-触发
2174
2295
  * @param details 配置
2175
- * @param argumentsList 参数列表
2296
+ * @param argsResult 返回的参数列表
2176
2297
  */
2177
- onReadyStateChange(details, argumentsList) {
2298
+ onReadyStateChange(details, argsResult) {
2299
+ // console.log(argsResult);
2178
2300
  if ("onreadystatechange" in details) {
2179
- details.onreadystatechange.apply(this, argumentsList);
2301
+ details.onreadystatechange.apply(this, argsResult);
2180
2302
  }
2181
2303
  else if ("onreadystatechange" in this.context.#defaultDetails) {
2182
- this.context.#defaultDetails.onreadystatechange.apply(this, argumentsList);
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
- const { fetchDetails, fetchRequestInit, abortController } = this.context.HttpxRequestDetails.handleFetchDetail(details);
2205
- return this.fetch(fetchDetails, fetchRequestInit, abortController);
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
- Reflect.deleteProperty(details, "fetchInit");
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 details
2222
- * @param fetchRequestInit
2344
+ * @param option
2345
+ * @param fetchRequestOption
2223
2346
  * @param abortController
2224
2347
  */
2225
- fetch(details, fetchRequestInit, abortController) {
2226
- fetch(details.url, fetchRequestInit)
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: details.responseType,
2365
+ responseType: option.responseType,
2242
2366
  responseXML: void 0,
2243
2367
  };
2244
- Object.assign(httpxResponse, details.context || {});
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 (details.responseType === "stream" ||
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
- details.onload(httpxResponse);
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 (details.responseType === "arraybuffer") {
2414
+ if (option.responseType === "arraybuffer") {
2291
2415
  // response返回格式是二进制流
2292
2416
  response = arrayBuffer;
2293
2417
  }
2294
- else if (details.responseType === "blob") {
2418
+ else if (option.responseType === "blob") {
2295
2419
  // response返回格式是blob
2296
2420
  response = new Blob([arrayBuffer]);
2297
2421
  }
2298
- else if (details.responseType === "json" ||
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 (details.responseType === "document" ||
2305
- details.responseType == null) {
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
- details.onload(httpxResponse);
2441
+ option.onload(httpxResponse);
2318
2442
  })
2319
2443
  .catch((error) => {
2320
2444
  if (error.name === "AbortError") {
2321
2445
  return;
2322
2446
  }
2323
- details.onerror({
2447
+ option.onerror({
2324
2448
  isFetch: true,
2325
- finalUrl: details.url,
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
- details.onloadstart({
2458
+ option.onloadstart({
2335
2459
  isFetch: true,
2336
- finalUrl: details.url,
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 __xmlHttpRequest__
2515
+ * @param xmlHttpRequest
2392
2516
  */
2393
- constructor(__xmlHttpRequest__) {
2394
- if (typeof __xmlHttpRequest__ !== "function") {
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 = __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 details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2617
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2494
2618
  let abortFn = null;
2495
- const promise = new Promise((resolve, reject) => {
2496
- let requestDetails = this.HttpxRequestDetails.getDetails("GET", details, resolve, reject);
2497
- Reflect.deleteProperty(requestDetails, "onprogress");
2498
- // @ts-ignore
2499
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
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
- Object.defineProperty(promise, "abort", {
2507
- value: () => {
2508
- return () => {
2509
- if (typeof abortFn === "function") {
2510
- abortFn();
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 details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2642
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2523
2643
  let abortFn = null;
2524
- const promise = new Promise((resolve, reject) => {
2525
- let requestDetails = this.HttpxRequestDetails.getDetails("POST", details, resolve, reject);
2644
+ let promise = new Promise((resolve, reject) => {
2645
+ let requestOption = this.HttpxRequestDetails.getRequestOption("POST", userRequestOption, resolve, reject);
2526
2646
  // @ts-ignore
2527
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2528
- const requestResult = this.HttpxRequest.request(requestDetails);
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
- Object.defineProperty(promise, "abort", {
2535
- value: () => {
2536
- return () => {
2537
- if (typeof abortFn === "function") {
2538
- abortFn();
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 details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2668
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2551
2669
  let abortFn = null;
2552
- const promise = new Promise((resolve, reject) => {
2553
- let requestDetails = this.HttpxRequestDetails.getDetails("HEAD", details, resolve, reject);
2554
- Reflect.deleteProperty(requestDetails, "onprogress");
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
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2557
- const requestResult = this.HttpxRequest.request(requestDetails);
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
- Object.defineProperty(promise, "abort", {
2564
- value: () => {
2565
- return () => {
2566
- if (typeof abortFn === "function") {
2567
- abortFn();
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 details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2695
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2580
2696
  let abortFn = null;
2581
- const promise = new Promise((resolve, reject) => {
2582
- let requestDetails = this.HttpxRequestDetails.getDetails("OPTIONS", details, resolve, reject);
2583
- Reflect.deleteProperty(requestDetails, "onprogress");
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
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2586
- const requestResult = this.HttpxRequest.request(requestDetails);
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
- Object.defineProperty(promise, "abort", {
2593
- value: () => {
2594
- return () => {
2595
- if (typeof abortFn === "function") {
2596
- abortFn();
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 details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2722
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2609
2723
  let abortFn = null;
2610
- const promise = new Promise((resolve, reject) => {
2611
- let requestDetails = this.HttpxRequestDetails.getDetails("DELETE", details, resolve, reject);
2612
- Reflect.deleteProperty(requestDetails, "onprogress");
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
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2615
- const requestResult = this.HttpxRequest.request(requestDetails);
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
- Object.defineProperty(promise, "abort", {
2622
- value: () => {
2623
- return () => {
2624
- if (typeof abortFn === "function") {
2625
- abortFn();
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 details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2749
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(...args);
2638
2750
  let abortFn = null;
2639
- const promise = new Promise((resolve, reject) => {
2640
- let requestDetails = this.HttpxRequestDetails.getDetails("PUT", details, resolve, reject);
2751
+ let promise = new Promise((resolve, reject) => {
2752
+ let requestOption = this.HttpxRequestDetails.getRequestOption("PUT", userRequestOption, resolve, reject);
2641
2753
  // @ts-ignore
2642
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2643
- const requestResult = this.HttpxRequest.request(requestDetails);
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
- Object.defineProperty(promise, "abort", {
2650
- value: () => {
2651
- return () => {
2652
- if (typeof abortFn === "function") {
2653
- abortFn();
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
  }
@@ -2685,6 +2795,10 @@ System.register('Utils', [], (function (exports) {
2685
2795
  code: 401,
2686
2796
  msg: "操作失败",
2687
2797
  },
2798
+ empty: {
2799
+ code: 201,
2800
+ msg: "操作成功,但是没有数据",
2801
+ },
2688
2802
  openFailed: { code: 91001, msg: "打开数据库失败" },
2689
2803
  saveFailed: { code: 91002, msg: "保存数据失败" },
2690
2804
  getFailed: { code: 91003, msg: "获取数据失败" },
@@ -2873,11 +2987,11 @@ System.register('Utils', [], (function (exports) {
2873
2987
  /* result 返回的是 {key: string, value: any} */
2874
2988
  /* 键值对存储 */
2875
2989
  let data = result ? result.value : void 0;
2876
- if (data) {
2990
+ if (data == null) {
2877
2991
  resolve({
2878
2992
  success: true,
2879
- code: that.#statusCode.operationSuccess.code,
2880
- msg: that.#statusCode.operationSuccess.msg,
2993
+ code: that.#statusCode.empty.code,
2994
+ msg: that.#statusCode.empty.msg,
2881
2995
  data: data,
2882
2996
  event: event,
2883
2997
  result: result,
@@ -2885,10 +2999,10 @@ System.register('Utils', [], (function (exports) {
2885
2999
  }
2886
3000
  else {
2887
3001
  resolve({
2888
- success: false,
2889
- code: that.#statusCode.operationFailed.code,
2890
- msg: that.#statusCode.operationFailed.msg,
2891
- data: void 0,
3002
+ success: true,
3003
+ code: that.#statusCode.operationSuccess.code,
3004
+ msg: that.#statusCode.operationSuccess.msg,
3005
+ data: data,
2892
3006
  event: event,
2893
3007
  result: result,
2894
3008
  });
@@ -3955,7 +4069,7 @@ System.register('Utils', [], (function (exports) {
3955
4069
  this.windowApi = new WindowApi(option);
3956
4070
  }
3957
4071
  /** 版本号 */
3958
- version = "2024.10.19";
4072
+ version = "2024.10.28";
3959
4073
  addStyle(cssText) {
3960
4074
  if (typeof cssText !== "string") {
3961
4075
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4102,22 +4216,33 @@ System.register('Utils', [], (function (exports) {
4102
4216
  if (!UtilsContext.isDOM(element)) {
4103
4217
  throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
4104
4218
  }
4105
- let mouseClickPosX = Number(window.event.clientX.toString()); /* 鼠标相对屏幕横坐标 */
4106
- let mouseClickPosY = Number(window.event.clientY.toString()); /* 鼠标相对屏幕纵坐标 */
4107
- let elementPosXLeft = Number(element.getBoundingClientRect().left); /* 要检测的元素的相对屏幕的横坐标最左边 */
4108
- let elementPosXRight = Number(element.getBoundingClientRect().right); /* 要检测的元素的相对屏幕的横坐标最右边 */
4109
- let elementPosYTop = Number(element.getBoundingClientRect().top); /* 要检测的元素的相对屏幕的纵坐标最上边 */
4110
- let elementPosYBottom = Number(element.getBoundingClientRect().bottom); /* 要检测的元素的相对屏幕的纵坐标最下边 */
4111
- let clickNodeHTML = this.windowApi.window.event.target
4112
- .innerHTML;
4113
- if (mouseClickPosX >= elementPosXLeft &&
4114
- mouseClickPosX <= elementPosXRight &&
4115
- mouseClickPosY >= elementPosYTop &&
4116
- mouseClickPosY <= elementPosYBottom) {
4219
+ let clickEvent = UtilsContext.windowApi.window.event;
4220
+ let touchEvent = UtilsContext.windowApi.window.event;
4221
+ let $click = clickEvent?.composedPath()?.[0];
4222
+ // 点击的x坐标
4223
+ let clickPosX = clickEvent?.clientX != null
4224
+ ? clickEvent.clientX
4225
+ : touchEvent.touches[0].clientX;
4226
+ // 点击的y坐标
4227
+ let clickPosY = clickEvent?.clientY != null
4228
+ ? clickEvent.clientY
4229
+ : touchEvent.touches[0].clientY;
4230
+ let {
4231
+ /* 要检测的元素的相对屏幕的横坐标最左边 */
4232
+ left: elementPosXLeft,
4233
+ /* 要检测的元素的相对屏幕的横坐标最右边 */
4234
+ right: elementPosXRight,
4235
+ /* 要检测的元素的相对屏幕的纵坐标最上边 */
4236
+ top: elementPosYTop,
4237
+ /* 要检测的元素的相对屏幕的纵坐标最下边 */
4238
+ bottom: elementPosYBottom, } = element.getBoundingClientRect();
4239
+ if (clickPosX >= elementPosXLeft &&
4240
+ clickPosX <= elementPosXRight &&
4241
+ clickPosY >= elementPosYTop &&
4242
+ clickPosY <= elementPosYBottom) {
4117
4243
  return true;
4118
4244
  }
4119
- else if (clickNodeHTML &&
4120
- element.innerHTML.includes(clickNodeHTML)) {
4245
+ else if (($click && element.contains($click)) || $click == element) {
4121
4246
  /* 这种情况是应对在界面中隐藏的元素,getBoundingClientRect获取的都是0 */
4122
4247
  return true;
4123
4248
  }
@@ -6175,7 +6300,8 @@ System.register('Utils', [], (function (exports) {
6175
6300
  dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
6176
6301
  let UtilsContext = this;
6177
6302
  function initMouseEvent(eventName, offSetX, offSetY) {
6178
- let win = unsafeWindow || window;
6303
+ // @ts-ignore
6304
+ let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
6179
6305
  let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
6180
6306
  mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
6181
6307
  return mouseEvent;