@conecli/cone-render 0.9.1-shop2.30 → 0.9.1-shop2.32

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
  area && area !== "" && this.updateApiClientParamsResInfo({
709
709
  area,
710
710
  })
711
711
  console.log("cone-render收到原生端获取传来的四级地址信息",area,"更新后的接口底层信息", this.resInfo.apiClientParams)
712
712
  })
713
713
  }
714
714
  updateApiClientParamsResInfo(opt = {}) {
715
715
  const { area, ...others} = opt
716
716
  this.resInfo.apiClientParams = {
717
717
  ...this.resInfo.apiClientParams,
718
718
  ...others
719
719
  }
720
720
  if(area){
721
721
  this.resInfo.apiClientParams.area = area
722
722
  }
723
723
  }
724
724
 
725
725
  checkFunctionIdToReturnAppId(functionId) {
726
726
  if (JshopxColorFunctionIdList.includes(functionId)) {
727
727
  return APPID.JSHOPX_COLOR_APPID
728
728
  } else if (
729
729
  this.isPageDomain &&
730
730
  PagesColorFunctionIdList.includes(functionId)
731
731
  ) {
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(
745
745
  functionId: string,
746
746
  bodyParams = {},
747
747
  clientParams = {},
748
748
  ): Promise<any> {
749
749
  if (
750
750
  functionId === 'receiveShopCoupon' &&
751
751
  ((isH5 &&
752
752
  (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
753
753
  isWxMinAndWxapp)
754
754
  ) {
755
755
  clientParams = Object.assign(
756
756
  {},
757
757
  {
758
758
  loginType: '1',
759
759
  loginWQBiz: WXAPP_BIZ_KEY,
760
760
  },
761
761
  clientParams,
762
762
  )
763
763
  }
764
764
  const apiClientParams = Object.assign(
765
765
  {},
766
766
  this.resInfo.apiClientParams,
767
767
  clientParams,
768
768
  )
769
769
  typeof apiClientParams.appid === 'undefined' &&
770
770
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId))
771
771
  const isColorVerify = this.verifyColorList.includes(functionId)
772
772
  const getReqData = {
773
773
  functionId: functionId,
774
774
  body: JSON.stringify(bodyParams),
775
775
  t: Date.now(),
776
776
  ...apiClientParams,
777
777
  }
778
778
  return http
779
779
  .request({
780
780
  url: this.api.apiFunc,
781
781
  data: getReqData,
782
782
  isColorVerify,
783
783
  })
784
784
  .then((res: ServiceInterFace.RequestPromiseRes) => {
785
785
  const { statusCode, data, status, msg } = res
786
786
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
787
787
  ok: true,
788
788
  }
789
789
  if ((statusCode === 200 || status === '0') && data) {
790
790
  changeRes = this.dealResponseFormatRes(data)
791
791
  return changeRes
792
792
  } else {
793
793
  changeRes = {
794
794
  ...data,
795
795
  statusCode,
796
796
  status,
797
797
  msg,
798
798
  ok: false,
799
799
  }
800
800
  return changeRes
801
801
  }
802
802
  })
803
803
  .catch((res) => {
804
804
  const propertyNames = Object.getOwnPropertyNames(res);
805
805
  const resObject = {};
806
806
  propertyNames.forEach((propertyName) => {
807
807
  resObject[propertyName] = res[propertyName];
808
808
  });
809
809
  draInterfaceCustomReport({
810
810
  subMsg:
811
811
  '接口请求异常,进入catch逻辑,例如h5请求神盾(反爬、小号、风控)或加固拦截返回status为403等',
812
812
  url: this.api.apiFunc,
813
813
  source: 'remote',
814
814
  requestType: res?.requestType,
815
815
  errorType: 'catchError',
816
816
  functionId: getReqData?.functionId,
817
817
  appid: getReqData?.appid,
818
818
  client: getReqData?.client,
819
819
  clientVersion: getReqData?.clientVersion,
820
820
  statusCode: res?.statusCode,
821
821
  status: res?.status,
822
822
  statusText: res?.statusText,
823
823
  code: res?.data?.code || res?.data?.subCode,
824
824
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
825
825
  originReqDataStr: JSON.stringify(getReqData),
826
826
  originResDataStr: JSON.stringify(res, propertyNames),
827
827
  });
828
828
  return {
829
829
  ...resObject,
830
830
  ok: false,
831
831
  } as ServiceInterFace.RequestResponseFormatRes;
832
832
  })
833
833
  }
834
834
 
835
835
  dealResponseFormatRes(data) {
836
836
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
837
837
  ok: true,
838
838
  }
839
839
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
840
840
  ? Number(data.code)
841
841
  : -1
842
842
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
843
843
  ? Number(data.subCode)
844
844
  : -1
845
845
  if (
846
846
  data.success === true ||
847
847
  data.isSuccess ||
848
848
  resCode === 0 ||
849
849
  resCode === 200 ||
850
850
  subCode === 0
851
851
  ) {
852
852
  changeRes = {
853
853
  result: Object.prototype.hasOwnProperty.call(data, 'result')
854
854
  ? data.result
855
855
  : Object.prototype.hasOwnProperty.call(data, 'data')
856
856
  ? data.data
857
857
  : data,
858
858
  code: data.code ?? 200,
859
859
  ok: true,
860
860
  source: data,
861
861
  }
862
862
  return changeRes
863
863
  } else {
864
864
  changeRes = {
865
865
  ...data,
866
866
  ok: false,
867
867
  }
868
868
  return changeRes
869
869
  }
870
870
  }
871
871
 
872
872
  async receiveCoupon(param = {}, clientParams) {
873
873
  const loginType = isPc ? { loginType: 3 } : {}
874
874
  return await this.gatewayReq(
875
875
  'receiveShopCoupon',
876
876
  {
877
877
  operation: '3',
878
878
  ...param,
879
879
  },
880
880
  { ...loginType, ...clientParams },
881
881
  )
882
882
  }
883
883
 
884
884
  getCustomerCenterDispatch(params = {}) {
885
885
  return this.gatewayReq('customerCenterDispatch', params, {
886
886
  clientVersion: '9.2.0',
887
887
  client: 'H5',
888
888
  uuid: 88888,
889
889
  appid: 'shopmember_m_jd_com',
890
890
  })
891
891
  }
892
892
 
893
893
  batchAddCart(skuIdsStr, num = 1, showToast = true) {
894
894
  if (skuIdsStr) {
895
895
  return this._addShopGoodCart(`${skuIdsStr}`, `${num}`)
896
896
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
897
897
  if (res?.ok) {
898
898
  if (showToast && !res?.isOpenApp)
899
899
  showSuccessToast({
900
900
  title: '加入购物车成功',
901
901
  })
902
902
  } else {
903
903
  showToast &&
904
904
  showFailToast({
905
905
  title: res?.errMsg || '加入购物车失败,请稍后重试!',
906
906
  })
907
907
  }
908
908
  return Promise.resolve(res)
909
909
  })
910
910
  .catch((e) => {
911
911
  console.log('调用加购方法异常=======>', e)
912
912
  return Promise.resolve({
913
913
  ok: false,
914
914
  msg: '加入购物车失败,请稍后重试!',
915
915
  })
916
916
  })
917
917
  } else {
918
918
  return Promise.resolve({
919
919
  ok: false,
920
920
  msg: '加入购物车失败,请稍后重试!',
921
921
  })
922
922
  }
923
923
  }
924
924
 
925
925
  _addShopGoodCart(skuIdsStr, addCardNum = '1') {
926
926
  return new Promise((resolve) => {
927
927
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
928
928
  if (productIdsArr.length > 0) {
929
929
  if (isJdApp) {
930
930
  console.log('==========>', '原生批量加车!')
931
931
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now()}`
932
932
  if (!window[nativeAddCartCallBack]) {
933
933
  window[nativeAddCartCallBack] = (res) => {
934
934
  const getMessageJsonData =
935
935
  typeof res === 'string' ? JSON.parse(res) : res
936
936
  console.info(
937
937
  '获取批量加车原始数据',
938
938
  res,
939
939
  '====转换后的json数据为===',
940
940
  getMessageJsonData,
941
941
  )
942
942
  try {
943
943
  if (isAndroidDevice) {
944
944
  getMessageJsonData?.status === '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 if (isIosDevice) {
954
954
  getMessageJsonData?.status === '0' &&
955
955
  getMessageJsonData?.data?.code === 0
956
956
  ? resolve({
957
957
  ok: true,
958
958
  msg: '已加入购物车!',
959
959
  })
960
960
  : resolve({
961
961
  ok: false,
962
962
  msg: '批量加车失败,请稍后重试',
963
963
  })
964
964
  } else {
965
965
  resolve({
966
966
  ok: false,
967
967
  msg: '加购失败,请稍后重试',
968
968
  })
969
969
  }
970
970
  } catch (e) {
971
971
  resolve({
972
972
  ok: false,
973
973
  msg: '加购失败,请稍后重试',
974
974
  })
975
975
  console.warn('批量加车转换数据异常', e)
976
976
  }
977
977
  window[nativeAddCartCallBack] = null
978
978
  }
979
979
  }
980
980
  const productsAddCartList = productIdsArr.map((skuItem) => {
981
981
  return isAndroidDevice
982
982
  ? {
983
983
  sku: skuItem,
984
984
  num: addCardNum,
985
985
  }
986
986
  : {
987
987
  productCode: skuItem,
988
988
  buyCount: addCardNum,
989
989
  }
990
990
  })
991
991
  if (isAndroidDevice) {
992
992
  const androidProductsStr = JSON.stringify(productsAddCartList)
993
993
  callRouterAndroid({
994
994
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
995
995
  routerParam: {
996
996
  wareList: productsAddCartList,
997
997
  },
998
998
  callBackName: nativeAddCartCallBack,
999
999
  })
1000
1000
  } else if (isIosDevice) {
1001
1001
  if (isLowAppVer) {
1002
1002
  const lowVersionAppList = productIdsArr.map((skuItem) => {
1003
1003
  return {
1004
1004
  sku: skuItem,
1005
1005
  num: addCardNum,
1006
1006
  }
1007
1007
  })
1008
1008
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList)
1009
1009
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`
1010
1010
  jump.side.jdJumpToWeb(url, {})
1011
1011
  resolve({
1012
1012
  ok: true,
1013
1013
  isOpenApp: true,
1014
1014
  msg: '加购完成, 加购结果请点击购物车确认',
1015
1015
  })
1016
1016
  } else {
1017
1017
  callRouterIOS({
1018
1018
  routerURL: 'router://JDCartModule/batchAddService',
1019
1019
  routerParam: {
1020
1020
  sourceType: 'h5',
1021
1021
  sourceValue: '店铺批量加购',
1022
1022
  businessName: 'storeModel',
1023
1023
  isNewMode: '1',
1024
1024
  NotPassWebview: '1',
1025
1025
  products: productsAddCartList,
1026
1026
  },
1027
1027
  callBackName: nativeAddCartCallBack,
1028
1028
  })
1029
1029
  }
1030
1030
  }
1031
1031
  } else if (isMin) {
1032
1032
  console.log('==========>', '京购批量加车!')
1033
1033
  const productsAddCartList = productIdsArr.map((skuItem) => {
1034
1034
  return {
1035
1035
  skuId: skuItem,
1036
1036
  buyNum: addCardNum,
1037
1037
  }
1038
1038
  })
1039
1039
  global.wxAppBizInstance
1040
1040
  .addCart({ commArr: productsAddCartList })
1041
1041
  .then((res) => {
1042
1042
  console.log('dealCartSuccess: ', res)
1043
1043
  resolve({
1044
1044
  ok: true,
1045
1045
  msg: '已加入购物车!',
1046
1046
  data: res,
1047
1047
  })
1048
1048
  })
1049
1049
  .catch((e) => {
1050
1050
  console.log('京购小程序批量加车失败dealCartFail: ', e)
1051
1051
  resolve({
1052
1052
  ok: false,
1053
1053
  msg: '加购失败,请稍后重试',
1054
1054
  })
1055
1055
  })
1056
1056
  } else {
1057
1057
  console.log('==========>', 'M站批量加车!')
1058
1058
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
1059
1059
  resolve(res),
1060
1060
  )
1061
1061
  }
1062
1062
  } else {
1063
1063
  resolve({
1064
1064
  ok: false,
1065
1065
  msg: '加购sku不能为空',
1066
1066
  })
1067
1067
  }
1068
1068
  })
1069
1069
  }
1070
1070
 
1071
1071
  productAddToCart(skuIdsStr, num) {
1072
1072
  return new Promise((resolve) => {
1073
1073
  if (window.AddcartToolObj) {
1074
1074
  window.AddcartToolObj.addCart({
1075
1075
  skuId: skuIdsStr,
1076
1076
  num,
1077
1077
  source: 'sjdpyw',
1078
1078
  actId: '1',
1079
1079
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
1080
1080
  sucFun(res) {
1081
1081
  console.log(
1082
1082
  'ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0',
1083
1083
  res,
1084
1084
  )
1085
1085
  if (res.errId === '0' && res.cartJson) {
1086
1086
  resolve({
1087
1087
  ok: true,
1088
1088
  msg: '已加入购物车!',
1089
1089
  ...res,
1090
1090
  })
1091
1091
  } else {
1092
1092
  if (res.errId === '13') {
1093
1093
  global.doLogin()
1094
1094
  } else {
1095
1095
  resolve({
1096
1096
  ok: false,
1097
1097
  msg: '加购失败,请稍后重试',
1098
1098
  ...res,
1099
1099
  })
1100
1100
  }
1101
1101
  }
1102
1102
  },
1103
1103
  failFun(err) {
1104
1104
  console.log('fail', err)
1105
1105
  resolve({
1106
1106
  ok: false,
1107
1107
  msg: '加购失败,请稍后重试',
1108
1108
  ...err,
1109
1109
  })
1110
1110
  },
1111
1111
  })
1112
1112
  } else {
1113
1113
  resolve({
1114
1114
  ok: false,
1115
1115
  msg: '购物车方法检查异常',
1116
1116
  })
1117
1117
  }
1118
1118
  })
1119
1119
  }
1120
1120
  bMallGetUserInfo = () => {
1121
1121
  return getBMallUserInfo()
1122
1122
  }
1123
1123
  async bMallAddCart(params = {}) {
1124
1124
  return await this.gatewayReq('bmall_cartAdd', params, {
1125
1125
  client: 'H5',
1126
1126
  clientVersion: '5.5.0',
1127
1127
  })
1128
1128
  }
1129
1129
  async bMallChangeCart(params = {}) {
1130
1130
  return await this.gatewayReq('bmall_cartChange', params, {
1131
1131
  client: 'H5',
1132
1132
  clientVersion: '5.5.0',
1133
1133
  })
1134
1134
  }
1135
1135
  async bMallRemoveCart(params = {}) {
1136
1136
  return await this.gatewayReq(
1137
1137
  'bmall_cartRemove',
1138
1138
  params,
1139
1139
  {
1140
1140
  client: 'H5',
1141
1141
  clientVersion: '5.5.0',
1142
1142
  },
1143
1143
  )
1144
1144
  }
1145
1145
  async bMallGetOmittedProduct(params = {}) {
1146
1146
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1147
1147
  client: 'H5',
1148
1148
  clientVersion: '5.5.0',
1149
1149
  })
1150
1150
  }
1151
1151
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1152
1152
  const params = await getParams({ ...data, skuId, bMallTag, num })
1153
1153
  return await this.bMallAddCart(params)
1154
1154
  }
1155
1155
  async bMallGetSkuNumService(bMallTag = 1) {
1156
1156
  const params = await getParams({ bMallTag })
1157
1157
  delete params.operations
1158
1158
  return await this.bMallGetOmittedProduct(params)
1159
1159
  }
1160
1160
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1161
1161
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
1162
1162
  return await this.bMallRemoveCart(params)
1163
1163
  }
1164
1164
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1165
1165
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
1166
1166
  return await this.bMallChangeCart(params)
1167
1167
  }
1168
1168
 
1169
1169
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1170
1170
  if (!needRequest && isH5 && window?.bMallCartData) {
1171
1171
  return window?.bMallCartData
1172
1172
  }
1173
1173
  const cartData = await this.bMallGetSkuNumService(bMallTag)
1174
1174
  let items
1175
1175
  if (cartData.ok && cartData.result) {
1176
1176
  items = cartData?.result?.items || {}
1177
1177
  }
1178
1178
  if (isH5) {
1179
1179
  window.bMallCartData = items
1180
1180
  }
1181
1181
  return items
1182
1182
  }
1183
1183
 
1184
1184
  async bMallCartHandle(goodItem, num) {
1185
1185
  try {
1186
1186
  const {
1187
1187
  skuUuid,
1188
1188
  limitUpper,
1189
1189
  limitLower,
1190
1190
  } = goodItem
1191
1191
  let cartNum = Number(num)
1192
1192
  if (limitLower && cartNum && cartNum < limitLower) {
1193
1193
  cartNum = limitLower
1194
1194
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1195
1195
  cartNum = limitUpper
1196
1196
  }
1197
1197
  if (skuUuid && cartNum > 0) {
1198
1198
  return this.bMallChangeCartService({
1199
1199
  ...goodItem,
1200
1200
  skuUuid,
1201
1201
  num: cartNum,
1202
1202
  })
1203
1203
  } else if (!skuUuid && cartNum > 0) {
1204
1204
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
1205
1205
  } else if (skuUuid && !cartNum) {
1206
1206
  return this.bMallRemoveCartService({
1207
1207
  ...goodItem,
1208
1208
  skuUuid,
1209
1209
  num: cartNum,
1210
1210
  })
1211
1211
  } else {
1212
1212
  console.error('参数不全')
1213
1213
  return false
1214
1214
  }
1215
1215
  } catch (e) {
1216
1216
  console.error(e)
1217
1217
  }
1218
1218
  }