@base-web-kits/base-tools-web 1.2.10 → 1.3.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/base-tools-web.umd.global.js +7 -7
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/{index.js → index.mjs} +8 -8
- package/dist/{index.js.map → index.mjs.map} +1 -1
- package/dist/network/uploadFile.d.ts +2 -2
- package/dist/network/uploadFile.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/web/network/uploadFile.ts +9 -9
|
@@ -11,8 +11,8 @@ export type UploadFileOption = {
|
|
|
11
11
|
name?: string;
|
|
12
12
|
/** 请求头 */
|
|
13
13
|
header?: Record<string, string | number>;
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/** 请求参数 */
|
|
15
|
+
data?: Record<string, string | number>;
|
|
16
16
|
/** 超时时间,单位 ms,默认 0(不超时) */
|
|
17
17
|
timeout?: number;
|
|
18
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../../src/web/network/uploadFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,aAAa;IACb,GAAG,EAAE,MAAM,CAAC;IAEZ,eAAe;IACf,IAAI,EAAE,IAAI,CAAC;IAEX,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,UAAU;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAEzC,
|
|
1
|
+
{"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../../src/web/network/uploadFile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base-web-kits/base-tools-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "Independent Web utilities package built from src/web.",
|
|
6
6
|
"keywords": [
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"main": "./dist/index.cjs",
|
|
13
|
-
"module": "./dist/index.
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
|
-
"import": "./dist/index.
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
19
|
"require": "./dist/index.cjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
@@ -17,8 +17,8 @@ export type UploadFileOption = {
|
|
|
17
17
|
/** 请求头 */
|
|
18
18
|
header?: Record<string, string | number>;
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/** 请求参数 */
|
|
21
|
+
data?: Record<string, string | number>;
|
|
22
22
|
|
|
23
23
|
/** 超时时间,单位 ms,默认 0(不超时) */
|
|
24
24
|
timeout?: number;
|
|
@@ -55,7 +55,7 @@ export type UploadFail = {
|
|
|
55
55
|
function upload(option: UploadFileOption, config?: UploadConfig) {
|
|
56
56
|
return new Promise<string>((resolve, reject) => {
|
|
57
57
|
const xhr = new XMLHttpRequest();
|
|
58
|
-
const { url, file, name = 'file', header,
|
|
58
|
+
const { url, file, name = 'file', header, data, timeout = 0 } = option;
|
|
59
59
|
|
|
60
60
|
const fail = (error: UploadFail) => reject(error);
|
|
61
61
|
|
|
@@ -110,18 +110,18 @@ function upload(option: UploadFileOption, config?: UploadConfig) {
|
|
|
110
110
|
xhr.timeout = timeout;
|
|
111
111
|
|
|
112
112
|
// 组装 FormData
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
Object.entries(
|
|
116
|
-
if (v !== undefined && v !== null)
|
|
113
|
+
const formData = new FormData();
|
|
114
|
+
if (data) {
|
|
115
|
+
Object.entries(data).forEach(([k, v]) => {
|
|
116
|
+
if (v !== undefined && v !== null) formData.append(k, String(v));
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// OSS直传的file字段必须写在最后
|
|
121
|
-
|
|
121
|
+
formData.append(name, file);
|
|
122
122
|
|
|
123
123
|
// 发送请求
|
|
124
|
-
xhr.send(
|
|
124
|
+
xhr.send(formData);
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
|