@base-web-kits/base-tools-web 1.1.18-alpha.0 → 1.2.0-alpha.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.cjs CHANGED
@@ -1801,7 +1801,7 @@ function logRequestInfo(options) {
1801
1801
  const { isLog = true } = options.config;
1802
1802
  if (!log || !isLog) return;
1803
1803
  const { config, res, fromCache = false, startTime, status, e } = options;
1804
- const { url, data, header, method, extraLog } = config;
1804
+ const { url, data, header, method, logExtra } = config;
1805
1805
  const endTime = Date.now();
1806
1806
  const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
1807
1807
  const info = __spreadValues({
@@ -1815,7 +1815,7 @@ function logRequestInfo(options) {
1815
1815
  startTime: toDayjs(startTime).format(fmt),
1816
1816
  endTime: toDayjs(endTime).format(fmt),
1817
1817
  duration: endTime - startTime
1818
- }, extraLog);
1818
+ }, logExtra);
1819
1819
  if (status === "success") {
1820
1820
  info.res = (0, ts_exports.cloneDeep)(res);
1821
1821
  log("info", info);
@@ -1905,14 +1905,16 @@ function toFormData(data) {
1905
1905
  }
1906
1906
 
1907
1907
  // src/web/async/index.ts
1908
- function promisifyWebApi(webApi, apiName) {
1908
+ function enhanceWebApi(webApi, apiName) {
1909
1909
  return (option, config) => {
1910
1910
  const finalConfig = config || {};
1911
1911
  const {
1912
1912
  showLoading = false,
1913
1913
  toastSuccess = false,
1914
1914
  toastError = true,
1915
- showLog = true
1915
+ showLog = true,
1916
+ resFilter,
1917
+ logExtra
1916
1918
  } = finalConfig;
1917
1919
  const {
1918
1920
  log,
@@ -1920,7 +1922,7 @@ function promisifyWebApi(webApi, apiName) {
1920
1922
  showLoading: showLoadingFn,
1921
1923
  hideLoading: hideLoadingFn
1922
1924
  } = getBaseToolsConfig();
1923
- const fname = apiName || "promisifyWebApi";
1925
+ const fname = apiName || "enhanceWebApi";
1924
1926
  if (showLoading) {
1925
1927
  const title = typeof showLoading === "string" ? showLoading : "";
1926
1928
  showLoadingFn == null ? void 0 : showLoadingFn({ title });
@@ -1928,13 +1930,23 @@ function promisifyWebApi(webApi, apiName) {
1928
1930
  return new Promise((resolve, reject) => {
1929
1931
  webApi(option, finalConfig).then((res) => {
1930
1932
  if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
1931
- if (showLog) log == null ? void 0 : log("info", { name: fname, status: "success", option, res });
1932
- resolve(res);
1933
- const msg = typeof toastSuccess === "function" ? toastSuccess(res) : toastSuccess;
1933
+ const finalRes = resFilter ? resFilter(res) : res;
1934
+ if (showLog) {
1935
+ const logData = __spreadValues({ name: fname, status: "success", option }, logExtra);
1936
+ if (resFilter) {
1937
+ logData.res = res;
1938
+ logData.resFilter = (0, ts_exports.cloneDeep)(finalRes);
1939
+ } else {
1940
+ logData.res = (0, ts_exports.cloneDeep)(res);
1941
+ }
1942
+ log == null ? void 0 : log("info", logData);
1943
+ }
1944
+ resolve(finalRes);
1945
+ const msg = typeof toastSuccess === "function" ? toastSuccess(finalRes) : toastSuccess;
1934
1946
  if (msg) toast == null ? void 0 : toast({ msg, status: "success" });
1935
1947
  }).catch((e) => {
1936
1948
  if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
1937
- if (showLog) log == null ? void 0 : log("error", { name: fname, status: "fail", option, e });
1949
+ if (showLog) log == null ? void 0 : log("error", __spreadValues({ name: fname, status: "fail", option, e }, logExtra));
1938
1950
  const msg = typeof toastError === "function" ? toastError(e) : toastError;
1939
1951
  if (msg) {
1940
1952
  toast == null ? void 0 : toast({
@@ -2000,17 +2012,14 @@ function upload(option, config) {
2000
2012
  data.append(name, file);
2001
2013
  if (formData) {
2002
2014
  Object.entries(formData).forEach(([k, v]) => {
2003
- if (v !== void 0) data.append(k, String(v));
2015
+ if (v !== void 0 && v !== null) data.append(k, String(v));
2004
2016
  });
2005
2017
  }
2006
2018
  xhr.send(data);
2007
2019
  });
2008
2020
  }
2009
2021
  function uploadFile(option, config) {
2010
- return promisifyWebApi(upload, "uploadFile")(
2011
- option,
2012
- config
2013
- );
2022
+ return enhanceWebApi(upload, "uploadFile")(option, config);
2014
2023
  }
2015
2024
 
2016
2025
  // src/web/storage/index.ts