@tarojs/taro-h5 3.5.6-alpha.2 → 3.5.7
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/api/ad/index.d.ts +2 -6
- package/dist/api/ai/facial.d.ts +3 -9
- package/dist/api/ai/visual.d.ts +2 -6
- package/dist/api/alipay/index.d.ts +1 -3
- package/dist/api/base/crypto.d.ts +1 -3
- package/dist/api/base/debug.d.ts +3 -9
- package/dist/api/base/index.d.ts +1 -3
- package/dist/api/base/performance.d.ts +2 -6
- package/dist/api/base/system.d.ts +2 -8
- package/dist/api/base/system.js +1 -1
- package/dist/api/base/update.d.ts +2 -6
- package/dist/api/base/weapp/app-event.d.ts +12 -36
- package/dist/api/canvas/CanvasContext.js +1 -1
- package/dist/api/canvas/index.d.ts +1 -3
- package/dist/api/cloud/index.d.ts +9 -27
- package/dist/api/data-analysis/index.d.ts +4 -12
- package/dist/api/device/accessibility.d.ts +1 -3
- package/dist/api/device/battery.d.ts +1 -3
- package/dist/api/device/bluetooth-ble.d.ts +16 -48
- package/dist/api/device/bluetooth-peripheral.d.ts +3 -9
- package/dist/api/device/bluetooth.d.ts +13 -39
- package/dist/api/device/calendar.d.ts +2 -6
- package/dist/api/device/contact.d.ts +2 -6
- package/dist/api/device/crypto.d.ts +1 -3
- package/dist/api/device/gyroscope.d.ts +4 -12
- package/dist/api/device/iBeacon.d.ts +7 -21
- package/dist/api/device/keyboard.d.ts +4 -12
- package/dist/api/device/memory.d.ts +2 -6
- package/dist/api/device/network.d.ts +3 -9
- package/dist/api/device/nfc.d.ts +7 -21
- package/dist/api/device/screen.d.ts +6 -18
- package/dist/api/device/wifi.d.ts +11 -33
- package/dist/api/ext/index.d.ts +2 -6
- package/dist/api/files/index.d.ts +8 -24
- package/dist/api/location/index.d.ts +9 -27
- package/dist/api/media/EditorContext.d.ts +13 -39
- package/dist/api/media/audio/index.d.ts +8 -24
- package/dist/api/media/background-audio/BackgroundAudioManager.d.ts +4 -12
- package/dist/api/media/background-audio/index.d.ts +8 -24
- package/dist/api/media/camera.d.ts +1 -3
- package/dist/api/media/image/index.d.ts +4 -12
- package/dist/api/media/live.d.ts +2 -6
- package/dist/api/media/map.d.ts +1 -3
- package/dist/api/media/media-recorder.d.ts +1 -3
- package/dist/api/media/recorder.d.ts +3 -9
- package/dist/api/media/video/index.d.ts +5 -15
- package/dist/api/media/video-decoder.d.ts +1 -3
- package/dist/api/media/video-processing.d.ts +1 -3
- package/dist/api/media/voip.d.ts +14 -42
- package/dist/api/navigate/index.d.ts +5 -15
- package/dist/api/network/download.js +4 -3
- package/dist/api/network/mdns.d.ts +10 -30
- package/dist/api/network/request/index.js +5 -4
- package/dist/api/network/tcp.d.ts +1 -3
- package/dist/api/network/udp.d.ts +1 -3
- package/dist/api/network/upload.js +4 -3
- package/dist/api/open-api/account.d.ts +1 -3
- package/dist/api/open-api/address.d.ts +1 -3
- package/dist/api/open-api/authorize.d.ts +2 -6
- package/dist/api/open-api/card.d.ts +2 -6
- package/dist/api/open-api/channels-live.d.ts +6 -18
- package/dist/api/open-api/customer-service.d.ts +1 -3
- package/dist/api/open-api/facial.d.ts +4 -12
- package/dist/api/open-api/favorites.d.ts +2 -6
- package/dist/api/open-api/group.d.ts +1 -3
- package/dist/api/open-api/invoice.d.ts +2 -6
- package/dist/api/open-api/license-plate.d.ts +1 -3
- package/dist/api/open-api/login.d.ts +3 -9
- package/dist/api/open-api/red-package.d.ts +1 -3
- package/dist/api/open-api/settings.d.ts +2 -6
- package/dist/api/open-api/soter.d.ts +3 -9
- package/dist/api/open-api/subscribe-message.d.ts +1 -3
- package/dist/api/open-api/user-info.d.ts +2 -6
- package/dist/api/open-api/werun.d.ts +2 -6
- package/dist/api/payment/index.d.ts +2 -6
- package/dist/api/share/index.d.ts +10 -30
- package/dist/api/storage/background-fetch.d.ts +4 -12
- package/dist/api/storage/index.d.ts +2 -6
- package/dist/api/swan/index.d.ts +21 -63
- package/dist/api/taro.d.ts +1 -3
- package/dist/api/ui/background.d.ts +2 -6
- package/dist/api/ui/interaction/index.d.ts +2 -6
- package/dist/api/ui/menu.d.ts +1 -3
- package/dist/api/ui/navigation-bar/index.d.ts +3 -9
- package/dist/api/ui/sticky.d.ts +1 -3
- package/dist/api/ui/window.d.ts +1 -3
- package/dist/api/worker/index.d.ts +1 -3
- package/dist/api/wxml/index.d.ts +1 -3
- package/dist/index.cjs.d.ts +306 -918
- package/dist/index.cjs.js +142 -129
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.d.ts +306 -918
- package/dist/index.esm.js +142 -129
- package/dist/index.esm.js.map +1 -1
- package/dist/taroApis.d.ts +305 -915
- package/dist/utils/index.d.ts +4 -9
- package/dist/utils/index.js +48 -36
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -8,6 +8,87 @@ import { parse, stringify } from 'query-string';
|
|
|
8
8
|
import 'whatwg-fetch';
|
|
9
9
|
import jsonpRetry from 'jsonp-retry';
|
|
10
10
|
|
|
11
|
+
class MethodHandler {
|
|
12
|
+
constructor({ name, success, fail, complete }) {
|
|
13
|
+
this.methodName = name;
|
|
14
|
+
this.__success = success;
|
|
15
|
+
this.__fail = fail;
|
|
16
|
+
this.__complete = complete;
|
|
17
|
+
}
|
|
18
|
+
success(res = {}, resolve = Promise.resolve.bind(Promise)) {
|
|
19
|
+
if (!res.errMsg) {
|
|
20
|
+
res.errMsg = `${this.methodName}:ok`;
|
|
21
|
+
}
|
|
22
|
+
typeof this.__success === 'function' && this.__success(res);
|
|
23
|
+
typeof this.__complete === 'function' && this.__complete(res);
|
|
24
|
+
return resolve(res);
|
|
25
|
+
}
|
|
26
|
+
fail(res = {}, reject = Promise.reject.bind(Promise)) {
|
|
27
|
+
if (!res.errMsg) {
|
|
28
|
+
res.errMsg = `${this.methodName}:fail`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
|
|
32
|
+
}
|
|
33
|
+
console.error(res.errMsg);
|
|
34
|
+
typeof this.__fail === 'function' && this.__fail(res);
|
|
35
|
+
typeof this.__complete === 'function' && this.__complete(res);
|
|
36
|
+
return reject(res);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class CallbackManager {
|
|
40
|
+
constructor() {
|
|
41
|
+
this.callbacks = [];
|
|
42
|
+
/**
|
|
43
|
+
* 添加回调
|
|
44
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
45
|
+
*/
|
|
46
|
+
this.add = (opt) => {
|
|
47
|
+
if (opt)
|
|
48
|
+
this.callbacks.push(opt);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 移除回调
|
|
52
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
53
|
+
*/
|
|
54
|
+
this.remove = (opt) => {
|
|
55
|
+
if (opt) {
|
|
56
|
+
let pos = -1;
|
|
57
|
+
this.callbacks.forEach((callback, k) => {
|
|
58
|
+
if (callback === opt) {
|
|
59
|
+
pos = k;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (pos > -1) {
|
|
63
|
+
this.callbacks.splice(pos, 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 获取回调函数数量
|
|
69
|
+
* @return {number}
|
|
70
|
+
*/
|
|
71
|
+
this.count = () => {
|
|
72
|
+
return this.callbacks.length;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 触发回调
|
|
76
|
+
* @param {...any} args 回调的调用参数
|
|
77
|
+
*/
|
|
78
|
+
this.trigger = (...args) => {
|
|
79
|
+
this.callbacks.forEach(opt => {
|
|
80
|
+
if (typeof opt === 'function') {
|
|
81
|
+
opt(...args);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const { callback, ctx } = opt;
|
|
85
|
+
typeof callback === 'function' && callback.call(ctx, ...args);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
11
92
|
/**
|
|
12
93
|
* ease-in-out的函数
|
|
13
94
|
* @param t 0-1的数字
|
|
@@ -62,6 +143,7 @@ const isValidColor = (color) => {
|
|
|
62
143
|
};
|
|
63
144
|
|
|
64
145
|
/* eslint-disable prefer-promise-reject-errors */
|
|
146
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
65
147
|
function shouldBeObject(target) {
|
|
66
148
|
if (target && typeof target === 'object')
|
|
67
149
|
return { flag: true };
|
|
@@ -129,54 +211,63 @@ function serializeParams(params) {
|
|
|
129
211
|
: encodeURIComponent(params[key])}`))
|
|
130
212
|
.join('&');
|
|
131
213
|
}
|
|
132
|
-
function temporarilyNotSupport(
|
|
133
|
-
return () => {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
214
|
+
function temporarilyNotSupport(name = '') {
|
|
215
|
+
return (option = {}, ...args) => {
|
|
216
|
+
const { success, fail, complete } = option;
|
|
217
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
218
|
+
const errMsg = '暂时不支持 API';
|
|
219
|
+
Taro.eventCenter.trigger('__taroNotSupport', {
|
|
220
|
+
name,
|
|
221
|
+
args: [option, ...args],
|
|
222
|
+
type: 'method',
|
|
223
|
+
category: 'temporarily',
|
|
224
|
+
});
|
|
225
|
+
if (isProd) {
|
|
226
|
+
console.warn(errMsg);
|
|
227
|
+
return handle.success({ errMsg });
|
|
140
228
|
}
|
|
141
229
|
else {
|
|
142
|
-
|
|
143
|
-
return Promise.resolve({
|
|
144
|
-
errMsg
|
|
145
|
-
});
|
|
230
|
+
return handle.fail({ errMsg });
|
|
146
231
|
}
|
|
147
232
|
};
|
|
148
233
|
}
|
|
149
|
-
function weixinCorpSupport(
|
|
150
|
-
return () => {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
234
|
+
function weixinCorpSupport(name) {
|
|
235
|
+
return (option = {}, ...args) => {
|
|
236
|
+
const { success, fail, complete } = option;
|
|
237
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
238
|
+
const errMsg = 'h5 端当前仅在微信公众号 JS-SDK 环境下支持此 API';
|
|
239
|
+
Taro.eventCenter.trigger('__taroNotSupport', {
|
|
240
|
+
name,
|
|
241
|
+
args: [option, ...args],
|
|
242
|
+
type: 'method',
|
|
243
|
+
category: 'weixin_corp',
|
|
244
|
+
});
|
|
245
|
+
if (isProd) {
|
|
246
|
+
console.warn(errMsg);
|
|
247
|
+
return handle.success({ errMsg });
|
|
157
248
|
}
|
|
158
249
|
else {
|
|
159
|
-
|
|
160
|
-
return Promise.resolve({
|
|
161
|
-
errMsg
|
|
162
|
-
});
|
|
250
|
+
return handle.fail({ errMsg });
|
|
163
251
|
}
|
|
164
252
|
};
|
|
165
253
|
}
|
|
166
|
-
function permanentlyNotSupport(
|
|
167
|
-
return () => {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
254
|
+
function permanentlyNotSupport(name = '') {
|
|
255
|
+
return (option = {}, ...args) => {
|
|
256
|
+
const { success, fail, complete } = option;
|
|
257
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
258
|
+
const errMsg = '不支持 API';
|
|
259
|
+
Taro.eventCenter.trigger('__taroNotSupport', {
|
|
260
|
+
name,
|
|
261
|
+
args: [option, ...args],
|
|
262
|
+
type: 'method',
|
|
263
|
+
category: 'permanently',
|
|
264
|
+
});
|
|
265
|
+
if (isProd) {
|
|
266
|
+
console.warn(errMsg);
|
|
267
|
+
return handle.success({ errMsg });
|
|
174
268
|
}
|
|
175
269
|
else {
|
|
176
|
-
|
|
177
|
-
return Promise.resolve({
|
|
178
|
-
errMsg
|
|
179
|
-
});
|
|
270
|
+
return handle.fail({ errMsg });
|
|
180
271
|
}
|
|
181
272
|
};
|
|
182
273
|
}
|
|
@@ -460,87 +551,6 @@ function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
|
460
551
|
return value;
|
|
461
552
|
}
|
|
462
553
|
|
|
463
|
-
class MethodHandler {
|
|
464
|
-
constructor({ name, success, fail, complete }) {
|
|
465
|
-
this.methodName = name;
|
|
466
|
-
this.__success = success;
|
|
467
|
-
this.__fail = fail;
|
|
468
|
-
this.__complete = complete;
|
|
469
|
-
}
|
|
470
|
-
success(res = {}, resolve = Promise.resolve.bind(Promise)) {
|
|
471
|
-
if (!res.errMsg) {
|
|
472
|
-
res.errMsg = `${this.methodName}:ok`;
|
|
473
|
-
}
|
|
474
|
-
typeof this.__success === 'function' && this.__success(res);
|
|
475
|
-
typeof this.__complete === 'function' && this.__complete(res);
|
|
476
|
-
return resolve(res);
|
|
477
|
-
}
|
|
478
|
-
fail(res = {}, reject = Promise.reject.bind(Promise)) {
|
|
479
|
-
if (!res.errMsg) {
|
|
480
|
-
res.errMsg = `${this.methodName}:fail`;
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
|
|
484
|
-
}
|
|
485
|
-
console.error(res.errMsg);
|
|
486
|
-
typeof this.__fail === 'function' && this.__fail(res);
|
|
487
|
-
typeof this.__complete === 'function' && this.__complete(res);
|
|
488
|
-
return reject(res);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
class CallbackManager {
|
|
492
|
-
constructor() {
|
|
493
|
-
this.callbacks = [];
|
|
494
|
-
/**
|
|
495
|
-
* 添加回调
|
|
496
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
497
|
-
*/
|
|
498
|
-
this.add = (opt) => {
|
|
499
|
-
if (opt)
|
|
500
|
-
this.callbacks.push(opt);
|
|
501
|
-
};
|
|
502
|
-
/**
|
|
503
|
-
* 移除回调
|
|
504
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
505
|
-
*/
|
|
506
|
-
this.remove = (opt) => {
|
|
507
|
-
if (opt) {
|
|
508
|
-
let pos = -1;
|
|
509
|
-
this.callbacks.forEach((callback, k) => {
|
|
510
|
-
if (callback === opt) {
|
|
511
|
-
pos = k;
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
if (pos > -1) {
|
|
515
|
-
this.callbacks.splice(pos, 1);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
/**
|
|
520
|
-
* 获取回调函数数量
|
|
521
|
-
* @return {number}
|
|
522
|
-
*/
|
|
523
|
-
this.count = () => {
|
|
524
|
-
return this.callbacks.length;
|
|
525
|
-
};
|
|
526
|
-
/**
|
|
527
|
-
* 触发回调
|
|
528
|
-
* @param {...any} args 回调的调用参数
|
|
529
|
-
*/
|
|
530
|
-
this.trigger = (...args) => {
|
|
531
|
-
this.callbacks.forEach(opt => {
|
|
532
|
-
if (typeof opt === 'function') {
|
|
533
|
-
opt(...args);
|
|
534
|
-
}
|
|
535
|
-
else {
|
|
536
|
-
const { callback, ctx } = opt;
|
|
537
|
-
typeof callback === 'function' && callback.call(ctx, ...args);
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
554
|
/** 跳转系统蓝牙设置页 */
|
|
545
555
|
const openSystemBluetoothSetting = temporarilyNotSupport('openSystemBluetoothSetting');
|
|
546
556
|
/** 跳转系统微信授权管理页 */
|
|
@@ -617,7 +627,7 @@ const getAppBaseInfo = () => {
|
|
|
617
627
|
/** 客户端基础库版本 */
|
|
618
628
|
SDKVersion: '',
|
|
619
629
|
/** 是否已打开调试。可通过右上角菜单或 [Taro.setEnableDebug](/docs/apis/base/debug/setEnableDebug) 打开调试。 */
|
|
620
|
-
enableDebug: process.env.NODE_ENV
|
|
630
|
+
enableDebug: process.env.NODE_ENV !== 'production',
|
|
621
631
|
/** 当前小程序运行的宿主环境 */
|
|
622
632
|
// host: { appId: '' },
|
|
623
633
|
/** 微信设置的语言 */
|
|
@@ -1005,7 +1015,7 @@ class CanvasContext {
|
|
|
1005
1015
|
return radialGradient;
|
|
1006
1016
|
}
|
|
1007
1017
|
createLinearGradient(x0, y0, x1, y1) {
|
|
1008
|
-
return this.createLinearGradient(x0, y0, x1, y1);
|
|
1018
|
+
return this.ctx.createLinearGradient(x0, y0, x1, y1);
|
|
1009
1019
|
}
|
|
1010
1020
|
}
|
|
1011
1021
|
|
|
@@ -2642,7 +2652,7 @@ const convertObjectUrlToBlob = url => {
|
|
|
2642
2652
|
});
|
|
2643
2653
|
};
|
|
2644
2654
|
|
|
2645
|
-
const createDownloadTask = ({ url, header, success, error }) => {
|
|
2655
|
+
const createDownloadTask = ({ url, header, withCredentials = true, success, error }) => {
|
|
2646
2656
|
let timeout;
|
|
2647
2657
|
const apiName = 'downloadFile';
|
|
2648
2658
|
const xhr = new XMLHttpRequest();
|
|
@@ -2651,7 +2661,7 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
2651
2661
|
progressUpdate: new CallbackManager()
|
|
2652
2662
|
};
|
|
2653
2663
|
xhr.open('GET', url, true);
|
|
2654
|
-
xhr.withCredentials =
|
|
2664
|
+
xhr.withCredentials = !!withCredentials;
|
|
2655
2665
|
xhr.responseType = 'blob';
|
|
2656
2666
|
setHeader(xhr, header);
|
|
2657
2667
|
xhr.onprogress = e => {
|
|
@@ -2742,12 +2752,13 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
2742
2752
|
* 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
|
|
2743
2753
|
* 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
|
|
2744
2754
|
*/
|
|
2745
|
-
const downloadFile = ({ url, header, success, fail, complete }) => {
|
|
2755
|
+
const downloadFile = ({ url, header, withCredentials, success, fail, complete }) => {
|
|
2746
2756
|
let task;
|
|
2747
2757
|
const result = new Promise((resolve, reject) => {
|
|
2748
2758
|
task = createDownloadTask({
|
|
2749
2759
|
url,
|
|
2750
2760
|
header,
|
|
2761
|
+
withCredentials,
|
|
2751
2762
|
success: res => {
|
|
2752
2763
|
success && success(res);
|
|
2753
2764
|
complete && complete(res);
|
|
@@ -2869,15 +2880,14 @@ function _request(options) {
|
|
|
2869
2880
|
for (const key of response.headers.keys()) {
|
|
2870
2881
|
res.header[key] = response.headers.get(key);
|
|
2871
2882
|
}
|
|
2872
|
-
if (!response.ok) {
|
|
2873
|
-
throw response;
|
|
2874
|
-
}
|
|
2875
2883
|
if (options.responseType === 'arraybuffer') {
|
|
2876
2884
|
return response.arrayBuffer();
|
|
2877
2885
|
}
|
|
2878
2886
|
if (res.statusCode !== 204) {
|
|
2879
2887
|
if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
|
|
2880
|
-
return response.json()
|
|
2888
|
+
return response.json().catch(() => {
|
|
2889
|
+
return null;
|
|
2890
|
+
});
|
|
2881
2891
|
}
|
|
2882
2892
|
}
|
|
2883
2893
|
if (options.responseType === 'text' || options.dataType === 'text') {
|
|
@@ -2894,6 +2904,8 @@ function _request(options) {
|
|
|
2894
2904
|
.catch(err => {
|
|
2895
2905
|
typeof fail === 'function' && fail(err);
|
|
2896
2906
|
typeof complete === 'function' && complete(res);
|
|
2907
|
+
err.statusCode = res.statusCode;
|
|
2908
|
+
err.errMsg = err.message;
|
|
2897
2909
|
return Promise.reject(err);
|
|
2898
2910
|
});
|
|
2899
2911
|
}
|
|
@@ -2910,7 +2922,7 @@ const createTCPSocket = temporarilyNotSupport('createTCPSocket');
|
|
|
2910
2922
|
// UDP 通信
|
|
2911
2923
|
const createUDPSocket = temporarilyNotSupport('createUDPSocket');
|
|
2912
2924
|
|
|
2913
|
-
const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, success, error }) => {
|
|
2925
|
+
const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, withCredentials = true, success, error }) => {
|
|
2914
2926
|
let timeoutInter;
|
|
2915
2927
|
let formKey;
|
|
2916
2928
|
const apiName = 'uploadFile';
|
|
@@ -2921,7 +2933,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
|
|
|
2921
2933
|
progressUpdate: new CallbackManager()
|
|
2922
2934
|
};
|
|
2923
2935
|
xhr.open('POST', url);
|
|
2924
|
-
xhr.withCredentials =
|
|
2936
|
+
xhr.withCredentials = !!withCredentials;
|
|
2925
2937
|
setHeader(xhr, header);
|
|
2926
2938
|
for (formKey in formData) {
|
|
2927
2939
|
form.append(formKey, formData[formKey]);
|
|
@@ -3027,7 +3039,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
|
|
|
3027
3039
|
/**
|
|
3028
3040
|
* 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
|
|
3029
3041
|
*/
|
|
3030
|
-
const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
|
|
3042
|
+
const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, withCredentials, success, fail, complete }) => {
|
|
3031
3043
|
let task;
|
|
3032
3044
|
const result = new Promise((resolve, reject) => {
|
|
3033
3045
|
task = createUploadTask({
|
|
@@ -3038,6 +3050,7 @@ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName,
|
|
|
3038
3050
|
formData,
|
|
3039
3051
|
timeout,
|
|
3040
3052
|
fileName,
|
|
3053
|
+
withCredentials,
|
|
3041
3054
|
success: res => {
|
|
3042
3055
|
success && success(res);
|
|
3043
3056
|
complete && complete(res);
|