@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.js CHANGED
@@ -1732,7 +1732,7 @@ function logRequestInfo(options) {
1732
1732
  const { isLog = true } = options.config;
1733
1733
  if (!log || !isLog) return;
1734
1734
  const { config, res, fromCache = false, startTime, status, e } = options;
1735
- const { url, data, header, method, extraLog } = config;
1735
+ const { url, data, header, method, logExtra } = config;
1736
1736
  const endTime = Date.now();
1737
1737
  const fmt = "YYYY-MM-DD HH:mm:ss.SSS";
1738
1738
  const info = __spreadValues({
@@ -1746,7 +1746,7 @@ function logRequestInfo(options) {
1746
1746
  startTime: toDayjs(startTime).format(fmt),
1747
1747
  endTime: toDayjs(endTime).format(fmt),
1748
1748
  duration: endTime - startTime
1749
- }, extraLog);
1749
+ }, logExtra);
1750
1750
  if (status === "success") {
1751
1751
  info.res = (0, ts_exports.cloneDeep)(res);
1752
1752
  log("info", info);
@@ -1836,14 +1836,16 @@ function toFormData(data) {
1836
1836
  }
1837
1837
 
1838
1838
  // src/web/async/index.ts
1839
- function promisifyWebApi(webApi, apiName) {
1839
+ function enhanceWebApi(webApi, apiName) {
1840
1840
  return (option, config) => {
1841
1841
  const finalConfig = config || {};
1842
1842
  const {
1843
1843
  showLoading = false,
1844
1844
  toastSuccess = false,
1845
1845
  toastError = true,
1846
- showLog = true
1846
+ showLog = true,
1847
+ resFilter,
1848
+ logExtra
1847
1849
  } = finalConfig;
1848
1850
  const {
1849
1851
  log,
@@ -1851,7 +1853,7 @@ function promisifyWebApi(webApi, apiName) {
1851
1853
  showLoading: showLoadingFn,
1852
1854
  hideLoading: hideLoadingFn
1853
1855
  } = getBaseToolsConfig();
1854
- const fname = apiName || "promisifyWebApi";
1856
+ const fname = apiName || "enhanceWebApi";
1855
1857
  if (showLoading) {
1856
1858
  const title = typeof showLoading === "string" ? showLoading : "";
1857
1859
  showLoadingFn == null ? void 0 : showLoadingFn({ title });
@@ -1859,13 +1861,23 @@ function promisifyWebApi(webApi, apiName) {
1859
1861
  return new Promise((resolve, reject) => {
1860
1862
  webApi(option, finalConfig).then((res) => {
1861
1863
  if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
1862
- if (showLog) log == null ? void 0 : log("info", { name: fname, status: "success", option, res });
1863
- resolve(res);
1864
- const msg = typeof toastSuccess === "function" ? toastSuccess(res) : toastSuccess;
1864
+ const finalRes = resFilter ? resFilter(res) : res;
1865
+ if (showLog) {
1866
+ const logData = __spreadValues({ name: fname, status: "success", option }, logExtra);
1867
+ if (resFilter) {
1868
+ logData.res = res;
1869
+ logData.resFilter = (0, ts_exports.cloneDeep)(finalRes);
1870
+ } else {
1871
+ logData.res = (0, ts_exports.cloneDeep)(res);
1872
+ }
1873
+ log == null ? void 0 : log("info", logData);
1874
+ }
1875
+ resolve(finalRes);
1876
+ const msg = typeof toastSuccess === "function" ? toastSuccess(finalRes) : toastSuccess;
1865
1877
  if (msg) toast == null ? void 0 : toast({ msg, status: "success" });
1866
1878
  }).catch((e) => {
1867
1879
  if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
1868
- if (showLog) log == null ? void 0 : log("error", { name: fname, status: "fail", option, e });
1880
+ if (showLog) log == null ? void 0 : log("error", __spreadValues({ name: fname, status: "fail", option, e }, logExtra));
1869
1881
  const msg = typeof toastError === "function" ? toastError(e) : toastError;
1870
1882
  if (msg) {
1871
1883
  toast == null ? void 0 : toast({
@@ -1931,17 +1943,14 @@ function upload(option, config) {
1931
1943
  data.append(name, file);
1932
1944
  if (formData) {
1933
1945
  Object.entries(formData).forEach(([k, v]) => {
1934
- if (v !== void 0) data.append(k, String(v));
1946
+ if (v !== void 0 && v !== null) data.append(k, String(v));
1935
1947
  });
1936
1948
  }
1937
1949
  xhr.send(data);
1938
1950
  });
1939
1951
  }
1940
1952
  function uploadFile(option, config) {
1941
- return promisifyWebApi(upload, "uploadFile")(
1942
- option,
1943
- config
1944
- );
1953
+ return enhanceWebApi(upload, "uploadFile")(option, config);
1945
1954
  }
1946
1955
 
1947
1956
  // src/web/storage/index.ts