@conecli/cone-render 0.9.1-shop2.30 → 0.9.1-shop2.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.
@@ -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
  this.updateApiClientParamsResInfo({
99
98
  area,
100
99
  })
101
100
  })
102
101
  }
103
102
  updateApiClientParamsResInfo(opt = {}) {
104
103
  this.resInfo.apiClientParams = {
105
104
  ...this.resInfo.apiClientParams,
106
105
  ...opt,
107
106
  }
108
107
  }
109
108
 
110
109
  checkFunctionIdToReturnAppId(functionId) {
111
110
  if (JshopxColorFunctionIdList.includes(functionId)) {
112
111
  return APPID.JSHOPX_COLOR_APPID
113
112
  } else if (
114
113
  this.isPageDomain &&
115
114
  PagesColorFunctionIdList.includes(functionId)
116
115
  ) {
117
116
  return APPID.PAGES_COLOR_APPID
118
117
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
119
118
  return APPID.SHOP_MEMBER_COLOR_APPID
120
119
  } else if (B2BColorFunctionIdList.includes(functionId)) {
121
120
  return APPID.B2B_COLOR_APPID
122
121
  } else if (isPc) {
123
122
  return APPID.MALL_COLOR_APPID
124
123
  } else {
125
124
  return APPID.SHOP_COLOR_APPID
126
125
  }
127
126
  }
128
127
 
129
128
  gatewayReq(
130
129
  functionId: string,
131
130
  bodyParams = {},
132
131
  clientParams = {},
133
132
  ): Promise<any> {
134
133
  if (
135
134
  functionId === 'receiveShopCoupon' &&
136
135
  ((isH5 &&
137
136
  (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
138
137
  isWxMinAndWxapp)
139
138
  ) {
140
139
  clientParams = Object.assign(
141
140
  {},
142
141
  {
143
142
  loginType: '1',
144
143
  loginWQBiz: WXAPP_BIZ_KEY,
145
144
  },
146
145
  clientParams,
147
146
  )
148
147
  }
149
148
  const apiClientParams = Object.assign(
150
149
  {},
151
150
  this.resInfo.apiClientParams,
152
151
  clientParams,
153
152
  )
154
153
  typeof apiClientParams.appid === 'undefined' &&
155
154
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId))
156
155
  const isColorVerify = this.verifyColorList.includes(functionId)
157
156
  const getReqData = {
158
157
  functionId: functionId,
159
158
  body: JSON.stringify(bodyParams),
160
159
  t: Date.now(),
161
160
  ...apiClientParams,
162
161
  }
163
162
  const requestParams = {
164
163
  functionId: getReqData?.functionId,
165
164
  body: getReqData?.body,
166
165
  appid: getReqData?.appid,
167
166
  client: getReqData?.client,
168
167
  clientVersion: getReqData?.clientVersion,
169
168
  area: getReqData?.area,
170
169
  requestTimeStamp: getReqData?.t,
171
170
  }
172
171
  return http
173
172
  .request({
174
173
  url: this.api.apiFunc,
175
174
  data: getReqData,
176
175
  isColorVerify,
177
176
  })
178
177
  .then((res: ServiceInterFace.RequestPromiseRes) => {
179
178
  const { statusCode, data, status, msg } = res
180
179
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
181
180
  ok: true,
182
181
  }
183
182
  if ((statusCode === 200 || status === '0') && data) {
184
183
  changeRes = this.dealResponseFormatRes(data)
185
184
  return changeRes
186
185
  } else {
187
186
  changeRes = {
188
187
  ...data,
189
188
  statusCode,
190
189
  status,
191
190
  msg,
192
191
  ok: false,
193
192
  }
194
193
  return changeRes
195
194
  }
196
195
  })
197
196
  .catch((res) => {
198
197
  const propertyNames = Object.getOwnPropertyNames(res)
199
198
  const resObject = {}
200
199
  propertyNames.forEach((propertyName) => {
201
200
  resObject[propertyName] = res[propertyName]
202
201
  })
203
202
  sgmCustomReport({
204
203
  code: getSgmCustomCode('interface_data_error'),
205
204
  msg: {
206
205
  subMsg: '接口请求错误',
207
206
  functionId,
208
207
  source: 'remote',
209
208
  requestParams,
210
209
  catchError: resObject,
211
210
  errorType: 'catchError',
212
211
  },
213
212
  })
214
213
  draInterfaceCustomReport({
215
214
  ...getReqData,
216
215
  ...resObject,
217
216
  source: 'remote',
218
217
  errorType: 'catchError',
219
218
  subMsg: '接口请求错误',
220
219
  })
221
220
  return {
222
221
  ...resObject,
223
222
  ok: false,
224
223
  } as ServiceInterFace.RequestResponseFormatRes
225
224
  })
226
225
  }
227
226
 
228
227
  dealResponseFormatRes(data) {
229
228
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
230
229
  ok: true,
231
230
  }
232
231
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
233
232
  ? Number(data.code)
234
233
  : -1
235
234
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
236
235
  ? Number(data.subCode)
237
236
  : -1
238
237
  if (
239
238
  data.success === true ||
240
239
  data.isSuccess ||
241
240
  resCode === 0 ||
242
241
  resCode === 200 ||
243
242
  subCode === 0
244
243
  ) {
245
244
  changeRes = {
246
245
  result: Object.prototype.hasOwnProperty.call(data, 'result')
247
246
  ? data.result
248
247
  : Object.prototype.hasOwnProperty.call(data, 'data')
249
248
  ? data.data
250
249
  : data,
251
250
  code: data.code ?? 200,
252
251
  ok: true,
253
252
  source: data,
254
253
  }
255
254
  return changeRes
256
255
  } else {
257
256
  changeRes = {
258
257
  ...data,
259
258
  ok: false,
260
259
  }
261
260
  return changeRes
262
261
  }
263
262
  }
264
263
 
265
264
  async receiveCoupon(param = {}, clientParams) {
266
265
  const loginType = isPc ? { loginType: 3 } : {}
267
266
  return await this.gatewayReq(
268
267
  'receiveShopCoupon',
269
268
  {
270
269
  operation: '3',
271
270
  ...param,
272
271
  },
273
272
  { ...loginType, ...clientParams },
274
273
  )
275
274
  }
276
275
 
277
276
  getCustomerCenterDispatch(params = {}) {
278
277
  return this.gatewayReq('customerCenterDispatch', params, {
279
278
  clientVersion: '9.2.0',
280
279
  client: 'H5',
281
280
  uuid: 88888,
282
281
  appid: 'shopmember_m_jd_com',
283
282
  })
284
283
  }
285
284
 
286
285
  batchAddCart(skuIdsStr, num = 1, showToast = true) {
287
286
  if (skuIdsStr) {
288
287
  return this._addShopGoodCart(`${skuIdsStr}`, `${num}`)
289
288
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
290
289
  if (res?.ok) {
291
290
  if (showToast && !res?.isOpenApp)
292
291
  showSuccessToast({
293
292
  title: '加入购物车成功',
294
293
  })
295
294
  } else {
296
295
  showToast &&
297
296
  showFailToast({
298
297
  title: res?.errMsg || '加入购物车失败,请稍后重试!',
299
298
  })
300
299
  }
301
300
  return Promise.resolve(res)
302
301
  })
303
302
  .catch((e) => {
304
303
  console.log('调用加购方法异常=======>', e)
305
304
  return Promise.resolve({
306
305
  ok: false,
307
306
  msg: '加入购物车失败,请稍后重试!',
308
307
  })
309
308
  })
310
309
  } else {
311
310
  return Promise.resolve({
312
311
  ok: false,
313
312
  msg: '加入购物车失败,请稍后重试!',
314
313
  })
315
314
  }
316
315
  }
317
316
 
318
317
  _addShopGoodCart(skuIdsStr, addCardNum = '1') {
319
318
  return new Promise((resolve) => {
320
319
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
321
320
  if (productIdsArr.length > 0) {
322
321
  if (isJdApp) {
323
322
  console.log('==========>', '原生批量加车!')
324
323
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now()}`
325
324
  if (!window[nativeAddCartCallBack]) {
326
325
  window[nativeAddCartCallBack] = (res) => {
327
326
  const getMessageJsonData =
328
327
  typeof res === 'string' ? JSON.parse(res) : res
329
328
  console.info(
330
329
  '获取批量加车原始数据',
331
330
  res,
332
331
  '====转换后的json数据为===',
333
332
  getMessageJsonData,
334
333
  )
335
334
  try {
336
335
  if (isAndroidDevice) {
337
336
  getMessageJsonData?.status === '0'
338
337
  ? resolve({
339
338
  ok: true,
340
339
  msg: '已加入购物车!',
341
340
  })
342
341
  : resolve({
343
342
  ok: false,
344
343
  msg: '加购失败,请稍后重试',
345
344
  })
346
345
  } else if (isIosDevice) {
347
346
  getMessageJsonData?.status === '0' &&
348
347
  getMessageJsonData?.data?.code === 0
349
348
  ? resolve({
350
349
  ok: true,
351
350
  msg: '已加入购物车!',
352
351
  })
353
352
  : resolve({
354
353
  ok: false,
355
354
  msg: '批量加车失败,请稍后重试',
356
355
  })
357
356
  } else {
358
357
  resolve({
359
358
  ok: false,
360
359
  msg: '加购失败,请稍后重试',
361
360
  })
362
361
  }
363
362
  } catch (e) {
364
363
  resolve({
365
364
  ok: false,
366
365
  msg: '加购失败,请稍后重试',
367
366
  })
368
367
  console.warn('批量加车转换数据异常', e)
369
368
  }
370
369
  window[nativeAddCartCallBack] = null
371
370
  }
372
371
  }
373
372
  const productsAddCartList = productIdsArr.map((skuItem) => {
374
373
  return isAndroidDevice
375
374
  ? {
376
375
  sku: skuItem,
377
376
  num: addCardNum,
378
377
  }
379
378
  : {
380
379
  productCode: skuItem,
381
380
  buyCount: addCardNum,
382
381
  }
383
382
  })
384
383
  if (isAndroidDevice) {
385
384
  const androidProductsStr = JSON.stringify(productsAddCartList)
386
385
  callRouterAndroid({
387
386
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
388
387
  routerParam: {
389
388
  wareList: productsAddCartList,
390
389
  },
391
390
  callBackName: nativeAddCartCallBack,
392
391
  })
393
392
  } else if (isIosDevice) {
394
393
  if (isLowAppVer) {
395
394
  const lowVersionAppList = productIdsArr.map((skuItem) => {
396
395
  return {
397
396
  sku: skuItem,
398
397
  num: addCardNum,
399
398
  }
400
399
  })
401
400
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList)
402
401
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`
403
402
  jump.side.jdJumpToWeb(url, {})
404
403
  resolve({
405
404
  ok: true,
406
405
  isOpenApp: true,
407
406
  msg: '加购完成, 加购结果请点击购物车确认',
408
407
  })
409
408
  } else {
410
409
  callRouterIOS({
411
410
  routerURL: 'router://JDCartModule/batchAddService',
412
411
  routerParam: {
413
412
  sourceType: 'h5',
414
413
  sourceValue: '店铺批量加购',
415
414
  businessName: 'storeModel',
416
415
  isNewMode: '1',
417
416
  NotPassWebview: '1',
418
417
  products: productsAddCartList,
419
418
  },
420
419
  callBackName: nativeAddCartCallBack,
421
420
  })
422
421
  }
423
422
  }
424
423
  } else if (isMin) {
425
424
  console.log('==========>', '京购批量加车!')
426
425
  const productsAddCartList = productIdsArr.map((skuItem) => {
427
426
  return {
428
427
  skuId: skuItem,
429
428
  buyNum: addCardNum,
430
429
  }
431
430
  })
432
431
  global.wxAppBizInstance
433
432
  .addCart({ commArr: productsAddCartList })
434
433
  .then((res) => {
435
434
  console.log('dealCartSuccess: ', res)
436
435
  resolve({
437
436
  ok: true,
438
437
  msg: '已加入购物车!',
439
438
  data: res,
440
439
  })
441
440
  })
442
441
  .catch((e) => {
443
442
  console.log('京购小程序批量加车失败dealCartFail: ', e)
444
443
  resolve({
445
444
  ok: false,
446
445
  msg: '加购失败,请稍后重试',
447
446
  })
448
447
  })
449
448
  } else {
450
449
  console.log('==========>', 'M站批量加车!')
451
450
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
452
451
  resolve(res),
453
452
  )
454
453
  }
455
454
  } else {
456
455
  resolve({
457
456
  ok: false,
458
457
  msg: '加购sku不能为空',
459
458
  })
460
459
  }
461
460
  })
462
461
  }
463
462
 
464
463
  productAddToCart(skuIdsStr, num) {
465
464
  return new Promise((resolve) => {
466
465
  if (window.AddcartToolObj) {
467
466
  window.AddcartToolObj.addCart({
468
467
  skuId: skuIdsStr,
469
468
  num,
470
469
  source: 'sjdpyw',
471
470
  actId: '1',
472
471
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
473
472
  sucFun(res) {
474
473
  console.log(
475
474
  'ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0',
476
475
  res,
477
476
  )
478
477
  if (res.errId === '0' && res.cartJson) {
479
478
  resolve({
480
479
  ok: true,
481
480
  msg: '已加入购物车!',
482
481
  ...res,
483
482
  })
484
483
  } else {
485
484
  if (res.errId === '13') {
486
485
  global.doLogin()
487
486
  } else {
488
487
  resolve({
489
488
  ok: false,
490
489
  msg: '加购失败,请稍后重试',
491
490
  ...res,
492
491
  })
493
492
  }
494
493
  }
495
494
  },
496
495
  failFun(err) {
497
496
  console.log('fail', err)
498
497
  resolve({
499
498
  ok: false,
500
499
  msg: '加购失败,请稍后重试',
501
500
  ...err,
502
501
  })
503
502
  },
504
503
  })
505
504
  } else {
506
505
  resolve({
507
506
  ok: false,
508
507
  msg: '购物车方法检查异常',
509
508
  })
510
509
  }
511
510
  })
512
511
  }
513
512
  bMallGetUserInfo = () => {
514
513
  return getBMallUserInfo()
515
514
  }
516
515
  async bMallAddCart(params = {}) {
517
516
  return await this.gatewayReq('bmall_cartAdd', params, {
518
517
  client: 'H5',
519
518
  clientVersion: '5.5.0',
520
519
  })
521
520
  }
522
521
  async bMallChangeCart(params = {}) {
523
522
  return await this.gatewayReq('bmall_cartChange', params, {
524
523
  client: 'H5',
525
524
  clientVersion: '5.5.0',
526
525
  })
527
526
  }
528
527
  async bMallRemoveCart(params = {}) {
529
528
  return await this.gatewayReq(
530
529
  'bmall_cartRemove',
531
530
  params,
532
531
  {
533
532
  client: 'H5',
534
533
  clientVersion: '5.5.0',
535
534
  },
536
535
  )
537
536
  }
538
537
  async bMallGetOmittedProduct(params = {}) {
539
538
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
540
539
  client: 'H5',
541
540
  clientVersion: '5.5.0',
542
541
  })
543
542
  }
544
543
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
545
544
  const params = await getParams({ ...data, skuId, bMallTag, num })
546
545
  return await this.bMallAddCart(params)
547
546
  }
548
547
  async bMallGetSkuNumService(bMallTag = 1) {
549
548
  const params = await getParams({ bMallTag })
550
549
  delete params.operations
551
550
  return await this.bMallGetOmittedProduct(params)
552
551
  }
553
552
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
554
553
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
555
554
  return await this.bMallRemoveCart(params)
556
555
  }
557
556
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
558
557
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
559
558
  return await this.bMallChangeCart(params)
560
559
  }
561
560
 
562
561
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
563
562
  if (!needRequest && isH5 && window?.bMallCartData) {
564
563
  return window?.bMallCartData
565
564
  }
566
565
  const cartData = await this.bMallGetSkuNumService(bMallTag)
567
566
  let items
568
567
  if (cartData.ok && cartData.result) {
569
568
  items = cartData?.result?.items || {}
570
569
  }
571
570
  if (isH5) {
572
571
  window.bMallCartData = items
573
572
  }
574
573
  return items
575
574
  }
576
575
 
577
576
  async bMallCartHandle(goodItem, num) {
578
577
  try {
579
578
  const {
580
579
  skuUuid,
581
580
  limitUpper,
582
581
  limitLower,
583
582
  } = goodItem
584
583
  let cartNum = Number(num)
585
584
  if (limitLower && cartNum && cartNum < limitLower) {
586
585
  cartNum = limitLower
587
586
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
588
587
  cartNum = limitUpper
589
588
  }
590
589
  if (skuUuid && cartNum > 0) {
591
590
  return this.bMallChangeCartService({
592
591
  ...goodItem,
593
592
  skuUuid,
594
593
  num: cartNum,
595
594
  })
596
595
  } else if (!skuUuid && cartNum > 0) {
597
596
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
598
597
  } else if (skuUuid && !cartNum) {
599
598
  return this.bMallRemoveCartService({
600
599
  ...goodItem,
601
600
  skuUuid,
602
601
  num: cartNum,
603
602
  })
604
603
  } else {
605
604
  console.error('参数不全')
606
605
  return false
607
606
  }
608
607
  } catch (e) {
609
608
  console.error(e)
610
609
  }
611
610
  }
611
+ import Taro from '@tarojs/taro'
612
612
  APPID,
613
613
  JshopxColorFunctionIdList,
614
614
  PagesColorFunctionIdList,
615
615
  PAGES_DOMAIN,
616
616
  B2BColorFunctionIdList,
617
617
  MobileVerifyColorList,
618
618
  AppVerifyColorList,
619
619
  JshopxVerifyColorList,
620
620
  BMallVerifyColorList,
621
621
  shopMemberColorFunctionIdList,
622
622
  isJdApp,
623
623
  isIosDevice,
624
624
  isAndroidDevice,
625
625
  showSuccessToast,
626
626
  showFailToast,
627
627
  isH5,
628
628
  isWxMinAndWxapp,
629
629
  isMin,
630
630
  isPc,
631
631
  sgmCustomReport,
632
632
  getSgmCustomCode,
633
633
  draInterfaceCustomReport,
634
634
  callRouterIOS,
635
635
  callRouterAndroid,
636
636
  cookiesStr: '',
637
637
  requestHeaderContentType: {
638
638
  jsonHeader: {
639
639
  'content-type': 'application/json;charset=utf-8',
640
640
  },
641
641
  formDataHeader: {
642
642
  'content-type': 'application/x-www-form-urlencoded',
643
643
  },
644
644
  },
645
645
  requestBaseParam: {
646
646
  data: null,
647
647
  header: {
648
648
  'content-type': 'application/json;charset=utf-8',
649
649
  },
650
650
  },
651
651
  timeOut: 7000,
652
652
  apiClientParams: {
653
653
  clientVersion:
654
654
  isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
655
655
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
656
656
  area: '1_72_2799_0',
657
657
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
658
658
  window.screen?.height * devicePixelRatio,
659
659
  )}`,
660
660
  uuid: UUID,
661
661
  },
662
662
  public addressFetchInfo: {
663
663
  reqState: boolean
664
664
  promiseInstance: null | Promise<any>
665
665
  }
666
666
  public getPromotionConfig: {
667
667
  projectId: null | string | number
668
668
  pageId: null | string | number
669
669
  }
670
670
  public resInfo: ServiceInterFace.HttpRequestInfo
671
671
  public api: ServiceInterFace.HttpApi
672
672
  public isPageDomain: boolean
673
673
  public verifyColorList: string[]
674
674
  constructor(opt) {
675
675
  this._init()
676
676
  this.addressFetchInfo = {
677
677
  reqState: false,
678
678
  promiseInstance: null,
679
679
  }
680
680
  this.getPromotionConfig = {
681
681
  projectId: null,
682
682
  pageId: null,
683
683
  }
684
684
  this._userAreaUpdateListen()
685
685
  this.resInfo = this._getResConfig(opt)
686
686
  this.api = api
687
687
  this.isPageDomain = isH5
688
688
  ? window?.location?.hostname === PAGES_DOMAIN
689
689
  : false
690
690
  this.verifyColorList = [
691
691
  ...MobileVerifyColorList,
692
692
  ...AppVerifyColorList,
693
693
  ...JshopxVerifyColorList,
694
694
  ...BMallVerifyColorList,
695
695
  ]
696
696
  }
697
697
  _init(): void {
698
698
  httpInterceptors.forEach((item) => {
699
699
  Taro.addInterceptor((chain) => item(chain))
700
700
  })
701
701
  }
702
702
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
703
703
  return Object.assign({}, DefaultConfig, opt)
704
704
  }
705
705
 
706
706
  _userAreaUpdateListen() {
707
707
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
708
708
  this.updateApiClientParamsResInfo({
709
709
  area,
710
710
  })
711
711
  })
712
712
  }
713
713
  updateApiClientParamsResInfo(opt = {}) {
714
714
  this.resInfo.apiClientParams = {
715
715
  ...this.resInfo.apiClientParams,
716
716
  ...opt,
717
717
  }
718
718
  }
719
719
 
720
720
  checkFunctionIdToReturnAppId(functionId) {
721
721
  if (JshopxColorFunctionIdList.includes(functionId)) {
722
722
  return APPID.JSHOPX_COLOR_APPID
723
723
  } else if (
724
724
  this.isPageDomain &&
725
725
  PagesColorFunctionIdList.includes(functionId)
726
726
  ) {
727
727
  return APPID.PAGES_COLOR_APPID
728
728
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
729
729
  return APPID.SHOP_MEMBER_COLOR_APPID
730
730
  } else if (B2BColorFunctionIdList.includes(functionId)) {
731
731
  return APPID.B2B_COLOR_APPID
732
732
  } else if (isPc) {
733
733
  return APPID.MALL_COLOR_APPID
734
734
  } else {
735
735
  return APPID.SHOP_COLOR_APPID
736
736
  }
737
737
  }
738
738
 
739
739
  gatewayReq(
740
740
  functionId: string,
741
741
  bodyParams = {},
742
742
  clientParams = {},
743
743
  ): Promise<any> {
744
744
  if (
745
745
  functionId === 'receiveShopCoupon' &&
746
746
  ((isH5 &&
747
747
  (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(
760
760
  {},
761
761
  this.resInfo.apiClientParams,
762
762
  clientParams,
763
763
  )
764
764
  typeof apiClientParams.appid === 'undefined' &&
765
765
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId))
766
766
  const isColorVerify = this.verifyColorList.includes(functionId)
767
767
  const getReqData = {
768
768
  functionId: functionId,
769
769
  body: JSON.stringify(bodyParams),
770
770
  t: Date.now(),
771
771
  ...apiClientParams,
772
772
  }
773
773
  return http
774
774
  .request({
775
775
  url: this.api.apiFunc,
776
776
  data: getReqData,
777
777
  isColorVerify,
778
778
  })
779
779
  .then((res: ServiceInterFace.RequestPromiseRes) => {
780
780
  const { statusCode, data, status, msg } = res
781
781
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
782
782
  ok: true,
783
783
  }
784
784
  if ((statusCode === 200 || status === '0') && data) {
785
785
  changeRes = this.dealResponseFormatRes(data)
786
786
  return changeRes
787
787
  } else {
788
788
  changeRes = {
789
789
  ...data,
790
790
  statusCode,
791
791
  status,
792
792
  msg,
793
793
  ok: false,
794
794
  }
795
795
  return changeRes
796
796
  }
797
797
  })
798
798
  .catch((res) => {
799
799
  const propertyNames = Object.getOwnPropertyNames(res)
800
800
  const resObject = {}
801
801
  propertyNames.forEach((propertyName) => {
802
802
  resObject[propertyName] = res[propertyName]
803
803
  })
804
804
  draInterfaceCustomReport({
805
805
  subMsg: '接口请求错误',
806
806
  url: this.api.apiFunc,
807
807
  source: 'remote',
808
808
  requestType: res?.requestType,
809
809
  errorType: 'catchError',
810
810
  body: getReqData?.body,
811
811
  appid: getReqData?.appid,
812
812
  t: getReqData?.t,
813
813
  client: getReqData?.client,
814
814
  clientVersion: getReqData?.clientVersion,
815
815
  ...resObject,
816
816
  });
817
817
  return {
818
818
  ...resObject,
819
819
  ok: false,
820
820
  } as ServiceInterFace.RequestResponseFormatRes
821
821
  })
822
822
  }
823
823
 
824
824
  dealResponseFormatRes(data) {
825
825
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
826
826
  ok: true,
827
827
  }
828
828
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
829
829
  ? Number(data.code)
830
830
  : -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(skuIdsStr, num = 1, showToast = true) {
883
883
  if (skuIdsStr) {
884
884
  return this._addShopGoodCart(`${skuIdsStr}`, `${num}`)
885
885
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
886
886
  if (res?.ok) {
887
887
  if (showToast && !res?.isOpenApp)
888
888
  showSuccessToast({
889
889
  title: '加入购物车成功',
890
890
  })
891
891
  } else {
892
892
  showToast &&
893
893
  showFailToast({
894
894
  title: res?.errMsg || '加入购物车失败,请稍后重试!',
895
895
  })
896
896
  }
897
897
  return Promise.resolve(res)
898
898
  })
899
899
  .catch((e) => {
900
900
  console.log('调用加购方法异常=======>', e)
901
901
  return Promise.resolve({
902
902
  ok: false,
903
903
  msg: '加入购物车失败,请稍后重试!',
904
904
  })
905
905
  })
906
906
  } else {
907
907
  return Promise.resolve({
908
908
  ok: false,
909
909
  msg: '加入购物车失败,请稍后重试!',
910
910
  })
911
911
  }
912
912
  }
913
913
 
914
914
  _addShopGoodCart(skuIdsStr, addCardNum = '1') {
915
915
  return new Promise((resolve) => {
916
916
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
917
917
  if (productIdsArr.length > 0) {
918
918
  if (isJdApp) {
919
919
  console.log('==========>', '原生批量加车!')
920
920
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now()}`
921
921
  if (!window[nativeAddCartCallBack]) {
922
922
  window[nativeAddCartCallBack] = (res) => {
923
923
  const getMessageJsonData =
924
924
  typeof res === 'string' ? JSON.parse(res) : res
925
925
  console.info(
926
926
  '获取批量加车原始数据',
927
927
  res,
928
928
  '====转换后的json数据为===',
929
929
  getMessageJsonData,
930
930
  )
931
931
  try {
932
932
  if (isAndroidDevice) {
933
933
  getMessageJsonData?.status === '0'
934
934
  ? resolve({
935
935
  ok: true,
936
936
  msg: '已加入购物车!',
937
937
  })
938
938
  : resolve({
939
939
  ok: false,
940
940
  msg: '加购失败,请稍后重试',
941
941
  })
942
942
  } else if (isIosDevice) {
943
943
  getMessageJsonData?.status === '0' &&
944
944
  getMessageJsonData?.data?.code === 0
945
945
  ? resolve({
946
946
  ok: true,
947
947
  msg: '已加入购物车!',
948
948
  })
949
949
  : resolve({
950
950
  ok: false,
951
951
  msg: '批量加车失败,请稍后重试',
952
952
  })
953
953
  } else {
954
954
  resolve({
955
955
  ok: false,
956
956
  msg: '加购失败,请稍后重试',
957
957
  })
958
958
  }
959
959
  } catch (e) {
960
960
  resolve({
961
961
  ok: false,
962
962
  msg: '加购失败,请稍后重试',
963
963
  })
964
964
  console.warn('批量加车转换数据异常', e)
965
965
  }
966
966
  window[nativeAddCartCallBack] = null
967
967
  }
968
968
  }
969
969
  const productsAddCartList = productIdsArr.map((skuItem) => {
970
970
  return isAndroidDevice
971
971
  ? {
972
972
  sku: skuItem,
973
973
  num: addCardNum,
974
974
  }
975
975
  : {
976
976
  productCode: skuItem,
977
977
  buyCount: addCardNum,
978
978
  }
979
979
  })
980
980
  if (isAndroidDevice) {
981
981
  const androidProductsStr = JSON.stringify(productsAddCartList)
982
982
  callRouterAndroid({
983
983
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
984
984
  routerParam: {
985
985
  wareList: productsAddCartList,
986
986
  },
987
987
  callBackName: nativeAddCartCallBack,
988
988
  })
989
989
  } else if (isIosDevice) {
990
990
  if (isLowAppVer) {
991
991
  const lowVersionAppList = productIdsArr.map((skuItem) => {
992
992
  return {
993
993
  sku: skuItem,
994
994
  num: addCardNum,
995
995
  }
996
996
  })
997
997
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList)
998
998
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`
999
999
  jump.side.jdJumpToWeb(url, {})
1000
1000
  resolve({
1001
1001
  ok: true,
1002
1002
  isOpenApp: true,
1003
1003
  msg: '加购完成, 加购结果请点击购物车确认',
1004
1004
  })
1005
1005
  } else {
1006
1006
  callRouterIOS({
1007
1007
  routerURL: 'router://JDCartModule/batchAddService',
1008
1008
  routerParam: {
1009
1009
  sourceType: 'h5',
1010
1010
  sourceValue: '店铺批量加购',
1011
1011
  businessName: 'storeModel',
1012
1012
  isNewMode: '1',
1013
1013
  NotPassWebview: '1',
1014
1014
  products: productsAddCartList,
1015
1015
  },
1016
1016
  callBackName: nativeAddCartCallBack,
1017
1017
  })
1018
1018
  }
1019
1019
  }
1020
1020
  } else if (isMin) {
1021
1021
  console.log('==========>', '京购批量加车!')
1022
1022
  const productsAddCartList = productIdsArr.map((skuItem) => {
1023
1023
  return {
1024
1024
  skuId: skuItem,
1025
1025
  buyNum: addCardNum,
1026
1026
  }
1027
1027
  })
1028
1028
  global.wxAppBizInstance
1029
1029
  .addCart({ commArr: productsAddCartList })
1030
1030
  .then((res) => {
1031
1031
  console.log('dealCartSuccess: ', res)
1032
1032
  resolve({
1033
1033
  ok: true,
1034
1034
  msg: '已加入购物车!',
1035
1035
  data: res,
1036
1036
  })
1037
1037
  })
1038
1038
  .catch((e) => {
1039
1039
  console.log('京购小程序批量加车失败dealCartFail: ', e)
1040
1040
  resolve({
1041
1041
  ok: false,
1042
1042
  msg: '加购失败,请稍后重试',
1043
1043
  })
1044
1044
  })
1045
1045
  } else {
1046
1046
  console.log('==========>', 'M站批量加车!')
1047
1047
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
1048
1048
  resolve(res),
1049
1049
  )
1050
1050
  }
1051
1051
  } else {
1052
1052
  resolve({
1053
1053
  ok: false,
1054
1054
  msg: '加购sku不能为空',
1055
1055
  })
1056
1056
  }
1057
1057
  })
1058
1058
  }
1059
1059
 
1060
1060
  productAddToCart(skuIdsStr, num) {
1061
1061
  return new Promise((resolve) => {
1062
1062
  if (window.AddcartToolObj) {
1063
1063
  window.AddcartToolObj.addCart({
1064
1064
  skuId: skuIdsStr,
1065
1065
  num,
1066
1066
  source: 'sjdpyw',
1067
1067
  actId: '1',
1068
1068
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
1069
1069
  sucFun(res) {
1070
1070
  console.log(
1071
1071
  'ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0',
1072
1072
  res,
1073
1073
  )
1074
1074
  if (res.errId === '0' && res.cartJson) {
1075
1075
  resolve({
1076
1076
  ok: true,
1077
1077
  msg: '已加入购物车!',
1078
1078
  ...res,
1079
1079
  })
1080
1080
  } else {
1081
1081
  if (res.errId === '13') {
1082
1082
  global.doLogin()
1083
1083
  } else {
1084
1084
  resolve({
1085
1085
  ok: false,
1086
1086
  msg: '加购失败,请稍后重试',
1087
1087
  ...res,
1088
1088
  })
1089
1089
  }
1090
1090
  }
1091
1091
  },
1092
1092
  failFun(err) {
1093
1093
  console.log('fail', err)
1094
1094
  resolve({
1095
1095
  ok: false,
1096
1096
  msg: '加购失败,请稍后重试',
1097
1097
  ...err,
1098
1098
  })
1099
1099
  },
1100
1100
  })
1101
1101
  } else {
1102
1102
  resolve({
1103
1103
  ok: false,
1104
1104
  msg: '购物车方法检查异常',
1105
1105
  })
1106
1106
  }
1107
1107
  })
1108
1108
  }
1109
1109
  bMallGetUserInfo = () => {
1110
1110
  return getBMallUserInfo()
1111
1111
  }
1112
1112
  async bMallAddCart(params = {}) {
1113
1113
  return await this.gatewayReq('bmall_cartAdd', params, {
1114
1114
  client: 'H5',
1115
1115
  clientVersion: '5.5.0',
1116
1116
  })
1117
1117
  }
1118
1118
  async bMallChangeCart(params = {}) {
1119
1119
  return await this.gatewayReq('bmall_cartChange', params, {
1120
1120
  client: 'H5',
1121
1121
  clientVersion: '5.5.0',
1122
1122
  })
1123
1123
  }
1124
1124
  async bMallRemoveCart(params = {}) {
1125
1125
  return await this.gatewayReq(
1126
1126
  'bmall_cartRemove',
1127
1127
  params,
1128
1128
  {
1129
1129
  client: 'H5',
1130
1130
  clientVersion: '5.5.0',
1131
1131
  },
1132
1132
  )
1133
1133
  }
1134
1134
  async bMallGetOmittedProduct(params = {}) {
1135
1135
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1136
1136
  client: 'H5',
1137
1137
  clientVersion: '5.5.0',
1138
1138
  })
1139
1139
  }
1140
1140
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1141
1141
  const params = await getParams({ ...data, skuId, bMallTag, num })
1142
1142
  return await this.bMallAddCart(params)
1143
1143
  }
1144
1144
  async bMallGetSkuNumService(bMallTag = 1) {
1145
1145
  const params = await getParams({ bMallTag })
1146
1146
  delete params.operations
1147
1147
  return await this.bMallGetOmittedProduct(params)
1148
1148
  }
1149
1149
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1150
1150
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
1151
1151
  return await this.bMallRemoveCart(params)
1152
1152
  }
1153
1153
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1154
1154
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
1155
1155
  return await this.bMallChangeCart(params)
1156
1156
  }
1157
1157
 
1158
1158
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1159
1159
  if (!needRequest && isH5 && window?.bMallCartData) {
1160
1160
  return window?.bMallCartData
1161
1161
  }
1162
1162
  const cartData = await this.bMallGetSkuNumService(bMallTag)
1163
1163
  let items
1164
1164
  if (cartData.ok && cartData.result) {
1165
1165
  items = cartData?.result?.items || {}
1166
1166
  }
1167
1167
  if (isH5) {
1168
1168
  window.bMallCartData = items
1169
1169
  }
1170
1170
  return items
1171
1171
  }
1172
1172
 
1173
1173
  async bMallCartHandle(goodItem, num) {
1174
1174
  try {
1175
1175
  const {
1176
1176
  skuUuid,
1177
1177
  limitUpper,
1178
1178
  limitLower,
1179
1179
  } = goodItem
1180
1180
  let cartNum = Number(num)
1181
1181
  if (limitLower && cartNum && cartNum < limitLower) {
1182
1182
  cartNum = limitLower
1183
1183
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1184
1184
  cartNum = limitUpper
1185
1185
  }
1186
1186
  if (skuUuid && cartNum > 0) {
1187
1187
  return this.bMallChangeCartService({
1188
1188
  ...goodItem,
1189
1189
  skuUuid,
1190
1190
  num: cartNum,
1191
1191
  })
1192
1192
  } else if (!skuUuid && cartNum > 0) {
1193
1193
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
1194
1194
  } else if (skuUuid && !cartNum) {
1195
1195
  return this.bMallRemoveCartService({
1196
1196
  ...goodItem,
1197
1197
  skuUuid,
1198
1198
  num: cartNum,
1199
1199
  })
1200
1200
  } else {
1201
1201
  console.error('参数不全')
1202
1202
  return false
1203
1203
  }
1204
1204
  } catch (e) {
1205
1205
  console.error(e)
1206
1206
  }
1207
1207
  }