@conecli/cone-render 0.9.1-shop2.37 → 0.9.1-shop2.38

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