@conecli/cone-render 0.10.1-shop3.1 → 0.10.1-shop3.11

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.
Files changed (69) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/index.h5.ts +1 -1
  4. package/dist/common/index.jd.ts +1 -1
  5. package/dist/common/index.ts +1 -1
  6. package/dist/common/index.weapp.ts +1 -1
  7. package/dist/common/token/token.jd.ts +1 -1
  8. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  9. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  10. package/dist/components/base/CountDown/index.module.scss +49 -44
  11. package/dist/components/base/CountDown/index.tsx +1 -1
  12. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  13. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  14. package/dist/components/base/Dialog/index.module.scss +11 -0
  15. package/dist/components/base/ExposureSmart/index.h5.module.scss +12 -2
  16. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  17. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  18. package/dist/components/base/InViewRender/index.tsx +1 -1
  19. package/dist/components/base/ItemViewExposureSmart/index.module.scss +2 -2
  20. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  21. package/dist/components/base/Price/Double/index.module.scss +8 -0
  22. package/dist/components/base/Price/Double/index.tsx +1 -1
  23. package/dist/components/floorItem.weapp.tsx +1 -1
  24. package/dist/interface/common.ts +1 -1
  25. package/dist/interface/jumpEventReport.ts +1 -1
  26. package/dist/interface/service.ts +1 -1
  27. package/dist/jumpEventReport/base.ts +1 -1
  28. package/dist/jumpEventReport/const.ts +1 -1
  29. package/dist/jumpEventReport/index.jd.ts +1 -1
  30. package/dist/jumpEventReport/index.weapp.ts +1 -1
  31. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  32. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  33. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  34. package/dist/jumpEventReport/web/report.ts +1 -1
  35. package/dist/jumpEventReport/web.base.ts +1 -1
  36. package/dist/jumpEventReport/web.jd.ts +1 -1
  37. package/dist/jumpEventReport/web.jdb.ts +1 -1
  38. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  39. package/dist/jumpEventReport/web.jxwxapp.ts +1 -1
  40. package/dist/jumpEventReport/web.pc.ts +1 -1
  41. package/dist/jumpEventReport/web.tjapp.ts +1 -1
  42. package/dist/jumpEventReport/web.tjm.ts +1 -1
  43. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  44. package/dist/libs/taroAppReport.js +2 -2
  45. package/dist/modules/ContainerFloorList/index.h5.module.scss +66 -53
  46. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  47. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  48. package/dist/open/api/shopMember.ts +1 -1
  49. package/dist/open/api/util.ts +1 -1
  50. package/dist/sass/app.h5.scss +261 -224
  51. package/dist/sass/base.scss +142 -141
  52. package/dist/service/fetchGateway.ts +1 -1
  53. package/dist/service/fetchGateway.weapp.ts +1 -0
  54. package/dist/service/http/colorSign.ts +1 -1
  55. package/dist/service/http/const.ts +1 -1
  56. package/dist/service/http/h5Http.ts +1 -1
  57. package/dist/service/requestServer.h5.ts +1 -1
  58. package/dist/service/requestServer.ts +1 -1
  59. package/dist/service/requestServer.weapp.ts +1 -0
  60. package/dist/utils/connectNativeJsBridge.ts +1 -1
  61. package/dist/utils/h5Utils.ts +1 -1
  62. package/dist/utils/index.h5.ts +1 -1
  63. package/dist/utils/index.ts +1 -1
  64. package/dist/utils/index.weapp.ts +1 -1
  65. package/dist/utils/jumpExtMapUtil.js +1 -0
  66. package/dist/utils/sColor.js +1 -0
  67. package/dist/utils/utils.ts +1 -1
  68. package/package.json +1 -1
  69. package/dist/utils/memberFormatUtils.js +0 -1
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  isSupportHybridHttpRequest,
3
2
  draInterfaceCustomReport,
4
3
  draBusinessCustomReport,
5
4
  jsonHeader = 'application/json;charset=utf-8',
6
5
  formDataHeader = 'application/x-www-form-urlencoded',
7
6
  HYBRID: 'httpRequest_hybrid',
8
7
  TARO: 'httpRequest_taro',
9
8
  #requestTimeStamp: number
10
9
  #responseTimeStamp: number
11
10
  #getResTimeStamp: number
12
11
  #reportType: string
13
12
  #callbackFunction: string
14
13
 
15
14
  async request({
16
15
  url,
17
16
  method = 'POST',
18
17
  timeout = 7000,
19
18
  isColorVerify = false,
20
19
  ...otherOptions
21
20
  }): Promise<Taro.request.SuccessCallbackResult<any>> {
22
21
  const { header: otherHeader, ...otherOpts } = otherOptions
23
22
  const header = {
24
23
  'content-type':
25
24
  method === 'POST'
26
25
  ? RequestHeaderContentType.formDataHeader
27
26
  : RequestHeaderContentType.jsonHeader,
28
27
  ...otherHeader,
29
28
  }
30
29
  let getRequestUrl = url
31
30
  let requestTask
32
31
  const data = otherOpts?.data
33
32
  const isGatewayRequest =
34
33
  url === this.api.apiFunc && typeof data === 'object'
35
34
  if (isGatewayRequest) {
36
35
  getRequestUrl = this._handleSpecialGatewayUrl(url)
37
36
  const shouldUseHybridRequest = this._shouldUseHybridRequest()
38
37
  if (shouldUseHybridRequest) {
39
38
  requestTask = this._hybridRequest(getRequestUrl, data)
40
39
  } else {
41
40
  otherOpts.data = await this._prepareGatewayReqData(data, isColorVerify)
42
41
  requestTask = this._taroRequest(
43
42
  getRequestUrl,
44
43
  otherOpts,
45
44
  method,
46
45
  timeout,
47
46
  header,
48
47
  )
49
48
  }
50
49
  } else {
51
50
  requestTask = this._taroRequest(
52
51
  getRequestUrl,
53
52
  otherOpts,
54
53
  method,
55
54
  timeout,
56
55
  header,
57
56
  )
58
57
  }
59
58
  const requestTimeoutPromise =
60
59
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
61
60
  setTimeout(() => {
62
61
  resolve({
63
62
  statusCode: 500,
64
63
  resTimeoutState: true,
65
64
  errMsg: 'request timeout',
66
65
  })
67
66
  }, timeout)
68
67
  })
69
68
  return Promise.race([requestTask, requestTimeoutPromise]).then(
70
69
  (res: any) => {
71
70
  if (res && res.statusCode === 500 && res.resTimeoutState) {
72
71
  if (this.#reportType === HTTP_REQUEST_TYPE.HYBRID) {
73
72
  this._clearFunction(this.#callbackFunction)
74
73
  } else {
75
74
  requestTask.abort && requestTask.abort()
76
75
  }
77
76
  }
78
77
  this._handleReportInterfaceError(url, data, timeout, res)
79
78
  return res
80
79
  },
81
80
  )
82
81
  }
83
82
 
84
83
  _handleSpecialGatewayUrl(url: string): string {
85
84
  if (isPc && window.location.hostname.includes('.jd.hk')) {
86
85
  return this.api.hkApiFunc
87
86
  }
88
87
  if (
89
88
  isJdApp &&
90
89
  window?.shopGlobalSwitch?.dualProtocol &&
91
90
  !window.location.href.includes('jshopx_vconsole')
92
91
  ) {
93
92
  return window?.shopGlobalSwitch?.dualProtocol?.apiTestApp || url
94
93
  }
95
94
  return url
96
95
  }
97
96
 
98
97
  _shouldUseHybridRequest(): boolean {
99
98
  try {
100
99
  if (!isJdApp || !isSupportHybridHttpRequest || isJdAndHarmonyDevice) {
101
100
  return false
102
101
  }
103
102
  const configData = global.getDynamicConfig('hybridHttpSwitch')
104
103
  const { globalOn = false, grayscale = {} } = configData || {}
105
104
  const buildType = process.env.BUILD_TYPE || ''
106
105
  const isInvokeGray = globalOn || grayscale[buildType]
107
106
  console.log(
108
107
  '使用hybrid请求是否命中灰度,isInvokeGray:',
109
108
  isInvokeGray,
110
109
  '获取mpaas配置hybridHttpSwitch原始数据configData',
111
110
  configData,
112
111
  )
113
112
  const hasWindowXWebView = !!window.XWebView
114
113
  return isInvokeGray && hasWindowXWebView
115
114
  } catch (e) {
116
115
  console.log('获取是否使用Hybrid请求出错,e:', e)
117
116
  return false
118
117
  }
119
118
  }
120
119
 
121
120
  _hybridRequest(url: string, data: any): Promise<any> {
122
121
  return new Promise((resolve, reject) => {
123
122
  try {
124
123
  const changeCurrentUrl = url.startsWith('//') ? `https:${url}` : url
125
124
  const reqParams = {
126
125
  url: isIosDevice ? `${changeCurrentUrl}/` : changeCurrentUrl,
127
126
  functionId: data?.functionId,
128
127
  body: data?.body,
129
128
  headerType: '0',
130
129
  }
131
130
  const callbackFunction = this._generateCallbackFunction()
132
131
  this.#callbackFunction = callbackFunction
133
132
  this.#requestTimeStamp = Date.now()
134
133
  this.#reportType = HTTP_REQUEST_TYPE.HYBRID
135
134
  window.XWebView.callNative(
136
135
  'ColorQueryPlugin',
137
136
  'colorRequest',
138
137
  JSON.stringify(reqParams),
139
138
  callbackFunction,
140
139
  '1',
141
140
  )
142
141
  window[callbackFunction] = (result) => {
143
142
  this.#responseTimeStamp = Date.now()
144
143
  try {
145
144
  const resultObj =
146
145
  typeof result === 'string' ? JSON.parse(result) : result
147
146
  resolve(resultObj)
148
147
  } catch (error) {
149
148
  const errMsg = 'hybrid网络请求JSON解析失败, error: ' + error
150
149
  draBusinessCustomReport({
151
150
  type: `${HTTP_REQUEST_TYPE.HYBRID}_jsonParseError`,
152
151
  errMsg,
153
152
  result,
154
153
  })
155
154
  reject({ errMsg })
156
155
  }
157
156
  this._clearFunction(callbackFunction)
158
157
  }
159
158
  } catch (error) {
160
159
  reject({
161
160
  errMsg:
162
161
  'hybrid网络请求,App下调用window.XWebView.callNative出错, error: ' +
163
162
  error,
164
163
  })
165
164
  }
166
165
  })
167
166
  }
168
167
 
169
168
  _generateCallbackFunction() {
170
169
  return `hybridHttpRequestCallback_${Date.now()}_${Math.ceil(
171
170
  Math.random() * 100000,
172
171
  )}`
173
172
  }
174
173
 
175
174
  _clearFunction(functionName: string) {
176
175
  try {
177
176
  delete window[functionName]
178
177
  } catch (e) {
179
178
  window[functionName] = undefined
180
179
  }
181
180
  }
182
181
 
183
182
  async _prepareGatewayReqData(
184
183
  data: any,
185
184
  isColorVerify: boolean,
186
185
  ): Promise<any> {
187
186
  const { functionId } = data
188
187
  console.log('获取当前是否需要color加固', isColorVerify, functionId)
189
188
  if (isColorVerify) {
190
189
  const { h5st } = await colorSign.paramsSign(data)
191
190
  h5st && (data.h5st = encodeURI(h5st))
192
191
  console.log(`${functionId}的apiReq_h5st===>:${h5st}`)
193
192
  }
194
193
  const { jsToken } = await colorSign.getFmInfo()
195
194
  console.log(`${functionId}的api jsToken指纹===>:${jsToken}`)
196
195
  jsToken && (data['x-api-eid-token'] = jsToken)
197
196
  return data
198
197
  }
199
198
 
200
199
  _taroRequest(
201
200
  url: string,
202
201
  otherOpts: any,
203
202
  method: string,
204
203
  timeout: number,
205
204
  header: string,
206
205
  ): Promise<any> {
207
206
  const reqParam = {
208
207
  url,
209
208
  method,
210
209
  timeout,
211
210
  header,
212
211
  credentials: 'include',
213
212
  ...otherOpts,
214
213
  }
215
214
  this.#requestTimeStamp = Date.now()
216
215
  this.#reportType = HTTP_REQUEST_TYPE.TARO
217
216
  return Taro.request(reqParam)
218
217
  }
219
218
 
220
219
  _reportRequestTime(url: string, data: any): void {
221
220
  this.#getResTimeStamp = Date.now()
222
221
  if (this.#reportType === HTTP_REQUEST_TYPE.TARO) {
223
222
  this.#responseTimeStamp = this.#getResTimeStamp
224
223
  }
225
224
  draInterfaceCustomReport(
226
225
  {
227
226
  type: `${this.#reportType}_consumeTime`,
228
227
  url,
229
228
  functionId: data?.functionId,
230
229
  requestTimeStamp: this.#requestTimeStamp,
231
230
  responseTimeStamp: this.#responseTimeStamp,
232
231
  errMsg: `使用${this.#reportType}调用接口请求响应耗时`,
233
232
  source: 'remote',
234
233
  },
235
234
  {
236
235
  consumeTime: `${this.#responseTimeStamp - this.#requestTimeStamp}ms`,
237
236
  getResTime: `${this.#getResTimeStamp - this.#requestTimeStamp}ms`,
238
237
  },
239
238
  )
240
239
  }
241
240
 
242
241
  _handleReportInterfaceError(
243
242
  url: string,
244
243
  reqData: any,
245
244
  timeOut: any,
246
245
  res: any,
247
246
  ): void {
248
247
  const source = 'remote'
249
248
  const requestType = this.#reportType
250
249
  let errorType = ''
251
250
  let subMsg = ''
252
251
  let reportFlag = false
253
252
  if (res) {
254
253
  const { statusCode, data, status, resTimeoutState } = res
255
254
  if (statusCode === 500 && resTimeoutState) {
256
255
  reportFlag = true
257
256
  errorType = 'timeout'
258
257
  subMsg = `接口请求超时${timeOut}ms`
259
258
  } else if ((statusCode === 200 || status === '0') && data) {
260
259
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
261
260
  ? Number(data.code)
262
261
  : -1
263
262
  const isSuccess = resCode === 0 || resCode === 200
264
263
  if (!isSuccess) {
265
264
  reportFlag = true
266
265
  errorType = 'dataError'
267
266
  subMsg = '接口请求返回数据异常'
268
267
  }
269
268
  } else {
270
269
  reportFlag = true
271
270
  errorType = 'statusError'
272
271
  subMsg = '接口请求本身异常'
273
272
  }
274
273
  }
275
274
  reportFlag &&
276
275
  draInterfaceCustomReport({
277
276
  subMsg,
278
277
  url,
279
278
  source,
280
279
  requestType,
281
280
  errorType,
282
281
  ...reqData,
283
282
  ...res,
284
283
  })
285
284
  }
285
+ import Taro from '@tarojs/taro';
286
286
  isSupportHybridHttpRequest,
287
287
  draInterfaceCustomReport,
288
288
  draBusinessCustomReport,
289
289
  jsonHeader = 'application/json;charset=utf-8',
290
290
  formDataHeader = 'application/x-www-form-urlencoded',
291
291
  HYBRID: 'httpRequest_hybrid',
292
292
  TARO: 'httpRequest_taro',
293
293
  #requestTimeStamp: number;
294
294
  #responseTimeStamp: number;
295
295
  #getResTimeStamp: number;
296
296
  #reportType: string;
297
297
  #callbackFunction: string;
298
298
 
299
299
  async request({
300
300
  url,
301
301
  method = 'POST',
302
302
  timeout = 7000,
303
303
  isColorVerify = false,
304
304
  ...otherOptions
305
305
  }): Promise<Taro.request.SuccessCallbackResult<any>> {
306
306
  const { header: otherHeader, ...otherOpts } = otherOptions;
307
307
  const header = {
308
308
  'content-type':
309
309
  method === 'POST'
310
310
  ? RequestHeaderContentType.formDataHeader
311
311
  : RequestHeaderContentType.jsonHeader,
312
312
  ...otherHeader,
313
313
  };
314
314
  let getRequestUrl = url;
315
315
  let requestTask;
316
316
  const data = otherOpts?.data;
317
317
  const isGatewayRequest = url === this.api.apiFunc && typeof data === 'object';
318
318
  if (isGatewayRequest) {
319
319
  getRequestUrl = this._handleSpecialGatewayUrl(url);
320
320
  const shouldUseHybridRequest = this._shouldUseHybridRequest(data);
321
321
  if (shouldUseHybridRequest && window?.XWebView && window?.XWebView?.callNative) {
322
322
  requestTask = this._hybridRequest(getRequestUrl, data);
323
323
  } else {
324
324
  otherOpts.data = await this._prepareGatewayReqData(data, isColorVerify);
325
325
  requestTask = this._taroRequest(getRequestUrl, otherOpts, method, timeout, header);
326
326
  }
327
327
  } else {
328
328
  requestTask = this._taroRequest(getRequestUrl, otherOpts, method, timeout, header);
329
329
  }
330
330
  const requestTimeoutPromise = new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
331
331
  setTimeout(() => {
332
332
  resolve({
333
333
  statusCode: 500,
334
334
  resTimeoutState: true,
335
335
  errMsg: 'request timeout',
336
336
  });
337
337
  }, timeout);
338
338
  });
339
339
  return Promise.race([requestTask, requestTimeoutPromise]).then((res: any) => {
340
340
  if (res && res.statusCode === 500 && res.resTimeoutState) {
341
341
  if (this.#reportType === HTTP_REQUEST_TYPE.HYBRID) {
342
342
  this._clearFunction(this.#callbackFunction);
343
343
  } else {
344
344
  requestTask.abort && requestTask.abort();
345
345
  }
346
346
  }
347
347
  this._handleReportInterfaceError(url, data, timeout, res);
348
348
  return res;
349
349
  });
350
350
  }
351
351
 
352
352
  _handleSpecialGatewayUrl(url: string): string {
353
353
  if (isPc && window.location.hostname.includes('.jd.hk')) {
354
354
  return this.api.hkApiFunc;
355
355
  }
356
356
  if (
357
357
  isJdApp &&
358
358
  window?.shopGlobalSwitch?.dualProtocol &&
359
359
  !window.location.href.includes('jshopx_vconsole')
360
360
  ) {
361
361
  return window?.shopGlobalSwitch?.dualProtocol?.apiTestApp || url;
362
362
  }
363
363
  return url;
364
364
  }
365
365
 
366
366
  _shouldUseHybridRequest(data: any): boolean {
367
367
  try {
368
368
  const isWhxFunctionId = /^whx\_/.test(data?.functionId);
369
369
  const isGlobalOpenHybirdHttpRequest =
370
370
  window?.shopGlobalSwitch?.openHybirdHttpRequest === 'true';
371
371
  if (
372
372
  !isJdApp ||
373
373
  !isSupportHybridHttpRequest ||
374
374
  !isGlobalOpenHybirdHttpRequest ||
375
375
  isWhxFunctionId ||
376
376
  isJdAndHarmonyDevice
377
377
  ) {
378
378
  return false;
379
379
  }
380
380
  const configData = global.getDynamicConfig('hybridHttpSwitch');
381
381
  const { globalOn = false, grayscale = {} } = configData || {};
382
382
  const buildType = process.env.BUILD_TYPE || '';
383
383
  const isInvokeGray = globalOn || grayscale[buildType];
384
384
  console.log(
385
385
  '使用hybrid请求是否命中灰度,isInvokeGray:',
386
386
  isInvokeGray,
387
387
  '获取mpaas配置hybridHttpSwitch原始数据configData',
388
388
  configData,
389
389
  );
390
390
  const hasWindowXWebView = !!window.XWebView;
391
391
  return isInvokeGray && hasWindowXWebView;
392
392
  } catch (e) {
393
393
  console.log('获取是否使用Hybrid请求出错,e:', e);
394
394
  return false;
395
395
  }
396
396
  }
397
397
 
398
398
  _hybridRequest(url: string, data: any): Promise<any> {
399
399
  return new Promise((resolve, reject) => {
400
400
  try {
401
401
  const changeCurrentUrl = url.startsWith('//') ? `https:${url}` : url;
402
402
  const { functionId, body, ...otherH5Param } = data;
403
403
  const reqParams = {
404
404
  url: isIosDevice ? `${changeCurrentUrl}/` : changeCurrentUrl,
405
405
  functionId: functionId,
406
406
  body: body,
407
407
  headerType: '0',
408
408
  param: {
409
409
  ...otherH5Param,
410
410
  },
411
411
  header: {
412
412
  Referer: window.location.origin,
413
413
  },
414
414
  };
415
415
  const callbackFunction = this._generateCallbackFunction();
416
416
  this.#callbackFunction = callbackFunction;
417
417
  this.#requestTimeStamp = Date.now();
418
418
  this.#reportType = HTTP_REQUEST_TYPE.HYBRID;
419
419
  window.XWebView.callNative(
420
420
  'ColorQueryPlugin',
421
421
  'colorRequest',
422
422
  JSON.stringify(reqParams),
423
423
  callbackFunction,
424
424
  '1',
425
425
  );
426
426
  window[callbackFunction] = (result) => {
427
427
  this.#responseTimeStamp = Date.now();
428
428
  try {
429
429
  const resultObj = typeof result === 'string' ? JSON.parse(result) : result;
430
430
  resolve(resultObj);
431
431
  } catch (error) {
432
432
  const errMsg = 'hybrid网络请求JSON解析失败, error: ' + error;
433
433
  draBusinessCustomReport({
434
434
  type: `${HTTP_REQUEST_TYPE.HYBRID}_jsonParseError`,
435
435
  errMsg,
436
436
  result,
437
437
  });
438
438
  reject({ errMsg });
439
439
  }
440
440
  this._clearFunction(callbackFunction);
441
441
  };
442
442
  } catch (error) {
443
443
  reject({
444
444
  errMsg: 'hybrid网络请求,App下调用window.XWebView.callNative出错, error: ' + error,
445
445
  });
446
446
  }
447
447
  });
448
448
  }
449
449
 
450
450
  _generateCallbackFunction() {
451
451
  return `hybridHttpRequestCallback_${Date.now()}_${Math.ceil(Math.random() * 100000)}`;
452
452
  }
453
453
 
454
454
  _clearFunction(functionName: string) {
455
455
  try {
456
456
  delete window[functionName];
457
457
  } catch (e) {
458
458
  window[functionName] = undefined;
459
459
  }
460
460
  }
461
461
 
462
462
  async _prepareGatewayReqData(data: any, isColorVerify: boolean): Promise<any> {
463
463
  const { functionId } = data;
464
464
  console.log('获取当前是否需要color加固', isColorVerify, functionId);
465
465
  if (isColorVerify) {
466
466
  const { h5st } = await colorSign.paramsSign(data);
467
467
  h5st && (data.h5st = encodeURI(h5st));
468
468
  console.log(`${functionId}的apiReq_h5st===>:${h5st}`);
469
469
  }
470
470
  const { jsToken } = await colorSign.getFmInfo();
471
471
  console.log(`${functionId}的api jsToken指纹===>:${jsToken}`);
472
472
  jsToken && (data['x-api-eid-token'] = jsToken);
473
473
  return data;
474
474
  }
475
475
 
476
476
  _taroRequest(
477
477
  url: string,
478
478
  otherOpts: any,
479
479
  method: string,
480
480
  timeout: number,
481
481
  header: string,
482
482
  ): Promise<any> {
483
483
  const reqParam = {
484
484
  url,
485
485
  method,
486
486
  timeout,
487
487
  header,
488
488
  credentials: 'include',
489
489
  ...otherOpts,
490
490
  };
491
491
  this.#requestTimeStamp = Date.now();
492
492
  this.#reportType = HTTP_REQUEST_TYPE.TARO;
493
493
  return Taro.request(reqParam);
494
494
  }
495
495
 
496
496
  _reportRequestTime(url: string, data: any): void {
497
497
  this.#getResTimeStamp = Date.now();
498
498
  if (this.#reportType === HTTP_REQUEST_TYPE.TARO) {
499
499
  this.#responseTimeStamp = this.#getResTimeStamp;
500
500
  }
501
501
  draInterfaceCustomReport(
502
502
  {
503
503
  type: `${this.#reportType}_consumeTime`,
504
504
  url,
505
505
  functionId: data?.functionId,
506
506
  requestTimeStamp: this.#requestTimeStamp,
507
507
  responseTimeStamp: this.#responseTimeStamp,
508
508
  errMsg: `使用${this.#reportType}调用接口请求响应耗时`,
509
509
  source: 'remote',
510
510
  },
511
511
  {
512
512
  consumeTime: `${this.#responseTimeStamp - this.#requestTimeStamp}ms`,
513
513
  getResTime: `${this.#getResTimeStamp - this.#requestTimeStamp}ms`,
514
514
  },
515
515
  );
516
516
  }
517
517
 
518
518
  _handleReportInterfaceError(url: string, reqData: any, timeOut: any, res: any): void {
519
519
  const source = 'remote';
520
520
  const requestType = this.#reportType;
521
521
  let errorType = '';
522
522
  let subMsg = '';
523
523
  let reportFlag = false;
524
524
  if (res) {
525
525
  const { statusCode, data, status, resTimeoutState } = res;
526
526
  if (statusCode === 500 && resTimeoutState) {
527
527
  reportFlag = true;
528
528
  errorType = 'timeout';
529
529
  subMsg = `接口请求超时${timeOut}ms`;
530
530
  } else if ((statusCode === 200 || status === '0') && data) {
531
531
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
532
532
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
533
533
  ? Number(data.subCode)
534
534
  : -1;
535
535
  const isSuccess =
536
536
  data.success === true ||
537
537
  data.isSuccess ||
538
538
  resCode === 0 ||
539
539
  resCode === 200 ||
540
540
  subCode === 0;
541
541
  if (!isSuccess && resCode !== 3) {
542
542
  reportFlag = true;
543
543
  errorType = 'dataError';
544
544
  subMsg = '接口请求返回数据异常';
545
545
  }
546
546
  } else {
547
547
  reportFlag = true;
548
548
  errorType = 'statusError';
549
549
  subMsg = '接口请求错误,h5请求statusCode非200,或hybrid请求status非0,或未返回data字段';
550
550
  }
551
551
  }
552
552
  reportFlag &&
553
553
  draInterfaceCustomReport({
554
554
  subMsg,
555
555
  url,
556
556
  source,
557
557
  requestType,
558
558
  errorType,
559
559
  functionId: reqData?.functionId,
560
560
  appid: reqData?.appId,
561
561
  client: reqData?.client,
562
562
  clientVersion: reqData?.clientVersion,
563
563
  statusCode: res?.statusCode,
564
564
  status: res?.status,
565
565
  code: res?.data?.code || res?.data?.subCode,
566
566
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
567
567
  originReqDataStr: JSON.stringify(reqData),
568
568
  originResDataStr: JSON.stringify(res),
569
569
  });
570
570
  }