@conecli/cone-render 0.10.1-shop3.47 → 0.10.1-shop3.48

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 (32) hide show
  1. package/dist/common/index.h5.ts +1 -1
  2. package/dist/common/index.jd.ts +1 -1
  3. package/dist/common/index.ts +1 -1
  4. package/dist/common/index.weapp.ts +1 -1
  5. package/dist/common/jdplayerSdk.weapp.tsx +1 -0
  6. package/dist/common/jssdk.weapp.ts +1 -0
  7. package/dist/components/ErrorBoundary.tsx +1 -1
  8. package/dist/components/base/CustomVideo/index.weapp.tsx +1 -0
  9. package/dist/components/base/InOrOutViewObserver/index.weapp.tsx +1 -0
  10. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  11. package/dist/components/base/MobileCommonHeader/index.weapp.tsx +1 -0
  12. package/dist/interface/component.ts +1 -1
  13. package/dist/jumpEventReport/logEventConfig.h5.ts +1 -0
  14. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  15. package/dist/libs/taroAppReport.js +2 -2
  16. package/dist/modules/DecorateContainerFloorList/index.weapp.tsx +1 -0
  17. package/dist/open/api/shopMember.weapp.ts +1 -0
  18. package/dist/open/index.ts +1 -1
  19. package/dist/service/fetchGateway.weapp.ts +1 -1
  20. package/dist/service/fetchJsonp.weapp.ts +1 -0
  21. package/dist/service/http/httpInterceptors.weapp.ts +1 -0
  22. package/dist/service/requestServer.h5.ts +1 -1
  23. package/dist/service/requestServer.ts +1 -1
  24. package/dist/service/requestServer.weapp.ts +1 -1
  25. package/dist/utils/connectNativeJsBridge.ts +1 -1
  26. package/dist/utils/harmonyCallRouter.h5.ts +1 -0
  27. package/dist/utils/harmonyCallRouter.ts +0 -0
  28. package/dist/utils/sColor.weapp.ts +1 -0
  29. package/package.json +1 -1
  30. package/dist/jumpEventReport/web/wqshop.report.ts +0 -1
  31. package/dist/utils/priceUtils.js +0 -1
  32. /package/dist/utils/{sColor.js → sColor.ts} +0 -0
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro';
2
1
  APPID,
3
2
  JshopxColorFunctionIdList,
4
3
  PagesColorFunctionIdList,
5
4
  PAGES_DOMAIN,
6
5
  B2BColorFunctionIdList,
7
6
  MobileVerifyColorList,
8
7
  AppVerifyColorList,
9
8
  JshopxVerifyColorList,
10
9
  BMallVerifyColorList,
11
10
  shopMemberColorFunctionIdList,
12
11
  isLanguageForEn,
13
12
  isJdApp,
14
13
  isIosDevice,
15
14
  isAndroidDevice,
16
15
  showSuccessToast,
17
16
  showFailToast,
18
17
  isH5,
19
18
  isWxMinAndWxapp,
20
19
  isMin,
21
20
  isPc,
22
21
  cookiesStr: '',
23
22
  requestHeaderContentType: {
24
23
  jsonHeader: {
25
24
  'content-type': 'application/json;charset=utf-8',
26
25
  },
27
26
  formDataHeader: {
28
27
  'content-type': 'application/x-www-form-urlencoded',
29
28
  },
30
29
  },
31
30
  requestBaseParam: {
32
31
  data: null,
33
32
  header: {
34
33
  'content-type': 'application/json;charset=utf-8',
35
34
  },
36
35
  },
37
36
  timeOut: 7000,
38
37
  apiClientParams: {
39
38
  appid: 'wx_mini_app',
40
39
  clientVersion: '11.0.0',
41
40
  client: 'wh5',
42
41
  area: '1_72_2799_0',
43
42
  screen: `${Math.ceil(
44
43
  getSystemInfo?.screenWidth * devicePixelRatio,
45
44
  )}*${Math.ceil(getSystemInfo?.screenHeight * devicePixelRatio)}`,
46
45
  uuid: UUID,
47
46
  loginType: '11',
48
47
  },
49
48
  public addressFetchInfo: {
50
49
  reqState: boolean
51
50
  promiseInstance: null | Promise<any>
52
51
  }
53
52
  public getPromotionConfig: {
54
53
  projectId: null | string | number
55
54
  pageId: null | string | number
56
55
  }
57
56
  public resInfo: ServiceInterFace.HttpRequestInfo
58
57
  public api: ServiceInterFace.HttpApi
59
58
  public isPageDomain: boolean
60
59
  public verifyColorList: string[]
61
60
  constructor(opt) {
62
61
  this._init()
63
62
  this.addressFetchInfo = {
64
63
  reqState: false,
65
64
  promiseInstance: null,
66
65
  }
67
66
  this.getPromotionConfig = {
68
67
  projectId: null,
69
68
  pageId: null,
70
69
  }
71
70
  this._userAreaUpdateListen()
72
71
  this.resInfo = this._getResConfig(opt)
73
72
  this.api = api
74
73
  this.isPageDomain = isH5
75
74
  ? window?.location?.hostname === PAGES_DOMAIN
76
75
  : false
77
76
  this.verifyColorList = [
78
77
  ...MobileVerifyColorList,
79
78
  ...AppVerifyColorList,
80
79
  ...JshopxVerifyColorList,
81
80
  ...BMallVerifyColorList,
82
81
  ]
83
82
  }
84
83
  _init(): void {
85
84
  httpInterceptors.forEach((item) => {
86
85
  Taro.addInterceptor((chain) => item(chain))
87
86
  })
88
87
  }
89
88
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
90
89
  return Object.assign({}, DefaultConfig, opt)
91
90
  }
92
91
 
93
92
  _userAreaUpdateListen() {
94
93
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
95
94
  this.updateApiClientParamsResInfo(areaInfo);
96
95
  });
97
96
  }
98
97
  updateApiClientParamsResInfo(opt = {}) {
99
98
  const { area, realTimeArea, ...others } = opt;
100
99
  this.resInfo.apiClientParams = {
101
100
  ...this.resInfo.apiClientParams,
102
101
  ...others,
103
102
  };
104
103
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
105
104
  realTimeArea &&
106
105
  realTimeArea !== '' &&
107
106
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
108
107
  }
109
108
 
110
109
  checkFunctionIdToReturnAppId(functionId) {
111
110
  if (JshopxColorFunctionIdList.includes(functionId)) {
112
111
  return APPID.JSHOPX_COLOR_APPID
113
112
  } else if (
114
113
  this.isPageDomain &&
115
114
  PagesColorFunctionIdList.includes(functionId)
116
115
  ) {
117
116
  return APPID.PAGES_COLOR_APPID
118
117
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
119
118
  return APPID.SHOP_MEMBER_COLOR_APPID
120
119
  } else if (B2BColorFunctionIdList.includes(functionId)) {
121
120
  return APPID.B2B_COLOR_APPID
122
121
  } else if (isPc) {
123
122
  return APPID.MALL_COLOR_APPID
124
123
  } else {
125
124
  return APPID.SHOP_COLOR_APPID
126
125
  }
127
126
  }
128
127
 
129
128
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
130
129
  if (functionId === 'receiveShopCoupon') {
131
130
  clientParams = Object.assign(
132
131
  {},
133
132
  {
134
133
  loginType: '1',
135
134
  loginWQBiz: WXAPP_BIZ_KEY,
136
135
  },
137
136
  clientParams,
138
137
  )
139
138
  }
140
139
  const apiClientParams = Object.assign(
141
140
  {},
142
141
  this.resInfo.apiClientParams,
143
142
  clientParams,
144
143
  )
145
144
  const isColorVerify = this.verifyColorList.includes(functionId);
146
145
  const getReqData = {
147
146
  functionId: functionId,
148
147
  body: JSON.stringify(bodyParams),
149
148
  t: Date.now(),
150
149
  ...apiClientParams,
151
150
  }
152
151
  const requestParams = {
153
152
  functionId: getReqData?.functionId,
154
153
  body: getReqData?.body,
155
154
  appid: getReqData?.appid,
156
155
  client: getReqData?.client,
157
156
  clientVersion: getReqData?.clientVersion,
158
157
  area: getReqData?.area,
159
158
  requestTimeStamp: getReqData?.t,
160
159
  }
161
160
  return http
162
161
  .request({
163
162
  url: this.api.apiFunc,
164
163
  data: getReqData,
165
164
  isColorVerify,
166
165
  })
167
166
  .then((res: ServiceInterFace.RequestPromiseRes) => {
168
167
  const { statusCode, data, status, msg } = res
169
168
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
170
169
  ok: true,
171
170
  }
172
171
  if ((statusCode === 200 || status === '0') && data) {
173
172
  changeRes = this.dealResponseFormatRes(data, getReqData)
174
173
  return changeRes
175
174
  } else {
176
175
  sgmCustomReport({
177
176
  code: getSgmCustomCode('interface_data_error'),
178
177
  msg: {
179
178
  subMsg: '接口请求异常',
180
179
  functionId,
181
180
  statusCode,
182
181
  source: 'remote',
183
182
  status,
184
183
  msg,
185
184
  requestParams,
186
185
  },
187
186
  })
188
187
  draInterfaceCustomReport({
189
188
  ...getReqData,
190
189
  ...res,
191
190
  source: 'remote',
192
191
  })
193
192
  changeRes = {
194
193
  ...data,
195
194
  statusCode,
196
195
  status,
197
196
  msg,
198
197
  ok: false,
199
198
  }
200
199
  return changeRes
201
200
  }
202
201
  })
203
202
  .catch((res) => {
204
203
  const propertyNames = Object.getOwnPropertyNames(res)
205
204
  const resObject = {}
206
205
  propertyNames.forEach((propertyName) => {
207
206
  resObject[propertyName] = res[propertyName]
208
207
  })
209
208
  sgmCustomReport({
210
209
  code: getSgmCustomCode('interface_data_error'),
211
210
  msg: {
212
211
  subMsg: '接口请求错误',
213
212
  functionId,
214
213
  source: 'remote',
215
214
  requestParams,
216
215
  catchError: resObject,
217
216
  },
218
217
  })
219
218
  draInterfaceCustomReport({
220
219
  ...getReqData,
221
220
  ...resObject,
222
221
  source: 'remote',
223
222
  })
224
223
  return {
225
224
  ...resObject,
226
225
  ok: false,
227
226
  } as ServiceInterFace.RequestResponseFormatRes
228
227
  })
229
228
  }
230
229
 
231
230
  dealResponseFormatRes(data, reqData) {
232
231
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
233
232
  ok: true,
234
233
  }
235
234
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
236
235
  ? Number(data.code)
237
236
  : -1
238
237
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
239
238
  ? Number(data.subCode)
240
239
  : -1
241
240
  if (
242
241
  data.success === true ||
243
242
  data.isSuccess ||
244
243
  resCode === 0 ||
245
244
  resCode === 200 ||
246
245
  subCode === 0
247
246
  ) {
248
247
  changeRes = {
249
248
  result: Object.prototype.hasOwnProperty.call(data, 'result')
250
249
  ? data.result
251
250
  : Object.prototype.hasOwnProperty.call(data, 'data')
252
251
  ? data.data
253
252
  : data,
254
253
  code: data.code ?? 200,
255
254
  ok: true,
256
255
  source: data,
257
256
  }
258
257
  return changeRes
259
258
  } else {
260
259
  changeRes = {
261
260
  ...data,
262
261
  ok: false,
263
262
  }
264
263
  if (reqData && resCode !== 3) {
265
264
  const getReportMsgData = reqData['hybridId']
266
265
  ? {
267
266
  subMsg: '预加载接口请求数据异常',
268
267
  hybridId: reqData?.hybridId,
269
268
  requestId: reqData?.requestId,
270
269
  param: reqData?.param,
271
270
  source: 'remote',
272
271
  }
273
272
  : {
274
273
  subMsg: '接口请求返回数据异常',
275
274
  functionId: reqData?.functionId,
276
275
  code: resCode,
277
276
  source: 'remote',
278
277
  requestParams: {
279
278
  functionId: reqData?.functionId,
280
279
  body: reqData?.body,
281
280
  appid: reqData?.appid,
282
281
  client: reqData?.client,
283
282
  clientVersion: reqData?.clientVersion,
284
283
  area: reqData?.area,
285
284
  requestTimeStamp: reqData?.t,
286
285
  },
287
286
  resData: data,
288
287
  }
289
288
  sgmCustomReport({
290
289
  code: getSgmCustomCode('interface_data_error'),
291
290
  msg: getReportMsgData,
292
291
  })
293
292
  draInterfaceCustomReport({
294
293
  ...reqData,
295
294
  ...data,
296
295
  source: 'remote',
297
296
  })
298
297
  }
299
298
  return changeRes
300
299
  }
301
300
  }
302
301
 
303
302
  async receiveCoupon(param = {}, clientParams) {
304
303
  console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
305
304
  return await this.gatewayReq(
306
305
  'receiveShopCoupon',
307
306
  {
308
307
  operation: '3',
309
308
  ...param,
310
309
  },
311
310
  { ...clientParams },
312
311
  );
313
312
  }
314
313
 
315
314
  getCustomerCenterDispatch(params = {}) {
316
315
  return this.gatewayReq('customerCenterDispatch', params, {
317
316
  clientVersion: '9.2.0',
318
317
  client: 'H5',
319
318
  uuid: 88888,
320
319
  appid: 'shopmember_m_jd_com',
321
320
  })
322
321
  }
323
322
 
324
323
  batchAddCart(...args) {
325
324
  let skuIds, num, showToast, giftCard;
326
325
  if (['number', 'string'].includes(typeof args[0])) {
327
326
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
328
327
  } else if (typeof args[0] === 'object' && args[0] !== null) {
329
328
  const params = args[0];
330
329
  skuIds = params.skuIds;
331
330
  num = params.num || 1;
332
331
  showToast = params.showToast !== undefined ? params.showToast : true;
333
332
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
334
333
  } else {
335
334
  console.error('batchAddCart() Invalid arguments!', args);
336
335
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
337
336
  showFailToast({
338
337
  title: msg,
339
338
  });
340
339
  return Promise.resolve({
341
340
  ok: false,
342
341
  msg,
343
342
  });
344
343
  }
345
344
  const addToWhereText = giftCard ? '购物清单' : '购物车';
346
345
  const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
347
346
  const failMsg = isLanguageForEn
348
347
  ? 'Please retry later'
349
348
  : `加入${addToWhereText}失败,请稍后重试!`;
350
349
  if (skuIds) {
351
350
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
352
351
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
353
352
  if (res?.ok) {
354
353
  if (showToast && !res?.isOpenApp)
355
354
  showSuccessToast({
356
355
  title: successMsg,
357
356
  });
358
357
  } else {
359
358
  showToast &&
360
359
  showFailToast({
361
360
  title: res?.errMsg || failMsg,
362
361
  });
363
362
  }
364
363
  return Promise.resolve(res)
365
364
  })
366
365
  .catch((e) => {
367
366
  console.log('调用加购方法异常=======>', e)
368
367
  return Promise.resolve({
369
368
  ok: false,
370
369
  msg: failMsg,
371
370
  });
372
371
  });
373
372
  } else {
374
373
  return Promise.resolve({
375
374
  ok: false,
376
375
  msg: failMsg,
377
376
  });
378
377
  }
379
378
  }
380
379
 
381
380
  async giftCardAddCart(skuList, num) {
382
381
  const loginType = isPc ? { loginType: 3 } : {};
383
382
  return this.gatewayReq(
384
383
  'giftCardAddCart',
385
384
  {
386
385
  skuList,
387
386
  num: Number(num),
388
387
  },
389
388
  { ...loginType },
390
389
  );
391
390
  }
392
391
 
393
392
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
394
393
  return new Promise((resolve) => {
395
394
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
396
395
  if (productIdsArr.length > 0) {
397
396
  if (giftCard) {
398
397
  this.giftCardAddCart(productIdsArr, addCardNum)
399
398
  .then((res) => {
400
399
  if (res?.code === '0' && res?.result?.value) {
401
400
  resolve({
402
401
  ok: true,
403
402
  });
404
403
  } else {
405
404
  resolve({
406
405
  ok: false,
407
406
  msg: '加购失败,请稍后重试',
408
407
  });
409
408
  }
410
409
  })
411
410
  .catch((e) => {
412
411
  console.error('礼品卡加车失败: ', e);
413
412
  resolve({
414
413
  ok: false,
415
414
  msg: '加购失败,请稍后重试',
416
415
  });
417
416
  });
418
417
  } else if (isJdApp) {
419
418
  console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
420
419
  } else if (isMin) {
421
420
  console.log('==========>', '京购批量加车!')
422
421
  const productsAddCartList = productIdsArr.map((skuItem) => {
423
422
  return {
424
423
  skuId: skuItem,
425
424
  buyNum: addCardNum,
426
425
  }
427
426
  })
428
427
  global.wxAppBizInstance
429
428
  .addCart({ commArr: productsAddCartList })
430
429
  .then((res) => {
431
430
  console.log('dealCartSuccess: ', res)
432
431
  resolve({
433
432
  ok: true,
434
433
  msg: '已加入购物车!',
435
434
  data: res,
436
435
  })
437
436
  })
438
437
  .catch((e) => {
439
438
  console.log('京购小程序批量加车失败dealCartFail: ', e)
440
439
  resolve({
441
440
  ok: false,
442
441
  msg: '加购失败,请稍后重试',
443
442
  })
444
443
  })
445
444
  } else {
446
445
  console.log('==========>', 'M站批量加车!')
447
446
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
448
447
  resolve(res),
449
448
  )
450
449
  }
451
450
  } else {
452
451
  resolve({
453
452
  ok: false,
454
453
  msg: '加购sku不能为空',
455
454
  })
456
455
  }
457
456
  })
458
457
  }
459
458
 
460
459
  productAddToCart() {
461
460
  return Promise.resolve({
462
461
  ok: false,
463
462
  msg: 'productAddToCart暂不支持小程序',
464
463
  });
465
464
  }
466
465
  bMallGetUserInfo = () => {
467
466
  return getBMallUserInfo()
468
467
  }
469
468
  async bMallAddCart(params = {}) {
470
469
  console.warn('bMallAddCart 方法在微信京购小程序环境未经验证,请不要使用!');
471
470
  return await this.gatewayReq('bmall_cartAdd', params, {
472
471
  client: 'H5',
473
472
  clientVersion: '5.5.0',
474
473
  })
475
474
  }
476
475
  async bMallChangeCart(params = {}) {
477
476
  console.warn('bMallChangeCart 方法在微信京购小程序环境未经验证,请不要使用!');
478
477
  return await this.gatewayReq('bmall_cartChange', params, {
479
478
  client: 'H5',
480
479
  clientVersion: '5.5.0',
481
480
  })
482
481
  }
483
482
  async bMallRemoveCart(params = {}) {
484
483
  console.warn('bMallRemoveCart 方法在微信京购小程序环境未经验证,请不要使用!');
485
484
  return await this.gatewayReq(
486
485
  'bmall_cartRemove',
487
486
  params,
488
487
  {
489
488
  client: 'H5',
490
489
  clientVersion: '5.5.0',
491
490
  },
492
491
  )
493
492
  }
494
493
  async bMallGetOmittedProduct(params = {}) {
495
494
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
496
495
  client: 'H5',
497
496
  clientVersion: '5.5.0',
498
497
  })
499
498
  }
500
499
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
501
500
  const params = await getParams({ ...data, skuId, bMallTag, num })
502
501
  return await this.bMallAddCart(params)
503
502
  }
504
503
  async bMallGetSkuNumService(bMallTag = 1) {
505
504
  const params = await getParams({ bMallTag })
506
505
  delete params.operations
507
506
  return await this.bMallGetOmittedProduct(params)
508
507
  }
509
508
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
510
509
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
511
510
  return await this.bMallRemoveCart(params)
512
511
  }
513
512
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
514
513
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
515
514
  return await this.bMallChangeCart(params)
516
515
  }
517
516
 
518
517
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
519
518
  if (!needRequest && isH5 && window?.bMallCartData) {
520
519
  return window?.bMallCartData
521
520
  }
522
521
  const cartData = await this.bMallGetSkuNumService(bMallTag)
523
522
  let items
524
523
  if (cartData.ok && cartData.result) {
525
524
  items = cartData?.result?.items || {}
526
525
  }
527
526
  if (isH5) {
528
527
  window.bMallCartData = items
529
528
  }
530
529
  return items
531
530
  }
532
531
 
533
532
  async bMallCartHandle(goodItem, num) {
534
533
  try {
535
534
  const {
536
535
  skuUuid,
537
536
  limitUpper,
538
537
  limitLower,
539
538
  } = goodItem
540
539
  let cartNum = Number(num)
541
540
  if (limitLower && cartNum && cartNum < limitLower) {
542
541
  cartNum = limitLower
543
542
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
544
543
  cartNum = limitUpper
545
544
  }
546
545
  if (skuUuid && cartNum > 0) {
547
546
  return this.bMallChangeCartService({
548
547
  ...goodItem,
549
548
  skuUuid,
550
549
  num: cartNum,
551
550
  })
552
551
  } else if (!skuUuid && cartNum > 0) {
553
552
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
554
553
  } else if (skuUuid && !cartNum) {
555
554
  return this.bMallRemoveCartService({
556
555
  ...goodItem,
557
556
  skuUuid,
558
557
  num: cartNum,
559
558
  })
560
559
  } else {
561
560
  console.error('参数不全')
562
561
  return false
563
562
  }
564
563
  } catch (e) {
565
564
  console.error(e)
566
565
  }
567
566
  }
567
+ import Taro from '@tarojs/taro';
568
568
  APPID,
569
569
  JshopxColorFunctionIdList,
570
570
  PagesColorFunctionIdList,
571
571
  PAGES_DOMAIN,
572
572
  B2BColorFunctionIdList,
573
573
  MobileVerifyColorList,
574
574
  AppVerifyColorList,
575
575
  JshopxVerifyColorList,
576
576
  BMallVerifyColorList,
577
577
  shopMemberColorFunctionIdList,
578
578
  isLanguageForEn,
579
579
  isJdApp,
580
580
  isIosDevice,
581
581
  isAndroidDevice,
582
582
  showSuccessToast,
583
583
  showFailToast,
584
584
  isH5,
585
585
  isWxMinAndWxapp,
586
586
  isMin,
587
587
  isPc,
588
588
  cookiesStr: '',
589
589
  requestHeaderContentType: {
590
590
  jsonHeader: {
591
591
  'content-type': 'application/json;charset=utf-8',
592
592
  },
593
593
  formDataHeader: {
594
594
  'content-type': 'application/x-www-form-urlencoded',
595
595
  },
596
596
  },
597
597
  requestBaseParam: {
598
598
  data: null,
599
599
  header: {
600
600
  'content-type': 'application/json;charset=utf-8',
601
601
  },
602
602
  },
603
603
  timeOut: 7000,
604
604
  apiClientParams: {
605
605
  appid: 'wx_mini_app',
606
606
  clientVersion: '11.0.0',
607
607
  client: 'wh5',
608
608
  area: '1_72_2799_0',
609
609
  screen: `${Math.ceil(
610
610
  getSystemInfo?.screenWidth * devicePixelRatio,
611
611
  )}*${Math.ceil(getSystemInfo?.screenHeight * devicePixelRatio)}`,
612
612
  uuid: UUID,
613
613
  loginType: '11',
614
614
  },
615
615
  public addressFetchInfo: {
616
616
  reqState: boolean
617
617
  promiseInstance: null | Promise<any>
618
618
  }
619
619
  public getPromotionConfig: {
620
620
  projectId: null | string | number
621
621
  pageId: null | string | number
622
622
  }
623
623
  public resInfo: ServiceInterFace.HttpRequestInfo
624
624
  public api: ServiceInterFace.HttpApi
625
625
  public isPageDomain: boolean
626
626
  public verifyColorList: string[]
627
627
  constructor(opt) {
628
628
  this._init()
629
629
  this.addressFetchInfo = {
630
630
  reqState: false,
631
631
  promiseInstance: null,
632
632
  }
633
633
  this.getPromotionConfig = {
634
634
  projectId: null,
635
635
  pageId: null,
636
636
  }
637
637
  this._userAreaUpdateListen()
638
638
  this.resInfo = this._getResConfig(opt)
639
639
  this.api = api
640
640
  this.isPageDomain = isH5
641
641
  ? window?.location?.hostname === PAGES_DOMAIN
642
642
  : false
643
643
  this.verifyColorList = [
644
644
  ...MobileVerifyColorList,
645
645
  ...AppVerifyColorList,
646
646
  ...JshopxVerifyColorList,
647
647
  ...BMallVerifyColorList,
648
648
  ]
649
649
  }
650
650
  _init(): void {
651
651
  httpInterceptors.forEach((item) => {
652
652
  Taro.addInterceptor((chain) => item(chain))
653
653
  })
654
654
  }
655
655
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
656
656
  return Object.assign({}, DefaultConfig, opt)
657
657
  }
658
658
 
659
659
  _userAreaUpdateListen() {
660
660
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
661
661
  this.updateApiClientParamsResInfo(areaInfo);
662
662
  });
663
663
  }
664
664
  updateApiClientParamsResInfo(opt = {}) {
665
665
  const { area, realTimeArea, ...others } = opt;
666
666
  this.resInfo.apiClientParams = {
667
667
  ...this.resInfo.apiClientParams,
668
668
  ...others,
669
669
  };
670
670
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
671
671
  realTimeArea &&
672
672
  realTimeArea !== '' &&
673
673
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
674
674
  }
675
675
 
676
676
  checkFunctionIdToReturnAppId(functionId) {
677
677
  if (JshopxColorFunctionIdList.includes(functionId)) {
678
678
  return APPID.JSHOPX_COLOR_APPID
679
679
  } else if (
680
680
  this.isPageDomain &&
681
681
  PagesColorFunctionIdList.includes(functionId)
682
682
  ) {
683
683
  return APPID.PAGES_COLOR_APPID
684
684
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
685
685
  return APPID.SHOP_MEMBER_COLOR_APPID
686
686
  } else if (B2BColorFunctionIdList.includes(functionId)) {
687
687
  return APPID.B2B_COLOR_APPID
688
688
  } else if (isPc) {
689
689
  return APPID.MALL_COLOR_APPID
690
690
  } else {
691
691
  return APPID.SHOP_COLOR_APPID
692
692
  }
693
693
  }
694
694
 
695
695
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
696
696
  if (functionId === 'receiveShopCoupon') {
697
697
  clientParams = Object.assign(
698
698
  {},
699
699
  {
700
700
  loginType: '1',
701
701
  loginWQBiz: WXAPP_BIZ_KEY,
702
702
  },
703
703
  clientParams,
704
704
  )
705
705
  }
706
706
  const apiClientParams = Object.assign(
707
707
  {},
708
708
  this.resInfo.apiClientParams,
709
709
  clientParams,
710
710
  )
711
711
  const isColorVerify = this.verifyColorList.includes(functionId);
712
712
  const getReqData = {
713
713
  functionId: functionId,
714
714
  body: JSON.stringify(bodyParams),
715
715
  t: Date.now(),
716
716
  ...apiClientParams,
717
717
  }
718
718
  const requestParams = {
719
719
  functionId: getReqData?.functionId,
720
720
  body: getReqData?.body,
721
721
  appid: getReqData?.appid,
722
722
  client: getReqData?.client,
723
723
  clientVersion: getReqData?.clientVersion,
724
724
  area: getReqData?.area,
725
725
  requestTimeStamp: getReqData?.t,
726
726
  }
727
727
  return http
728
728
  .request({
729
729
  url: this.api.apiFunc,
730
730
  data: getReqData,
731
731
  isColorVerify,
732
732
  })
733
733
  .then((res: ServiceInterFace.RequestPromiseRes) => {
734
734
  const { statusCode, data, status, msg } = res
735
735
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
736
736
  ok: true,
737
737
  }
738
738
  if ((statusCode === 200 || status === '0') && data) {
739
739
  changeRes = this.dealResponseFormatRes(data, getReqData)
740
740
  return changeRes
741
741
  } else {
742
742
  sgmCustomReport({
743
743
  code: getSgmCustomCode('interface_data_error'),
744
744
  msg: {
745
745
  subMsg: '接口请求异常',
746
746
  functionId,
747
747
  statusCode,
748
748
  source: 'remote',
749
749
  status,
750
750
  msg,
751
751
  requestParams,
752
752
  },
753
753
  })
754
754
  draInterfaceCustomReport({
755
755
  ...getReqData,
756
756
  ...res,
757
757
  source: 'remote',
758
758
  })
759
759
  changeRes = {
760
760
  ...data,
761
761
  statusCode,
762
762
  status,
763
763
  msg,
764
764
  ok: false,
765
765
  }
766
766
  return changeRes
767
767
  }
768
768
  })
769
769
  .catch((res) => {
770
770
  const propertyNames = Object.getOwnPropertyNames(res)
771
771
  const resObject = {}
772
772
  propertyNames.forEach((propertyName) => {
773
773
  resObject[propertyName] = res[propertyName]
774
774
  })
775
775
  sgmCustomReport({
776
776
  code: getSgmCustomCode('interface_data_error'),
777
777
  msg: {
778
778
  subMsg: '接口请求错误',
779
779
  functionId,
780
780
  source: 'remote',
781
781
  requestParams,
782
782
  catchError: resObject,
783
783
  },
784
784
  })
785
785
  draInterfaceCustomReport({
786
786
  ...getReqData,
787
787
  ...resObject,
788
788
  source: 'remote',
789
789
  })
790
790
  return {
791
791
  ...resObject,
792
792
  ok: false,
793
793
  } as ServiceInterFace.RequestResponseFormatRes
794
794
  })
795
795
  }
796
796
 
797
797
  dealResponseFormatRes(data, reqData) {
798
798
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
799
799
  ok: true,
800
800
  }
801
801
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
802
802
  ? Number(data.code)
803
803
  : -1
804
804
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
805
805
  ? Number(data.subCode)
806
806
  : -1
807
807
  if (
808
808
  data.success === true ||
809
809
  data.isSuccess ||
810
810
  resCode === 0 ||
811
811
  resCode === 200 ||
812
812
  subCode === 0
813
813
  ) {
814
814
  changeRes = {
815
815
  result: Object.prototype.hasOwnProperty.call(data, 'result')
816
816
  ? data.result
817
817
  : Object.prototype.hasOwnProperty.call(data, 'data')
818
818
  ? data.data
819
819
  : data,
820
820
  code: data.code ?? 200,
821
821
  ok: true,
822
822
  source: data,
823
823
  }
824
824
  return changeRes
825
825
  } else {
826
826
  changeRes = {
827
827
  ...data,
828
828
  ok: false,
829
829
  }
830
830
  if (reqData && resCode !== 3) {
831
831
  const getReportMsgData = reqData['hybridId']
832
832
  ? {
833
833
  subMsg: '预加载接口请求数据异常',
834
834
  hybridId: reqData?.hybridId,
835
835
  requestId: reqData?.requestId,
836
836
  param: reqData?.param,
837
837
  source: 'remote',
838
838
  }
839
839
  : {
840
840
  subMsg: '接口请求返回数据异常',
841
841
  functionId: reqData?.functionId,
842
842
  code: resCode,
843
843
  source: 'remote',
844
844
  requestParams: {
845
845
  functionId: reqData?.functionId,
846
846
  body: reqData?.body,
847
847
  appid: reqData?.appid,
848
848
  client: reqData?.client,
849
849
  clientVersion: reqData?.clientVersion,
850
850
  area: reqData?.area,
851
851
  requestTimeStamp: reqData?.t,
852
852
  },
853
853
  resData: data,
854
854
  }
855
855
  sgmCustomReport({
856
856
  code: getSgmCustomCode('interface_data_error'),
857
857
  msg: getReportMsgData,
858
858
  })
859
859
  draInterfaceCustomReport({
860
860
  ...reqData,
861
861
  ...data,
862
862
  source: 'remote',
863
863
  })
864
864
  }
865
865
  return changeRes
866
866
  }
867
867
  }
868
868
 
869
869
  async receiveCoupon(param = {}, clientParams) {
870
870
  console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
871
871
  return await this.gatewayReq(
872
872
  'receiveShopCoupon',
873
873
  {
874
874
  operation: '3',
875
875
  ...param,
876
876
  },
877
877
  { ...clientParams },
878
878
  );
879
879
  }
880
880
 
881
881
  getCustomerCenterDispatch(params = {}) {
882
882
  return this.gatewayReq('customerCenterDispatch', params, {
883
883
  clientVersion: '9.2.0',
884
884
  client: 'H5',
885
885
  uuid: 88888,
886
886
  appid: 'shopmember_m_jd_com',
887
887
  })
888
888
  }
889
889
 
890
890
  batchAddCart(...args) {
891
891
  let skuIds, num, showToast, giftCard;
892
892
  if (['number', 'string'].includes(typeof args[0])) {
893
893
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
894
894
  } else if (typeof args[0] === 'object' && args[0] !== null) {
895
895
  const params = args[0];
896
896
  skuIds = params.skuIds;
897
897
  num = params.num || 1;
898
898
  showToast = params.showToast !== undefined ? params.showToast : true;
899
899
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
900
900
  } else {
901
901
  console.error('batchAddCart() Invalid arguments!', args);
902
902
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
903
903
  showFailToast({
904
904
  title: msg,
905
905
  });
906
906
  return Promise.resolve({
907
907
  ok: false,
908
908
  msg,
909
909
  });
910
910
  }
911
911
  const addToWhereText = giftCard ? '购物清单' : '购物车';
912
912
  const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
913
913
  const failMsg = isLanguageForEn
914
914
  ? 'Please retry later'
915
915
  : `加入${addToWhereText}失败,请稍后重试!`;
916
916
  if (skuIds) {
917
917
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
918
918
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
919
919
  if (res?.ok) {
920
920
  if (showToast && !res?.isOpenApp)
921
921
  showSuccessToast({
922
922
  title: successMsg,
923
923
  });
924
924
  } else {
925
925
  showToast &&
926
926
  showFailToast({
927
927
  title: res?.errMsg || failMsg,
928
928
  });
929
929
  }
930
930
  return Promise.resolve(res)
931
931
  })
932
932
  .catch((e) => {
933
933
  console.log('调用加购方法异常=======>', e)
934
934
  return Promise.resolve({
935
935
  ok: false,
936
936
  msg: failMsg,
937
937
  });
938
938
  });
939
939
  } else {
940
940
  return Promise.resolve({
941
941
  ok: false,
942
942
  msg: failMsg,
943
943
  });
944
944
  }
945
945
  }
946
946
 
947
947
  async giftCardAddCart(skuList, num) {
948
948
  const loginType = isPc ? { loginType: 3 } : {};
949
949
  return this.gatewayReq(
950
950
  'giftCardAddCart',
951
951
  {
952
952
  skuList,
953
953
  num: Number(num),
954
954
  },
955
955
  { ...loginType },
956
956
  );
957
957
  }
958
958
 
959
959
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
960
960
  return new Promise((resolve) => {
961
961
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
962
962
  if (productIdsArr.length > 0) {
963
963
  if (giftCard) {
964
964
  this.giftCardAddCart(productIdsArr, addCardNum)
965
965
  .then((res) => {
966
966
  if (res?.code === '0' && res?.result?.value) {
967
967
  resolve({
968
968
  ok: true,
969
969
  });
970
970
  } else {
971
971
  resolve({
972
972
  ok: false,
973
973
  msg: '加购失败,请稍后重试',
974
974
  });
975
975
  }
976
976
  })
977
977
  .catch((e) => {
978
978
  console.error('礼品卡加车失败: ', e);
979
979
  resolve({
980
980
  ok: false,
981
981
  msg: '加购失败,请稍后重试',
982
982
  });
983
983
  });
984
984
  } else if (isJdApp) {
985
985
  console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
986
986
  } else if (isMin) {
987
987
  console.log('==========>', '京购批量加车!')
988
988
  const productsAddCartList = productIdsArr.map((skuItem) => {
989
989
  return {
990
990
  skuId: skuItem,
991
991
  buyNum: addCardNum,
992
992
  }
993
993
  })
994
994
  global.wxAppBizInstance
995
995
  .addCart({ commArr: productsAddCartList })
996
996
  .then((res) => {
997
997
  console.log('dealCartSuccess: ', res)
998
998
  resolve({
999
999
  ok: true,
1000
1000
  msg: '已加入购物车!',
1001
1001
  data: res,
1002
1002
  })
1003
1003
  })
1004
1004
  .catch((e) => {
1005
1005
  console.log('京购小程序批量加车失败dealCartFail: ', e)
1006
1006
  resolve({
1007
1007
  ok: false,
1008
1008
  msg: '加购失败,请稍后重试',
1009
1009
  })
1010
1010
  })
1011
1011
  } else {
1012
1012
  console.log('==========>', 'M站批量加车!')
1013
1013
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
1014
1014
  resolve(res),
1015
1015
  )
1016
1016
  }
1017
1017
  } else {
1018
1018
  resolve({
1019
1019
  ok: false,
1020
1020
  msg: '加购sku不能为空',
1021
1021
  })
1022
1022
  }
1023
1023
  })
1024
1024
  }
1025
1025
 
1026
1026
  productAddToCart() {
1027
1027
  return Promise.resolve({
1028
1028
  ok: false,
1029
1029
  msg: 'productAddToCart暂不支持小程序',
1030
1030
  });
1031
1031
  }
1032
1032
  bMallGetUserInfo(){
1033
1033
  return Promise.resolve({
1034
1034
  ok: false,
1035
1035
  msg: 'productAddToCart暂不支持小程序',
1036
1036
  });
1037
1037
  }
1038
1038
  bMallGetSkuNumApi(){
1039
1039
  return Promise.resolve({
1040
1040
  ok: false,
1041
1041
  msg: 'productAddToCart暂不支持小程序',
1042
1042
  });
1043
1043
  }
1044
1044
  bMallCartHandle(){
1045
1045
  return Promise.resolve({
1046
1046
  ok: false,
1047
1047
  msg: 'productAddToCart暂不支持小程序',
1048
1048
  });
1049
1049
  }