@tmsfe/tms-core 0.0.197 → 0.0.198

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.197",
3
+ "version": "0.0.198",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -61,7 +61,8 @@ function proxyWxRequest(): void {
61
61
  // 如果用户自定义了dataType或者responseType,则不做处理
62
62
  if (dataType || responseType) {
63
63
  util.reportFunc(url, traceparent, '用户自定义了dataType和responseType');
64
- originalRequestApi.call(this, {
64
+ // 出行业务请求流式接口时要求必须传responseType,所以这里返回 wx.request 的 requestTask,用于监听流式数据
65
+ return originalRequestApi.call(this, {
65
66
  ...originalOptions,
66
67
  success: (res) => {
67
68
  encryptUtil.dealEncryptionSwitch(url, traceId, res.header).then((msg) => {
@@ -71,7 +72,6 @@ function proxyWxRequest(): void {
71
72
  },
72
73
  header: { ...header, Traceparent: traceparent },
73
74
  });
74
- return;
75
75
  }
76
76
  // 加密请求数据
77
77
  const { data: formatData, header: formatHeader, cryptoKeyInfo } = util
package/src/request.js CHANGED
@@ -191,6 +191,9 @@ export default class Request {
191
191
  secretKey = '';
192
192
  withAuth = true;
193
193
  baseParam = {};
194
+ enableChunked = false;
195
+ responseType = '';
196
+ enableHttp2 = false;
194
197
 
195
198
  /**
196
199
  * Request 构造函数
@@ -208,6 +211,15 @@ export default class Request {
208
211
  this.withAuth = !!config.withAuth;
209
212
  }
210
213
  this.baseParam = config.baseParam || {};
214
+ if (config.enableChunked) {
215
+ this.enableChunked = !!config.enableChunked;
216
+ }
217
+ if (config.responseType) {
218
+ this.responseType = config.responseType;
219
+ }
220
+ if (config.enableHttp2) {
221
+ this.enableHttp2 = !!config.enableHttp2;
222
+ }
211
223
  }
212
224
 
213
225
  /**
@@ -299,6 +311,18 @@ export default class Request {
299
311
  return this.createRequestTask(path, param, 'POST', header);
300
312
  }
301
313
 
314
+ /**
315
+ * 发送post方式的请求(返回 wx.request 的 requestTask,用于监听流式数据)
316
+ * @memberof Request
317
+ * @param {string} path 请求接口路径
318
+ * @param {object} param 业务参数
319
+ * @param {object} header 自定义请求头
320
+ * @returns {Promise} Promise<WechatMiniprogram.RequestTask>
321
+ */
322
+ execPostTask(path, param, header) {
323
+ return this.createStreamRequestTask(path, param, 'POST', header);
324
+ }
325
+
302
326
  /**
303
327
  * @memberof Request
304
328
  * @param {String} path 请求接口路径
@@ -530,6 +554,33 @@ export default class Request {
530
554
  });
531
555
  });
532
556
  }
557
+
558
+ /**
559
+ * 创建发送请求任务(返回 requestTask,用于流式场景)
560
+ * 不封装为 Promise,直接返回 wx.request 的 requestTask,便于调用方绑定 onChunkReceived
561
+ * @memberof Request
562
+ * @param {string} path 请求接口路径
563
+ * @param {object} param 业务参数
564
+ * @param {string} method 请求方法 get/post
565
+ * @param {object} header 自定义的请求头
566
+ * @returns {Promise} 返回 wx.request 的 requestTask
567
+ */
568
+ async createStreamRequestTask(path, param = {}, method = 'POST', header = {}) {
569
+ const requestParam = await composeParam(param, this.withAuth, this.baseParam);
570
+ const data = sign(requestParam, this.secretKey);
571
+
572
+ // 返回原始 requestTask,供外部绑定 onChunkReceived
573
+ const requestTask = wx.request({
574
+ url: this.makeUrl(path),
575
+ header,
576
+ method,
577
+ data,
578
+ enableHttp2: this.enableHttp2,
579
+ enableChunked: this.enableChunked,
580
+ responseType: this.responseType,
581
+ });
582
+ return requestTask;
583
+ }
533
584
  }
534
585
 
535
586
  /**