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

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