@conecli/cone-render 0.10.1-shop-beta.24 → 0.10.1-shop-beta.26

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