@base-web-kits/base-tools-web 1.1.11 → 1.1.18-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async/index.d.ts +26 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/base-tools-web.umd.global.js +130 -19
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/index.cjs +134 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +131 -5
- package/dist/index.js.map +1 -1
- package/dist/network/{load.d.ts → download.d.ts} +1 -1
- package/dist/network/download.d.ts.map +1 -0
- package/dist/network/index.d.ts +2 -1
- package/dist/network/index.d.ts.map +1 -1
- package/dist/network/request.d.ts +11 -3
- package/dist/network/request.d.ts.map +1 -1
- package/dist/network/uploadFile.d.ts +57 -0
- package/dist/network/uploadFile.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/web/async/index.ts +85 -0
- package/src/web/config/index.ts +1 -1
- package/src/web/network/index.ts +2 -1
- package/src/web/network/request.ts +33 -12
- package/src/web/network/uploadFile.ts +146 -0
- package/dist/network/load.d.ts.map +0 -1
- /package/src/web/network/{load.ts → download.ts} +0 -0
package/dist/config/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/config/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,kBAAkB;IAClB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACtE,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/config/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,kBAAkB;IAClB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACtE,mBAAmB;IACnB,WAAW,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACpD,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,eAAe;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,aAAa;IACb,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IAEb,cAAc;IACd,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAE5B,cAAc;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,cAAc;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,cAAc;IACd,CAAC,CAAC,EAAE,OAAO,CAAC;IAEZ,WAAW;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAIF;;GAEG;AACH,wBAAgB,kBAAkB,cAEjC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,QAEtD"}
|
package/dist/index.cjs
CHANGED
|
@@ -79,6 +79,8 @@ __export(index_exports, {
|
|
|
79
79
|
copyText: () => copyText,
|
|
80
80
|
copyUrl: () => copyUrl,
|
|
81
81
|
download: () => download,
|
|
82
|
+
filterRequestData: () => filterRequestData,
|
|
83
|
+
filterRequestHeader: () => filterRequestHeader,
|
|
82
84
|
getBaseToolsConfig: () => getBaseToolsConfig,
|
|
83
85
|
getBrowserName: () => getBrowserName,
|
|
84
86
|
getBrowserVersion: () => getBrowserVersion,
|
|
@@ -118,6 +120,7 @@ __export(index_exports, {
|
|
|
118
120
|
setCookie: () => setCookie,
|
|
119
121
|
setLocalStorage: () => setLocalStorage,
|
|
120
122
|
unlockBodyScroll: () => unlockBodyScroll,
|
|
123
|
+
uploadFile: () => uploadFile,
|
|
121
124
|
windowScrollTo: () => windowScrollTo
|
|
122
125
|
});
|
|
123
126
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -506,7 +509,7 @@ function unlockBodyScroll() {
|
|
|
506
509
|
window.scrollTo(0, y);
|
|
507
510
|
}
|
|
508
511
|
|
|
509
|
-
// src/web/network/
|
|
512
|
+
// src/web/network/download.ts
|
|
510
513
|
function download(url, fileName = "") {
|
|
511
514
|
return __async(this, null, function* () {
|
|
512
515
|
if (!url) return;
|
|
@@ -777,6 +780,7 @@ var EventBus = class {
|
|
|
777
780
|
return this;
|
|
778
781
|
}
|
|
779
782
|
};
|
|
783
|
+
var EventBus_default = new EventBus();
|
|
780
784
|
|
|
781
785
|
// src/ts/day/index.ts
|
|
782
786
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
@@ -1668,9 +1672,8 @@ function request(config) {
|
|
|
1668
1672
|
const isGet = method === "GET";
|
|
1669
1673
|
const isObjectData = (0, ts_exports.isPlainObject)(data);
|
|
1670
1674
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
1671
|
-
const fillData = isObjectData ? (
|
|
1672
|
-
const
|
|
1673
|
-
const fillHeader = header ? (0, ts_exports.pickBy)(header, (val) => !emptyValue.includes(val)) : {};
|
|
1675
|
+
const fillData = isObjectData ? filterRequestData(data) : data;
|
|
1676
|
+
const fillHeader = filterRequestHeader(header);
|
|
1674
1677
|
const contentTypeKey = Object.keys(fillHeader).find(
|
|
1675
1678
|
(k) => k.toLowerCase() === "content-type"
|
|
1676
1679
|
);
|
|
@@ -1711,7 +1714,8 @@ function request(config) {
|
|
|
1711
1714
|
}
|
|
1712
1715
|
}
|
|
1713
1716
|
const appConfig2 = getBaseToolsConfig();
|
|
1714
|
-
if (showLoading)
|
|
1717
|
+
if (showLoading)
|
|
1718
|
+
(_a = appConfig2.showLoading) == null ? void 0 : _a.call(appConfig2, typeof showLoading === "string" ? { title: showLoading } : {});
|
|
1715
1719
|
let isTimeout = false;
|
|
1716
1720
|
const timeoutId = setTimeout(() => {
|
|
1717
1721
|
isTimeout = true;
|
|
@@ -1776,6 +1780,22 @@ function request(config) {
|
|
|
1776
1780
|
promise.task = task;
|
|
1777
1781
|
return promise;
|
|
1778
1782
|
}
|
|
1783
|
+
function filterRequestData(data) {
|
|
1784
|
+
const res = {};
|
|
1785
|
+
Object.entries(data).forEach(([k, v]) => {
|
|
1786
|
+
if (v !== void 0) res[k] = v;
|
|
1787
|
+
});
|
|
1788
|
+
return res;
|
|
1789
|
+
}
|
|
1790
|
+
function filterRequestHeader(header) {
|
|
1791
|
+
const newHeader = {};
|
|
1792
|
+
if (header) {
|
|
1793
|
+
Object.entries(header).forEach(([k, v]) => {
|
|
1794
|
+
if (v !== void 0 && v !== null && v !== "") newHeader[k] = String(v);
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
return newHeader;
|
|
1798
|
+
}
|
|
1779
1799
|
function logRequestInfo(options) {
|
|
1780
1800
|
const { log } = getBaseToolsConfig();
|
|
1781
1801
|
const { isLog = true } = options.config;
|
|
@@ -1884,6 +1904,112 @@ function toFormData(data) {
|
|
|
1884
1904
|
return formData;
|
|
1885
1905
|
}
|
|
1886
1906
|
|
|
1907
|
+
// src/web/async/index.ts
|
|
1908
|
+
function enhanceWebApi(webApi, apiName) {
|
|
1909
|
+
return (option, config) => {
|
|
1910
|
+
const finalConfig = config || {};
|
|
1911
|
+
const {
|
|
1912
|
+
showLoading = false,
|
|
1913
|
+
toastSuccess = false,
|
|
1914
|
+
toastError = true,
|
|
1915
|
+
showLog = true
|
|
1916
|
+
} = finalConfig;
|
|
1917
|
+
const {
|
|
1918
|
+
log,
|
|
1919
|
+
toast,
|
|
1920
|
+
showLoading: showLoadingFn,
|
|
1921
|
+
hideLoading: hideLoadingFn
|
|
1922
|
+
} = getBaseToolsConfig();
|
|
1923
|
+
const fname = apiName || "enhanceWebApi";
|
|
1924
|
+
if (showLoading) {
|
|
1925
|
+
const title = typeof showLoading === "string" ? showLoading : "";
|
|
1926
|
+
showLoadingFn == null ? void 0 : showLoadingFn({ title });
|
|
1927
|
+
}
|
|
1928
|
+
return new Promise((resolve, reject) => {
|
|
1929
|
+
webApi(option, finalConfig).then((res) => {
|
|
1930
|
+
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;
|
|
1934
|
+
if (msg) toast == null ? void 0 : toast({ msg, status: "success" });
|
|
1935
|
+
}).catch((e) => {
|
|
1936
|
+
if (showLoading) hideLoadingFn == null ? void 0 : hideLoadingFn();
|
|
1937
|
+
if (showLog) log == null ? void 0 : log("error", { name: fname, status: "fail", option, e });
|
|
1938
|
+
const msg = typeof toastError === "function" ? toastError(e) : toastError;
|
|
1939
|
+
if (msg) {
|
|
1940
|
+
toast == null ? void 0 : toast({
|
|
1941
|
+
msg: typeof msg === "string" ? msg : `${fname} fail: ${JSON.stringify(e)}`,
|
|
1942
|
+
status: "fail"
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
reject(e);
|
|
1946
|
+
});
|
|
1947
|
+
});
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
// src/web/network/uploadFile.ts
|
|
1952
|
+
function upload(option, config) {
|
|
1953
|
+
return new Promise((resolve, reject) => {
|
|
1954
|
+
var _a;
|
|
1955
|
+
const xhr = new XMLHttpRequest();
|
|
1956
|
+
const { url, file, name = "file", header, formData, timeout = 0 } = option;
|
|
1957
|
+
const fail = (error) => reject(error);
|
|
1958
|
+
const success = (responseText) => {
|
|
1959
|
+
try {
|
|
1960
|
+
resolve(JSON.parse(responseText));
|
|
1961
|
+
} catch (e) {
|
|
1962
|
+
resolve(responseText);
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1965
|
+
let onProgressUpdate;
|
|
1966
|
+
const task = {
|
|
1967
|
+
onProgressUpdate: (callback) => {
|
|
1968
|
+
onProgressUpdate = callback;
|
|
1969
|
+
},
|
|
1970
|
+
abort: () => xhr.abort()
|
|
1971
|
+
};
|
|
1972
|
+
(_a = config == null ? void 0 : config.onTaskReady) == null ? void 0 : _a.call(config, task);
|
|
1973
|
+
xhr.upload.onprogress = (e) => {
|
|
1974
|
+
if (!e.lengthComputable) return;
|
|
1975
|
+
const ev = {
|
|
1976
|
+
progress: Math.round(e.loaded / e.total * 100),
|
|
1977
|
+
loaded: e.loaded,
|
|
1978
|
+
total: e.total
|
|
1979
|
+
};
|
|
1980
|
+
onProgressUpdate == null ? void 0 : onProgressUpdate(ev);
|
|
1981
|
+
};
|
|
1982
|
+
xhr.onload = () => {
|
|
1983
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
1984
|
+
success(xhr.responseText);
|
|
1985
|
+
} else {
|
|
1986
|
+
fail({ message: `\u4E0A\u4F20\u5931\u8D25`, status: xhr.status });
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
xhr.onerror = () => fail({ message: "\u7F51\u7EDC\u9519\u8BEF", status: 0 });
|
|
1990
|
+
xhr.ontimeout = () => fail({ message: "\u4E0A\u4F20\u8D85\u65F6", status: -1 });
|
|
1991
|
+
xhr.onabort = () => fail({ message: "\u7528\u6237\u53D6\u6D88", status: -2 });
|
|
1992
|
+
xhr.open("POST", url);
|
|
1993
|
+
if (header) {
|
|
1994
|
+
Object.entries(header).forEach(([k, v]) => {
|
|
1995
|
+
if (v !== void 0 && v !== null && v !== "") xhr.setRequestHeader(k, String(v));
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
xhr.timeout = timeout;
|
|
1999
|
+
const data = new FormData();
|
|
2000
|
+
data.append(name, file);
|
|
2001
|
+
if (formData) {
|
|
2002
|
+
Object.entries(formData).forEach(([k, v]) => {
|
|
2003
|
+
if (v !== void 0 && v !== null) data.append(k, String(v));
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
xhr.send(data);
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
function uploadFile(option, config) {
|
|
2010
|
+
return enhanceWebApi(upload, "uploadFile")(option, config);
|
|
2011
|
+
}
|
|
2012
|
+
|
|
1887
2013
|
// src/web/storage/index.ts
|
|
1888
2014
|
var WK = {
|
|
1889
2015
|
val: "__l_val",
|
|
@@ -1960,6 +2086,8 @@ function getUrlParams(url = window.location.href) {
|
|
|
1960
2086
|
copyText,
|
|
1961
2087
|
copyUrl,
|
|
1962
2088
|
download,
|
|
2089
|
+
filterRequestData,
|
|
2090
|
+
filterRequestHeader,
|
|
1963
2091
|
getBaseToolsConfig,
|
|
1964
2092
|
getBrowserName,
|
|
1965
2093
|
getBrowserVersion,
|
|
@@ -1999,6 +2127,7 @@ function getUrlParams(url = window.location.href) {
|
|
|
1999
2127
|
setCookie,
|
|
2000
2128
|
setLocalStorage,
|
|
2001
2129
|
unlockBodyScroll,
|
|
2130
|
+
uploadFile,
|
|
2002
2131
|
windowScrollTo
|
|
2003
2132
|
});
|
|
2004
2133
|
//# sourceMappingURL=index.cjs.map
|