@tarojs/taro-h5 3.5.6 → 3.5.7-alpha.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/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 +8 -4
package/dist/index.cjs.js
CHANGED
|
@@ -16,6 +16,87 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
16
16
|
var Taro__default = /*#__PURE__*/_interopDefaultLegacy(Taro);
|
|
17
17
|
var jsonpRetry__default = /*#__PURE__*/_interopDefaultLegacy(jsonpRetry);
|
|
18
18
|
|
|
19
|
+
class MethodHandler {
|
|
20
|
+
constructor({ name, success, fail, complete }) {
|
|
21
|
+
this.methodName = name;
|
|
22
|
+
this.__success = success;
|
|
23
|
+
this.__fail = fail;
|
|
24
|
+
this.__complete = complete;
|
|
25
|
+
}
|
|
26
|
+
success(res = {}, resolve = Promise.resolve.bind(Promise)) {
|
|
27
|
+
if (!res.errMsg) {
|
|
28
|
+
res.errMsg = `${this.methodName}:ok`;
|
|
29
|
+
}
|
|
30
|
+
typeof this.__success === 'function' && this.__success(res);
|
|
31
|
+
typeof this.__complete === 'function' && this.__complete(res);
|
|
32
|
+
return resolve(res);
|
|
33
|
+
}
|
|
34
|
+
fail(res = {}, reject = Promise.reject.bind(Promise)) {
|
|
35
|
+
if (!res.errMsg) {
|
|
36
|
+
res.errMsg = `${this.methodName}:fail`;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
|
|
40
|
+
}
|
|
41
|
+
console.error(res.errMsg);
|
|
42
|
+
typeof this.__fail === 'function' && this.__fail(res);
|
|
43
|
+
typeof this.__complete === 'function' && this.__complete(res);
|
|
44
|
+
return reject(res);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class CallbackManager {
|
|
48
|
+
constructor() {
|
|
49
|
+
this.callbacks = [];
|
|
50
|
+
/**
|
|
51
|
+
* 添加回调
|
|
52
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
53
|
+
*/
|
|
54
|
+
this.add = (opt) => {
|
|
55
|
+
if (opt)
|
|
56
|
+
this.callbacks.push(opt);
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 移除回调
|
|
60
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
61
|
+
*/
|
|
62
|
+
this.remove = (opt) => {
|
|
63
|
+
if (opt) {
|
|
64
|
+
let pos = -1;
|
|
65
|
+
this.callbacks.forEach((callback, k) => {
|
|
66
|
+
if (callback === opt) {
|
|
67
|
+
pos = k;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (pos > -1) {
|
|
71
|
+
this.callbacks.splice(pos, 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* 获取回调函数数量
|
|
77
|
+
* @return {number}
|
|
78
|
+
*/
|
|
79
|
+
this.count = () => {
|
|
80
|
+
return this.callbacks.length;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* 触发回调
|
|
84
|
+
* @param {...any} args 回调的调用参数
|
|
85
|
+
*/
|
|
86
|
+
this.trigger = (...args) => {
|
|
87
|
+
this.callbacks.forEach(opt => {
|
|
88
|
+
if (typeof opt === 'function') {
|
|
89
|
+
opt(...args);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const { callback, ctx } = opt;
|
|
93
|
+
typeof callback === 'function' && callback.call(ctx, ...args);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
19
100
|
/**
|
|
20
101
|
* ease-in-out的函数
|
|
21
102
|
* @param t 0-1的数字
|
|
@@ -70,6 +151,7 @@ const isValidColor = (color) => {
|
|
|
70
151
|
};
|
|
71
152
|
|
|
72
153
|
/* eslint-disable prefer-promise-reject-errors */
|
|
154
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
73
155
|
function shouldBeObject(target) {
|
|
74
156
|
if (target && typeof target === 'object')
|
|
75
157
|
return { flag: true };
|
|
@@ -137,54 +219,63 @@ function serializeParams(params) {
|
|
|
137
219
|
: encodeURIComponent(params[key])}`))
|
|
138
220
|
.join('&');
|
|
139
221
|
}
|
|
140
|
-
function temporarilyNotSupport(
|
|
141
|
-
return () => {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
222
|
+
function temporarilyNotSupport(name = '') {
|
|
223
|
+
return (option = {}, ...args) => {
|
|
224
|
+
const { success, fail, complete } = option;
|
|
225
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
226
|
+
const errMsg = '暂时不支持 API';
|
|
227
|
+
Taro__default["default"].eventCenter.trigger('__taroNotSupport', {
|
|
228
|
+
name,
|
|
229
|
+
args: [option, ...args],
|
|
230
|
+
type: 'method',
|
|
231
|
+
category: 'temporarily',
|
|
232
|
+
});
|
|
233
|
+
if (isProd) {
|
|
234
|
+
console.warn(errMsg);
|
|
235
|
+
return handle.success({ errMsg });
|
|
148
236
|
}
|
|
149
237
|
else {
|
|
150
|
-
|
|
151
|
-
return Promise.resolve({
|
|
152
|
-
errMsg
|
|
153
|
-
});
|
|
238
|
+
return handle.fail({ errMsg });
|
|
154
239
|
}
|
|
155
240
|
};
|
|
156
241
|
}
|
|
157
|
-
function weixinCorpSupport(
|
|
158
|
-
return () => {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
242
|
+
function weixinCorpSupport(name) {
|
|
243
|
+
return (option = {}, ...args) => {
|
|
244
|
+
const { success, fail, complete } = option;
|
|
245
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
246
|
+
const errMsg = 'h5 端当前仅在微信公众号 JS-SDK 环境下支持此 API';
|
|
247
|
+
Taro__default["default"].eventCenter.trigger('__taroNotSupport', {
|
|
248
|
+
name,
|
|
249
|
+
args: [option, ...args],
|
|
250
|
+
type: 'method',
|
|
251
|
+
category: 'weixin_corp',
|
|
252
|
+
});
|
|
253
|
+
if (isProd) {
|
|
254
|
+
console.warn(errMsg);
|
|
255
|
+
return handle.success({ errMsg });
|
|
165
256
|
}
|
|
166
257
|
else {
|
|
167
|
-
|
|
168
|
-
return Promise.resolve({
|
|
169
|
-
errMsg
|
|
170
|
-
});
|
|
258
|
+
return handle.fail({ errMsg });
|
|
171
259
|
}
|
|
172
260
|
};
|
|
173
261
|
}
|
|
174
|
-
function permanentlyNotSupport(
|
|
175
|
-
return () => {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
262
|
+
function permanentlyNotSupport(name = '') {
|
|
263
|
+
return (option = {}, ...args) => {
|
|
264
|
+
const { success, fail, complete } = option;
|
|
265
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
266
|
+
const errMsg = '不支持 API';
|
|
267
|
+
Taro__default["default"].eventCenter.trigger('__taroNotSupport', {
|
|
268
|
+
name,
|
|
269
|
+
args: [option, ...args],
|
|
270
|
+
type: 'method',
|
|
271
|
+
category: 'permanently',
|
|
272
|
+
});
|
|
273
|
+
if (isProd) {
|
|
274
|
+
console.warn(errMsg);
|
|
275
|
+
return handle.success({ errMsg });
|
|
182
276
|
}
|
|
183
277
|
else {
|
|
184
|
-
|
|
185
|
-
return Promise.resolve({
|
|
186
|
-
errMsg
|
|
187
|
-
});
|
|
278
|
+
return handle.fail({ errMsg });
|
|
188
279
|
}
|
|
189
280
|
};
|
|
190
281
|
}
|
|
@@ -468,87 +559,6 @@ function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
|
468
559
|
return value;
|
|
469
560
|
}
|
|
470
561
|
|
|
471
|
-
class MethodHandler {
|
|
472
|
-
constructor({ name, success, fail, complete }) {
|
|
473
|
-
this.methodName = name;
|
|
474
|
-
this.__success = success;
|
|
475
|
-
this.__fail = fail;
|
|
476
|
-
this.__complete = complete;
|
|
477
|
-
}
|
|
478
|
-
success(res = {}, resolve = Promise.resolve.bind(Promise)) {
|
|
479
|
-
if (!res.errMsg) {
|
|
480
|
-
res.errMsg = `${this.methodName}:ok`;
|
|
481
|
-
}
|
|
482
|
-
typeof this.__success === 'function' && this.__success(res);
|
|
483
|
-
typeof this.__complete === 'function' && this.__complete(res);
|
|
484
|
-
return resolve(res);
|
|
485
|
-
}
|
|
486
|
-
fail(res = {}, reject = Promise.reject.bind(Promise)) {
|
|
487
|
-
if (!res.errMsg) {
|
|
488
|
-
res.errMsg = `${this.methodName}:fail`;
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
|
|
492
|
-
}
|
|
493
|
-
console.error(res.errMsg);
|
|
494
|
-
typeof this.__fail === 'function' && this.__fail(res);
|
|
495
|
-
typeof this.__complete === 'function' && this.__complete(res);
|
|
496
|
-
return reject(res);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
class CallbackManager {
|
|
500
|
-
constructor() {
|
|
501
|
-
this.callbacks = [];
|
|
502
|
-
/**
|
|
503
|
-
* 添加回调
|
|
504
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
505
|
-
*/
|
|
506
|
-
this.add = (opt) => {
|
|
507
|
-
if (opt)
|
|
508
|
-
this.callbacks.push(opt);
|
|
509
|
-
};
|
|
510
|
-
/**
|
|
511
|
-
* 移除回调
|
|
512
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
513
|
-
*/
|
|
514
|
-
this.remove = (opt) => {
|
|
515
|
-
if (opt) {
|
|
516
|
-
let pos = -1;
|
|
517
|
-
this.callbacks.forEach((callback, k) => {
|
|
518
|
-
if (callback === opt) {
|
|
519
|
-
pos = k;
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
if (pos > -1) {
|
|
523
|
-
this.callbacks.splice(pos, 1);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
/**
|
|
528
|
-
* 获取回调函数数量
|
|
529
|
-
* @return {number}
|
|
530
|
-
*/
|
|
531
|
-
this.count = () => {
|
|
532
|
-
return this.callbacks.length;
|
|
533
|
-
};
|
|
534
|
-
/**
|
|
535
|
-
* 触发回调
|
|
536
|
-
* @param {...any} args 回调的调用参数
|
|
537
|
-
*/
|
|
538
|
-
this.trigger = (...args) => {
|
|
539
|
-
this.callbacks.forEach(opt => {
|
|
540
|
-
if (typeof opt === 'function') {
|
|
541
|
-
opt(...args);
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
const { callback, ctx } = opt;
|
|
545
|
-
typeof callback === 'function' && callback.call(ctx, ...args);
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
562
|
/** 跳转系统蓝牙设置页 */
|
|
553
563
|
const openSystemBluetoothSetting = temporarilyNotSupport('openSystemBluetoothSetting');
|
|
554
564
|
/** 跳转系统微信授权管理页 */
|
|
@@ -625,7 +635,7 @@ const getAppBaseInfo = () => {
|
|
|
625
635
|
/** 客户端基础库版本 */
|
|
626
636
|
SDKVersion: '',
|
|
627
637
|
/** 是否已打开调试。可通过右上角菜单或 [Taro.setEnableDebug](/docs/apis/base/debug/setEnableDebug) 打开调试。 */
|
|
628
|
-
enableDebug: process.env.NODE_ENV
|
|
638
|
+
enableDebug: process.env.NODE_ENV !== 'production',
|
|
629
639
|
/** 当前小程序运行的宿主环境 */
|
|
630
640
|
// host: { appId: '' },
|
|
631
641
|
/** 微信设置的语言 */
|
|
@@ -799,9 +809,20 @@ const offAppHide = callback => {
|
|
|
799
809
|
}
|
|
800
810
|
};
|
|
801
811
|
|
|
812
|
+
const launchOptions = {
|
|
813
|
+
path: '',
|
|
814
|
+
query: {},
|
|
815
|
+
scene: 0,
|
|
816
|
+
shareTicket: '',
|
|
817
|
+
referrerInfo: {}
|
|
818
|
+
};
|
|
819
|
+
function initLaunchOptions(options = {}) {
|
|
820
|
+
Object.assign(launchOptions, options);
|
|
821
|
+
}
|
|
822
|
+
Taro__default["default"].eventCenter.once('__taroRouterLaunch', initLaunchOptions);
|
|
802
823
|
// 生命周期
|
|
803
|
-
const getLaunchOptionsSync =
|
|
804
|
-
const getEnterOptionsSync =
|
|
824
|
+
const getLaunchOptionsSync = () => launchOptions;
|
|
825
|
+
const getEnterOptionsSync = () => launchOptions;
|
|
805
826
|
|
|
806
827
|
// TODO env 环境变量
|
|
807
828
|
const canIUse = temporarilyNotSupport('canIUse');
|
|
@@ -1002,7 +1023,7 @@ class CanvasContext {
|
|
|
1002
1023
|
return radialGradient;
|
|
1003
1024
|
}
|
|
1004
1025
|
createLinearGradient(x0, y0, x1, y1) {
|
|
1005
|
-
return this.createLinearGradient(x0, y0, x1, y1);
|
|
1026
|
+
return this.ctx.createLinearGradient(x0, y0, x1, y1);
|
|
1006
1027
|
}
|
|
1007
1028
|
}
|
|
1008
1029
|
|
|
@@ -2639,7 +2660,7 @@ const convertObjectUrlToBlob = url => {
|
|
|
2639
2660
|
});
|
|
2640
2661
|
};
|
|
2641
2662
|
|
|
2642
|
-
const createDownloadTask = ({ url, header, success, error }) => {
|
|
2663
|
+
const createDownloadTask = ({ url, header, withCredentials = true, success, error }) => {
|
|
2643
2664
|
let timeout;
|
|
2644
2665
|
const apiName = 'downloadFile';
|
|
2645
2666
|
const xhr = new XMLHttpRequest();
|
|
@@ -2648,7 +2669,7 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
2648
2669
|
progressUpdate: new CallbackManager()
|
|
2649
2670
|
};
|
|
2650
2671
|
xhr.open('GET', url, true);
|
|
2651
|
-
xhr.withCredentials =
|
|
2672
|
+
xhr.withCredentials = !!withCredentials;
|
|
2652
2673
|
xhr.responseType = 'blob';
|
|
2653
2674
|
setHeader(xhr, header);
|
|
2654
2675
|
xhr.onprogress = e => {
|
|
@@ -2739,12 +2760,13 @@ const createDownloadTask = ({ url, header, success, error }) => {
|
|
|
2739
2760
|
* 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径。使用前请注意阅读相关说明。
|
|
2740
2761
|
* 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。
|
|
2741
2762
|
*/
|
|
2742
|
-
const downloadFile = ({ url, header, success, fail, complete }) => {
|
|
2763
|
+
const downloadFile = ({ url, header, withCredentials, success, fail, complete }) => {
|
|
2743
2764
|
let task;
|
|
2744
2765
|
const result = new Promise((resolve, reject) => {
|
|
2745
2766
|
task = createDownloadTask({
|
|
2746
2767
|
url,
|
|
2747
2768
|
header,
|
|
2769
|
+
withCredentials,
|
|
2748
2770
|
success: res => {
|
|
2749
2771
|
success && success(res);
|
|
2750
2772
|
complete && complete(res);
|
|
@@ -2866,15 +2888,14 @@ function _request(options) {
|
|
|
2866
2888
|
for (const key of response.headers.keys()) {
|
|
2867
2889
|
res.header[key] = response.headers.get(key);
|
|
2868
2890
|
}
|
|
2869
|
-
if (!response.ok) {
|
|
2870
|
-
throw response;
|
|
2871
|
-
}
|
|
2872
2891
|
if (options.responseType === 'arraybuffer') {
|
|
2873
2892
|
return response.arrayBuffer();
|
|
2874
2893
|
}
|
|
2875
2894
|
if (res.statusCode !== 204) {
|
|
2876
2895
|
if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
|
|
2877
|
-
return response.json()
|
|
2896
|
+
return response.json().catch(() => {
|
|
2897
|
+
return null;
|
|
2898
|
+
});
|
|
2878
2899
|
}
|
|
2879
2900
|
}
|
|
2880
2901
|
if (options.responseType === 'text' || options.dataType === 'text') {
|
|
@@ -2891,6 +2912,8 @@ function _request(options) {
|
|
|
2891
2912
|
.catch(err => {
|
|
2892
2913
|
typeof fail === 'function' && fail(err);
|
|
2893
2914
|
typeof complete === 'function' && complete(res);
|
|
2915
|
+
err.statusCode = res.statusCode;
|
|
2916
|
+
err.errMsg = err.message;
|
|
2894
2917
|
return Promise.reject(err);
|
|
2895
2918
|
});
|
|
2896
2919
|
}
|
|
@@ -2907,7 +2930,7 @@ const createTCPSocket = temporarilyNotSupport('createTCPSocket');
|
|
|
2907
2930
|
// UDP 通信
|
|
2908
2931
|
const createUDPSocket = temporarilyNotSupport('createUDPSocket');
|
|
2909
2932
|
|
|
2910
|
-
const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, success, error }) => {
|
|
2933
|
+
const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, withCredentials = true, success, error }) => {
|
|
2911
2934
|
let timeoutInter;
|
|
2912
2935
|
let formKey;
|
|
2913
2936
|
const apiName = 'uploadFile';
|
|
@@ -2918,7 +2941,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
|
|
|
2918
2941
|
progressUpdate: new CallbackManager()
|
|
2919
2942
|
};
|
|
2920
2943
|
xhr.open('POST', url);
|
|
2921
|
-
xhr.withCredentials =
|
|
2944
|
+
xhr.withCredentials = !!withCredentials;
|
|
2922
2945
|
setHeader(xhr, header);
|
|
2923
2946
|
for (formKey in formData) {
|
|
2924
2947
|
form.append(formKey, formData[formKey]);
|
|
@@ -3024,7 +3047,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
|
|
|
3024
3047
|
/**
|
|
3025
3048
|
* 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
|
|
3026
3049
|
*/
|
|
3027
|
-
const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
|
|
3050
|
+
const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, withCredentials, success, fail, complete }) => {
|
|
3028
3051
|
let task;
|
|
3029
3052
|
const result = new Promise((resolve, reject) => {
|
|
3030
3053
|
task = createUploadTask({
|
|
@@ -3035,6 +3058,7 @@ const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName,
|
|
|
3035
3058
|
formData,
|
|
3036
3059
|
timeout,
|
|
3037
3060
|
fileName,
|
|
3061
|
+
withCredentials,
|
|
3038
3062
|
success: res => {
|
|
3039
3063
|
success && success(res);
|
|
3040
3064
|
complete && complete(res);
|