@tarojs/taro-h5 3.5.6 → 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/base/weapp/life-cycle.d.ts +3 -6
- package/dist/api/base/weapp/life-cycle.js +14 -3
- 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 +308 -924
- package/dist/index.cjs.js +155 -131
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.d.ts +308 -924
- package/dist/index.esm.js +155 -131
- package/dist/index.esm.js.map +1 -1
- package/dist/taroApis.d.ts +307 -921
- 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
|
/** 微信设置的语言 */
|
|
@@ -791,9 +801,20 @@ const offAppHide = callback => {
|
|
|
791
801
|
}
|
|
792
802
|
};
|
|
793
803
|
|
|
804
|
+
const launchOptions = {
|
|
805
|
+
path: '',
|
|
806
|
+
query: {},
|
|
807
|
+
scene: 0,
|
|
808
|
+
shareTicket: '',
|
|
809
|
+
referrerInfo: {}
|
|
810
|
+
};
|
|
811
|
+
function initLaunchOptions(options = {}) {
|
|
812
|
+
Object.assign(launchOptions, options);
|
|
813
|
+
}
|
|
814
|
+
Taro.eventCenter.once('__taroRouterLaunch', initLaunchOptions);
|
|
794
815
|
// 生命周期
|
|
795
|
-
const getLaunchOptionsSync =
|
|
796
|
-
const getEnterOptionsSync =
|
|
816
|
+
const getLaunchOptionsSync = () => launchOptions;
|
|
817
|
+
const getEnterOptionsSync = () => launchOptions;
|
|
797
818
|
|
|
798
819
|
// TODO env 环境变量
|
|
799
820
|
const canIUse = temporarilyNotSupport('canIUse');
|
|
@@ -994,7 +1015,7 @@ class CanvasContext {
|
|
|
994
1015
|
return radialGradient;
|
|
995
1016
|
}
|
|
996
1017
|
createLinearGradient(x0, y0, x1, y1) {
|
|
997
|
-
return this.createLinearGradient(x0, y0, x1, y1);
|
|
1018
|
+
return this.ctx.createLinearGradient(x0, y0, x1, y1);
|
|
998
1019
|
}
|
|
999
1020
|
}
|
|
1000
1021
|
|
|
@@ -2631,7 +2652,7 @@ const convertObjectUrlToBlob = url => {
|
|
|
2631
2652
|
});
|
|
2632
2653
|
};
|
|
2633
2654
|
|
|
2634
|
-
const createDownloadTask = ({ url, header, success, error }) => {
|
|
2655
|
+
const createDownloadTask = ({ url, header, withCredentials = true, success, error }) => {
|
|
2635
2656
|
let timeout;
|
|
2636
2657
|
const apiName = 'downloadFile';
|
|
2637
2658
|
const xhr = new XMLHttpRequest();
|
|
@@ -2640,7 +2661,7 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
2640
2661
|
progressUpdate: new CallbackManager()
|
|
2641
2662
|
};
|
|
2642
2663
|
xhr.open('GET', url, true);
|
|
2643
|
-
xhr.withCredentials =
|
|
2664
|
+
xhr.withCredentials = !!withCredentials;
|
|
2644
2665
|
xhr.responseType = 'blob';
|
|
2645
2666
|
setHeader(xhr, header);
|
|
2646
2667
|
xhr.onprogress = e => {
|
|
@@ -2731,12 +2752,13 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
2731
2752
|
* 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
|
|
2732
2753
|
* 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
|
|
2733
2754
|
*/
|
|
2734
|
-
const downloadFile = ({ url, header, success, fail, complete }) => {
|
|
2755
|
+
const downloadFile = ({ url, header, withCredentials, success, fail, complete }) => {
|
|
2735
2756
|
let task;
|
|
2736
2757
|
const result = new Promise((resolve, reject) => {
|
|
2737
2758
|
task = createDownloadTask({
|
|
2738
2759
|
url,
|
|
2739
2760
|
header,
|
|
2761
|
+
withCredentials,
|
|
2740
2762
|
success: res => {
|
|
2741
2763
|
success && success(res);
|
|
2742
2764
|
complete && complete(res);
|
|
@@ -2858,15 +2880,14 @@ function _request(options) {
|
|
|
2858
2880
|
for (const key of response.headers.keys()) {
|
|
2859
2881
|
res.header[key] = response.headers.get(key);
|
|
2860
2882
|
}
|
|
2861
|
-
if (!response.ok) {
|
|
2862
|
-
throw response;
|
|
2863
|
-
}
|
|
2864
2883
|
if (options.responseType === 'arraybuffer') {
|
|
2865
2884
|
return response.arrayBuffer();
|
|
2866
2885
|
}
|
|
2867
2886
|
if (res.statusCode !== 204) {
|
|
2868
2887
|
if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
|
|
2869
|
-
return response.json()
|
|
2888
|
+
return response.json().catch(() => {
|
|
2889
|
+
return null;
|
|
2890
|
+
});
|
|
2870
2891
|
}
|
|
2871
2892
|
}
|
|
2872
2893
|
if (options.responseType === 'text' || options.dataType === 'text') {
|
|
@@ -2883,6 +2904,8 @@ function _request(options) {
|
|
|
2883
2904
|
.catch(err => {
|
|
2884
2905
|
typeof fail === 'function' && fail(err);
|
|
2885
2906
|
typeof complete === 'function' && complete(res);
|
|
2907
|
+
err.statusCode = res.statusCode;
|
|
2908
|
+
err.errMsg = err.message;
|
|
2886
2909
|
return Promise.reject(err);
|
|
2887
2910
|
});
|
|
2888
2911
|
}
|
|
@@ -2899,7 +2922,7 @@ const createTCPSocket = temporarilyNotSupport('createTCPSocket');
|
|
|
2899
2922
|
// UDP 通信
|
|
2900
2923
|
const createUDPSocket = temporarilyNotSupport('createUDPSocket');
|
|
2901
2924
|
|
|
2902
|
-
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 }) => {
|
|
2903
2926
|
let timeoutInter;
|
|
2904
2927
|
let formKey;
|
|
2905
2928
|
const apiName = 'uploadFile';
|
|
@@ -2910,7 +2933,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
|
|
|
2910
2933
|
progressUpdate: new CallbackManager()
|
|
2911
2934
|
};
|
|
2912
2935
|
xhr.open('POST', url);
|
|
2913
|
-
xhr.withCredentials =
|
|
2936
|
+
xhr.withCredentials = !!withCredentials;
|
|
2914
2937
|
setHeader(xhr, header);
|
|
2915
2938
|
for (formKey in formData) {
|
|
2916
2939
|
form.append(formKey, formData[formKey]);
|
|
@@ -3016,7 +3039,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
|
|
|
3016
3039
|
/**
|
|
3017
3040
|
* 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
|
|
3018
3041
|
*/
|
|
3019
|
-
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 }) => {
|
|
3020
3043
|
let task;
|
|
3021
3044
|
const result = new Promise((resolve, reject) => {
|
|
3022
3045
|
task = createUploadTask({
|
|
@@ -3027,6 +3050,7 @@ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName,
|
|
|
3027
3050
|
formData,
|
|
3028
3051
|
timeout,
|
|
3029
3052
|
fileName,
|
|
3053
|
+
withCredentials,
|
|
3030
3054
|
success: res => {
|
|
3031
3055
|
success && success(res);
|
|
3032
3056
|
complete && complete(res);
|