@conecli/cone-render 0.10.1-beta.7 → 0.10.1-beta.8

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 (65) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/index.h5.ts +1 -1
  4. package/dist/common/index.jd.ts +1 -1
  5. package/dist/common/index.ts +1 -1
  6. package/dist/common/index.weapp.ts +1 -1
  7. package/dist/common/jssdk.ts +1 -1
  8. package/dist/common/token/index.h5.ts +1 -1
  9. package/dist/common/token/token.jd.ts +1 -1
  10. package/dist/common/wxappApi.ts +1 -1
  11. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  12. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  13. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  14. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  15. package/dist/components/base/Dialog/index.module.scss +11 -0
  16. package/dist/components/base/ExposureSmart/index.h5.module.scss +12 -2
  17. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  18. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  19. package/dist/components/base/InViewRender/index.tsx +1 -1
  20. package/dist/components/base/ItemViewExposureSmart/index.module.scss +2 -2
  21. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  22. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  23. package/dist/components/floorItem.weapp.tsx +1 -1
  24. package/dist/interface/common.ts +1 -1
  25. package/dist/interface/jumpEventReport.ts +1 -1
  26. package/dist/interface/service.ts +1 -1
  27. package/dist/jumpEventReport/base.ts +1 -1
  28. package/dist/jumpEventReport/const.ts +1 -1
  29. package/dist/jumpEventReport/index.weapp.ts +1 -1
  30. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  31. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  32. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  33. package/dist/jumpEventReport/web/report.ts +1 -1
  34. package/dist/jumpEventReport/web.base.ts +1 -1
  35. package/dist/jumpEventReport/web.jd.ts +1 -1
  36. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  37. package/dist/libs/taroAppReport.js +2 -2
  38. package/dist/modules/ContainerFloorList/index.h5.module.scss +66 -53
  39. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  40. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  41. package/dist/open/api/environment.ts +1 -1
  42. package/dist/open/api/shopMember.ts +1 -1
  43. package/dist/open/api/util.ts +1 -1
  44. package/dist/sass/app.h5.scss +273 -224
  45. package/dist/service/fetchGateway.ts +1 -1
  46. package/dist/service/fetchGateway.weapp.ts +1 -0
  47. package/dist/service/http/colorSign.ts +1 -1
  48. package/dist/service/http/const.ts +1 -1
  49. package/dist/service/http/h5Http.ts +1 -1
  50. package/dist/service/requestServer.h5.ts +1 -1
  51. package/dist/service/requestServer.ts +1 -1
  52. package/dist/service/requestServer.weapp.ts +1 -0
  53. package/dist/utils/connectNativeJsBridge.ts +1 -1
  54. package/dist/utils/h5Utils.ts +1 -1
  55. package/dist/utils/index.h5.ts +1 -1
  56. package/dist/utils/index.ts +1 -1
  57. package/dist/utils/index.weapp.ts +1 -1
  58. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  59. package/dist/utils/jumpExtMapUtil.ts +1 -0
  60. package/dist/utils/log.ts +1 -0
  61. package/dist/utils/sColor.js +1 -0
  62. package/dist/utils/utils.ts +1 -1
  63. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  64. package/dist/wxapp/common/user_info.js +1 -1
  65. 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
  showSuccessToast,
16
15
  showFailToast,
17
16
  isH5,
18
17
  isWxMinAndWxapp,
19
18
  isMin,
20
19
  isPc,
21
20
  sgmCustomReport,
22
21
  getSgmCustomCode,
23
22
  draInterfaceCustomReport,
24
23
  callRouterIOS,
25
24
  callRouterAndroid,
26
25
  cookiesStr: '',
27
26
  requestHeaderContentType: {
28
27
  jsonHeader: {
29
28
  'content-type': 'application/json;charset=utf-8',
30
29
  },
31
30
  formDataHeader: {
32
31
  'content-type': 'application/x-www-form-urlencoded',
33
32
  },
34
33
  },
35
34
  requestBaseParam: {
36
35
  data: null,
37
36
  header: {
38
37
  'content-type': 'application/json;charset=utf-8',
39
38
  },
40
39
  },
41
40
  timeOut: 7000,
42
41
  apiClientParams: {
43
42
  clientVersion:
44
43
  isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
45
44
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
46
45
  area: '1_72_2799_0',
47
46
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
48
47
  window.screen?.height * devicePixelRatio,
49
48
  )}`,
50
49
  uuid: UUID,
51
50
  },
52
51
  public addressFetchInfo: {
53
52
  reqState: boolean
54
53
  promiseInstance: null | Promise<any>
55
54
  }
56
55
  public getPromotionConfig: {
57
56
  projectId: null | string | number
58
57
  pageId: null | string | number
59
58
  }
60
59
  public resInfo: ServiceInterFace.HttpRequestInfo
61
60
  public api: ServiceInterFace.HttpApi
62
61
  public isPageDomain: boolean
63
62
  public verifyColorList: string[]
64
63
  constructor(opt) {
65
64
  this._init()
66
65
  this.addressFetchInfo = {
67
66
  reqState: false,
68
67
  promiseInstance: null,
69
68
  }
70
69
  this.getPromotionConfig = {
71
70
  projectId: null,
72
71
  pageId: null,
73
72
  }
74
73
  this._userAreaUpdateListen()
75
74
  this.resInfo = this._getResConfig(opt)
76
75
  this.api = api
77
76
  this.isPageDomain = isH5
78
77
  ? window?.location?.hostname === PAGES_DOMAIN
79
78
  : false
80
79
  this.verifyColorList = [
81
80
  ...MobileVerifyColorList,
82
81
  ...AppVerifyColorList,
83
82
  ...JshopxVerifyColorList,
84
83
  ...BMallVerifyColorList,
85
84
  ]
86
85
  }
87
86
  _init(): void {
88
87
  httpInterceptors.forEach((item) => {
89
88
  Taro.addInterceptor((chain) => item(chain))
90
89
  })
91
90
  }
92
91
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
93
92
  return Object.assign({}, DefaultConfig, opt)
94
93
  }
95
94
 
96
95
  _userAreaUpdateListen() {
97
96
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
98
97
  area && area !== "" && this.updateApiClientParamsResInfo({
99
98
  area,
100
99
  })
101
100
  console.log("cone-render收到原生端获取传来的四级地址信息",area,"更新后的接口底层信息", this.resInfo.apiClientParams)
102
101
  })
103
102
  }
104
103
  updateApiClientParamsResInfo(opt = {}) {
105
104
  const { area, ...others} = opt
106
105
  this.resInfo.apiClientParams = {
107
106
  ...this.resInfo.apiClientParams,
108
107
  ...others
109
108
  }
110
109
  if(area){
111
110
  this.resInfo.apiClientParams.area = area
112
111
  }
113
112
  }
114
113
 
115
114
  checkFunctionIdToReturnAppId(functionId) {
116
115
  if (JshopxColorFunctionIdList.includes(functionId)) {
117
116
  return APPID.JSHOPX_COLOR_APPID
118
117
  } else if (
119
118
  this.isPageDomain &&
120
119
  PagesColorFunctionIdList.includes(functionId)
121
120
  ) {
122
121
  return APPID.PAGES_COLOR_APPID
123
122
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
124
123
  return APPID.SHOP_MEMBER_COLOR_APPID
125
124
  } else if (B2BColorFunctionIdList.includes(functionId)) {
126
125
  return APPID.B2B_COLOR_APPID
127
126
  } else if (isPc) {
128
127
  return APPID.MALL_COLOR_APPID
129
128
  } else {
130
129
  return APPID.SHOP_COLOR_APPID
131
130
  }
132
131
  }
133
132
 
134
133
  gatewayReq(
135
134
  functionId: string,
136
135
  bodyParams = {},
137
136
  clientParams = {},
138
137
  ): Promise<any> {
139
138
  if (
140
139
  functionId === 'receiveShopCoupon' &&
141
140
  ((isH5 &&
142
141
  (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
143
142
  isWxMinAndWxapp)
144
143
  ) {
145
144
  clientParams = Object.assign(
146
145
  {},
147
146
  {
148
147
  loginType: '1',
149
148
  loginWQBiz: WXAPP_BIZ_KEY,
150
149
  },
151
150
  clientParams,
152
151
  )
153
152
  }
154
153
  const apiClientParams = Object.assign(
155
154
  {},
156
155
  this.resInfo.apiClientParams,
157
156
  clientParams,
158
157
  )
159
158
  typeof apiClientParams.appid === 'undefined' &&
160
159
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId))
161
160
  const isColorVerify = this.verifyColorList.includes(functionId)
162
161
  const getReqData = {
163
162
  functionId: functionId,
164
163
  body: JSON.stringify(bodyParams),
165
164
  t: Date.now(),
166
165
  ...apiClientParams,
167
166
  }
168
167
  return http
169
168
  .request({
170
169
  url: this.api.apiFunc,
171
170
  data: getReqData,
172
171
  isColorVerify,
173
172
  })
174
173
  .then((res: ServiceInterFace.RequestPromiseRes) => {
175
174
  const { statusCode, data, status, msg } = res
176
175
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
177
176
  ok: true,
178
177
  }
179
178
  if ((statusCode === 200 || status === '0') && data) {
180
179
  changeRes = this.dealResponseFormatRes(data)
181
180
  return changeRes
182
181
  } else {
183
182
  changeRes = {
184
183
  ...data,
185
184
  statusCode,
186
185
  status,
187
186
  msg,
188
187
  ok: false,
189
188
  }
190
189
  return changeRes
191
190
  }
192
191
  })
193
192
  .catch((res) => {
194
193
  const propertyNames = Object.getOwnPropertyNames(res);
195
194
  const resObject = {};
196
195
  propertyNames.forEach((propertyName) => {
197
196
  resObject[propertyName] = res[propertyName];
198
197
  });
199
198
  draInterfaceCustomReport({
200
199
  subMsg:
201
200
  '接口请求异常,进入catch逻辑,例如h5请求神盾(反爬、小号、风控)或加固拦截返回status为403等',
202
201
  url: this.api.apiFunc,
203
202
  source: 'remote',
204
203
  requestType: res?.requestType,
205
204
  errorType: 'catchError',
206
205
  functionId: getReqData?.functionId,
207
206
  appid: getReqData?.appid,
208
207
  client: getReqData?.client,
209
208
  clientVersion: getReqData?.clientVersion,
210
209
  statusCode: res?.statusCode,
211
210
  status: res?.status,
212
211
  statusText: res?.statusText,
213
212
  code: res?.data?.code || res?.data?.subCode,
214
213
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
215
214
  originReqDataStr: JSON.stringify(getReqData),
216
215
  originResDataStr: JSON.stringify(res, propertyNames),
217
216
  });
218
217
  return {
219
218
  ...resObject,
220
219
  ok: false,
221
220
  } as ServiceInterFace.RequestResponseFormatRes;
222
221
  })
223
222
  }
224
223
 
225
224
  dealResponseFormatRes(data) {
226
225
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
227
226
  ok: true,
228
227
  }
229
228
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
230
229
  ? Number(data.code)
231
230
  : -1
232
231
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
233
232
  ? Number(data.subCode)
234
233
  : -1
235
234
  if (
236
235
  data.success === true ||
237
236
  data.isSuccess ||
238
237
  resCode === 0 ||
239
238
  resCode === 200 ||
240
239
  subCode === 0
241
240
  ) {
242
241
  changeRes = {
243
242
  result: Object.prototype.hasOwnProperty.call(data, 'result')
244
243
  ? data.result
245
244
  : Object.prototype.hasOwnProperty.call(data, 'data')
246
245
  ? data.data
247
246
  : data,
248
247
  code: data.code ?? 200,
249
248
  ok: true,
250
249
  source: data,
251
250
  }
252
251
  return changeRes
253
252
  } else {
254
253
  changeRes = {
255
254
  ...data,
256
255
  ok: false,
257
256
  }
258
257
  return changeRes
259
258
  }
260
259
  }
261
260
 
262
261
  async receiveCoupon(param = {}, clientParams) {
263
262
  const loginType = isPc ? { loginType: 3 } : {}
264
263
  return await this.gatewayReq(
265
264
  'receiveShopCoupon',
266
265
  {
267
266
  operation: '3',
268
267
  ...param,
269
268
  },
270
269
  { ...loginType, ...clientParams },
271
270
  )
272
271
  }
273
272
 
274
273
  getCustomerCenterDispatch(params = {}) {
275
274
  return this.gatewayReq('customerCenterDispatch', params, {
276
275
  clientVersion: '9.2.0',
277
276
  client: 'H5',
278
277
  uuid: 88888,
279
278
  appid: 'shopmember_m_jd_com',
280
279
  })
281
280
  }
282
281
 
283
282
  batchAddCart(skuIdsStr, num = 1, showToast = true) {
284
283
  if (skuIdsStr) {
285
284
  return this._addShopGoodCart(`${skuIdsStr}`, `${num}`)
286
285
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
287
286
  if (res?.ok) {
288
287
  if (showToast && !res?.isOpenApp)
289
288
  showSuccessToast({
290
289
  title: '加入购物车成功',
291
290
  })
292
291
  } else {
293
292
  showToast &&
294
293
  showFailToast({
295
294
  title: res?.errMsg || '加入购物车失败,请稍后重试!',
296
295
  })
297
296
  }
298
297
  return Promise.resolve(res)
299
298
  })
300
299
  .catch((e) => {
301
300
  console.log('调用加购方法异常=======>', e)
302
301
  return Promise.resolve({
303
302
  ok: false,
304
303
  msg: '加入购物车失败,请稍后重试!',
305
304
  })
306
305
  })
307
306
  } else {
308
307
  return Promise.resolve({
309
308
  ok: false,
310
309
  msg: '加入购物车失败,请稍后重试!',
311
310
  })
312
311
  }
313
312
  }
314
313
 
315
314
  _addShopGoodCart(skuIdsStr, addCardNum = '1') {
316
315
  return new Promise((resolve) => {
317
316
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
318
317
  if (productIdsArr.length > 0) {
319
318
  if (isJdApp) {
320
319
  console.log('==========>', '原生批量加车!')
321
320
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now()}`
322
321
  if (!window[nativeAddCartCallBack]) {
323
322
  window[nativeAddCartCallBack] = (res) => {
324
323
  const getMessageJsonData =
325
324
  typeof res === 'string' ? JSON.parse(res) : res
326
325
  console.info(
327
326
  '获取批量加车原始数据',
328
327
  res,
329
328
  '====转换后的json数据为===',
330
329
  getMessageJsonData,
331
330
  )
332
331
  try {
333
332
  if (isAndroidDevice) {
334
333
  getMessageJsonData?.status === '0'
335
334
  ? resolve({
336
335
  ok: true,
337
336
  msg: '已加入购物车!',
338
337
  })
339
338
  : resolve({
340
339
  ok: false,
341
340
  msg: '加购失败,请稍后重试',
342
341
  })
343
342
  } else if (isIosDevice) {
344
343
  getMessageJsonData?.status === '0' &&
345
344
  getMessageJsonData?.data?.code === 0
346
345
  ? resolve({
347
346
  ok: true,
348
347
  msg: '已加入购物车!',
349
348
  })
350
349
  : resolve({
351
350
  ok: false,
352
351
  msg: '批量加车失败,请稍后重试',
353
352
  })
354
353
  } else {
355
354
  resolve({
356
355
  ok: false,
357
356
  msg: '加购失败,请稍后重试',
358
357
  })
359
358
  }
360
359
  } catch (e) {
361
360
  resolve({
362
361
  ok: false,
363
362
  msg: '加购失败,请稍后重试',
364
363
  })
365
364
  console.warn('批量加车转换数据异常', e)
366
365
  }
367
366
  window[nativeAddCartCallBack] = null
368
367
  }
369
368
  }
370
369
  const productsAddCartList = productIdsArr.map((skuItem) => {
371
370
  return isAndroidDevice
372
371
  ? {
373
372
  sku: skuItem,
374
373
  num: addCardNum,
375
374
  }
376
375
  : {
377
376
  productCode: skuItem,
378
377
  buyCount: addCardNum,
379
378
  }
380
379
  })
381
380
  if (isAndroidDevice) {
382
381
  const androidProductsStr = JSON.stringify(productsAddCartList)
383
382
  callRouterAndroid({
384
383
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
385
384
  routerParam: {
386
385
  wareList: productsAddCartList,
387
386
  },
388
387
  callBackName: nativeAddCartCallBack,
389
388
  })
390
389
  } else if (isIosDevice) {
391
390
  if (isLowAppVer) {
392
391
  const lowVersionAppList = productIdsArr.map((skuItem) => {
393
392
  return {
394
393
  sku: skuItem,
395
394
  num: addCardNum,
396
395
  }
397
396
  })
398
397
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList)
399
398
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`
400
399
  jump.side.jdJumpToWeb(url, {})
401
400
  resolve({
402
401
  ok: true,
403
402
  isOpenApp: true,
404
403
  msg: '加购完成, 加购结果请点击购物车确认',
405
404
  })
406
405
  } else {
407
406
  callRouterIOS({
408
407
  routerURL: 'router://JDCartModule/batchAddService',
409
408
  routerParam: {
410
409
  sourceType: 'h5',
411
410
  sourceValue: '店铺批量加购',
412
411
  businessName: 'storeModel',
413
412
  isNewMode: '1',
414
413
  NotPassWebview: '1',
415
414
  products: productsAddCartList,
416
415
  },
417
416
  callBackName: nativeAddCartCallBack,
418
417
  })
419
418
  }
420
419
  }
421
420
  } else if (isMin) {
422
421
  console.log('==========>', '京购批量加车!')
423
422
  const productsAddCartList = productIdsArr.map((skuItem) => {
424
423
  return {
425
424
  skuId: skuItem,
426
425
  buyNum: addCardNum,
427
426
  }
428
427
  })
429
428
  global.wxAppBizInstance
430
429
  .addCart({ commArr: productsAddCartList })
431
430
  .then((res) => {
432
431
  console.log('dealCartSuccess: ', res)
433
432
  resolve({
434
433
  ok: true,
435
434
  msg: '已加入购物车!',
436
435
  data: res,
437
436
  })
438
437
  })
439
438
  .catch((e) => {
440
439
  console.log('京购小程序批量加车失败dealCartFail: ', e)
441
440
  resolve({
442
441
  ok: false,
443
442
  msg: '加购失败,请稍后重试',
444
443
  })
445
444
  })
446
445
  } else {
447
446
  console.log('==========>', 'M站批量加车!')
448
447
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
449
448
  resolve(res),
450
449
  )
451
450
  }
452
451
  } else {
453
452
  resolve({
454
453
  ok: false,
455
454
  msg: '加购sku不能为空',
456
455
  })
457
456
  }
458
457
  })
459
458
  }
460
459
 
461
460
  productAddToCart(skuIdsStr, num) {
462
461
  return new Promise((resolve) => {
463
462
  if (window.AddcartToolObj) {
464
463
  window.AddcartToolObj.addCart({
465
464
  skuId: skuIdsStr,
466
465
  num,
467
466
  source: 'sjdpyw',
468
467
  actId: '1',
469
468
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
470
469
  sucFun(res) {
471
470
  console.log(
472
471
  'ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0',
473
472
  res,
474
473
  )
475
474
  if (res.errId === '0' && res.cartJson) {
476
475
  resolve({
477
476
  ok: true,
478
477
  msg: '已加入购物车!',
479
478
  ...res,
480
479
  })
481
480
  } else {
482
481
  if (res.errId === '13') {
483
482
  global.doLogin()
484
483
  } else {
485
484
  resolve({
486
485
  ok: false,
487
486
  msg: '加购失败,请稍后重试',
488
487
  ...res,
489
488
  })
490
489
  }
491
490
  }
492
491
  },
493
492
  failFun(err) {
494
493
  console.log('fail', err)
495
494
  resolve({
496
495
  ok: false,
497
496
  msg: '加购失败,请稍后重试',
498
497
  ...err,
499
498
  })
500
499
  },
501
500
  })
502
501
  } else {
503
502
  resolve({
504
503
  ok: false,
505
504
  msg: '购物车方法检查异常',
506
505
  })
507
506
  }
508
507
  })
509
508
  }
510
509
  bMallGetUserInfo = () => {
511
510
  return getBMallUserInfo()
512
511
  }
513
512
  async bMallAddCart(params = {}) {
514
513
  return await this.gatewayReq('bmall_cartAdd', params, {
515
514
  client: 'H5',
516
515
  clientVersion: '5.5.0',
517
516
  })
518
517
  }
519
518
  async bMallChangeCart(params = {}) {
520
519
  return await this.gatewayReq('bmall_cartChange', params, {
521
520
  client: 'H5',
522
521
  clientVersion: '5.5.0',
523
522
  })
524
523
  }
525
524
  async bMallRemoveCart(params = {}) {
526
525
  return await this.gatewayReq(
527
526
  'bmall_cartRemove',
528
527
  params,
529
528
  {
530
529
  client: 'H5',
531
530
  clientVersion: '5.5.0',
532
531
  },
533
532
  )
534
533
  }
535
534
  async bMallGetOmittedProduct(params = {}) {
536
535
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
537
536
  client: 'H5',
538
537
  clientVersion: '5.5.0',
539
538
  })
540
539
  }
541
540
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
542
541
  const params = await getParams({ ...data, skuId, bMallTag, num })
543
542
  return await this.bMallAddCart(params)
544
543
  }
545
544
  async bMallGetSkuNumService(bMallTag = 1) {
546
545
  const params = await getParams({ bMallTag })
547
546
  delete params.operations
548
547
  return await this.bMallGetOmittedProduct(params)
549
548
  }
550
549
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
551
550
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
552
551
  return await this.bMallRemoveCart(params)
553
552
  }
554
553
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
555
554
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
556
555
  return await this.bMallChangeCart(params)
557
556
  }
558
557
 
559
558
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
560
559
  if (!needRequest && isH5 && window?.bMallCartData) {
561
560
  return window?.bMallCartData
562
561
  }
563
562
  const cartData = await this.bMallGetSkuNumService(bMallTag)
564
563
  let items
565
564
  if (cartData.ok && cartData.result) {
566
565
  items = cartData?.result?.items || {}
567
566
  }
568
567
  if (isH5) {
569
568
  window.bMallCartData = items
570
569
  }
571
570
  return items
572
571
  }
573
572
 
574
573
  async bMallCartHandle(goodItem, num) {
575
574
  try {
576
575
  const {
577
576
  skuUuid,
578
577
  limitUpper,
579
578
  limitLower,
580
579
  } = goodItem
581
580
  let cartNum = Number(num)
582
581
  if (limitLower && cartNum && cartNum < limitLower) {
583
582
  cartNum = limitLower
584
583
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
585
584
  cartNum = limitUpper
586
585
  }
587
586
  if (skuUuid && cartNum > 0) {
588
587
  return this.bMallChangeCartService({
589
588
  ...goodItem,
590
589
  skuUuid,
591
590
  num: cartNum,
592
591
  })
593
592
  } else if (!skuUuid && cartNum > 0) {
594
593
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
595
594
  } else if (skuUuid && !cartNum) {
596
595
  return this.bMallRemoveCartService({
597
596
  ...goodItem,
598
597
  skuUuid,
599
598
  num: cartNum,
600
599
  })
601
600
  } else {
602
601
  console.error('参数不全')
603
602
  return false
604
603
  }
605
604
  } catch (e) {
606
605
  console.error(e)
607
606
  }
608
607
  }
608
+ import Taro from '@tarojs/taro';
609
609
  APPID,
610
610
  JshopxColorFunctionIdList,
611
611
  PagesColorFunctionIdList,
612
612
  PAGES_DOMAIN,
613
613
  B2BColorFunctionIdList,
614
614
  MobileVerifyColorList,
615
615
  AppVerifyColorList,
616
616
  JshopxVerifyColorList,
617
617
  BMallVerifyColorList,
618
618
  shopMemberColorFunctionIdList,
619
619
  draBusinessCustomReport,
620
620
  isLanguageForEn,
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 = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
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 addToWhereText = giftCard ? '购物清单' : '购物车';
915
915
  const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
916
916
  const failMsg = isLanguageForEn
917
917
  ? 'Please retry later'
918
918
  : `加入${addToWhereText}失败,请稍后重试!`;
919
919
  if (skuIds) {
920
920
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
921
921
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
922
922
  if (res?.ok) {
923
923
  showToast &&
924
924
  !res?.isOpenApp &&
925
925
  showSuccessToast({
926
926
  title: successMsg,
927
927
  });
928
928
  this.isShowJdShopCartFloatBtn &&
929
929
  sendNativePageToShowCartFloatBtn({
930
930
  isShow: true,
931
931
  });
932
932
  } else {
933
933
  showToast &&
934
934
  showFailToast({
935
935
  title: res?.errMsg || failMsg,
936
936
  });
937
937
  }
938
938
  return Promise.resolve(res);
939
939
  })
940
940
  .catch((e) => {
941
941
  console.log('调用加购方法异常=======>', e);
942
942
  return Promise.resolve({
943
943
  ok: false,
944
944
  msg: failMsg,
945
945
  });
946
946
  });
947
947
  } else {
948
948
  try {
949
949
  const data = {
950
950
  type: 'batchAddCart',
951
951
  subType: 'invalidInputParameter',
952
952
  errMsg: '没有传入合法的skuIds',
953
953
  originData: skuIds,
954
954
  };
955
955
  draBusinessCustomReport(data);
956
956
  } catch (e) {
957
957
  console.error('draBusinessCustomReport error:', e);
958
958
  }
959
959
  return Promise.resolve({
960
960
  ok: false,
961
961
  msg: failMsg,
962
962
  });
963
963
  }
964
964
  }
965
965
 
966
966
  async giftCardAddCart(skuList, num) {
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)
984
984
  .then((res) => {
985
985
  if (res?.code === '0' && res?.result?.value) {
986
986
  resolve({
987
987
  ok: true,
988
988
  });
989
989
  } else {
990
990
  try {
991
991
  const data = {
992
992
  type: 'batchAddCart',
993
993
  subType: 'addCartFailByGiftCard',
994
994
  errMsg: '礼品卡加车接口返回加车失败标识',
995
995
  originData: res,
996
996
  };
997
997
  draBusinessCustomReport(data);
998
998
  } catch (e) {
999
999
  console.error('draBusinessCustomReport error:', e);
1000
1000
  }
1001
1001
  resolve({
1002
1002
  ok: false,
1003
1003
  msg: '加购失败,请稍后重试',
1004
1004
  });
1005
1005
  }
1006
1006
  })
1007
1007
  .catch((e) => {
1008
1008
  console.error('礼品卡加车失败: ', e);
1009
1009
  resolve({
1010
1010
  ok: false,
1011
1011
  msg: '加购失败,请稍后重试',
1012
1012
  });
1013
1013
  });
1014
1014
  } else if (isJdApp && !isJdAndHarmonyDevice) {
1015
1015
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now() + Number(productIdsArr[0]) + Number(addCardNum)}`;
1016
1016
  console.log(
1017
1017
  '==========>',
1018
1018
  '原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
1019
1019
  nativeAddCartCallBack,
1020
1020
  );
1021
1021
  if (!window[nativeAddCartCallBack]) {
1022
1022
  window[nativeAddCartCallBack] = (res) => {
1023
1023
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
1024
1024
  console.info(
1025
1025
  '获取批量加车原始数据',
1026
1026
  res,
1027
1027
  '====转换后的json数据为===',
1028
1028
  getMessageJsonData,
1029
1029
  );
1030
1030
  try {
1031
1031
  if (isAndroidDevice) {
1032
1032
  const isOk = getMessageJsonData?.status === '0';
1033
1033
  isOk
1034
1034
  ? resolve({
1035
1035
  ok: true,
1036
1036
  msg: '已加入购物车!',
1037
1037
  })
1038
1038
  : resolve({
1039
1039
  ok: false,
1040
1040
  msg: '加购失败,请稍后重试',
1041
1041
  errMsg: getMessageJsonData?.data?.message ?? '',
1042
1042
  });
1043
1043
  if (!isOk) {
1044
1044
  const data = {
1045
1045
  type: 'batchAddCart',
1046
1046
  subType: 'addCartFailByH5CallAndroidNative',
1047
1047
  errMsg: 'H5调用安卓原生加车失败',
1048
1048
  originData: getMessageJsonData,
1049
1049
  };
1050
1050
  draBusinessCustomReport(data);
1051
1051
  }
1052
1052
  } else if (isIosDevice) {
1053
1053
  const isOk =
1054
1054
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
1055
1055
  isOk
1056
1056
  ? resolve({
1057
1057
  ok: true,
1058
1058
  msg: '已加入购物车!',
1059
1059
  })
1060
1060
  : resolve({
1061
1061
  ok: false,
1062
1062
  msg: '批量加车失败,请稍后重试',
1063
1063
  errMsg: getMessageJsonData?.data?.message ?? '',
1064
1064
  });
1065
1065
  if (!isOk) {
1066
1066
  const data = {
1067
1067
  type: 'batchAddCart',
1068
1068
  subType: 'addCartFailByH5CallIosNative',
1069
1069
  errMsg: 'H5调用IOS原生加车失败',
1070
1070
  originData: getMessageJsonData,
1071
1071
  };
1072
1072
  draBusinessCustomReport(data);
1073
1073
  }
1074
1074
  } else {
1075
1075
  resolve({
1076
1076
  ok: false,
1077
1077
  msg: '加购失败,请稍后重试',
1078
1078
  });
1079
1079
  const data = {
1080
1080
  type: 'batchAddCart',
1081
1081
  subType: 'addCartFailByH5CallUnknownNative',
1082
1082
  errMsg: 'H5调用未知原生加车失败',
1083
1083
  };
1084
1084
  draBusinessCustomReport(data);
1085
1085
  }
1086
1086
  } catch (e) {
1087
1087
  resolve({
1088
1088
  ok: false,
1089
1089
  msg: '加购失败,请稍后重试',
1090
1090
  });
1091
1091
  console.warn('批量加车转换数据异常', e);
1092
1092
  const data = {
1093
1093
  type: 'batchAddCart',
1094
1094
  subType: 'addCartFailByTransformData',
1095
1095
  errMsg: '批量加车转换数据异常',
1096
1096
  originData: e,
1097
1097
  };
1098
1098
  draBusinessCustomReport(data);
1099
1099
  }
1100
1100
  window[nativeAddCartCallBack] = null;
1101
1101
  };
1102
1102
  }
1103
1103
  const productsAddCartList = productIdsArr.map((skuItem) => {
1104
1104
  const adInfos = getAdInfoBySkuId(skuItem);
1105
1105
  const extFlag = adInfos ? { adInfos } : {};
1106
1106
  return isAndroidDevice
1107
1107
  ? {
1108
1108
  sku: skuItem,
1109
1109
  num: addCardNum,
1110
1110
  extFlag,
1111
1111
  }
1112
1112
  : {
1113
1113
  productCode: skuItem,
1114
1114
  buyCount: addCardNum,
1115
1115
  extFlag,
1116
1116
  };
1117
1117
  });
1118
1118
  if (isAndroidDevice) {
1119
1119
  const androidProductsStr = JSON.stringify(productsAddCartList);
1120
1120
  callRouterAndroid({
1121
1121
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
1122
1122
  routerParam: {
1123
1123
  wareList: productsAddCartList,
1124
1124
  },
1125
1125
  callBackName: nativeAddCartCallBack,
1126
1126
  });
1127
1127
  } else if (isIosDevice) {
1128
1128
  if (isLowAppVer) {
1129
1129
  const lowVersionAppList = productIdsArr.map((skuItem) => {
1130
1130
  return {
1131
1131
  sku: skuItem,
1132
1132
  num: addCardNum,
1133
1133
  };
1134
1134
  });
1135
1135
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
1136
1136
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
1137
1137
  jump.side.jdJumpToWeb(url, {});
1138
1138
  resolve({
1139
1139
  ok: true,
1140
1140
  isOpenApp: true,
1141
1141
  msg: '加购完成, 加购结果请点击购物车确认',
1142
1142
  });
1143
1143
  } else {
1144
1144
  callRouterIOS({
1145
1145
  routerURL: 'router://JDCartModule/batchAddService',
1146
1146
  routerParam: {
1147
1147
  sourceType: 'h5',
1148
1148
  sourceValue: '店铺批量加购',
1149
1149
  businessName: 'storeModel',
1150
1150
  isNewMode: '1',
1151
1151
  NotPassWebview: '1',
1152
1152
  products: productsAddCartList,
1153
1153
  },
1154
1154
  callBackName: nativeAddCartCallBack,
1155
1155
  });
1156
1156
  }
1157
1157
  }
1158
1158
  } else if (isMin) {
1159
1159
  console.log('==========>', '京购批量加车!');
1160
1160
  const productsAddCartList = productIdsArr.map((skuItem) => {
1161
1161
  return {
1162
1162
  skuId: skuItem,
1163
1163
  buyNum: addCardNum,
1164
1164
  };
1165
1165
  });
1166
1166
  global.wxAppBizInstance
1167
1167
  .addCart({ commArr: productsAddCartList })
1168
1168
  .then((res) => {
1169
1169
  console.log('dealCartSuccess: ', res);
1170
1170
  resolve({
1171
1171
  ok: true,
1172
1172
  msg: '已加入购物车!',
1173
1173
  data: res,
1174
1174
  });
1175
1175
  })
1176
1176
  .catch((e) => {
1177
1177
  console.log('京购小程序批量加车失败dealCartFail: ', e);
1178
1178
  resolve({
1179
1179
  ok: false,
1180
1180
  msg: '加购失败,请稍后重试',
1181
1181
  });
1182
1182
  const data = {
1183
1183
  type: 'batchAddCart',
1184
1184
  subType: 'addCartFailByH5CallMini',
1185
1185
  errMsg: 'H5调用小程序加车失败',
1186
1186
  originData: e,
1187
1187
  };
1188
1188
  draBusinessCustomReport(data);
1189
1189
  });
1190
1190
  } else {
1191
1191
  console.log('==========>', 'M站批量加车!');
1192
1192
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
1193
1193
  }
1194
1194
  } else {
1195
1195
  resolve({
1196
1196
  ok: false,
1197
1197
  msg: '加购sku不能为空',
1198
1198
  });
1199
1199
  const data = {
1200
1200
  type: 'batchAddCart',
1201
1201
  subType: 'addCartFailNoSku',
1202
1202
  errMsg: '加购sku不能为空',
1203
1203
  originData: skuIdsStr,
1204
1204
  };
1205
1205
  draBusinessCustomReport(data);
1206
1206
  }
1207
1207
  });
1208
1208
  }
1209
1209
 
1210
1210
  productAddToCart(skuIdsStr, num) {
1211
1211
  return new Promise((resolve) => {
1212
1212
  if (window.AddcartToolObj) {
1213
1213
  window.AddcartToolObj.addCart({
1214
1214
  skuId: skuIdsStr,
1215
1215
  num,
1216
1216
  source: 'sjdpyw',
1217
1217
  actId: '1',
1218
1218
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
1219
1219
  sucFun(res) {
1220
1220
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
1221
1221
  if (res.errId === '0' && res.cartJson) {
1222
1222
  resolve({
1223
1223
  ok: true,
1224
1224
  msg: '已加入购物车!',
1225
1225
  ...res,
1226
1226
  });
1227
1227
  } else {
1228
1228
  if (res.errId === '13') {
1229
1229
  global.doLogin();
1230
1230
  } else {
1231
1231
  resolve({
1232
1232
  ok: false,
1233
1233
  msg: '加购失败,请稍后重试',
1234
1234
  ...res,
1235
1235
  });
1236
1236
  const data = {
1237
1237
  type: 'batchAddCart',
1238
1238
  subType: 'addCartFailByH5CallM',
1239
1239
  errMsg: 'H5调用M站加车失败',
1240
1240
  originData: res,
1241
1241
  };
1242
1242
  draBusinessCustomReport(data);
1243
1243
  }
1244
1244
  }
1245
1245
  },
1246
1246
  failFun(err) {
1247
1247
  console.log('fail', err);
1248
1248
  resolve({
1249
1249
  ok: false,
1250
1250
  msg: '加购失败,请稍后重试',
1251
1251
  ...err,
1252
1252
  });
1253
1253
  const data = {
1254
1254
  type: 'batchAddCart',
1255
1255
  subType: 'addCartFailByH5CallM',
1256
1256
  errMsg: 'H5调用M站加车失败',
1257
1257
  originData: err,
1258
1258
  };
1259
1259
  draBusinessCustomReport(data);
1260
1260
  },
1261
1261
  });
1262
1262
  } else {
1263
1263
  resolve({
1264
1264
  ok: false,
1265
1265
  msg: '购物车方法检查异常',
1266
1266
  });
1267
1267
  const data = {
1268
1268
  type: 'batchAddCart',
1269
1269
  subType: 'addCartFailByH5CallM',
1270
1270
  errMsg: 'H5调用M站加车检查依赖方法异常',
1271
1271
  };
1272
1272
  draBusinessCustomReport(data);
1273
1273
  }
1274
1274
  });
1275
1275
  }
1276
1276
  bMallGetUserInfo = () => {
1277
1277
  return getBMallUserInfo();
1278
1278
  };
1279
1279
  async bMallAddCart(params = {}) {
1280
1280
  return await this.gatewayReq('bmall_cartAdd', params, {
1281
1281
  client: 'H5',
1282
1282
  clientVersion: '5.5.0',
1283
1283
  });
1284
1284
  }
1285
1285
  async bMallChangeCart(params = {}) {
1286
1286
  return await this.gatewayReq('bmall_cartChange', params, {
1287
1287
  client: 'H5',
1288
1288
  clientVersion: '5.5.0',
1289
1289
  });
1290
1290
  }
1291
1291
  async bMallRemoveCart(params = {}) {
1292
1292
  return await this.gatewayReq(
1293
1293
  'bmall_cartRemove',
1294
1294
  params,
1295
1295
  {
1296
1296
  client: 'H5',
1297
1297
  clientVersion: '5.5.0',
1298
1298
  },
1299
1299
  );
1300
1300
  }
1301
1301
  async bMallGetOmittedProduct(params = {}) {
1302
1302
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1303
1303
  client: 'H5',
1304
1304
  clientVersion: '5.5.0',
1305
1305
  });
1306
1306
  }
1307
1307
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1308
1308
  const params = await getParams({ ...data, skuId, bMallTag, num });
1309
1309
  return await this.bMallAddCart(params);
1310
1310
  }
1311
1311
  async bMallGetSkuNumService(bMallTag = 1) {
1312
1312
  const params = await getParams({ bMallTag });
1313
1313
  delete params.operations;
1314
1314
  return await this.bMallGetOmittedProduct(params);
1315
1315
  }
1316
1316
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1317
1317
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1318
1318
  return await this.bMallRemoveCart(params);
1319
1319
  }
1320
1320
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1321
1321
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1322
1322
  return await this.bMallChangeCart(params);
1323
1323
  }
1324
1324
 
1325
1325
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1326
1326
  if (!needRequest && isH5 && window?.bMallCartData) {
1327
1327
  return window?.bMallCartData;
1328
1328
  }
1329
1329
  const cartData = await this.bMallGetSkuNumService(bMallTag);
1330
1330
  let items;
1331
1331
  if (cartData.ok && cartData.result) {
1332
1332
  items = cartData?.result?.items || {};
1333
1333
  }
1334
1334
  if (isH5) {
1335
1335
  window.bMallCartData = items;
1336
1336
  }
1337
1337
  return items;
1338
1338
  }
1339
1339
 
1340
1340
  async bMallCartHandle(goodItem, num) {
1341
1341
  try {
1342
1342
  const {
1343
1343
  skuUuid,
1344
1344
  limitUpper,
1345
1345
  limitLower,
1346
1346
  } = goodItem;
1347
1347
  let cartNum = Number(num);
1348
1348
  if (limitLower && cartNum && cartNum < limitLower) {
1349
1349
  cartNum = limitLower;
1350
1350
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1351
1351
  cartNum = limitUpper;
1352
1352
  }
1353
1353
  if (skuUuid && cartNum > 0) {
1354
1354
  return this.bMallChangeCartService({
1355
1355
  ...goodItem,
1356
1356
  skuUuid,
1357
1357
  num: cartNum,
1358
1358
  });
1359
1359
  } else if (!skuUuid && cartNum > 0) {
1360
1360
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
1361
1361
  } else if (skuUuid && !cartNum) {
1362
1362
  return this.bMallRemoveCartService({
1363
1363
  ...goodItem,
1364
1364
  skuUuid,
1365
1365
  num: cartNum,
1366
1366
  });
1367
1367
  } else {
1368
1368
  console.error('参数不全');
1369
1369
  return false;
1370
1370
  }
1371
1371
  } catch (e) {
1372
1372
  console.error(e);
1373
1373
  }
1374
1374
  }