@base-web-kits/base-tools-web 1.1.0 → 1.1.1-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/base-tools-web.umd.global.js +52 -2
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +52 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -2
- package/dist/index.js.map +1 -1
- package/dist/network/request.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/web/network/request.ts +70 -7
package/dist/index.js
CHANGED
|
@@ -1527,11 +1527,27 @@ function request(config) {
|
|
|
1527
1527
|
const isArrayData = !isObjectData && Array.isArray(data);
|
|
1528
1528
|
const fillData = isObjectData ? (0, ts_exports.pickBy)(data, (val) => val !== void 0) : data;
|
|
1529
1529
|
const fillHeader = header ? (0, ts_exports.pickBy)(header, (val) => !!val) : {};
|
|
1530
|
-
|
|
1530
|
+
const contentTypeKey = Object.keys(fillHeader).find(
|
|
1531
|
+
(k) => k.toLowerCase() === "content-type"
|
|
1532
|
+
);
|
|
1533
|
+
const contentType = contentTypeKey ? fillHeader[contentTypeKey].toLowerCase() : "";
|
|
1534
|
+
if (!isGet && fillData && (isObjectData || isArrayData) && !contentType) {
|
|
1531
1535
|
fillHeader["Content-Type"] = "application/json";
|
|
1532
1536
|
}
|
|
1533
1537
|
const fillUrl = isGet && isObjectData ? appendUrlParam(url, fillData) : url;
|
|
1534
|
-
|
|
1538
|
+
let fillBody;
|
|
1539
|
+
if (!isGet && fillData) {
|
|
1540
|
+
if (isObjectData && contentType.includes("application/x-www-form-urlencoded")) {
|
|
1541
|
+
fillBody = toSearchParams(fillData);
|
|
1542
|
+
} else if (isObjectData && contentType.includes("multipart/form-data")) {
|
|
1543
|
+
fillBody = toFormData(fillData);
|
|
1544
|
+
if (contentTypeKey) delete fillHeader[contentTypeKey];
|
|
1545
|
+
} else if (isObjectData || isArrayData) {
|
|
1546
|
+
fillBody = JSON.stringify(fillData);
|
|
1547
|
+
} else {
|
|
1548
|
+
fillBody = fillData;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1535
1551
|
const logConfig = { ...config, data: fillData, header: fillHeader, url: fillUrl };
|
|
1536
1552
|
const startTime = Date.now();
|
|
1537
1553
|
const isCache = cacheTime && cacheTime > 0;
|
|
@@ -1686,6 +1702,40 @@ async function parseResponse(response, responseType) {
|
|
|
1686
1702
|
}
|
|
1687
1703
|
return resData;
|
|
1688
1704
|
}
|
|
1705
|
+
function toSearchParams(data) {
|
|
1706
|
+
const params = new URLSearchParams();
|
|
1707
|
+
for (const key in data) {
|
|
1708
|
+
const val = data[key];
|
|
1709
|
+
if (val === null) continue;
|
|
1710
|
+
if (Array.isArray(val)) {
|
|
1711
|
+
val.forEach((v) => params.append(key, typeof v === "object" ? JSON.stringify(v) : String(v)));
|
|
1712
|
+
} else {
|
|
1713
|
+
params.append(key, typeof val === "object" ? JSON.stringify(val) : String(val));
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
return params;
|
|
1717
|
+
}
|
|
1718
|
+
function toFormData(data) {
|
|
1719
|
+
const formData = new FormData();
|
|
1720
|
+
for (const key in data) {
|
|
1721
|
+
const val = data[key];
|
|
1722
|
+
if (val === null) continue;
|
|
1723
|
+
if (Array.isArray(val)) {
|
|
1724
|
+
val.forEach(
|
|
1725
|
+
(v) => formData.append(
|
|
1726
|
+
key,
|
|
1727
|
+
v instanceof Blob ? v : typeof v === "object" ? JSON.stringify(v) : String(v)
|
|
1728
|
+
)
|
|
1729
|
+
);
|
|
1730
|
+
} else {
|
|
1731
|
+
formData.append(
|
|
1732
|
+
key,
|
|
1733
|
+
val instanceof Blob ? val : typeof val === "object" ? JSON.stringify(val) : String(val)
|
|
1734
|
+
);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
return formData;
|
|
1738
|
+
}
|
|
1689
1739
|
|
|
1690
1740
|
// src/web/storage/index.ts
|
|
1691
1741
|
var WK = {
|