@tmsfe/tms-core 0.0.198 → 0.0.199
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/package.json +1 -1
- package/src/request.js +36 -16
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -315,12 +315,15 @@ export default class Request {
|
|
|
315
315
|
* 发送post方式的请求(返回 wx.request 的 requestTask,用于监听流式数据)
|
|
316
316
|
* @memberof Request
|
|
317
317
|
* @param {string} path 请求接口路径
|
|
318
|
-
* @param {object}
|
|
319
|
-
* @param {object}
|
|
318
|
+
* @param {object} params 参数
|
|
319
|
+
* @param {object} params.param 业务参数
|
|
320
|
+
* @param {string} params.method 请求方法
|
|
321
|
+
* @param {object} params.header 自定义请求头
|
|
322
|
+
* @param {object} params.callBacks 监听流式数据的回调函数
|
|
320
323
|
* @returns {Promise} Promise<WechatMiniprogram.RequestTask>
|
|
321
324
|
*/
|
|
322
|
-
execPostTask(path,
|
|
323
|
-
return this.createStreamRequestTask(path,
|
|
325
|
+
execPostTask(path, params) {
|
|
326
|
+
return this.createStreamRequestTask(path, params);
|
|
324
327
|
}
|
|
325
328
|
|
|
326
329
|
/**
|
|
@@ -556,20 +559,28 @@ export default class Request {
|
|
|
556
559
|
}
|
|
557
560
|
|
|
558
561
|
/**
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
562
|
+
* 创建发送请求任务(返回 requestTask,用于流式场景)
|
|
563
|
+
* 支持流式输出,同时提供 success、fail 回调
|
|
564
|
+
* @memberof Request
|
|
565
|
+
* @param {string} path 请求接口路径
|
|
566
|
+
* @param {object} params 参数对象
|
|
567
|
+
* @param {object} params.param 业务参数
|
|
568
|
+
* @param {string} params.method 请求方法 get/post
|
|
569
|
+
* @param {object} params.header 自定义的请求头
|
|
570
|
+
* @param {object} params.callbacks 回调函数对象
|
|
571
|
+
* @param {function} data.callbacks.onSuccess 请求成功回调
|
|
572
|
+
* @param {function} data.callbacks.onFail 请求失败回调
|
|
573
|
+
* @param {function} data.callbacks.onComplete 请求完成回调
|
|
574
|
+
* @returns {Promise} 返回 wx.request 的 requestTask
|
|
575
|
+
*/
|
|
576
|
+
async createStreamRequestTask(path, params = {}) {
|
|
577
|
+
const { param = {}, method = 'POST', header = {}, callbacks = {} } = params;
|
|
569
578
|
const requestParam = await composeParam(param, this.withAuth, this.baseParam);
|
|
570
579
|
const data = sign(requestParam, this.secretKey);
|
|
571
580
|
|
|
572
|
-
|
|
581
|
+
const { onSuccess, onFail, onComplete } = callbacks;
|
|
582
|
+
|
|
583
|
+
// 创建 requestTask,支持流式输出 提供onChunkReceived监听、abort中断请求方法
|
|
573
584
|
const requestTask = wx.request({
|
|
574
585
|
url: this.makeUrl(path),
|
|
575
586
|
header,
|
|
@@ -578,11 +589,20 @@ export default class Request {
|
|
|
578
589
|
enableHttp2: this.enableHttp2,
|
|
579
590
|
enableChunked: this.enableChunked,
|
|
580
591
|
responseType: this.responseType,
|
|
592
|
+
success: (res) => {
|
|
593
|
+
onSuccess?.(res);
|
|
594
|
+
},
|
|
595
|
+
fail: (err) => {
|
|
596
|
+
onFail?.(err);
|
|
597
|
+
},
|
|
598
|
+
complete: (res) => {
|
|
599
|
+
onComplete?.(res);
|
|
600
|
+
},
|
|
581
601
|
});
|
|
602
|
+
|
|
582
603
|
return requestTask;
|
|
583
604
|
}
|
|
584
605
|
}
|
|
585
|
-
|
|
586
606
|
/**
|
|
587
607
|
* 判断指定路径是否需要token失效重试
|
|
588
608
|
* @param {string} path 请求路径
|