@conecli/cone-render 0.9.1-shop2.26 → 0.9.1-shop2.28

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 (33) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/assets/icon_blue_info.svg +1 -0
  3. package/dist/common/const.ts +1 -1
  4. package/dist/common/index.h5.ts +1 -1
  5. package/dist/common/index.jd.ts +1 -1
  6. package/dist/common/index.ts +1 -1
  7. package/dist/common/pageType.ts +1 -1
  8. package/dist/common/sgmCustomCode.ts +1 -1
  9. package/dist/common/token/token.jd.ts +1 -1
  10. package/dist/components/base/CustomVideo/common.ts +1 -0
  11. package/dist/components/base/CustomVideo/index.tsx +1 -1
  12. package/dist/components/base/Price/Base/index.tsx +1 -1
  13. package/dist/components/base/Price/Double/index.tsx +1 -1
  14. package/dist/components/debug/DebugLayout/index.module.scss +67 -0
  15. package/dist/components/debug/DebugLayout/index.tsx +1 -0
  16. package/dist/components/debug/DebugLayout/utils.ts +1 -0
  17. package/dist/components/floorItem.tsx +1 -1
  18. package/dist/components/isv/Floor/index.tsx +1 -1
  19. package/dist/interface/component.ts +1 -1
  20. package/dist/interface/service.ts +1 -1
  21. package/dist/jumpEventReport/index.weapp.ts +1 -1
  22. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  23. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  24. package/dist/service/http/colorSign.ts +1 -1
  25. package/dist/service/http/h5Http.ts +1 -0
  26. package/dist/service/http/index.h5.ts +1 -0
  27. package/dist/service/requestServer.h5.ts +1 -0
  28. package/dist/utils/h5Utils.ts +1 -1
  29. package/dist/utils/index.h5.ts +1 -1
  30. package/dist/utils/index.ts +1 -1
  31. package/dist/utils/index.weapp.ts +1 -1
  32. package/dist/utils/utils.ts +1 -1
  33. package/package.json +1 -1
@@ -1 +1 @@
1
- import { ServiceInterFace } from '../../interface'
2
1
  AppVerifyColorList,
3
2
  SHOP_VERIFY_CODE,
4
3
  PAGES_VERIFY_CODE,
5
4
  B2B_VERITY_CODE,
6
5
  PAGES_DOMAIN,
7
6
  B2BColorFunctionIdList,
8
7
  public fmInfo: {
9
8
  eid?: string
10
9
  fp?: string
11
10
  jsToken?: string
12
11
  sdkToken?: string
13
12
  }
14
13
  public api: ServiceInterFace.HttpApi
15
14
  public paramsSignInstance: any
16
15
  public paramsSignPagesInstance: any
17
16
  public paramsSignBmallInstance: any
18
17
  public isPageDomain: boolean
19
18
  constructor() {
20
19
  this.api = api
21
20
  this.isPageDomain = location?.hostname === PAGES_DOMAIN
22
21
  this.paramsSignInstance = undefined
23
22
  this.paramsSignPagesInstance = undefined
24
23
  this.paramsSignBmallInstance = undefined
25
24
  this.fmInfo = {}
26
25
  this._initSign()
27
26
  }
28
27
 
29
28
  _getMobileJsToken(): Promise<{
30
29
  ok: boolean
31
30
  data?: any
32
31
  error?: any
33
32
  }> {
34
33
  return new Promise((resolve, reject) => {
35
34
  try {
36
35
  if (window?.getJsToken) {
37
36
  window.getJsToken(function (res) {
38
37
  console.log('JS token 获取结果:', res)
39
38
  resolve({
40
39
  ok: true,
41
40
  data: res,
42
41
  })
43
42
  }, 600)
44
43
  } else {
45
44
  reject({
46
45
  ok: false,
47
46
  error: '没有识别到getJsToken全局方法',
48
47
  })
49
48
  }
50
49
  } catch (e) {
51
50
  console.log('获取指纹JS token 异常', e)
52
51
  reject({
53
52
  ok: false,
54
53
  error: e,
55
54
  })
56
55
  }
57
56
  })
58
57
  }
59
58
 
60
59
  async getFmInfo() {
61
60
  try {
62
61
  const { ok, data } = await this._getMobileJsToken()
63
62
  this.fmInfo = ok && data ? data : this.fmInfo
64
63
  return this.fmInfo
65
64
  } catch (e) {
66
65
  console.log('获取指纹信息异常', e)
67
66
  return this.fmInfo
68
67
  }
69
68
  }
70
69
 
71
70
  _initSign() {
72
71
  this.paramsSignInstance = window.PSign
73
72
  ? window.PSign
74
73
  : window.ParamsSign
75
74
  ? this._initParamsSignInstance(SHOP_VERIFY_CODE)
76
75
  : null
77
76
  this.paramsSignPagesInstance = window.ParamsSign
78
77
  ? this._initParamsSignInstance(PAGES_VERIFY_CODE)
79
78
  : null
80
79
  this.paramsSignBmallInstance = window.ParamsSign
81
80
  ? this._initParamsSignInstance(B2B_VERITY_CODE)
82
81
  : null
83
82
  }
84
83
 
85
84
  _initParamsSignInstance(appId) {
86
85
  return new window.ParamsSign({
87
86
  appId: appId,
88
87
  debug: false,
89
88
  preRequest: false,
90
89
  onSign: ({ code }) => {
91
90
  console.log('签名可用率监控', code)
92
91
  },
93
92
  onRequestTokenRemotely: ({ code, message }) => {
94
93
  console.log('算法接口可用率监控', code, message)
95
94
  },
96
95
  onRequestToken: ({ code, message }) => {
97
96
  console.log('token的可用率监控', code, message)
98
97
  },
99
98
  })
100
99
  }
101
100
 
102
101
  paramsSign(data) {
103
102
  try {
104
103
  console.log('获取加签参数', data, this.paramsSignInstance)
105
104
  if (!data || typeof data !== 'object' || !this.paramsSignInstance) {
106
105
  return Promise.resolve(data)
107
106
  } else {
108
107
  const param: any = {
109
108
  appid: data.appid,
110
109
  client: data.client,
111
110
  clientVersion: data.clientVersion,
112
111
  functionId: data.functionId,
113
112
  t: data.t,
114
113
  sign: data?.sign,
115
114
  jsonp: data?.jsonp,
116
115
  }
117
116
  data && data.body && (param.body = sha256(data.body).toString())
118
117
  console.log(
119
118
  '获取加签前的参数处理',
120
119
  param,
121
120
  '获取下发data',
122
121
  data,
123
122
  '获取加签实例',
124
123
  this.paramsSignInstance,
125
124
  this.paramsSignPagesInstance,
126
125
  )
127
126
  return this.isPageDomain &&
128
127
  this.paramsSignPagesInstance &&
129
128
  AppVerifyColorList.includes(param.functionId)
130
129
  ? this.paramsSignPagesInstance.sign(param)
131
130
  : this.paramsSignBmallInstance &&
132
131
  B2BColorFunctionIdList.includes(param.functionId)
133
132
  ? this.paramsSignBmallInstance.sign(param)
134
133
  : this.paramsSignInstance.sign(param)
135
134
  }
136
135
  } catch (e) {
137
136
  console.log('获取加签参数结果异常', e)
138
137
  return Promise.resolve(data)
139
138
  }
140
139
  }
140
+ import { ServiceInterFace } from '../../interface'
141
141
  AppVerifyColorList,
142
142
  SHOP_VERIFY_CODE,
143
143
  PAGES_VERIFY_CODE,
144
144
  B2B_VERITY_CODE,
145
145
  PAGES_DOMAIN,
146
146
  B2BColorFunctionIdList,
147
147
  public fmInfo: {
148
148
  eid?: string
149
149
  fp?: string
150
150
  jsToken?: string
151
151
  sdkToken?: string
152
152
  }
153
153
  public api: ServiceInterFace.HttpApi
154
154
  public paramsSignInstance: any
155
155
  public paramsSignPagesInstance: any
156
156
  public paramsSignBmallInstance: any
157
157
  public isPageDomain: boolean
158
158
  public initParamsSignInstance: any
159
159
  public initJsTokenInstance: any
160
160
  constructor() {
161
161
  this.api = api
162
162
  this.isPageDomain = location?.hostname === PAGES_DOMAIN
163
163
  this.paramsSignInstance = undefined
164
164
  this.paramsSignPagesInstance = undefined
165
165
  this.paramsSignBmallInstance = undefined
166
166
  this.initParamsSignInstance = undefined
167
167
  this.initJsTokenInstance = undefined
168
168
  this.fmInfo = {}
169
169
  }
170
170
 
171
171
  _loadSingleJs(jsFileName, successCallback?, failCallback?) {
172
172
  const jsInfo = global.loadJsSdkList.find(
173
173
  (item) => item?.fileName === jsFileName,
174
174
  )
175
175
  if (jsInfo) {
176
176
  global
177
177
  .loadItemSdkPromise(jsInfo)
178
178
  .then(() => {
179
179
  typeof successCallback === 'function' && successCallback()
180
180
  })
181
181
  .catch(() => {
182
182
  console.info('业务发起接口请求前置加载js异常' + jsInfo?.src)
183
183
  typeof failCallback === 'function' && failCallback()
184
184
  })
185
185
  } else {
186
186
  typeof failCallback === 'function' && failCallback()
187
187
  }
188
188
  }
189
189
 
190
190
  _getMobileJsToken(): Promise<{
191
191
  ok: boolean
192
192
  data?: any
193
193
  error?: any
194
194
  }> {
195
195
  return this._handleInitJsToken().then(() => {
196
196
  try {
197
197
  if (window?.getJsToken) {
198
198
  return new Promise((resolve) => {
199
199
  window.getJsToken(function (res) {
200
200
  console.log('JS token 获取结果', res)
201
201
  resolve({
202
202
  ok: true,
203
203
  data: res,
204
204
  })
205
205
  }, 600)
206
206
  })
207
207
  } else {
208
208
  console.log('没有识别到getJsToken全局方法')
209
209
  return Promise.resolve({
210
210
  ok: false,
211
211
  error: '没有识别到getJsToken全局方法',
212
212
  })
213
213
  }
214
214
  } catch (e) {
215
215
  console.log('获取指纹JS token 异常', e)
216
216
  return Promise.resolve({
217
217
  ok: false,
218
218
  error: e,
219
219
  })
220
220
  }
221
221
  })
222
222
  }
223
223
 
224
224
  async getFmInfo() {
225
225
  try {
226
226
  const { ok, data } = await this._getMobileJsToken()
227
227
  this.fmInfo = ok && data ? data : this.fmInfo
228
228
  return this.fmInfo
229
229
  } catch (e) {
230
230
  console.log('获取指纹信息异常', e)
231
231
  return this.fmInfo
232
232
  }
233
233
  }
234
234
 
235
235
  _initSign() {
236
236
  this.paramsSignInstance = window.PSign
237
237
  ? window.PSign
238
238
  : window.ParamsSign
239
239
  ? this._initParamsSignInstance(SHOP_VERIFY_CODE)
240
240
  : null
241
241
  this.paramsSignPagesInstance = window.ParamsSign
242
242
  ? this._initParamsSignInstance(PAGES_VERIFY_CODE)
243
243
  : null
244
244
  this.paramsSignBmallInstance = window.ParamsSign
245
245
  ? this._initParamsSignInstance(B2B_VERITY_CODE)
246
246
  : null
247
247
  }
248
248
 
249
249
  _initParamsSignInstance(appId) {
250
250
  return new window.ParamsSign({
251
251
  appId: appId,
252
252
  debug: false,
253
253
  preRequest: false,
254
254
  onSign: ({ code }) => {
255
255
  console.log('签名可用率监控', code)
256
256
  },
257
257
  onRequestTokenRemotely: ({ code, message }) => {
258
258
  console.log('算法接口可用率监控', code, message)
259
259
  },
260
260
  onRequestToken: ({ code, message }) => {
261
261
  console.log('token的可用率监控', code, message)
262
262
  },
263
263
  })
264
264
  }
265
265
 
266
266
  paramsSign(data) {
267
267
  try {
268
268
  return this._handleInitSign().then(() => {
269
269
  console.log('获取加签参数', data, this.paramsSignInstance)
270
270
  if (!data || typeof data !== 'object' || !this.paramsSignInstance) {
271
271
  return Promise.resolve(data)
272
272
  } else {
273
273
  const param: any = {
274
274
  appid: data.appid,
275
275
  client: data.client,
276
276
  clientVersion: data.clientVersion,
277
277
  functionId: data.functionId,
278
278
  t: data.t,
279
279
  sign: data?.sign,
280
280
  jsonp: data?.jsonp,
281
281
  }
282
282
  data && data.body && (param.body = sha256(data.body).toString())
283
283
  console.log(
284
284
  '获取加签前的参数处理',
285
285
  param,
286
286
  '获取下发data',
287
287
  data,
288
288
  '获取加签实例',
289
289
  this.paramsSignInstance,
290
290
  this.paramsSignPagesInstance,
291
291
  )
292
292
  return this.isPageDomain &&
293
293
  this.paramsSignPagesInstance &&
294
294
  AppVerifyColorList.includes(param.functionId)
295
295
  ? this.paramsSignPagesInstance.sign(param)
296
296
  : this.paramsSignBmallInstance &&
297
297
  B2BColorFunctionIdList.includes(param.functionId)
298
298
  ? this.paramsSignBmallInstance.sign(param)
299
299
  : this.paramsSignInstance.sign(param)
300
300
  }
301
301
  })
302
302
  } catch (e) {
303
303
  console.log('获取加签参数结果异常', e)
304
304
  return Promise.resolve(data)
305
305
  }
306
306
  }
307
307
 
308
308
  _handleInitSign() {
309
309
  if (!this.initParamsSignInstance) {
310
310
  this.initParamsSignInstance = new Promise((resolve) => {
311
311
  if (window?.ParamsSign) {
312
312
  this._initSign()
313
313
  resolve({
314
314
  ok: true,
315
315
  msg: '加固js已加载',
316
316
  })
317
317
  } else if (window?.PAGE_DATA?.asyncLoadSecurityJs) {
318
318
  this._loadSingleJs(
319
319
  'securityJs',
320
320
  () => {
321
321
  this._initSign()
322
322
  resolve({
323
323
  ok: true,
324
324
  msg: '异步请求加固js成功加载',
325
325
  })
326
326
  },
327
327
  () => {
328
328
  resolve({
329
329
  ok: true,
330
330
  msg: '加固js加载异常',
331
331
  })
332
332
  },
333
333
  )
334
334
  } else {
335
335
  resolve({
336
336
  ok: true,
337
337
  msg: '加固js开关配置为false不加载',
338
338
  })
339
339
  }
340
340
  })
341
341
  }
342
342
  return this.initParamsSignInstance
343
343
  }
344
344
 
345
345
  _handleInitJsToken() {
346
346
  if (!this.initJsTokenInstance) {
347
347
  this.initJsTokenInstance = new Promise((resolve) => {
348
348
  if (window?.getJsToken) {
349
349
  resolve({
350
350
  ok: true,
351
351
  msg: '指纹js已加载',
352
352
  })
353
353
  } else if (window?.PAGE_DATA?.asyncLoadMtkJs) {
354
354
  this._loadSingleJs(
355
355
  'mtkJs',
356
356
  () => {
357
357
  resolve({
358
358
  ok: true,
359
359
  msg: '异步请求指纹js成功加载',
360
360
  })
361
361
  },
362
362
  () => {
363
363
  resolve({
364
364
  ok: true,
365
365
  msg: '指纹js加载异常',
366
366
  })
367
367
  },
368
368
  )
369
369
  } else {
370
370
  resolve({
371
371
  ok: true,
372
372
  msg: '指纹js开关配置为false不加载',
373
373
  })
374
374
  }
375
375
  })
376
376
  }
377
377
  return this.initJsTokenInstance
378
378
  }
@@ -0,0 +1 @@
1
+ import Taro from '@tarojs/taro'
2
  isSupportHybridHttpRequest,
1
3
  draInterfaceCustomReport,
2
4
  draBusinessCustomReport,
3
5
  isIosDevice,
4
6
  isJdApp,
5
7
  isPc,
6
8
  isJdAndHarmonyDevice,
7
9
  jsonHeader = 'application/json;charset=utf-8',
8
10
  formDataHeader = 'application/x-www-form-urlencoded',
9
11
  HYBRID: 'httpRequest_hybrid',
10
12
  TARO: 'httpRequest_taro',
11
13
  #requestTimeStamp: number
12
14
  #responseTimeStamp: number
13
15
  #getResTimeStamp: number
14
16
  #reportType: string
15
17
  #callbackFunction: string
16
18
 
17
19
  async request({
18
20
  url,
19
21
  method = 'POST',
20
22
  timeout = 7000,
21
23
  isColorVerify = false,
22
24
  ...otherOptions
23
25
  }): Promise<Taro.request.SuccessCallbackResult<any>> {
24
26
  const { header: otherHeader, ...otherOpts } = otherOptions
25
27
  const header = {
26
28
  'content-type':
27
29
  method === 'POST'
28
30
  ? RequestHeaderContentType.formDataHeader
29
31
  : RequestHeaderContentType.jsonHeader,
30
32
  ...otherHeader,
31
33
  }
32
34
  let getRequestUrl = url
33
35
  let requestTask
34
36
  const data = otherOpts?.data
35
37
  const isGatewayRequest =
36
38
  url === this.api.apiFunc && typeof data === 'object'
37
39
  if (isGatewayRequest) {
38
40
  getRequestUrl = this._handleSpecialGatewayUrl(url)
39
41
  const shouldUseHybridRequest = this._shouldUseHybridRequest()
40
42
  if (shouldUseHybridRequest) {
41
43
  requestTask = this._hybridRequest(getRequestUrl, data)
42
44
  } else {
43
45
  otherOpts.data = await this._prepareGatewayReqData(data, isColorVerify)
44
46
  requestTask = this._taroRequest(
45
47
  getRequestUrl,
46
48
  otherOpts,
47
49
  method,
48
50
  timeout,
49
51
  header,
50
52
  )
51
53
  }
52
54
  } else {
53
55
  requestTask = this._taroRequest(
54
56
  getRequestUrl,
55
57
  otherOpts,
56
58
  method,
57
59
  timeout,
58
60
  header,
59
61
  )
60
62
  }
61
63
  const requestTimeoutPromise =
62
64
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
63
65
  setTimeout(() => {
64
66
  resolve({
65
67
  statusCode: 500,
66
68
  resTimeoutState: true,
67
69
  errMsg: 'request timeout',
68
70
  })
69
71
  }, timeout)
70
72
  })
71
73
  return Promise.race([requestTask, requestTimeoutPromise]).then(
72
74
  (res: any) => {
73
75
  if (res && res.statusCode === 500 && res.resTimeoutState) {
74
76
  if (this.#reportType === HTTP_REQUEST_TYPE.HYBRID) {
75
77
  this._clearFunction(this.#callbackFunction)
76
78
  } else {
77
79
  requestTask.abort && requestTask.abort()
78
80
  }
79
81
  }
80
82
  this._handleReportInterfaceError(url, data, timeout, res)
81
83
  return res
82
84
  },
83
85
  )
84
86
  }
85
87
 
86
88
  _handleSpecialGatewayUrl(url: string): string {
87
89
  if (isPc && window.location.hostname.includes('.jd.hk')) {
88
90
  return this.api.hkApiFunc
89
91
  }
90
92
  if (
91
93
  isJdApp &&
92
94
  window?.shopGlobalSwitch?.dualProtocol &&
93
95
  !window.location.href.includes('jshopx_vconsole')
94
96
  ) {
95
97
  return window?.shopGlobalSwitch?.dualProtocol?.apiTestApp || url
96
98
  }
97
99
  return url
98
100
  }
99
101
 
100
102
  _shouldUseHybridRequest(): boolean {
101
103
  try {
102
104
  if (!isJdApp || !isSupportHybridHttpRequest || isJdAndHarmonyDevice) {
103
105
  return false
104
106
  }
105
107
  const configData = global.getDynamicConfig('hybridHttpSwitch')
106
108
  const { globalOn = false, grayscale = {} } = configData || {}
107
109
  const buildType = process.env.BUILD_TYPE || ''
108
110
  const isInvokeGray = globalOn || grayscale[buildType]
109
111
  console.log(
110
112
  '使用hybrid请求是否命中灰度,isInvokeGray:',
111
113
  isInvokeGray,
112
114
  '获取mpaas配置hybridHttpSwitch原始数据configData',
113
115
  configData,
114
116
  )
115
117
  const hasWindowXWebView = !!window.XWebView
116
118
  return isInvokeGray && hasWindowXWebView
117
119
  } catch (e) {
118
120
  console.log('获取是否使用Hybrid请求出错,e:', e)
119
121
  return false
120
122
  }
121
123
  }
122
124
 
123
125
  _hybridRequest(url: string, data: any): Promise<any> {
124
126
  return new Promise((resolve, reject) => {
125
127
  try {
126
128
  const changeCurrentUrl = url.startsWith('//') ? `https:${url}` : url
127
129
  const reqParams = {
128
130
  url: isIosDevice ? `${changeCurrentUrl}/` : changeCurrentUrl,
129
131
  functionId: data?.functionId,
130
132
  body: data?.body,
131
133
  headerType: '1',
132
134
  }
133
135
  const callbackFunction = this._generateCallbackFunction()
134
136
  this.#callbackFunction = callbackFunction
135
137
  this.#requestTimeStamp = Date.now()
136
138
  this.#reportType = HTTP_REQUEST_TYPE.HYBRID
137
139
  window.XWebView.callNative(
138
140
  'ColorQueryPlugin',
139
141
  'colorRequest',
140
142
  JSON.stringify(reqParams),
141
143
  callbackFunction,
142
144
  '1',
143
145
  )
144
146
  window[callbackFunction] = (result) => {
145
147
  this.#responseTimeStamp = Date.now()
146
148
  try {
147
149
  const resultObj =
148
150
  typeof result === 'string' ? JSON.parse(result) : result
149
151
  resolve(resultObj)
150
152
  } catch (error) {
151
153
  const errMsg = 'hybrid网络请求JSON解析失败, error: ' + error
152
154
  draBusinessCustomReport({
153
155
  type: `${HTTP_REQUEST_TYPE.HYBRID}_jsonParseError`,
154
156
  errMsg,
155
157
  result,
156
158
  })
157
159
  reject({ errMsg })
158
160
  }
159
161
  this._clearFunction(callbackFunction)
160
162
  }
161
163
  } catch (error) {
162
164
  reject({
163
165
  errMsg:
164
166
  'hybrid网络请求,App下调用window.XWebView.callNative出错, error: ' +
165
167
  error,
166
168
  })
167
169
  }
168
170
  })
169
171
  }
170
172
 
171
173
  _generateCallbackFunction() {
172
174
  return `hybridHttpRequestCallback_${Date.now()}_${Math.ceil(
173
175
  Math.random() * 100000,
174
176
  )}`
175
177
  }
176
178
 
177
179
  _clearFunction(functionName: string) {
178
180
  try {
179
181
  delete window[functionName]
180
182
  } catch (e) {
181
183
  window[functionName] = undefined
182
184
  }
183
185
  }
184
186
 
185
187
  async _prepareGatewayReqData(
186
188
  data: any,
187
189
  isColorVerify: boolean,
188
190
  ): Promise<any> {
189
191
  const { functionId } = data
190
192
  console.log('获取当前是否需要color加固', isColorVerify, functionId)
191
193
  if (isColorVerify) {
192
194
  const { h5st } = await colorSign.paramsSign(data)
193
195
  h5st && (data.h5st = encodeURI(h5st))
194
196
  console.log(`${functionId}的apiReq_h5st===>:${h5st}`)
195
197
  }
196
198
  const { jsToken } = await colorSign.getFmInfo()
197
199
  console.log(`${functionId}的api jsToken指纹===>:${jsToken}`)
198
200
  jsToken && (data['x-api-eid-token'] = jsToken)
199
201
  return data
200
202
  }
201
203
 
202
204
  _taroRequest(
203
205
  url: string,
204
206
  otherOpts: any,
205
207
  method: string,
206
208
  timeout: number,
207
209
  header: string,
208
210
  ): Promise<any> {
209
211
  const reqParam = {
210
212
  url,
211
213
  method,
212
214
  timeout,
213
215
  header,
214
216
  credentials: 'include',
215
217
  ...otherOpts,
216
218
  }
217
219
  this.#requestTimeStamp = Date.now()
218
220
  this.#reportType = HTTP_REQUEST_TYPE.TARO
219
221
  return Taro.request(reqParam)
220
222
  }
221
223
 
222
224
  _reportRequestTime(url: string, data: any): void {
223
225
  this.#getResTimeStamp = Date.now()
224
226
  if (this.#reportType === HTTP_REQUEST_TYPE.TARO) {
225
227
  this.#responseTimeStamp = this.#getResTimeStamp
226
228
  }
227
229
  draInterfaceCustomReport(
228
230
  {
229
231
  type: `${this.#reportType}_consumeTime`,
230
232
  url,
231
233
  functionId: data?.functionId,
232
234
  requestTimeStamp: this.#requestTimeStamp,
233
235
  responseTimeStamp: this.#responseTimeStamp,
234
236
  errMsg: `使用${this.#reportType}调用接口请求响应耗时`,
235
237
  source: 'remote',
236
238
  },
237
239
  {
238
240
  consumeTime: `${this.#responseTimeStamp - this.#requestTimeStamp}ms`,
239
241
  getResTime: `${this.#getResTimeStamp - this.#requestTimeStamp}ms`,
240
242
  },
241
243
  )
242
244
  }
243
245
 
244
246
  _handleReportInterfaceError(
245
247
  url: string,
246
248
  reqData: any,
247
249
  timeOut: any,
248
250
  res: any,
249
251
  ): void {
250
252
  const source = 'remote'
251
253
  const requestType = this.#reportType
252
254
  let errorType = ''
253
255
  let subMsg = ''
254
256
  let reportFlag = false
255
257
  if (res) {
256
258
  const { statusCode, data, status, resTimeoutState } = res
257
259
  if (statusCode === 500 && resTimeoutState) {
258
260
  reportFlag = true
259
261
  errorType = 'timeout'
260
262
  subMsg = `接口请求超时${timeOut}ms`
261
263
  } else if ((statusCode === 200 || status === '0') && data) {
262
264
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
263
265
  ? Number(data.code)
264
266
  : -1
265
267
  const isSuccess = resCode === 0 || resCode === 200
266
268
  if (!isSuccess) {
267
269
  reportFlag = true
268
270
  errorType = 'dataError'
269
271
  subMsg = '接口请求返回数据异常'
270
272
  }
271
273
  } else {
272
274
  reportFlag = true
273
275
  errorType = 'statusError'
274
276
  subMsg = '接口请求本身异常'
275
277
  }
276
278
  }
277
279
  reportFlag && draInterfaceCustomReport({
278
280
  subMsg,
279
281
  url,
280
282
  source,
281
283
  requestType,
282
284
  errorType,
283
285
  ...reqData,
284
286
  ...res,
285
287
  })
286
288
  }
@@ -0,0 +1 @@
1
+ import H5Http from "./h5Http"