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