@base-web-kits/base-tools-web 1.2.10 → 1.3.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.
@@ -11,8 +11,8 @@ export type UploadFileOption = {
11
11
  name?: string;
12
12
  /** 请求头 */
13
13
  header?: Record<string, string | number>;
14
- /** 额外的formData参数 */
15
- formData?: Record<string, string | number>;
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,oBAAoB;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAE3C,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG;IAChC,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW;IACX,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW;IACX,gBAAgB,EAAE,CAA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AAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW;IACX,gBAAgB,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC7D,WAAW;IACX,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,eAAe;IACf,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA2EF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY,mBAExF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base-web-kits/base-tools-web",
3
- "version": "1.2.10",
3
+ "version": "1.3.0",
4
4
  "sideEffects": false,
5
5
  "description": "Independent Web utilities package built from src/web.",
6
6
  "keywords": [
@@ -17,8 +17,8 @@ export type UploadFileOption = {
17
17
  /** 请求头 */
18
18
  header?: Record<string, string | number>;
19
19
 
20
- /** 额外的formData参数 */
21
- formData?: Record<string, string | number>;
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, formData, timeout = 0 } = option;
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 data = new FormData();
114
- if (formData) {
115
- Object.entries(formData).forEach(([k, v]) => {
116
- if (v !== undefined && v !== null) data.append(k, String(v));
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
- data.append(name, file);
121
+ formData.append(name, file);
122
122
 
123
123
  // 发送请求
124
- xhr.send(data);
124
+ xhr.send(formData);
125
125
  });
126
126
  }
127
127