@conecli/cone-render 0.10.1-shop3.4 → 0.10.1-shop3.41

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