@conecli/cone-render 0.10.1-shop3.97 → 0.10.1-shop3.98

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.
@@ -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
  draBusinessCustomReport,
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
  draInterfaceCustomReport,
23
22
  isHarmonyDevice,
24
23
  isAscfApp,
25
24
  callRouterIOS,
26
25
  callRouterAndroid,
27
26
  callRouterHarmony,
28
27
  sendNativePageToShowCartFloatBtn,
29
28
  cookiesStr: '',
30
29
  requestHeaderContentType: {
31
30
  jsonHeader: {
32
31
  'content-type': 'application/json;charset=utf-8',
33
32
  },
34
33
  formDataHeader: {
35
34
  'content-type': 'application/x-www-form-urlencoded',
36
35
  },
37
36
  },
38
37
  requestBaseParam: {
39
38
  data: null,
40
39
  header: {
41
40
  'content-type': 'application/json;charset=utf-8',
42
41
  },
43
42
  },
44
43
  timeOut: 7000,
45
44
  apiClientParams: {
46
45
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
47
46
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
48
47
  area: '1_72_2799_0',
49
48
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
50
49
  window.screen?.height * devicePixelRatio,
51
50
  )}`,
52
51
  uuid: UUID,
53
52
  },
54
53
  window.shopGlobalSwitch?.useNativeHarmonyAddCartJdAppVersion;
55
54
  nativeHarmonyAddCartJdAppVersion && jdAppVersionCompare(nativeHarmonyAddCartJdAppVersion) >= 0;
56
55
  public addressFetchInfo: {
57
56
  reqState: boolean;
58
57
  promiseInstance: null | Promise<any>;
59
58
  };
60
59
  public getPromotionConfig: {
61
60
  projectId: null | string | number;
62
61
  pageId: null | string | number;
63
62
  };
64
63
  public resInfo: ServiceInterFace.HttpRequestInfo;
65
64
  public api: ServiceInterFace.HttpApi;
66
65
  public isPageDomain: boolean;
67
66
  public verifyColorList: string[];
68
67
  private isShowJdShopCartFloatBtn: boolean;
69
68
  constructor(opt) {
70
69
  this._init();
71
70
  this.addressFetchInfo = {
72
71
  reqState: false,
73
72
  promiseInstance: null,
74
73
  };
75
74
  this.getPromotionConfig = {
76
75
  projectId: null,
77
76
  pageId: null,
78
77
  };
79
78
  this._userAreaUpdateListen();
80
79
  this.resInfo = this._getResConfig(opt);
81
80
  this.api = api;
82
81
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
83
82
  this.verifyColorList = [
84
83
  ...MobileVerifyColorList,
85
84
  ...AppVerifyColorList,
86
85
  ...JshopxVerifyColorList,
87
86
  ...BMallVerifyColorList,
88
87
  ];
89
88
  this.isShowJdShopCartFloatBtn =
90
89
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
91
90
  }
92
91
  _init(): void {
93
92
  httpInterceptors.forEach((item) => {
94
93
  Taro.addInterceptor((chain) => item(chain));
95
94
  });
96
95
  }
97
96
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
98
97
  return Object.assign({}, DefaultConfig, opt);
99
98
  }
100
99
 
101
100
  _userAreaUpdateListen() {
102
101
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
103
102
  this.updateApiClientParamsResInfo(areaInfo);
104
103
  console.log(
105
104
  'cone-render收到原生端获取传来的四级地址信息',
106
105
  areaInfo,
107
106
  '更新后的接口底层信息',
108
107
  this.resInfo.apiClientParams,
109
108
  );
110
109
  });
111
110
  }
112
111
  updateApiClientParamsResInfo(opt = {}) {
113
112
  const { area, realTimeArea, ...others } = opt;
114
113
  this.resInfo.apiClientParams = {
115
114
  ...this.resInfo.apiClientParams,
116
115
  ...others,
117
116
  };
118
117
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
119
118
  realTimeArea &&
120
119
  realTimeArea !== '' &&
121
120
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
122
121
  }
123
122
 
124
123
  checkFunctionIdToReturnAppId(functionId) {
125
124
  if (JshopxColorFunctionIdList.includes(functionId)) {
126
125
  return APPID.JSHOPX_COLOR_APPID;
127
126
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
128
127
  return APPID.PAGES_COLOR_APPID;
129
128
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
130
129
  return APPID.SHOP_MEMBER_COLOR_APPID;
131
130
  } else if (B2BColorFunctionIdList.includes(functionId)) {
132
131
  return APPID.B2B_COLOR_APPID;
133
132
  } else if (isPc) {
134
133
  return APPID.MALL_COLOR_APPID;
135
134
  } else {
136
135
  return APPID.SHOP_COLOR_APPID;
137
136
  }
138
137
  }
139
138
 
140
139
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
141
140
  if (
142
141
  functionId === 'receiveShopCoupon' &&
143
142
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
144
143
  isWxMinAndWxapp)
145
144
  ) {
146
145
  clientParams = Object.assign(
147
146
  {},
148
147
  {
149
148
  loginType: isAscfApp ? '2' : '1',
150
149
  loginWQBiz: WXAPP_BIZ_KEY,
151
150
  },
152
151
  clientParams,
153
152
  );
154
153
  }
155
154
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
156
155
  typeof apiClientParams.appid === 'undefined' &&
157
156
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
158
157
  const isColorVerify = this.verifyColorList.includes(functionId);
159
158
  const getReqData = {
160
159
  functionId: functionId,
161
160
  body: JSON.stringify(bodyParams),
162
161
  t: Date.now(),
163
162
  ...apiClientParams,
164
163
  };
165
164
  return http
166
165
  .request({
167
166
  url: this.api.apiFunc,
168
167
  data: getReqData,
169
168
  isColorVerify,
170
169
  })
171
170
  .then((res: ServiceInterFace.RequestPromiseRes) => {
172
171
  const { statusCode, data, status, msg } = res;
173
172
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
174
173
  ok: true,
175
174
  };
176
175
  if ((statusCode === 200 || status === '0') && data) {
177
176
  changeRes = this.dealResponseFormatRes(data);
178
177
  return changeRes;
179
178
  } else {
180
179
  changeRes = {
181
180
  ...data,
182
181
  statusCode,
183
182
  status,
184
183
  msg,
185
184
  ok: false,
186
185
  };
187
186
  return changeRes;
188
187
  }
189
188
  })
190
189
  .catch((res) => {
191
190
  const propertyNames = Object.getOwnPropertyNames(res);
192
191
  const resObject = {};
193
192
  propertyNames.forEach((propertyName) => {
194
193
  resObject[propertyName] = res[propertyName];
195
194
  });
196
195
  draInterfaceCustomReport({
197
196
  eventName: 'apiStatusCode',
198
197
  errorName: `shop_${functionId}_error`,
199
198
  errorMessage: `接口返回statusCode为${res?.statusCode || res?.status}`,
200
199
  url: this.api.apiFunc,
201
200
  source: 'remote',
202
201
  requestType: res?.requestType,
203
202
  functionId: getReqData?.functionId,
204
203
  appid: getReqData?.appid,
205
204
  client: getReqData?.client,
206
205
  clientVersion: getReqData?.clientVersion,
207
206
  statusCode: res?.statusCode,
208
207
  status: res?.status,
209
208
  statusText: res?.statusText,
210
209
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
211
210
  originReqDataStr: JSON.stringify(getReqData),
212
211
  });
213
212
  return {
214
213
  ...resObject,
215
214
  ok: false,
216
215
  } as ServiceInterFace.RequestResponseFormatRes;
217
216
  });
218
217
  }
219
218
 
220
219
  dealResponseFormatRes(data) {
221
220
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
222
221
  ok: true,
223
222
  };
224
223
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
225
224
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
226
225
  ? Number(data.subCode)
227
226
  : -1;
228
227
  if (
229
228
  data.success === true ||
230
229
  data.isSuccess ||
231
230
  resCode === 0 ||
232
231
  resCode === 200 ||
233
232
  subCode === 0
234
233
  ) {
235
234
  changeRes = {
236
235
  result: Object.prototype.hasOwnProperty.call(data, 'result')
237
236
  ? data.result
238
237
  : Object.prototype.hasOwnProperty.call(data, 'data')
239
238
  ? data.data
240
239
  : data,
241
240
  code: data.code ?? 200,
242
241
  ok: true,
243
242
  source: data,
244
243
  };
245
244
  return changeRes;
246
245
  } else {
247
246
  changeRes = {
248
247
  ...data,
249
248
  ok: false,
250
249
  };
251
250
  return changeRes;
252
251
  }
253
252
  }
254
253
 
255
254
  async receiveCoupon(param = {}, clientParams) {
256
255
  const loginType = isPc ? { loginType: 3 } : {};
257
256
  return await this.gatewayReq(
258
257
  'receiveShopCoupon',
259
258
  {
260
259
  operation: '3',
261
260
  ...param,
262
261
  },
263
262
  { ...loginType, ...clientParams },
264
263
  );
265
264
  }
266
265
 
267
266
  getCustomerCenterDispatch(params = {}) {
268
267
  return this.gatewayReq('customerCenterDispatch', params, {
269
268
  clientVersion: '9.2.0',
270
269
  client: 'H5',
271
270
  uuid: 88888,
272
271
  appid: 'shopmember_m_jd_com',
273
272
  });
274
273
  }
275
274
 
276
275
  batchAddCart(...args) {
277
276
  let skuIds, num, showToast, giftCard;
278
277
  if (['number', 'string'].includes(typeof args[0])) {
279
278
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
280
279
  } else if (typeof args[0] === 'object' && args[0] !== null) {
281
280
  const params = args[0];
282
281
  skuIds = params.skuIds;
283
282
  num = params.num || 1;
284
283
  showToast = params.showToast !== undefined ? params.showToast : true;
285
284
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
286
285
  } else {
287
286
  try {
288
287
  const data = {
289
288
  eventName: 'business',
290
289
  errorName: 'shop_batchAddCart_error',
291
290
  errorMessage: '入参不合法',
292
291
  extraData: JSON.stringify(args),
293
292
  };
294
293
  draBusinessCustomReport(data);
295
294
  } catch (e) {
296
295
  console.error('draBusinessCustomReport error:', e);
297
296
  }
298
297
  const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
299
298
  showFailToast({
300
299
  title: msg,
301
300
  });
302
301
  return Promise.resolve({
303
302
  ok: false,
304
303
  msg,
305
304
  });
306
305
  }
307
306
  const successMsg = giftCard
308
307
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
309
308
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
310
309
  const failMsg = giftCard
311
310
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
312
311
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
313
312
  if (skuIds) {
314
313
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
315
314
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
316
315
  if (res?.ok) {
317
316
  showToast &&
318
317
  !res?.isOpenApp &&
319
318
  showSuccessToast({
320
319
  title: successMsg,
321
320
  });
322
321
  this.isShowJdShopCartFloatBtn &&
323
322
  sendNativePageToShowCartFloatBtn({
324
323
  isShow: true,
325
324
  });
326
325
  } else {
327
326
  showToast &&
328
327
  showFailToast({
329
328
  title: res?.errMsg || failMsg,
330
329
  });
331
330
  }
332
331
  return Promise.resolve(res);
333
332
  })
334
333
  .catch((e) => {
335
334
  console.log('调用加购方法异常=======>', e);
336
335
  return Promise.resolve({
337
336
  ok: false,
338
337
  msg: failMsg,
339
338
  });
340
339
  });
341
340
  } else {
342
341
  try {
343
342
  const data = {
344
343
  eventName: 'business',
345
344
  errorName: 'shop_batchAddCart_error',
346
345
  errorMessage: '没有传入合法的skuIds',
347
346
  };
348
347
  draBusinessCustomReport(data);
349
348
  } catch (e) {
350
349
  console.error('draBusinessCustomReport error:', e);
351
350
  }
352
351
  return Promise.resolve({
353
352
  ok: false,
354
353
  msg: failMsg,
355
354
  });
356
355
  }
357
356
  }
358
357
 
359
358
  async giftCardAddCart(skuList, num) {
360
359
  const loginType = isPc ? { loginType: 3 } : {};
361
360
  return this.gatewayReq(
362
361
  'giftCardAddCart',
363
362
  {
364
363
  skuList,
365
364
  num: Number(num),
366
365
  },
367
366
  { ...loginType },
368
367
  );
369
368
  }
370
369
 
371
370
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
372
371
  return new Promise((resolve) => {
373
372
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
374
373
  if (productIdsArr.length > 0) {
375
374
  if (giftCard) {
376
375
  this.giftCardAddCart(productIdsArr, addCardNum)
377
376
  .then((res) => {
378
377
  if (res?.code === '0' && res?.result?.value) {
379
378
  resolve({
380
379
  ok: true,
381
380
  });
382
381
  } else {
383
382
  try {
384
383
  const data = {
385
384
  eventName: 'business',
386
385
  errorName: 'shop_batchAddCart_error',
387
386
  errorMessage: '礼品卡加车接口返回加车失败标识',
388
387
  };
389
388
  draBusinessCustomReport(data);
390
389
  } catch (e) {
391
390
  console.error('draBusinessCustomReport error:', e);
392
391
  }
393
392
  resolve({
394
393
  ok: false,
395
394
  msg: '加购失败,请稍后重试',
396
395
  });
397
396
  }
398
397
  })
399
398
  .catch((e) => {
400
399
  console.error('礼品卡加车失败: ', e);
401
400
  resolve({
402
401
  ok: false,
403
402
  msg: '加购失败,请稍后重试',
404
403
  });
405
404
  });
406
405
  } else if (
407
406
  isJdApp &&
408
407
  (!isHarmonyDevice || (isHarmonyDevice && useNativeHarmonyAddCartJd))
409
408
  ) {
410
409
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now() + Number(productIdsArr[0]) + Number(addCardNum)}`;
411
410
  console.log(
412
411
  '==========>',
413
412
  '使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
414
413
  nativeAddCartCallBack,
415
414
  );
416
415
  if (!window[nativeAddCartCallBack]) {
417
416
  window[nativeAddCartCallBack] = (res) => {
418
417
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
419
418
  console.info(
420
419
  '获取批量加车原始数据',
421
420
  res,
422
421
  '====转换后的json数据为===',
423
422
  getMessageJsonData,
424
423
  );
425
424
  try {
426
425
  if (isAndroidDevice) {
427
426
  const isOk = getMessageJsonData?.status === '0';
428
427
  isOk
429
428
  ? resolve({
430
429
  ok: true,
431
430
  msg: '已加入购物车!',
432
431
  })
433
432
  : resolve({
434
433
  ok: false,
435
434
  msg: '加购失败,请稍后重试',
436
435
  errMsg: getMessageJsonData?.data?.message ?? '',
437
436
  });
438
437
  if (!isOk) {
439
438
  const data = {
440
439
  eventName: 'business',
441
440
  errorName: 'shop_batchAddCart_error',
442
441
  errorMessage: 'H5调用Android原生加车失败',
443
442
  };
444
443
  draBusinessCustomReport(data);
445
444
  }
446
445
  } else if (isIosDevice) {
447
446
  const isOk =
448
447
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
449
448
  isOk
450
449
  ? resolve({
451
450
  ok: true,
452
451
  msg: '已加入购物车!',
453
452
  })
454
453
  : resolve({
455
454
  ok: false,
456
455
  msg: '批量加车失败,请稍后重试',
457
456
  errMsg: getMessageJsonData?.data?.message ?? '',
458
457
  });
459
458
  if (!isOk) {
460
459
  const data = {
461
460
  eventName: 'business',
462
461
  errorName: 'shop_batchAddCart_error',
463
462
  errorMessage: 'H5调用IOS原生加车失败',
464
463
  };
465
464
  draBusinessCustomReport(data);
466
465
  }
467
466
  } else if (isHarmonyDevice) {
468
467
  const isOk =
469
468
  getMessageJsonData?.data?.code === 0 &&
470
469
  getMessageJsonData?.data?.response?.resultCode === 0;
471
470
  isOk
472
471
  ? resolve({
473
472
  ok: true,
474
473
  msg: '已加入购物车!',
475
474
  })
476
475
  : resolve({
477
476
  ok: false,
478
477
  msg: '加购失败,请稍后重试',
479
478
  errMsg: getMessageJsonData?.data?.message ?? '',
480
479
  });
481
480
  if (!isOk) {
482
481
  const data = {
483
482
  eventName: 'business',
484
483
  errorName: 'shop_batchAddCart_error',
485
484
  errorMessage: 'H5调用Harmony原生加车失败',
486
485
  };
487
486
  draBusinessCustomReport(data);
488
487
  }
489
488
  } else {
490
489
  resolve({
491
490
  ok: false,
492
491
  msg: '加购失败,请稍后重试',
493
492
  });
494
493
  const data = {
495
494
  eventName: 'business',
496
495
  errorName: 'shop_batchAddCart_error',
497
496
  errorMessage: 'H5调用未知原生加车失败',
498
497
  };
499
498
  draBusinessCustomReport(data);
500
499
  }
501
500
  } catch (e) {
502
501
  resolve({
503
502
  ok: false,
504
503
  msg: '加购失败,请稍后重试',
505
504
  });
506
505
  console.warn('批量加车转换数据异常', e);
507
506
  const data = {
508
507
  eventName: 'business',
509
508
  errorName: 'shop_batchAddCart_error',
510
509
  errorMessage: '批量加车转换数据异常',
511
510
  };
512
511
  draBusinessCustomReport(data);
513
512
  }
514
513
  window[nativeAddCartCallBack] = null;
515
514
  };
516
515
  }
517
516
  const productsAddCartList = productIdsArr.map((skuItem) => {
518
517
  const adInfos = getAdInfoBySkuId(skuItem);
519
518
  const extFlag = adInfos ? { adInfos } : {};
520
519
  let item = null;
521
520
  if (isAndroidDevice) {
522
521
  item = {
523
522
  sku: skuItem,
524
523
  num: addCardNum,
525
524
  extFlag,
526
525
  };
527
526
  } else if (isIosDevice) {
528
527
  item = {
529
528
  productCode: skuItem,
530
529
  buyCount: addCardNum,
531
530
  extFlag,
532
531
  };
533
532
  } else if (isHarmonyDevice) {
534
533
  item = {
535
534
  sourceType: 'native',
536
535
  sourceValue: 'shop',
537
536
  productCode: skuItem,
538
537
  buyCount: addCardNum,
539
538
  extFlag,
540
539
  };
541
540
  }
542
541
  return item;
543
542
  });
544
543
  if (isAndroidDevice) {
545
544
  const androidProductsStr = JSON.stringify(productsAddCartList);
546
545
  callRouterAndroid({
547
546
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
548
547
  routerParam: {
549
548
  wareList: productsAddCartList,
550
549
  },
551
550
  callBackName: nativeAddCartCallBack,
552
551
  });
553
552
  } else if (isIosDevice) {
554
553
  if (isLowAppVer) {
555
554
  const lowVersionAppList = productIdsArr.map((skuItem) => {
556
555
  return {
557
556
  sku: skuItem,
558
557
  num: addCardNum,
559
558
  };
560
559
  });
561
560
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
562
561
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
563
562
  jump.side.jdJumpToWeb(url, {});
564
563
  resolve({
565
564
  ok: true,
566
565
  isOpenApp: true,
567
566
  msg: '加购完成, 加购结果请点击购物车确认',
568
567
  });
569
568
  } else {
570
569
  callRouterIOS({
571
570
  routerURL: 'router://JDCartModule/batchAddService',
572
571
  routerParam: {
573
572
  sourceType: 'h5',
574
573
  sourceValue: '店铺批量加购',
575
574
  businessName: 'storeModel',
576
575
  isNewMode: '1',
577
576
  NotPassWebview: '1',
578
577
  products: productsAddCartList,
579
578
  },
580
579
  callBackName: nativeAddCartCallBack,
581
580
  });
582
581
  }
583
582
  } else if (isHarmonyDevice) {
584
583
  callRouterHarmony({
585
584
  routerURL: 'router://JDCartModule/batchAddService',
586
585
  routerParam: {
587
586
  sourceType: 'native',
588
587
  sourceValue: 'shop',
589
588
  products: productsAddCartList,
590
589
  },
591
590
  callBackName: nativeAddCartCallBack,
592
591
  });
593
592
  }
594
593
  } else if (isMin) {
595
594
  console.log('==========>', '京购批量加车!');
596
595
  const productsAddCartList = productIdsArr.map((skuItem) => {
597
596
  return {
598
597
  skuId: skuItem,
599
598
  buyNum: addCardNum,
600
599
  };
601
600
  });
602
601
  global.wxAppBizInstance
603
602
  .addCart({ commArr: productsAddCartList })
604
603
  .then((res) => {
605
604
  console.log('dealCartSuccess: ', res);
606
605
  resolve({
607
606
  ok: true,
608
607
  msg: '已加入购物车!',
609
608
  data: res,
610
609
  });
611
610
  })
612
611
  .catch((e) => {
613
612
  console.log('京购小程序批量加车失败dealCartFail: ', e);
614
613
  resolve({
615
614
  ok: false,
616
615
  msg: '加购失败,请稍后重试',
617
616
  });
618
617
  const data = {
619
618
  eventName: 'business',
620
619
  errorName: 'shop_batchAddCart_error',
621
620
  errorMessage: 'H5调用小程序加车失败',
622
621
  };
623
622
  draBusinessCustomReport(data);
624
623
  });
625
624
  } else {
626
625
  console.log('==========>', '使用M站批量加车!');
627
626
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
628
627
  }
629
628
  } else {
630
629
  resolve({
631
630
  ok: false,
632
631
  msg: '加购sku不能为空',
633
632
  });
634
633
  const data = {
635
634
  eventName: 'business',
636
635
  errorName: 'shop_batchAddCart_error',
637
636
  errorMessage: '加购sku不能为空',
638
637
  };
639
638
  draBusinessCustomReport(data);
640
639
  }
641
640
  });
642
641
  }
643
642
 
644
643
  productAddToCart(skuIdsStr, num) {
645
644
  return new Promise((resolve) => {
646
645
  if (window.AddcartToolObj) {
647
646
  window.AddcartToolObj.addCart({
648
647
  skuId: skuIdsStr,
649
648
  num,
650
649
  source: 'sjdpyw',
651
650
  actId: '1',
652
651
  loginType: isAscfApp ? '2' : window?.isJingGouMiniViewState ? '11' : isPc ? '3' : '2',
653
652
  sucFun(res) {
654
653
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
655
654
  if (res.errId === '0' && res.cartJson) {
656
655
  resolve({
657
656
  ok: true,
658
657
  msg: '已加入购物车!',
659
658
  ...res,
660
659
  });
661
660
  } else {
662
661
  if (res.errId === '13') {
663
662
  global.doLogin();
664
663
  } else {
665
664
  resolve({
666
665
  ok: false,
667
666
  msg: '加购失败,请稍后重试',
668
667
  ...res,
669
668
  });
670
669
  const data = {
671
670
  eventName: 'business',
672
671
  errorName: 'shop_batchAddCart_error',
673
672
  errorMessage: 'H5调用M站加车失败',
674
673
  };
675
674
  draBusinessCustomReport(data);
676
675
  }
677
676
  }
678
677
  },
679
678
  failFun(err) {
680
679
  console.log('fail', err);
681
680
  resolve({
682
681
  ok: false,
683
682
  msg: '加购失败,请稍后重试',
684
683
  ...err,
685
684
  });
686
685
  const data = {
687
686
  eventName: 'business',
688
687
  errorName: 'shop_batchAddCart_error',
689
688
  errorMessage: 'H5调用M站加车失败',
690
689
  };
691
690
  draBusinessCustomReport(data);
692
691
  },
693
692
  });
694
693
  } else {
695
694
  resolve({
696
695
  ok: false,
697
696
  msg: '购物车方法检查异常',
698
697
  });
699
698
  const data = {
700
699
  eventName: 'business',
701
700
  errorName: 'shop_batchAddCart_error',
702
701
  errorMessage: 'H5调用M站加车检查依赖方法异常',
703
702
  };
704
703
  draBusinessCustomReport(data);
705
704
  }
706
705
  });
707
706
  }
708
707
  bMallGetUserInfo = () => {
709
708
  return getBMallUserInfo();
710
709
  };
711
710
  async bMallAddCart(params = {}) {
712
711
  return await this.gatewayReq('bmall_cartAdd', params, {
713
712
  client: 'H5',
714
713
  clientVersion: '5.5.0',
715
714
  });
716
715
  }
717
716
  async bMallChangeCart(params = {}) {
718
717
  return await this.gatewayReq('bmall_cartChange', params, {
719
718
  client: 'H5',
720
719
  clientVersion: '5.5.0',
721
720
  });
722
721
  }
723
722
  async bMallRemoveCart(params = {}) {
724
723
  return await this.gatewayReq(
725
724
  'bmall_cartRemove',
726
725
  params,
727
726
  {
728
727
  client: 'H5',
729
728
  clientVersion: '5.5.0',
730
729
  },
731
730
  );
732
731
  }
733
732
  async bMallGetOmittedProduct(params = {}) {
734
733
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
735
734
  client: 'H5',
736
735
  clientVersion: '5.5.0',
737
736
  });
738
737
  }
739
738
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
740
739
  const params = await getParams({ ...data, skuId, bMallTag, num });
741
740
  return await this.bMallAddCart(params);
742
741
  }
743
742
  async bMallGetSkuNumService(bMallTag = 1) {
744
743
  const params = await getParams({ bMallTag });
745
744
  delete params.operations;
746
745
  return await this.bMallGetOmittedProduct(params);
747
746
  }
748
747
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
749
748
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
750
749
  return await this.bMallRemoveCart(params);
751
750
  }
752
751
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
753
752
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
754
753
  return await this.bMallChangeCart(params);
755
754
  }
756
755
 
757
756
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
758
757
  if (!needRequest && isH5 && window?.bMallCartData) {
759
758
  return window?.bMallCartData;
760
759
  }
761
760
  const cartData = await this.bMallGetSkuNumService(bMallTag);
762
761
  let items;
763
762
  if (cartData.ok && cartData.result) {
764
763
  items = cartData?.result?.items || {};
765
764
  }
766
765
  if (isH5) {
767
766
  window.bMallCartData = items;
768
767
  }
769
768
  return items;
770
769
  }
771
770
 
772
771
  async bMallCartHandle(goodItem, num) {
773
772
  try {
774
773
  const {
775
774
  skuUuid,
776
775
  limitUpper,
777
776
  limitLower,
778
777
  } = goodItem;
779
778
  let cartNum = Number(num);
780
779
  if (limitLower && cartNum && cartNum < limitLower) {
781
780
  cartNum = limitLower;
782
781
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
783
782
  cartNum = limitUpper;
784
783
  }
785
784
  if (skuUuid && cartNum > 0) {
786
785
  return this.bMallChangeCartService({
787
786
  ...goodItem,
788
787
  skuUuid,
789
788
  num: cartNum,
790
789
  });
791
790
  } else if (!skuUuid && cartNum > 0) {
792
791
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
793
792
  } else if (skuUuid && !cartNum) {
794
793
  return this.bMallRemoveCartService({
795
794
  ...goodItem,
796
795
  skuUuid,
797
796
  num: cartNum,
798
797
  });
799
798
  } else {
800
799
  console.error('参数不全');
801
800
  return false;
802
801
  }
803
802
  } catch (e) {
804
803
  console.error(e);
805
804
  }
806
805
  }
806
+ import Taro from '@tarojs/taro';
807
807
  APPID,
808
808
  JshopxColorFunctionIdList,
809
809
  PagesColorFunctionIdList,
810
810
  PAGES_DOMAIN,
811
811
  B2BColorFunctionIdList,
812
812
  MobileVerifyColorList,
813
813
  AppVerifyColorList,
814
814
  JshopxVerifyColorList,
815
815
  BMallVerifyColorList,
816
816
  shopMemberColorFunctionIdList,
817
817
  draBusinessCustomReport,
818
818
  isJdApp,
819
819
  isIosDevice,
820
820
  isAndroidDevice,
821
821
  showSuccessToast,
822
822
  showFailToast,
823
823
  isH5,
824
824
  isWxMinAndWxapp,
825
825
  isMin,
826
826
  isPc,
827
827
  draInterfaceCustomReport,
828
828
  isHarmonyDevice,
829
829
  isAscfApp,
830
830
  callRouterIOS,
831
831
  callRouterAndroid,
832
832
  callRouterHarmony,
833
833
  sendNativePageToShowCartFloatBtn,
834
834
  cookiesStr: '',
835
835
  requestHeaderContentType: {
836
836
  jsonHeader: {
837
837
  'content-type': 'application/json;charset=utf-8',
838
838
  },
839
839
  formDataHeader: {
840
840
  'content-type': 'application/x-www-form-urlencoded',
841
841
  },
842
842
  },
843
843
  requestBaseParam: {
844
844
  data: null,
845
845
  header: {
846
846
  'content-type': 'application/json;charset=utf-8',
847
847
  },
848
848
  },
849
849
  timeOut: 7000,
850
850
  apiClientParams: {
851
851
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
852
852
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
853
853
  area: '1_72_2799_0',
854
854
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
855
855
  window.screen?.height * devicePixelRatio,
856
856
  )}`,
857
857
  uuid: UUID,
858
858
  },
859
859
  window.shopGlobalSwitch?.useNativeHarmonyAddCartJdAppVersion;
860
860
  nativeHarmonyAddCartJdAppVersion && jdAppVersionCompare(nativeHarmonyAddCartJdAppVersion) >= 0;
861
861
  public addressFetchInfo: {
862
862
  reqState: boolean;
863
863
  promiseInstance: null | Promise<any>;
864
864
  };
865
865
  public getPromotionConfig: {
866
866
  projectId: null | string | number;
867
867
  pageId: null | string | number;
868
868
  };
869
869
  public resInfo: ServiceInterFace.HttpRequestInfo;
870
870
  public api: ServiceInterFace.HttpApi;
871
871
  public isPageDomain: boolean;
872
872
  public verifyColorList: string[];
873
873
  private isShowJdShopCartFloatBtn: boolean;
874
874
  constructor(opt) {
875
875
  this._init();
876
876
  this.addressFetchInfo = {
877
877
  reqState: false,
878
878
  promiseInstance: null,
879
879
  };
880
880
  this.getPromotionConfig = {
881
881
  projectId: null,
882
882
  pageId: null,
883
883
  };
884
884
  this._userAreaUpdateListen();
885
885
  this.resInfo = this._getResConfig(opt);
886
886
  this.api = api;
887
887
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
888
888
  this.verifyColorList = [
889
889
  ...MobileVerifyColorList,
890
890
  ...AppVerifyColorList,
891
891
  ...JshopxVerifyColorList,
892
892
  ...BMallVerifyColorList,
893
893
  ];
894
894
  this.isShowJdShopCartFloatBtn =
895
895
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
896
896
  }
897
897
  _init(): void {
898
898
  httpInterceptors.forEach((item) => {
899
899
  Taro.addInterceptor((chain) => item(chain));
900
900
  });
901
901
  }
902
902
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
903
903
  return Object.assign({}, DefaultConfig, opt);
904
904
  }
905
905
 
906
906
  _userAreaUpdateListen() {
907
907
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
908
908
  this.updateApiClientParamsResInfo(areaInfo);
909
909
  console.log(
910
910
  'cone-render收到原生端获取传来的四级地址信息',
911
911
  areaInfo,
912
912
  '更新后的接口底层信息',
913
913
  this.resInfo.apiClientParams,
914
914
  );
915
915
  });
916
916
  }
917
917
  updateApiClientParamsResInfo(opt = {}) {
918
918
  const { area, realTimeArea, ...others } = opt;
919
919
  this.resInfo.apiClientParams = {
920
920
  ...this.resInfo.apiClientParams,
921
921
  ...others,
922
922
  };
923
923
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
924
924
  realTimeArea &&
925
925
  realTimeArea !== '' &&
926
926
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
927
927
  }
928
928
 
929
929
  checkFunctionIdToReturnAppId(functionId) {
930
930
  if (JshopxColorFunctionIdList.includes(functionId)) {
931
931
  return APPID.JSHOPX_COLOR_APPID;
932
932
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
933
933
  return APPID.PAGES_COLOR_APPID;
934
934
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
935
935
  return APPID.SHOP_MEMBER_COLOR_APPID;
936
936
  } else if (B2BColorFunctionIdList.includes(functionId)) {
937
937
  return APPID.B2B_COLOR_APPID;
938
938
  } else if (isPc) {
939
939
  return APPID.MALL_COLOR_APPID;
940
940
  } else {
941
941
  return APPID.SHOP_COLOR_APPID;
942
942
  }
943
943
  }
944
944
 
945
945
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
946
946
  if (
947
947
  functionId === 'receiveShopCoupon' &&
948
948
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
949
949
  isWxMinAndWxapp)
950
950
  ) {
951
951
  clientParams = Object.assign(
952
952
  {},
953
953
  {
954
954
  loginType: isAscfApp ? '2' : '1',
955
955
  loginWQBiz: WXAPP_BIZ_KEY,
956
956
  },
957
957
  clientParams,
958
958
  );
959
959
  }
960
960
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
961
961
  typeof apiClientParams.appid === 'undefined' &&
962
962
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
963
963
  const isColorVerify = this.verifyColorList.includes(functionId);
964
964
  const getReqData = {
965
965
  functionId: functionId,
966
966
  body: JSON.stringify(bodyParams),
967
967
  t: Date.now(),
968
968
  ...apiClientParams,
969
969
  };
970
970
  return http
971
971
  .request({
972
972
  url: this.api.apiFunc,
973
973
  data: getReqData,
974
974
  isColorVerify,
975
975
  })
976
976
  .then((res: ServiceInterFace.RequestPromiseRes) => {
977
977
  const { statusCode, data, status, msg } = res;
978
978
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
979
979
  ok: true,
980
980
  };
981
981
  if ((statusCode === 200 || status === '0') && data) {
982
982
  changeRes = this.dealResponseFormatRes(data);
983
983
  return changeRes;
984
984
  } else {
985
985
  changeRes = {
986
986
  ...data,
987
987
  statusCode,
988
988
  status,
989
989
  msg,
990
990
  ok: false,
991
991
  };
992
992
  return changeRes;
993
993
  }
994
994
  })
995
995
  .catch((res) => {
996
996
  const propertyNames = Object.getOwnPropertyNames(res);
997
997
  const resObject = {};
998
998
  propertyNames.forEach((propertyName) => {
999
999
  resObject[propertyName] = res[propertyName];
1000
1000
  });
1001
1001
  draInterfaceCustomReport({
1002
1002
  eventName: 'apiStatusCode',
1003
1003
  errorName: `shop_${functionId}_error`,
1004
1004
  errorMessage: `接口返回statusCode为${res?.statusCode || res?.status}`,
1005
1005
  url: this.api.apiFunc,
1006
1006
  source: 'remote',
1007
1007
  requestType: res?.requestType,
1008
1008
  functionId: getReqData?.functionId,
1009
1009
  appid: getReqData?.appid,
1010
1010
  client: getReqData?.client,
1011
1011
  clientVersion: getReqData?.clientVersion,
1012
1012
  statusCode: res?.statusCode,
1013
1013
  status: res?.status,
1014
1014
  statusText: res?.statusText,
1015
1015
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
1016
1016
  originReqDataStr: JSON.stringify(getReqData),
1017
1017
  });
1018
1018
  return {
1019
1019
  ...resObject,
1020
1020
  ok: false,
1021
1021
  } as ServiceInterFace.RequestResponseFormatRes;
1022
1022
  });
1023
1023
  }
1024
1024
 
1025
1025
  dealResponseFormatRes(data) {
1026
1026
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
1027
1027
  ok: true,
1028
1028
  };
1029
1029
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
1030
1030
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
1031
1031
  ? Number(data.subCode)
1032
1032
  : -1;
1033
1033
  if (
1034
1034
  data.success === true ||
1035
1035
  data.isSuccess ||
1036
1036
  resCode === 0 ||
1037
1037
  resCode === 200 ||
1038
1038
  subCode === 0
1039
1039
  ) {
1040
1040
  changeRes = {
1041
1041
  result: Object.prototype.hasOwnProperty.call(data, 'result')
1042
1042
  ? data.result
1043
1043
  : Object.prototype.hasOwnProperty.call(data, 'data')
1044
1044
  ? data.data
1045
1045
  : data,
1046
1046
  code: data.code ?? 200,
1047
1047
  ok: true,
1048
1048
  source: data,
1049
1049
  };
1050
1050
  return changeRes;
1051
1051
  } else {
1052
1052
  changeRes = {
1053
1053
  ...data,
1054
1054
  ok: false,
1055
1055
  };
1056
1056
  return changeRes;
1057
1057
  }
1058
1058
  }
1059
1059
 
1060
1060
  async receiveCoupon(param = {}, clientParams) {
1061
1061
  const loginType = isPc ? { loginType: 3 } : {};
1062
1062
  return await this.gatewayReq(
1063
1063
  'receiveShopCoupon',
1064
1064
  {
1065
1065
  operation: '3',
1066
1066
  ...param,
1067
1067
  },
1068
1068
  { ...loginType, ...clientParams },
1069
1069
  );
1070
1070
  }
1071
1071
 
1072
1072
  getCustomerCenterDispatch(params = {}) {
1073
1073
  return this.gatewayReq('customerCenterDispatch', params, {
1074
1074
  clientVersion: '9.2.0',
1075
1075
  client: 'H5',
1076
1076
  uuid: 88888,
1077
1077
  appid: 'shopmember_m_jd_com',
1078
1078
  });
1079
1079
  }
1080
1080
 
1081
1081
  batchAddCart(...args) {
1082
1082
  let skuIds, num, showToast, giftCard, extFlag;
1083
1083
  if (['number', 'string'].includes(typeof args[0])) {
1084
1084
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
1085
1085
  } else if (typeof args[0] === 'object' && args[0] !== null) {
1086
1086
  const params = args[0];
1087
1087
  skuIds = params.skuIds;
1088
1088
  num = params.num || 1;
1089
1089
  showToast = params.showToast !== undefined ? params.showToast : true;
1090
1090
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
1091
1091
  extFlag = params.extFlag !== undefined ? params.extFlag : null;
1092
1092
  } else {
1093
1093
  try {
1094
1094
  const data = {
1095
1095
  eventName: 'business',
1096
1096
  errorName: 'shop_batchAddCart_error',
1097
1097
  errorMessage: '入参不合法',
1098
1098
  extraData: JSON.stringify(args),
1099
1099
  };
1100
1100
  draBusinessCustomReport(data);
1101
1101
  } catch (e) {
1102
1102
  console.error('draBusinessCustomReport error:', e);
1103
1103
  }
1104
1104
  const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
1105
1105
  showFailToast({
1106
1106
  title: msg,
1107
1107
  });
1108
1108
  return Promise.resolve({
1109
1109
  ok: false,
1110
1110
  msg,
1111
1111
  });
1112
1112
  }
1113
1113
  const successMsg = giftCard
1114
1114
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
1115
1115
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
1116
1116
  const failMsg = giftCard
1117
1117
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
1118
1118
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
1119
1119
  if (skuIds) {
1120
1120
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard, extFlag })
1121
1121
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
1122
1122
  if (res?.ok) {
1123
1123
  showToast &&
1124
1124
  !res?.isOpenApp &&
1125
1125
  showSuccessToast({
1126
1126
  title: successMsg,
1127
1127
  });
1128
1128
  this.isShowJdShopCartFloatBtn &&
1129
1129
  sendNativePageToShowCartFloatBtn({
1130
1130
  isShow: true,
1131
1131
  });
1132
1132
  } else {
1133
1133
  showToast &&
1134
1134
  showFailToast({
1135
1135
  title: res?.errMsg || failMsg,
1136
1136
  });
1137
1137
  }
1138
1138
  return Promise.resolve(res);
1139
1139
  })
1140
1140
  .catch((e) => {
1141
1141
  console.log('调用加购方法异常=======>', e);
1142
1142
  return Promise.resolve({
1143
1143
  ok: false,
1144
1144
  msg: failMsg,
1145
1145
  });
1146
1146
  });
1147
1147
  } else {
1148
1148
  try {
1149
1149
  const data = {
1150
1150
  eventName: 'business',
1151
1151
  errorName: 'shop_batchAddCart_error',
1152
1152
  errorMessage: '没有传入合法的skuIds',
1153
1153
  };
1154
1154
  draBusinessCustomReport(data);
1155
1155
  } catch (e) {
1156
1156
  console.error('draBusinessCustomReport error:', e);
1157
1157
  }
1158
1158
  return Promise.resolve({
1159
1159
  ok: false,
1160
1160
  msg: failMsg,
1161
1161
  });
1162
1162
  }
1163
1163
  }
1164
1164
 
1165
1165
  async giftCardAddCart(skuList, num) {
1166
1166
  const loginType = isPc ? { loginType: 3 } : {};
1167
1167
  return this.gatewayReq(
1168
1168
  'giftCardAddCart',
1169
1169
  {
1170
1170
  skuList,
1171
1171
  num: Number(num),
1172
1172
  },
1173
1173
  { ...loginType },
1174
1174
  );
1175
1175
  }
1176
1176
 
1177
1177
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard, extFlag }) {
1178
1178
  return new Promise((resolve) => {
1179
1179
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
1180
1180
  if (productIdsArr.length > 0) {
1181
1181
  if (giftCard) {
1182
1182
  this.giftCardAddCart(productIdsArr, addCardNum)
1183
1183
  .then((res) => {
1184
1184
  if (res?.code === '0' && res?.result?.value) {
1185
1185
  resolve({
1186
1186
  ok: true,
1187
1187
  });
1188
1188
  } else {
1189
1189
  try {
1190
1190
  const data = {
1191
1191
  eventName: 'business',
1192
1192
  errorName: 'shop_batchAddCart_error',
1193
1193
  errorMessage: '礼品卡加车接口返回加车失败标识',
1194
1194
  };
1195
1195
  draBusinessCustomReport(data);
1196
1196
  } catch (e) {
1197
1197
  console.error('draBusinessCustomReport error:', e);
1198
1198
  }
1199
1199
  resolve({
1200
1200
  ok: false,
1201
1201
  msg: '加购失败,请稍后重试',
1202
1202
  });
1203
1203
  }
1204
1204
  })
1205
1205
  .catch((e) => {
1206
1206
  console.error('礼品卡加车失败: ', e);
1207
1207
  resolve({
1208
1208
  ok: false,
1209
1209
  msg: '加购失败,请稍后重试',
1210
1210
  });
1211
1211
  });
1212
1212
  } else if (
1213
1213
  isJdApp &&
1214
1214
  (!isHarmonyDevice || (isHarmonyDevice && useNativeHarmonyAddCartJd))
1215
1215
  ) {
1216
1216
  const nativeAddCartCallBack = `nativeBatchAddCart${
1217
1217
  Date.now() + Number(productIdsArr[0]) + Number(addCardNum)
1218
1218
  }`;
1219
1219
  console.log(
1220
1220
  '==========>',
1221
1221
  '使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
1222
1222
  nativeAddCartCallBack,
1223
1223
  );
1224
1224
  if (!window[nativeAddCartCallBack]) {
1225
1225
  window[nativeAddCartCallBack] = (res) => {
1226
1226
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
1227
1227
  console.info(
1228
1228
  '获取批量加车原始数据',
1229
1229
  res,
1230
1230
  '====转换后的json数据为===',
1231
1231
  getMessageJsonData,
1232
1232
  );
1233
1233
  try {
1234
1234
  if (isAndroidDevice) {
1235
1235
  const isOk = getMessageJsonData?.status === '0';
1236
1236
  isOk
1237
1237
  ? resolve({
1238
1238
  ok: true,
1239
1239
  msg: '已加入购物车!',
1240
1240
  })
1241
1241
  : resolve({
1242
1242
  ok: false,
1243
1243
  msg: '加购失败,请稍后重试',
1244
1244
  errMsg: getMessageJsonData?.data?.message ?? '',
1245
1245
  });
1246
1246
  if (!isOk) {
1247
1247
  const data = {
1248
1248
  eventName: 'business',
1249
1249
  errorName: 'shop_batchAddCart_error',
1250
1250
  errorMessage: 'H5调用Android原生加车失败',
1251
1251
  };
1252
1252
  draBusinessCustomReport(data);
1253
1253
  }
1254
1254
  } else if (isIosDevice) {
1255
1255
  const isOk =
1256
1256
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
1257
1257
  isOk
1258
1258
  ? resolve({
1259
1259
  ok: true,
1260
1260
  msg: '已加入购物车!',
1261
1261
  })
1262
1262
  : resolve({
1263
1263
  ok: false,
1264
1264
  msg: '批量加车失败,请稍后重试',
1265
1265
  errMsg: getMessageJsonData?.data?.message ?? '',
1266
1266
  });
1267
1267
  if (!isOk) {
1268
1268
  const data = {
1269
1269
  eventName: 'business',
1270
1270
  errorName: 'shop_batchAddCart_error',
1271
1271
  errorMessage: 'H5调用IOS原生加车失败',
1272
1272
  };
1273
1273
  draBusinessCustomReport(data);
1274
1274
  }
1275
1275
  } else if (isHarmonyDevice) {
1276
1276
  const isOk =
1277
1277
  getMessageJsonData?.data?.code === 0 &&
1278
1278
  getMessageJsonData?.data?.response?.resultCode === 0;
1279
1279
  isOk
1280
1280
  ? resolve({
1281
1281
  ok: true,
1282
1282
  msg: '已加入购物车!',
1283
1283
  })
1284
1284
  : resolve({
1285
1285
  ok: false,
1286
1286
  msg: '加购失败,请稍后重试',
1287
1287
  errMsg: getMessageJsonData?.data?.message ?? '',
1288
1288
  });
1289
1289
  if (!isOk) {
1290
1290
  const data = {
1291
1291
  eventName: 'business',
1292
1292
  errorName: 'shop_batchAddCart_error',
1293
1293
  errorMessage: 'H5调用Harmony原生加车失败',
1294
1294
  };
1295
1295
  draBusinessCustomReport(data);
1296
1296
  }
1297
1297
  } else {
1298
1298
  resolve({
1299
1299
  ok: false,
1300
1300
  msg: '加购失败,请稍后重试',
1301
1301
  });
1302
1302
  const data = {
1303
1303
  eventName: 'business',
1304
1304
  errorName: 'shop_batchAddCart_error',
1305
1305
  errorMessage: 'H5调用未知原生加车失败',
1306
1306
  };
1307
1307
  draBusinessCustomReport(data);
1308
1308
  }
1309
1309
  } catch (e) {
1310
1310
  resolve({
1311
1311
  ok: false,
1312
1312
  msg: '加购失败,请稍后重试',
1313
1313
  });
1314
1314
  console.warn('批量加车转换数据异常', e);
1315
1315
  const data = {
1316
1316
  eventName: 'business',
1317
1317
  errorName: 'shop_batchAddCart_error',
1318
1318
  errorMessage: '批量加车转换数据异常',
1319
1319
  };
1320
1320
  draBusinessCustomReport(data);
1321
1321
  }
1322
1322
  window[nativeAddCartCallBack] = null;
1323
1323
  };
1324
1324
  }
1325
1325
  const productsAddCartList = productIdsArr.map((skuItem) => {
1326
1326
  const adInfos = getAdInfoBySkuId(skuItem);
1327
1327
  let allExtFlag = typeof extFlag === 'object' ? extFlag : {};
1328
1328
  if (adInfos) {
1329
1329
  allExtFlag = Object.assign({}, allExtFlag, { adInfos });
1330
1330
  }
1331
1331
  let item = null;
1332
1332
  if (isAndroidDevice) {
1333
1333
  item = {
1334
1334
  sku: skuItem,
1335
1335
  num: addCardNum,
1336
1336
  extFlag: allExtFlag,
1337
1337
  };
1338
1338
  } else if (isIosDevice) {
1339
1339
  item = {
1340
1340
  productCode: skuItem,
1341
1341
  buyCount: addCardNum,
1342
1342
  extFlag: allExtFlag,
1343
1343
  };
1344
1344
  } else if (isHarmonyDevice) {
1345
1345
  item = {
1346
1346
  sourceType: 'native',
1347
1347
  sourceValue: 'shop',
1348
1348
  productCode: skuItem,
1349
1349
  buyCount: addCardNum,
1350
1350
  extFlag: allExtFlag,
1351
1351
  };
1352
1352
  }
1353
1353
  return item;
1354
1354
  });
1355
1355
  if (isAndroidDevice) {
1356
1356
  const androidProductsStr = JSON.stringify(productsAddCartList);
1357
1357
  callRouterAndroid({
1358
1358
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
1359
1359
  routerParam: {
1360
1360
  wareList: productsAddCartList,
1361
1361
  },
1362
1362
  callBackName: nativeAddCartCallBack,
1363
1363
  });
1364
1364
  } else if (isIosDevice) {
1365
1365
  if (isLowAppVer) {
1366
1366
  const lowVersionAppList = productIdsArr.map((skuItem) => {
1367
1367
  return {
1368
1368
  sku: skuItem,
1369
1369
  num: addCardNum,
1370
1370
  };
1371
1371
  });
1372
1372
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
1373
1373
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
1374
1374
  jump.side.jdJumpToWeb(url, {});
1375
1375
  resolve({
1376
1376
  ok: true,
1377
1377
  isOpenApp: true,
1378
1378
  msg: '加购完成, 加购结果请点击购物车确认',
1379
1379
  });
1380
1380
  } else {
1381
1381
  callRouterIOS({
1382
1382
  routerURL: 'router://JDCartModule/batchAddService',
1383
1383
  routerParam: {
1384
1384
  sourceType: 'h5',
1385
1385
  sourceValue: '店铺批量加购',
1386
1386
  businessName: 'storeModel',
1387
1387
  isNewMode: '1',
1388
1388
  NotPassWebview: '1',
1389
1389
  products: productsAddCartList,
1390
1390
  },
1391
1391
  callBackName: nativeAddCartCallBack,
1392
1392
  });
1393
1393
  }
1394
1394
  } else if (isHarmonyDevice) {
1395
1395
  callRouterHarmony({
1396
1396
  routerURL: 'router://JDCartModule/batchAddService',
1397
1397
  routerParam: {
1398
1398
  sourceType: 'native',
1399
1399
  sourceValue: 'shop',
1400
1400
  products: productsAddCartList,
1401
1401
  },
1402
1402
  callBackName: nativeAddCartCallBack,
1403
1403
  });
1404
1404
  }
1405
1405
  } else if (isMin) {
1406
1406
  console.log('==========>', '京购批量加车!');
1407
1407
  const productsAddCartList = productIdsArr.map((skuItem) => {
1408
1408
  return {
1409
1409
  skuId: skuItem,
1410
1410
  buyNum: addCardNum,
1411
1411
  };
1412
1412
  });
1413
1413
  global.wxAppBizInstance
1414
1414
  .addCart({ commArr: productsAddCartList })
1415
1415
  .then((res) => {
1416
1416
  console.log('dealCartSuccess: ', res);
1417
1417
  resolve({
1418
1418
  ok: true,
1419
1419
  msg: '已加入购物车!',
1420
1420
  data: res,
1421
1421
  });
1422
1422
  })
1423
1423
  .catch((e) => {
1424
1424
  console.log('京购小程序批量加车失败dealCartFail: ', e);
1425
1425
  resolve({
1426
1426
  ok: false,
1427
1427
  msg: '加购失败,请稍后重试',
1428
1428
  });
1429
1429
  const data = {
1430
1430
  eventName: 'business',
1431
1431
  errorName: 'shop_batchAddCart_error',
1432
1432
  errorMessage: 'H5调用小程序加车失败',
1433
1433
  };
1434
1434
  draBusinessCustomReport(data);
1435
1435
  });
1436
1436
  } else {
1437
1437
  console.log('==========>', '使用M站批量加车!');
1438
1438
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
1439
1439
  }
1440
1440
  } else {
1441
1441
  resolve({
1442
1442
  ok: false,
1443
1443
  msg: '加购sku不能为空',
1444
1444
  });
1445
1445
  const data = {
1446
1446
  eventName: 'business',
1447
1447
  errorName: 'shop_batchAddCart_error',
1448
1448
  errorMessage: '加购sku不能为空',
1449
1449
  };
1450
1450
  draBusinessCustomReport(data);
1451
1451
  }
1452
1452
  });
1453
1453
  }
1454
1454
 
1455
1455
  productAddToCart(skuIdsStr, num) {
1456
1456
  return new Promise((resolve) => {
1457
1457
  if (window.AddcartToolObj) {
1458
1458
  window.AddcartToolObj.addCart({
1459
1459
  skuId: skuIdsStr,
1460
1460
  num,
1461
1461
  source: 'sjdpyw',
1462
1462
  actId: '1',
1463
1463
  loginType: isAscfApp ? '2' : window?.isJingGouMiniViewState ? '11' : isPc ? '3' : '2',
1464
1464
  sucFun(res) {
1465
1465
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
1466
1466
  if (res.errId === '0' && res.cartJson) {
1467
1467
  resolve({
1468
1468
  ok: true,
1469
1469
  msg: '已加入购物车!',
1470
1470
  ...res,
1471
1471
  });
1472
1472
  } else {
1473
1473
  if (res.errId === '13') {
1474
1474
  global.doLogin();
1475
1475
  } else {
1476
1476
  resolve({
1477
1477
  ok: false,
1478
1478
  msg: '加购失败,请稍后重试',
1479
1479
  ...res,
1480
1480
  });
1481
1481
  const data = {
1482
1482
  eventName: 'business',
1483
1483
  errorName: 'shop_batchAddCart_error',
1484
1484
  errorMessage: 'H5调用M站加车失败',
1485
1485
  };
1486
1486
  draBusinessCustomReport(data);
1487
1487
  }
1488
1488
  }
1489
1489
  },
1490
1490
  failFun(err) {
1491
1491
  console.log('fail', err);
1492
1492
  resolve({
1493
1493
  ok: false,
1494
1494
  msg: '加购失败,请稍后重试',
1495
1495
  ...err,
1496
1496
  });
1497
1497
  const data = {
1498
1498
  eventName: 'business',
1499
1499
  errorName: 'shop_batchAddCart_error',
1500
1500
  errorMessage: 'H5调用M站加车失败',
1501
1501
  };
1502
1502
  draBusinessCustomReport(data);
1503
1503
  },
1504
1504
  });
1505
1505
  } else {
1506
1506
  resolve({
1507
1507
  ok: false,
1508
1508
  msg: '购物车方法检查异常',
1509
1509
  });
1510
1510
  const data = {
1511
1511
  eventName: 'business',
1512
1512
  errorName: 'shop_batchAddCart_error',
1513
1513
  errorMessage: 'H5调用M站加车检查依赖方法异常',
1514
1514
  };
1515
1515
  draBusinessCustomReport(data);
1516
1516
  }
1517
1517
  });
1518
1518
  }
1519
1519
  bMallGetUserInfo = () => {
1520
1520
  return getBMallUserInfo();
1521
1521
  };
1522
1522
  async bMallAddCart(params = {}) {
1523
1523
  return await this.gatewayReq('bmall_cartAdd', params, {
1524
1524
  client: 'H5',
1525
1525
  clientVersion: '5.5.0',
1526
1526
  });
1527
1527
  }
1528
1528
  async bMallChangeCart(params = {}) {
1529
1529
  return await this.gatewayReq('bmall_cartChange', params, {
1530
1530
  client: 'H5',
1531
1531
  clientVersion: '5.5.0',
1532
1532
  });
1533
1533
  }
1534
1534
  async bMallRemoveCart(params = {}) {
1535
1535
  return await this.gatewayReq(
1536
1536
  'bmall_cartRemove',
1537
1537
  params,
1538
1538
  {
1539
1539
  client: 'H5',
1540
1540
  clientVersion: '5.5.0',
1541
1541
  },
1542
1542
  );
1543
1543
  }
1544
1544
  async bMallGetOmittedProduct(params = {}) {
1545
1545
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1546
1546
  client: 'H5',
1547
1547
  clientVersion: '5.5.0',
1548
1548
  });
1549
1549
  }
1550
1550
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1551
1551
  const params = await getParams({ ...data, skuId, bMallTag, num });
1552
1552
  return await this.bMallAddCart(params);
1553
1553
  }
1554
1554
  async bMallGetSkuNumService(bMallTag = 1) {
1555
1555
  const params = await getParams({ bMallTag });
1556
1556
  delete params.operations;
1557
1557
  return await this.bMallGetOmittedProduct(params);
1558
1558
  }
1559
1559
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1560
1560
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1561
1561
  return await this.bMallRemoveCart(params);
1562
1562
  }
1563
1563
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1564
1564
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1565
1565
  return await this.bMallChangeCart(params);
1566
1566
  }
1567
1567
 
1568
1568
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1569
1569
  if (!needRequest && isH5 && window?.bMallCartData) {
1570
1570
  return window?.bMallCartData;
1571
1571
  }
1572
1572
  const cartData = await this.bMallGetSkuNumService(bMallTag);
1573
1573
  let items;
1574
1574
  if (cartData.ok && cartData.result) {
1575
1575
  items = cartData?.result?.items || {};
1576
1576
  }
1577
1577
  if (isH5) {
1578
1578
  window.bMallCartData = items;
1579
1579
  }
1580
1580
  return items;
1581
1581
  }
1582
1582
 
1583
1583
  async bMallCartHandle(goodItem, num) {
1584
1584
  try {
1585
1585
  const {
1586
1586
  skuUuid,
1587
1587
  limitUpper,
1588
1588
  limitLower,
1589
1589
  } = goodItem;
1590
1590
  let cartNum = Number(num);
1591
1591
  if (limitLower && cartNum && cartNum < limitLower) {
1592
1592
  cartNum = limitLower;
1593
1593
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1594
1594
  cartNum = limitUpper;
1595
1595
  }
1596
1596
  if (skuUuid && cartNum > 0) {
1597
1597
  return this.bMallChangeCartService({
1598
1598
  ...goodItem,
1599
1599
  skuUuid,
1600
1600
  num: cartNum,
1601
1601
  });
1602
1602
  } else if (!skuUuid && cartNum > 0) {
1603
1603
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
1604
1604
  } else if (skuUuid && !cartNum) {
1605
1605
  return this.bMallRemoveCartService({
1606
1606
  ...goodItem,
1607
1607
  skuUuid,
1608
1608
  num: cartNum,
1609
1609
  });
1610
1610
  } else {
1611
1611
  console.error('参数不全');
1612
1612
  return false;
1613
1613
  }
1614
1614
  } catch (e) {
1615
1615
  console.error(e);
1616
1616
  }
1617
1617
  }