@conecli/cone-render 0.10.1-shop3.3 → 0.10.1-shop3.5

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