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

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 (82) hide show
  1. package/README.md +1 -1
  2. package/dist/api/index.ts +1 -1
  3. package/dist/common/const.ts +1 -1
  4. package/dist/common/index.h5.ts +1 -1
  5. package/dist/common/index.jd.ts +1 -1
  6. package/dist/common/index.ts +1 -1
  7. package/dist/common/index.weapp.ts +1 -1
  8. package/dist/common/jssdk.ts +1 -1
  9. package/dist/common/token/index.h5.ts +1 -1
  10. package/dist/common/token/token.jd.ts +1 -1
  11. package/dist/common/wxappApi.ts +1 -1
  12. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  13. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  14. package/dist/components/base/CountDown/index.tsx +1 -1
  15. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  16. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  17. package/dist/components/base/Dialog/index.module.scss +11 -0
  18. package/dist/components/base/ExposureSmart/index.h5.module.scss +12 -2
  19. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  20. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  21. package/dist/components/base/InViewRender/index.tsx +1 -1
  22. package/dist/components/base/ItemViewExposureSmart/index.module.scss +2 -2
  23. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  24. package/dist/components/base/NetworkDataError/const.ts +1 -1
  25. package/dist/components/base/NetworkDataError/index.module.scss +117 -71
  26. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  27. package/dist/components/base/Price/Base/index.module.scss +12 -0
  28. package/dist/components/base/Price/Base/index.tsx +1 -1
  29. package/dist/components/base/Price/Double/index.module.scss +6 -0
  30. package/dist/components/base/Price/Double/index.tsx +1 -1
  31. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  32. package/dist/components/floorItem.weapp.tsx +1 -1
  33. package/dist/interface/common.ts +1 -1
  34. package/dist/interface/component.ts +1 -1
  35. package/dist/interface/jumpEventReport.ts +1 -1
  36. package/dist/interface/service.ts +1 -1
  37. package/dist/jumpEventReport/base.ts +1 -1
  38. package/dist/jumpEventReport/const.ts +1 -1
  39. package/dist/jumpEventReport/index.h5.ts +1 -1
  40. package/dist/jumpEventReport/index.jd.ts +1 -1
  41. package/dist/jumpEventReport/index.weapp.ts +1 -1
  42. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  43. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  44. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  45. package/dist/jumpEventReport/web/report.ts +1 -1
  46. package/dist/jumpEventReport/web.base.ts +1 -1
  47. package/dist/jumpEventReport/web.jd.ts +1 -1
  48. package/dist/jumpEventReport/web.pc.ts +1 -1
  49. package/dist/jumpEventReport/web.tjm.ts +1 -1
  50. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  51. package/dist/language/en_US.json +176 -0
  52. package/dist/language/zh_CN.json +176 -0
  53. package/dist/language/zh_HK.json +176 -0
  54. package/dist/libs/taroAppReport.js +2 -2
  55. package/dist/modules/ContainerFloorList/index.h5.module.scss +66 -53
  56. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  57. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  58. package/dist/open/api/environment.ts +1 -1
  59. package/dist/open/api/shopMember.ts +1 -1
  60. package/dist/open/api/util.ts +1 -1
  61. package/dist/sass/app.h5.scss +273 -224
  62. package/dist/service/fetchGateway.ts +1 -1
  63. package/dist/service/fetchGateway.weapp.ts +1 -0
  64. package/dist/service/http/colorSign.ts +1 -1
  65. package/dist/service/http/const.ts +1 -1
  66. package/dist/service/http/h5Http.ts +1 -1
  67. package/dist/service/requestServer.h5.ts +1 -1
  68. package/dist/service/requestServer.ts +1 -1
  69. package/dist/service/requestServer.weapp.ts +1 -0
  70. package/dist/utils/connectNativeJsBridge.ts +1 -1
  71. package/dist/utils/h5Utils.ts +1 -1
  72. package/dist/utils/index.h5.ts +1 -1
  73. package/dist/utils/index.ts +1 -1
  74. package/dist/utils/index.weapp.ts +1 -1
  75. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  76. package/dist/utils/jumpExtMapUtil.ts +1 -0
  77. package/dist/utils/log.ts +1 -0
  78. package/dist/utils/sColor.js +1 -0
  79. package/dist/utils/utils.ts +1 -1
  80. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  81. package/dist/wxapp/common/user_info.js +1 -1
  82. package/package.json +158 -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
  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
  isJdApp,
622
622
  isIosDevice,
623
623
  isAndroidDevice,
624
624
  isJdAndHarmonyDevice,
625
625
  showSuccessToast,
626
626
  showFailToast,
627
627
  isH5,
628
628
  isWxMinAndWxapp,
629
629
  isMin,
630
630
  isPc,
631
631
  draInterfaceCustomReport,
632
632
  callRouterIOS,
633
633
  callRouterAndroid,
634
634
  sendNativePageToShowCartFloatBtn,
635
635
  cookiesStr: '',
636
636
  requestHeaderContentType: {
637
637
  jsonHeader: {
638
638
  'content-type': 'application/json;charset=utf-8',
639
639
  },
640
640
  formDataHeader: {
641
641
  'content-type': 'application/x-www-form-urlencoded',
642
642
  },
643
643
  },
644
644
  requestBaseParam: {
645
645
  data: null,
646
646
  header: {
647
647
  'content-type': 'application/json;charset=utf-8',
648
648
  },
649
649
  },
650
650
  timeOut: 7000,
651
651
  apiClientParams: {
652
652
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
653
653
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
654
654
  area: '1_72_2799_0',
655
655
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
656
656
  window.screen?.height * devicePixelRatio,
657
657
  )}`,
658
658
  uuid: UUID,
659
659
  },
660
660
  public addressFetchInfo: {
661
661
  reqState: boolean;
662
662
  promiseInstance: null | Promise<any>;
663
663
  };
664
664
  public getPromotionConfig: {
665
665
  projectId: null | string | number;
666
666
  pageId: null | string | number;
667
667
  };
668
668
  public resInfo: ServiceInterFace.HttpRequestInfo;
669
669
  public api: ServiceInterFace.HttpApi;
670
670
  public isPageDomain: boolean;
671
671
  public verifyColorList: string[];
672
672
  private isShowJdShopCartFloatBtn: boolean;
673
673
  constructor(opt) {
674
674
  this._init();
675
675
  this.addressFetchInfo = {
676
676
  reqState: false,
677
677
  promiseInstance: null,
678
678
  };
679
679
  this.getPromotionConfig = {
680
680
  projectId: null,
681
681
  pageId: null,
682
682
  };
683
683
  this._userAreaUpdateListen();
684
684
  this.resInfo = this._getResConfig(opt);
685
685
  this.api = api;
686
686
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
687
687
  this.verifyColorList = [
688
688
  ...MobileVerifyColorList,
689
689
  ...AppVerifyColorList,
690
690
  ...JshopxVerifyColorList,
691
691
  ...BMallVerifyColorList,
692
692
  ];
693
693
  this.isShowJdShopCartFloatBtn =
694
694
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
695
695
  }
696
696
  _init(): void {
697
697
  httpInterceptors.forEach((item) => {
698
698
  Taro.addInterceptor((chain) => item(chain));
699
699
  });
700
700
  }
701
701
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
702
702
  return Object.assign({}, DefaultConfig, opt);
703
703
  }
704
704
 
705
705
  _userAreaUpdateListen() {
706
706
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
707
707
  this.updateApiClientParamsResInfo(areaInfo);
708
708
  console.log(
709
709
  'cone-render收到原生端获取传来的四级地址信息',
710
710
  areaInfo,
711
711
  '更新后的接口底层信息',
712
712
  this.resInfo.apiClientParams,
713
713
  );
714
714
  });
715
715
  }
716
716
  updateApiClientParamsResInfo(opt = {}) {
717
717
  const { area, realTimeArea, ...others } = opt;
718
718
  this.resInfo.apiClientParams = {
719
719
  ...this.resInfo.apiClientParams,
720
720
  ...others,
721
721
  };
722
722
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
723
723
  realTimeArea &&
724
724
  realTimeArea !== '' &&
725
725
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
726
726
  }
727
727
 
728
728
  checkFunctionIdToReturnAppId(functionId) {
729
729
  if (JshopxColorFunctionIdList.includes(functionId)) {
730
730
  return APPID.JSHOPX_COLOR_APPID;
731
731
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
732
732
  return APPID.PAGES_COLOR_APPID;
733
733
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
734
734
  return APPID.SHOP_MEMBER_COLOR_APPID;
735
735
  } else if (B2BColorFunctionIdList.includes(functionId)) {
736
736
  return APPID.B2B_COLOR_APPID;
737
737
  } else if (isPc) {
738
738
  return APPID.MALL_COLOR_APPID;
739
739
  } else {
740
740
  return APPID.SHOP_COLOR_APPID;
741
741
  }
742
742
  }
743
743
 
744
744
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
745
745
  if (
746
746
  functionId === 'receiveShopCoupon' &&
747
747
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
748
748
  isWxMinAndWxapp)
749
749
  ) {
750
750
  clientParams = Object.assign(
751
751
  {},
752
752
  {
753
753
  loginType: '1',
754
754
  loginWQBiz: WXAPP_BIZ_KEY,
755
755
  },
756
756
  clientParams,
757
757
  );
758
758
  }
759
759
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
760
760
  typeof apiClientParams.appid === 'undefined' &&
761
761
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
762
762
  const isColorVerify = this.verifyColorList.includes(functionId);
763
763
  const getReqData = {
764
764
  functionId: functionId,
765
765
  body: JSON.stringify(bodyParams),
766
766
  t: Date.now(),
767
767
  ...apiClientParams,
768
768
  };
769
769
  return http
770
770
  .request({
771
771
  url: this.api.apiFunc,
772
772
  data: getReqData,
773
773
  isColorVerify,
774
774
  })
775
775
  .then((res: ServiceInterFace.RequestPromiseRes) => {
776
776
  const { statusCode, data, status, msg } = res;
777
777
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
778
778
  ok: true,
779
779
  };
780
780
  if ((statusCode === 200 || status === '0') && data) {
781
781
  changeRes = this.dealResponseFormatRes(data);
782
782
  return changeRes;
783
783
  } else {
784
784
  changeRes = {
785
785
  ...data,
786
786
  statusCode,
787
787
  status,
788
788
  msg,
789
789
  ok: false,
790
790
  };
791
791
  return changeRes;
792
792
  }
793
793
  })
794
794
  .catch((res) => {
795
795
  const propertyNames = Object.getOwnPropertyNames(res);
796
796
  const resObject = {};
797
797
  propertyNames.forEach((propertyName) => {
798
798
  resObject[propertyName] = res[propertyName];
799
799
  });
800
800
  draInterfaceCustomReport({
801
801
  subMsg:
802
802
  '接口请求异常,进入catch逻辑,例如h5请求神盾(反爬、小号、风控)或加固拦截返回status为403等',
803
803
  url: this.api.apiFunc,
804
804
  source: 'remote',
805
805
  requestType: res?.requestType,
806
806
  errorType: 'catchError',
807
807
  functionId: getReqData?.functionId,
808
808
  appid: getReqData?.appid,
809
809
  client: getReqData?.client,
810
810
  clientVersion: getReqData?.clientVersion,
811
811
  statusCode: res?.statusCode,
812
812
  status: res?.status,
813
813
  statusText: res?.statusText,
814
814
  code: res?.data?.code || res?.data?.subCode,
815
815
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
816
816
  originReqDataStr: JSON.stringify(getReqData),
817
817
  originResDataStr: JSON.stringify(res, propertyNames),
818
818
  });
819
819
  return {
820
820
  ...resObject,
821
821
  ok: false,
822
822
  } as ServiceInterFace.RequestResponseFormatRes;
823
823
  });
824
824
  }
825
825
 
826
826
  dealResponseFormatRes(data) {
827
827
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
828
828
  ok: true,
829
829
  };
830
830
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
831
831
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
832
832
  ? Number(data.subCode)
833
833
  : -1;
834
834
  if (
835
835
  data.success === true ||
836
836
  data.isSuccess ||
837
837
  resCode === 0 ||
838
838
  resCode === 200 ||
839
839
  subCode === 0
840
840
  ) {
841
841
  changeRes = {
842
842
  result: Object.prototype.hasOwnProperty.call(data, 'result')
843
843
  ? data.result
844
844
  : Object.prototype.hasOwnProperty.call(data, 'data')
845
845
  ? data.data
846
846
  : data,
847
847
  code: data.code ?? 200,
848
848
  ok: true,
849
849
  source: data,
850
850
  };
851
851
  return changeRes;
852
852
  } else {
853
853
  changeRes = {
854
854
  ...data,
855
855
  ok: false,
856
856
  };
857
857
  return changeRes;
858
858
  }
859
859
  }
860
860
 
861
861
  async receiveCoupon(param = {}, clientParams) {
862
862
  const loginType = isPc ? { loginType: 3 } : {};
863
863
  return await this.gatewayReq(
864
864
  'receiveShopCoupon',
865
865
  {
866
866
  operation: '3',
867
867
  ...param,
868
868
  },
869
869
  { ...loginType, ...clientParams },
870
870
  );
871
871
  }
872
872
 
873
873
  getCustomerCenterDispatch(params = {}) {
874
874
  return this.gatewayReq('customerCenterDispatch', params, {
875
875
  clientVersion: '9.2.0',
876
876
  client: 'H5',
877
877
  uuid: 88888,
878
878
  appid: 'shopmember_m_jd_com',
879
879
  });
880
880
  }
881
881
 
882
882
  batchAddCart(...args) {
883
883
  let skuIds, num, showToast, giftCard;
884
884
  if (['number', 'string'].includes(typeof args[0])) {
885
885
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
886
886
  } else if (typeof args[0] === 'object' && args[0] !== null) {
887
887
  const params = args[0];
888
888
  skuIds = params.skuIds;
889
889
  num = params.num || 1;
890
890
  showToast = params.showToast !== undefined ? params.showToast : true;
891
891
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
892
892
  } else {
893
893
  console.error('batchAddCart() Invalid arguments!', args);
894
894
  try {
895
895
  const data = {
896
896
  type: 'batchAddCart',
897
897
  subType: 'invalidInputParameter',
898
898
  errMsg: '入参不合法',
899
899
  originData: args,
900
900
  };
901
901
  draBusinessCustomReport(data);
902
902
  } catch (e) {
903
903
  console.error('draBusinessCustomReport error:', e);
904
904
  }
905
905
  const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
906
906
  showFailToast({
907
907
  title: msg,
908
908
  });
909
909
  return Promise.resolve({
910
910
  ok: false,
911
911
  msg,
912
912
  });
913
913
  }
914
914
  const successMsg = giftCard ? (global?.languageJsonData?.successAddShopList || '加入购物清单成功') : (global?.languageJsonData?.successAddCart || '加入购物车成功');
915
915
  const failMsg = giftCard ? (global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试') : (global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试');
916
916
  if (skuIds) {
917
917
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
918
918
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
919
919
  if (res?.ok) {
920
920
  showToast &&
921
921
  !res?.isOpenApp &&
922
922
  showSuccessToast({
923
923
  title: successMsg,
924
924
  });
925
925
  this.isShowJdShopCartFloatBtn &&
926
926
  sendNativePageToShowCartFloatBtn({
927
927
  isShow: true,
928
928
  });
929
929
  } else {
930
930
  showToast &&
931
931
  showFailToast({
932
932
  title: res?.errMsg || failMsg,
933
933
  });
934
934
  }
935
935
  return Promise.resolve(res);
936
936
  })
937
937
  .catch((e) => {
938
938
  console.log('调用加购方法异常=======>', e);
939
939
  return Promise.resolve({
940
940
  ok: false,
941
941
  msg: failMsg,
942
942
  });
943
943
  });
944
944
  } else {
945
945
  try {
946
946
  const data = {
947
947
  type: 'batchAddCart',
948
948
  subType: 'invalidInputParameter',
949
949
  errMsg: '没有传入合法的skuIds',
950
950
  originData: skuIds,
951
951
  };
952
952
  draBusinessCustomReport(data);
953
953
  } catch (e) {
954
954
  console.error('draBusinessCustomReport error:', e);
955
955
  }
956
956
  return Promise.resolve({
957
957
  ok: false,
958
958
  msg: failMsg,
959
959
  });
960
960
  }
961
961
  }
962
962
 
963
963
  async giftCardAddCart(skuList, num) {
964
964
  const loginType = isPc ? { loginType: 3 } : {};
965
965
  return this.gatewayReq(
966
966
  'giftCardAddCart',
967
967
  {
968
968
  skuList,
969
969
  num: Number(num),
970
970
  },
971
971
  { ...loginType },
972
972
  );
973
973
  }
974
974
 
975
975
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
976
976
  return new Promise((resolve) => {
977
977
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
978
978
  if (productIdsArr.length > 0) {
979
979
  if (giftCard) {
980
980
  this.giftCardAddCart(productIdsArr, addCardNum)
981
981
  .then((res) => {
982
982
  if (res?.code === '0' && res?.result?.value) {
983
983
  resolve({
984
984
  ok: true,
985
985
  });
986
986
  } else {
987
987
  try {
988
988
  const data = {
989
989
  type: 'batchAddCart',
990
990
  subType: 'addCartFailByGiftCard',
991
991
  errMsg: '礼品卡加车接口返回加车失败标识',
992
992
  originData: res,
993
993
  };
994
994
  draBusinessCustomReport(data);
995
995
  } catch (e) {
996
996
  console.error('draBusinessCustomReport error:', e);
997
997
  }
998
998
  resolve({
999
999
  ok: false,
1000
1000
  msg: '加购失败,请稍后重试',
1001
1001
  });
1002
1002
  }
1003
1003
  })
1004
1004
  .catch((e) => {
1005
1005
  console.error('礼品卡加车失败: ', e);
1006
1006
  resolve({
1007
1007
  ok: false,
1008
1008
  msg: '加购失败,请稍后重试',
1009
1009
  });
1010
1010
  });
1011
1011
  } else if (isJdApp && !isJdAndHarmonyDevice) {
1012
1012
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now() + Number(productIdsArr[0]) + Number(addCardNum)}`;
1013
1013
  console.log(
1014
1014
  '==========>',
1015
1015
  '原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
1016
1016
  nativeAddCartCallBack,
1017
1017
  );
1018
1018
  if (!window[nativeAddCartCallBack]) {
1019
1019
  window[nativeAddCartCallBack] = (res) => {
1020
1020
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
1021
1021
  console.info(
1022
1022
  '获取批量加车原始数据',
1023
1023
  res,
1024
1024
  '====转换后的json数据为===',
1025
1025
  getMessageJsonData,
1026
1026
  );
1027
1027
  try {
1028
1028
  if (isAndroidDevice) {
1029
1029
  const isOk = getMessageJsonData?.status === '0';
1030
1030
  isOk
1031
1031
  ? resolve({
1032
1032
  ok: true,
1033
1033
  msg: '已加入购物车!',
1034
1034
  })
1035
1035
  : resolve({
1036
1036
  ok: false,
1037
1037
  msg: '加购失败,请稍后重试',
1038
1038
  errMsg: getMessageJsonData?.data?.message ?? '',
1039
1039
  });
1040
1040
  if (!isOk) {
1041
1041
  const data = {
1042
1042
  type: 'batchAddCart',
1043
1043
  subType: 'addCartFailByH5CallAndroidNative',
1044
1044
  errMsg: 'H5调用安卓原生加车失败',
1045
1045
  originData: getMessageJsonData,
1046
1046
  };
1047
1047
  draBusinessCustomReport(data);
1048
1048
  }
1049
1049
  } else if (isIosDevice) {
1050
1050
  const isOk =
1051
1051
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
1052
1052
  isOk
1053
1053
  ? resolve({
1054
1054
  ok: true,
1055
1055
  msg: '已加入购物车!',
1056
1056
  })
1057
1057
  : resolve({
1058
1058
  ok: false,
1059
1059
  msg: '批量加车失败,请稍后重试',
1060
1060
  errMsg: getMessageJsonData?.data?.message ?? '',
1061
1061
  });
1062
1062
  if (!isOk) {
1063
1063
  const data = {
1064
1064
  type: 'batchAddCart',
1065
1065
  subType: 'addCartFailByH5CallIosNative',
1066
1066
  errMsg: 'H5调用IOS原生加车失败',
1067
1067
  originData: getMessageJsonData,
1068
1068
  };
1069
1069
  draBusinessCustomReport(data);
1070
1070
  }
1071
1071
  } else {
1072
1072
  resolve({
1073
1073
  ok: false,
1074
1074
  msg: '加购失败,请稍后重试',
1075
1075
  });
1076
1076
  const data = {
1077
1077
  type: 'batchAddCart',
1078
1078
  subType: 'addCartFailByH5CallUnknownNative',
1079
1079
  errMsg: 'H5调用未知原生加车失败',
1080
1080
  };
1081
1081
  draBusinessCustomReport(data);
1082
1082
  }
1083
1083
  } catch (e) {
1084
1084
  resolve({
1085
1085
  ok: false,
1086
1086
  msg: '加购失败,请稍后重试',
1087
1087
  });
1088
1088
  console.warn('批量加车转换数据异常', e);
1089
1089
  const data = {
1090
1090
  type: 'batchAddCart',
1091
1091
  subType: 'addCartFailByTransformData',
1092
1092
  errMsg: '批量加车转换数据异常',
1093
1093
  originData: e,
1094
1094
  };
1095
1095
  draBusinessCustomReport(data);
1096
1096
  }
1097
1097
  window[nativeAddCartCallBack] = null;
1098
1098
  };
1099
1099
  }
1100
1100
  const productsAddCartList = productIdsArr.map((skuItem) => {
1101
1101
  const adInfos = getAdInfoBySkuId(skuItem);
1102
1102
  const extFlag = adInfos ? { adInfos } : {};
1103
1103
  return isAndroidDevice
1104
1104
  ? {
1105
1105
  sku: skuItem,
1106
1106
  num: addCardNum,
1107
1107
  extFlag,
1108
1108
  }
1109
1109
  : {
1110
1110
  productCode: skuItem,
1111
1111
  buyCount: addCardNum,
1112
1112
  extFlag,
1113
1113
  };
1114
1114
  });
1115
1115
  if (isAndroidDevice) {
1116
1116
  const androidProductsStr = JSON.stringify(productsAddCartList);
1117
1117
  callRouterAndroid({
1118
1118
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
1119
1119
  routerParam: {
1120
1120
  wareList: productsAddCartList,
1121
1121
  },
1122
1122
  callBackName: nativeAddCartCallBack,
1123
1123
  });
1124
1124
  } else if (isIosDevice) {
1125
1125
  if (isLowAppVer) {
1126
1126
  const lowVersionAppList = productIdsArr.map((skuItem) => {
1127
1127
  return {
1128
1128
  sku: skuItem,
1129
1129
  num: addCardNum,
1130
1130
  };
1131
1131
  });
1132
1132
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
1133
1133
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
1134
1134
  jump.side.jdJumpToWeb(url, {});
1135
1135
  resolve({
1136
1136
  ok: true,
1137
1137
  isOpenApp: true,
1138
1138
  msg: '加购完成, 加购结果请点击购物车确认',
1139
1139
  });
1140
1140
  } else {
1141
1141
  callRouterIOS({
1142
1142
  routerURL: 'router://JDCartModule/batchAddService',
1143
1143
  routerParam: {
1144
1144
  sourceType: 'h5',
1145
1145
  sourceValue: '店铺批量加购',
1146
1146
  businessName: 'storeModel',
1147
1147
  isNewMode: '1',
1148
1148
  NotPassWebview: '1',
1149
1149
  products: productsAddCartList,
1150
1150
  },
1151
1151
  callBackName: nativeAddCartCallBack,
1152
1152
  });
1153
1153
  }
1154
1154
  }
1155
1155
  } else if (isMin) {
1156
1156
  console.log('==========>', '京购批量加车!');
1157
1157
  const productsAddCartList = productIdsArr.map((skuItem) => {
1158
1158
  return {
1159
1159
  skuId: skuItem,
1160
1160
  buyNum: addCardNum,
1161
1161
  };
1162
1162
  });
1163
1163
  global.wxAppBizInstance
1164
1164
  .addCart({ commArr: productsAddCartList })
1165
1165
  .then((res) => {
1166
1166
  console.log('dealCartSuccess: ', res);
1167
1167
  resolve({
1168
1168
  ok: true,
1169
1169
  msg: '已加入购物车!',
1170
1170
  data: res,
1171
1171
  });
1172
1172
  })
1173
1173
  .catch((e) => {
1174
1174
  console.log('京购小程序批量加车失败dealCartFail: ', e);
1175
1175
  resolve({
1176
1176
  ok: false,
1177
1177
  msg: '加购失败,请稍后重试',
1178
1178
  });
1179
1179
  const data = {
1180
1180
  type: 'batchAddCart',
1181
1181
  subType: 'addCartFailByH5CallMini',
1182
1182
  errMsg: 'H5调用小程序加车失败',
1183
1183
  originData: e,
1184
1184
  };
1185
1185
  draBusinessCustomReport(data);
1186
1186
  });
1187
1187
  } else {
1188
1188
  console.log('==========>', 'M站批量加车!');
1189
1189
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
1190
1190
  }
1191
1191
  } else {
1192
1192
  resolve({
1193
1193
  ok: false,
1194
1194
  msg: '加购sku不能为空',
1195
1195
  });
1196
1196
  const data = {
1197
1197
  type: 'batchAddCart',
1198
1198
  subType: 'addCartFailNoSku',
1199
1199
  errMsg: '加购sku不能为空',
1200
1200
  originData: skuIdsStr,
1201
1201
  };
1202
1202
  draBusinessCustomReport(data);
1203
1203
  }
1204
1204
  });
1205
1205
  }
1206
1206
 
1207
1207
  productAddToCart(skuIdsStr, num) {
1208
1208
  return new Promise((resolve) => {
1209
1209
  if (window.AddcartToolObj) {
1210
1210
  window.AddcartToolObj.addCart({
1211
1211
  skuId: skuIdsStr,
1212
1212
  num,
1213
1213
  source: 'sjdpyw',
1214
1214
  actId: '1',
1215
1215
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
1216
1216
  sucFun(res) {
1217
1217
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
1218
1218
  if (res.errId === '0' && res.cartJson) {
1219
1219
  resolve({
1220
1220
  ok: true,
1221
1221
  msg: '已加入购物车!',
1222
1222
  ...res,
1223
1223
  });
1224
1224
  } else {
1225
1225
  if (res.errId === '13') {
1226
1226
  global.doLogin();
1227
1227
  } else {
1228
1228
  resolve({
1229
1229
  ok: false,
1230
1230
  msg: '加购失败,请稍后重试',
1231
1231
  ...res,
1232
1232
  });
1233
1233
  const data = {
1234
1234
  type: 'batchAddCart',
1235
1235
  subType: 'addCartFailByH5CallM',
1236
1236
  errMsg: 'H5调用M站加车失败',
1237
1237
  originData: res,
1238
1238
  };
1239
1239
  draBusinessCustomReport(data);
1240
1240
  }
1241
1241
  }
1242
1242
  },
1243
1243
  failFun(err) {
1244
1244
  console.log('fail', err);
1245
1245
  resolve({
1246
1246
  ok: false,
1247
1247
  msg: '加购失败,请稍后重试',
1248
1248
  ...err,
1249
1249
  });
1250
1250
  const data = {
1251
1251
  type: 'batchAddCart',
1252
1252
  subType: 'addCartFailByH5CallM',
1253
1253
  errMsg: 'H5调用M站加车失败',
1254
1254
  originData: err,
1255
1255
  };
1256
1256
  draBusinessCustomReport(data);
1257
1257
  },
1258
1258
  });
1259
1259
  } else {
1260
1260
  resolve({
1261
1261
  ok: false,
1262
1262
  msg: '购物车方法检查异常',
1263
1263
  });
1264
1264
  const data = {
1265
1265
  type: 'batchAddCart',
1266
1266
  subType: 'addCartFailByH5CallM',
1267
1267
  errMsg: 'H5调用M站加车检查依赖方法异常',
1268
1268
  };
1269
1269
  draBusinessCustomReport(data);
1270
1270
  }
1271
1271
  });
1272
1272
  }
1273
1273
  bMallGetUserInfo = () => {
1274
1274
  return getBMallUserInfo();
1275
1275
  };
1276
1276
  async bMallAddCart(params = {}) {
1277
1277
  return await this.gatewayReq('bmall_cartAdd', params, {
1278
1278
  client: 'H5',
1279
1279
  clientVersion: '5.5.0',
1280
1280
  });
1281
1281
  }
1282
1282
  async bMallChangeCart(params = {}) {
1283
1283
  return await this.gatewayReq('bmall_cartChange', params, {
1284
1284
  client: 'H5',
1285
1285
  clientVersion: '5.5.0',
1286
1286
  });
1287
1287
  }
1288
1288
  async bMallRemoveCart(params = {}) {
1289
1289
  return await this.gatewayReq(
1290
1290
  'bmall_cartRemove',
1291
1291
  params,
1292
1292
  {
1293
1293
  client: 'H5',
1294
1294
  clientVersion: '5.5.0',
1295
1295
  },
1296
1296
  );
1297
1297
  }
1298
1298
  async bMallGetOmittedProduct(params = {}) {
1299
1299
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1300
1300
  client: 'H5',
1301
1301
  clientVersion: '5.5.0',
1302
1302
  });
1303
1303
  }
1304
1304
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1305
1305
  const params = await getParams({ ...data, skuId, bMallTag, num });
1306
1306
  return await this.bMallAddCart(params);
1307
1307
  }
1308
1308
  async bMallGetSkuNumService(bMallTag = 1) {
1309
1309
  const params = await getParams({ bMallTag });
1310
1310
  delete params.operations;
1311
1311
  return await this.bMallGetOmittedProduct(params);
1312
1312
  }
1313
1313
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1314
1314
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1315
1315
  return await this.bMallRemoveCart(params);
1316
1316
  }
1317
1317
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1318
1318
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1319
1319
  return await this.bMallChangeCart(params);
1320
1320
  }
1321
1321
 
1322
1322
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1323
1323
  if (!needRequest && isH5 && window?.bMallCartData) {
1324
1324
  return window?.bMallCartData;
1325
1325
  }
1326
1326
  const cartData = await this.bMallGetSkuNumService(bMallTag);
1327
1327
  let items;
1328
1328
  if (cartData.ok && cartData.result) {
1329
1329
  items = cartData?.result?.items || {};
1330
1330
  }
1331
1331
  if (isH5) {
1332
1332
  window.bMallCartData = items;
1333
1333
  }
1334
1334
  return items;
1335
1335
  }
1336
1336
 
1337
1337
  async bMallCartHandle(goodItem, num) {
1338
1338
  try {
1339
1339
  const {
1340
1340
  skuUuid,
1341
1341
  limitUpper,
1342
1342
  limitLower,
1343
1343
  } = goodItem;
1344
1344
  let cartNum = Number(num);
1345
1345
  if (limitLower && cartNum && cartNum < limitLower) {
1346
1346
  cartNum = limitLower;
1347
1347
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1348
1348
  cartNum = limitUpper;
1349
1349
  }
1350
1350
  if (skuUuid && cartNum > 0) {
1351
1351
  return this.bMallChangeCartService({
1352
1352
  ...goodItem,
1353
1353
  skuUuid,
1354
1354
  num: cartNum,
1355
1355
  });
1356
1356
  } else if (!skuUuid && cartNum > 0) {
1357
1357
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
1358
1358
  } else if (skuUuid && !cartNum) {
1359
1359
  return this.bMallRemoveCartService({
1360
1360
  ...goodItem,
1361
1361
  skuUuid,
1362
1362
  num: cartNum,
1363
1363
  });
1364
1364
  } else {
1365
1365
  console.error('参数不全');
1366
1366
  return false;
1367
1367
  }
1368
1368
  } catch (e) {
1369
1369
  console.error(e);
1370
1370
  }
1371
1371
  }