@base-web-kits/base-tools-web 1.4.3 → 1.4.5
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 +3 -4
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +3 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/dist/network/uploadFile.d.ts +4 -5
- package/dist/network/uploadFile.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/web/network/uploadFile.ts +88 -112
package/dist/index.d.cts
CHANGED
|
@@ -566,6 +566,8 @@ type UploadFileOption = {
|
|
|
566
566
|
data?: Record<string, string | number>;
|
|
567
567
|
/** 超时时间,单位 ms,默认 0(不超时) */
|
|
568
568
|
timeout?: number;
|
|
569
|
+
/** 响应类型, 默认'text' */
|
|
570
|
+
responseType?: 'text' | 'json';
|
|
569
571
|
};
|
|
570
572
|
type OnUploadProgressUpdate = (res: UploadProgressEvent) => void;
|
|
571
573
|
type UploadProgressEvent = {
|
|
@@ -585,8 +587,6 @@ type UploadTask = {
|
|
|
585
587
|
type UploadConfig = {
|
|
586
588
|
/** 获取task对象 */
|
|
587
589
|
onTaskReady?: (task: UploadTask) => void;
|
|
588
|
-
/** 响应类型, 默认'text' */
|
|
589
|
-
responseType?: 'text' | 'json';
|
|
590
590
|
};
|
|
591
591
|
type UploadFail = {
|
|
592
592
|
message: string;
|
|
@@ -608,13 +608,12 @@ type UploadFail = {
|
|
|
608
608
|
* });
|
|
609
609
|
*
|
|
610
610
|
* // 直接返回json对象
|
|
611
|
-
* const json = await uploadFile({ url: 'https://xx', file: file
|
|
611
|
+
* const json = await uploadFile({ url: 'https://xx', file: file, responseType: 'json' });
|
|
612
612
|
*
|
|
613
613
|
* // 解析上传结果
|
|
614
614
|
* console.log('uploadFile ok', JSON.parse(res));
|
|
615
615
|
*/
|
|
616
|
-
declare function uploadFile(option: UploadFileOption, config?: UploadConfig & WebApiConfig<
|
|
617
|
-
declare function uploadFile<T = unknown>(option: UploadFileOption, config?: UploadConfig & WebApiConfig<T, UploadFail>): Promise<T>;
|
|
616
|
+
declare function uploadFile<T = string>(option: UploadFileOption, config?: UploadConfig & WebApiConfig<T, UploadFail>): Promise<T>;
|
|
618
617
|
|
|
619
618
|
/**
|
|
620
619
|
* 写入 localStorage(自动 JSON 序列化)
|
package/dist/index.mjs
CHANGED
|
@@ -2360,10 +2360,9 @@ function getErrorMessage(responseText, fallback) {
|
|
|
2360
2360
|
}
|
|
2361
2361
|
function upload(option, config) {
|
|
2362
2362
|
return new Promise((resolve, reject) => {
|
|
2363
|
-
var _a
|
|
2363
|
+
var _a;
|
|
2364
2364
|
const xhr = new XMLHttpRequest();
|
|
2365
|
-
const { url, file, name = "file", header, data, timeout = 0 } = option;
|
|
2366
|
-
const responseType = (_a = config == null ? void 0 : config.responseType) != null ? _a : "text";
|
|
2365
|
+
const { url, file, name = "file", header, data, timeout = 0, responseType = "text" } = option;
|
|
2367
2366
|
const fail = (error) => reject(error);
|
|
2368
2367
|
const success = (responseText) => {
|
|
2369
2368
|
if (responseType === "json") {
|
|
@@ -2384,7 +2383,7 @@ function upload(option, config) {
|
|
|
2384
2383
|
},
|
|
2385
2384
|
abort: () => xhr.abort()
|
|
2386
2385
|
};
|
|
2387
|
-
(
|
|
2386
|
+
(_a = config == null ? void 0 : config.onTaskReady) == null ? void 0 : _a.call(config, task);
|
|
2388
2387
|
xhr.upload.onprogress = (e) => {
|
|
2389
2388
|
if (!e.lengthComputable) return;
|
|
2390
2389
|
const ev = {
|