@conecli/cone-render 0.10.1-shop-beta.11 → 0.10.1-shop-beta.13

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.
Files changed (78) hide show
  1. package/README.md +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/index.dynamic.ts +1 -0
  4. package/dist/common/index.h5.ts +1 -1
  5. package/dist/common/index.jd.ts +1 -1
  6. package/dist/common/index.ts +1 -1
  7. package/dist/common/index.weapp.ts +1 -1
  8. package/dist/common/jssdk.ts +1 -1
  9. package/dist/common/token/index.h5.ts +1 -1
  10. package/dist/common/wxappApi.ts +1 -1
  11. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  12. package/dist/components/base/CountDown/index.tsx +1 -1
  13. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  14. package/dist/components/base/Dialog/index.dynamic.module.scss +126 -0
  15. package/dist/components/base/Dialog/index.dynamic.tsx +1 -0
  16. package/dist/components/base/DynamicTest/index.dynamic.module.scss +15 -0
  17. package/dist/components/base/DynamicTest/index.module.scss +16 -0
  18. package/dist/components/base/DynamicTest/index.tsx +1 -0
  19. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  20. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  21. package/dist/components/base/JdLoading/index.module.scss +2 -0
  22. package/dist/components/base/JdLoading/index.tsx +1 -1
  23. package/dist/components/base/LazyLoadImage/index.tsx +1 -1
  24. package/dist/components/base/NetworkDataError/const.ts +1 -1
  25. package/dist/components/base/NetworkDataError/index.module.scss +116 -70
  26. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  27. package/dist/components/base/Price/Base/index.dynamic.module.scss +63 -0
  28. package/dist/components/base/Price/Base/index.dynamic.tsx +1 -0
  29. package/dist/components/base/Price/Base/index.module.scss +6 -0
  30. package/dist/components/base/Price/Base/index.tsx +1 -1
  31. package/dist/components/base/Price/Double/index.dynamic.module.scss +172 -0
  32. package/dist/components/base/Price/Double/index.dynamic.tsx +1 -0
  33. package/dist/components/base/Price/Double/index.module.scss +6 -0
  34. package/dist/components/base/Price/Double/index.tsx +1 -1
  35. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  36. package/dist/config/env.ts +1 -1
  37. package/dist/interface/common.ts +1 -1
  38. package/dist/interface/component.ts +1 -1
  39. package/dist/interface/jumpEventReport.ts +1 -1
  40. package/dist/jumpEventReport/const.ts +1 -1
  41. package/dist/jumpEventReport/index.dynamic.ts +1 -0
  42. package/dist/jumpEventReport/index.h5.ts +1 -1
  43. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  44. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  45. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  46. package/dist/jumpEventReport/web.base.ts +1 -1
  47. package/dist/jumpEventReport/web.jd.ts +1 -1
  48. package/dist/language/zh_CN.json +162 -0
  49. package/dist/open/api/index.ts +1 -1
  50. package/dist/open/api/shopMember.dynamic.ts +1 -0
  51. package/dist/open/api/shopMember.ts +1 -1
  52. package/dist/open/components/index.dynamic.ts +1 -0
  53. package/dist/open/components/index.ts +1 -1
  54. package/dist/sass/app.dynamic.scss +306 -0
  55. package/dist/service/fetchGateway.h5.ts +1 -0
  56. package/dist/service/fetchGateway.ts +1 -1
  57. package/dist/service/fetchGateway.weapp.ts +1 -1
  58. package/dist/service/fetchJsonp.h5.ts +1 -0
  59. package/dist/service/fetchJsonp.ts +1 -1
  60. package/dist/service/http/colorSign.dynamic.ts +1 -0
  61. package/dist/service/http/http.ts +1 -1
  62. package/dist/service/requestServer.h5.ts +1 -1
  63. package/dist/service/requestServer.ts +1 -1
  64. package/dist/service/requestServer.weapp.ts +1 -1
  65. package/dist/utils/connectNativeJsBridge.dynamic.ts +1 -0
  66. package/dist/utils/connectNativeJsBridge.ts +1 -1
  67. package/dist/utils/h5Utils.ts +1 -1
  68. package/dist/utils/index.h5.ts +1 -1
  69. package/dist/utils/index.ts +1 -1
  70. package/dist/utils/index.weapp.ts +1 -1
  71. package/dist/utils/intersectionObserver.ts +1 -1
  72. package/dist/utils/jumpExtMapUtil.ts +1 -0
  73. package/dist/utils/log.ts +1 -0
  74. package/dist/utils/utils.ts +1 -1
  75. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  76. package/dist/wxapp/common/user_info.js +1 -1
  77. package/package.json +51 -31
  78. /package/dist/utils/{jumpExtMapUtil.js → jumpExtMapUtil.h5.ts} +0 -0
@@ -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
  isLanguageForEn,
13
12
  isJdApp,
14
13
  isIosDevice,
15
14
  isAndroidDevice,
16
15
  showSuccessToast,
17
16
  showFailToast,
18
17
  isH5,
19
18
  isWxMinAndWxapp,
20
19
  isMin,
21
20
  isPc,
22
21
  cookiesStr: '',
23
22
  requestHeaderContentType: {
24
23
  jsonHeader: {
25
24
  'content-type': 'application/json;charset=utf-8',
26
25
  },
27
26
  formDataHeader: {
28
27
  'content-type': 'application/x-www-form-urlencoded',
29
28
  },
30
29
  },
31
30
  requestBaseParam: {
32
31
  data: null,
33
32
  header: {
34
33
  'content-type': 'application/json;charset=utf-8',
35
34
  },
36
35
  },
37
36
  timeOut: 7000,
38
37
  apiClientParams: {
39
38
  appid: 'wx_mini_app',
40
39
  clientVersion: '11.0.0',
41
40
  client: 'wh5',
42
41
  area: '1_72_2799_0',
43
42
  screen: `${Math.ceil(
44
43
  getSystemInfo?.screenWidth * devicePixelRatio,
45
44
  )}*${Math.ceil(getSystemInfo?.screenHeight * devicePixelRatio)}`,
46
45
  uuid: UUID,
47
46
  loginType: '11',
48
47
  },
49
48
  public addressFetchInfo: {
50
49
  reqState: boolean
51
50
  promiseInstance: null | Promise<any>
52
51
  }
53
52
  public getPromotionConfig: {
54
53
  projectId: null | string | number
55
54
  pageId: null | string | number
56
55
  }
57
56
  public resInfo: ServiceInterFace.HttpRequestInfo
58
57
  public api: ServiceInterFace.HttpApi
59
58
  public isPageDomain: boolean
60
59
  public verifyColorList: string[]
61
60
  constructor(opt) {
62
61
  this._init()
63
62
  this.addressFetchInfo = {
64
63
  reqState: false,
65
64
  promiseInstance: null,
66
65
  }
67
66
  this.getPromotionConfig = {
68
67
  projectId: null,
69
68
  pageId: null,
70
69
  }
71
70
  this._userAreaUpdateListen()
72
71
  this.resInfo = this._getResConfig(opt)
73
72
  this.api = api
74
73
  this.isPageDomain = isH5
75
74
  ? window?.location?.hostname === PAGES_DOMAIN
76
75
  : false
77
76
  this.verifyColorList = [
78
77
  ...MobileVerifyColorList,
79
78
  ...AppVerifyColorList,
80
79
  ...JshopxVerifyColorList,
81
80
  ...BMallVerifyColorList,
82
81
  ]
83
82
  }
84
83
  _init(): void {
85
84
  httpInterceptors.forEach((item) => {
86
85
  Taro.addInterceptor((chain) => item(chain))
87
86
  })
88
87
  }
89
88
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
90
89
  return Object.assign({}, DefaultConfig, opt)
91
90
  }
92
91
 
93
92
  _userAreaUpdateListen() {
94
93
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
95
94
  this.updateApiClientParamsResInfo({
96
95
  area,
97
96
  })
98
97
  })
99
98
  }
100
99
  updateApiClientParamsResInfo(opt = {}) {
101
100
  this.resInfo.apiClientParams = {
102
101
  ...this.resInfo.apiClientParams,
103
102
  ...opt,
104
103
  }
105
104
  }
106
105
 
107
106
  checkFunctionIdToReturnAppId(functionId) {
108
107
  if (JshopxColorFunctionIdList.includes(functionId)) {
109
108
  return APPID.JSHOPX_COLOR_APPID
110
109
  } else if (
111
110
  this.isPageDomain &&
112
111
  PagesColorFunctionIdList.includes(functionId)
113
112
  ) {
114
113
  return APPID.PAGES_COLOR_APPID
115
114
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
116
115
  return APPID.SHOP_MEMBER_COLOR_APPID
117
116
  } else if (B2BColorFunctionIdList.includes(functionId)) {
118
117
  return APPID.B2B_COLOR_APPID
119
118
  } else if (isPc) {
120
119
  return APPID.MALL_COLOR_APPID
121
120
  } else {
122
121
  return APPID.SHOP_COLOR_APPID
123
122
  }
124
123
  }
125
124
 
126
125
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
127
126
  if (functionId === 'receiveShopCoupon') {
128
127
  clientParams = Object.assign(
129
128
  {},
130
129
  {
131
130
  loginType: '1',
132
131
  loginWQBiz: WXAPP_BIZ_KEY,
133
132
  },
134
133
  clientParams,
135
134
  )
136
135
  }
137
136
  const apiClientParams = Object.assign(
138
137
  {},
139
138
  this.resInfo.apiClientParams,
140
139
  clientParams,
141
140
  )
142
141
  const isColorVerify = this.verifyColorList.includes(functionId);
143
142
  const getReqData = {
144
143
  functionId: functionId,
145
144
  body: JSON.stringify(bodyParams),
146
145
  t: Date.now(),
147
146
  ...apiClientParams,
148
147
  }
149
148
  const requestParams = {
150
149
  functionId: getReqData?.functionId,
151
150
  body: getReqData?.body,
152
151
  appid: getReqData?.appid,
153
152
  client: getReqData?.client,
154
153
  clientVersion: getReqData?.clientVersion,
155
154
  area: getReqData?.area,
156
155
  requestTimeStamp: getReqData?.t,
157
156
  }
158
157
  return http
159
158
  .request({
160
159
  url: this.api.apiFunc,
161
160
  data: getReqData,
162
161
  isColorVerify,
163
162
  })
164
163
  .then((res: ServiceInterFace.RequestPromiseRes) => {
165
164
  const { statusCode, data, status, msg } = res
166
165
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
167
166
  ok: true,
168
167
  }
169
168
  if ((statusCode === 200 || status === '0') && data) {
170
169
  changeRes = this.dealResponseFormatRes(data, getReqData)
171
170
  return changeRes
172
171
  } else {
173
172
  sgmCustomReport({
174
173
  code: getSgmCustomCode('interface_data_error'),
175
174
  msg: {
176
175
  subMsg: '接口请求异常',
177
176
  functionId,
178
177
  statusCode,
179
178
  source: 'remote',
180
179
  status,
181
180
  msg,
182
181
  requestParams,
183
182
  },
184
183
  })
185
184
  draInterfaceCustomReport({
186
185
  ...getReqData,
187
186
  ...res,
188
187
  source: 'remote',
189
188
  })
190
189
  changeRes = {
191
190
  ...data,
192
191
  statusCode,
193
192
  status,
194
193
  msg,
195
194
  ok: false,
196
195
  }
197
196
  return changeRes
198
197
  }
199
198
  })
200
199
  .catch((res) => {
201
200
  const propertyNames = Object.getOwnPropertyNames(res)
202
201
  const resObject = {}
203
202
  propertyNames.forEach((propertyName) => {
204
203
  resObject[propertyName] = res[propertyName]
205
204
  })
206
205
  sgmCustomReport({
207
206
  code: getSgmCustomCode('interface_data_error'),
208
207
  msg: {
209
208
  subMsg: '接口请求错误',
210
209
  functionId,
211
210
  source: 'remote',
212
211
  requestParams,
213
212
  catchError: resObject,
214
213
  },
215
214
  })
216
215
  draInterfaceCustomReport({
217
216
  ...getReqData,
218
217
  ...resObject,
219
218
  source: 'remote',
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, reqData) {
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
  if (reqData && resCode !== 3) {
262
261
  const getReportMsgData = reqData['hybridId']
263
262
  ? {
264
263
  subMsg: '预加载接口请求数据异常',
265
264
  hybridId: reqData?.hybridId,
266
265
  requestId: reqData?.requestId,
267
266
  param: reqData?.param,
268
267
  source: 'remote',
269
268
  }
270
269
  : {
271
270
  subMsg: '接口请求返回数据异常',
272
271
  functionId: reqData?.functionId,
273
272
  code: resCode,
274
273
  source: 'remote',
275
274
  requestParams: {
276
275
  functionId: reqData?.functionId,
277
276
  body: reqData?.body,
278
277
  appid: reqData?.appid,
279
278
  client: reqData?.client,
280
279
  clientVersion: reqData?.clientVersion,
281
280
  area: reqData?.area,
282
281
  requestTimeStamp: reqData?.t,
283
282
  },
284
283
  resData: data,
285
284
  }
286
285
  sgmCustomReport({
287
286
  code: getSgmCustomCode('interface_data_error'),
288
287
  msg: getReportMsgData,
289
288
  })
290
289
  draInterfaceCustomReport({
291
290
  ...reqData,
292
291
  ...data,
293
292
  source: 'remote',
294
293
  })
295
294
  }
296
295
  return changeRes
297
296
  }
298
297
  }
299
298
 
300
299
  async receiveCoupon(param = {}, clientParams) {
301
300
  console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
302
301
  return await this.gatewayReq(
303
302
  'receiveShopCoupon',
304
303
  {
305
304
  operation: '3',
306
305
  ...param,
307
306
  },
308
307
  { ...clientParams },
309
308
  );
310
309
  }
311
310
 
312
311
  getCustomerCenterDispatch(params = {}) {
313
312
  return this.gatewayReq('customerCenterDispatch', params, {
314
313
  clientVersion: '9.2.0',
315
314
  client: 'H5',
316
315
  uuid: 88888,
317
316
  appid: 'shopmember_m_jd_com',
318
317
  })
319
318
  }
320
319
 
321
320
  batchAddCart(...args) {
322
321
  let skuIds, num, showToast, giftCard;
323
322
  if (['number', 'string'].includes(typeof args[0])) {
324
323
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
325
324
  } else if (typeof args[0] === 'object' && args[0] !== null) {
326
325
  const params = args[0];
327
326
  skuIds = params.skuIds;
328
327
  num = params.num || 1;
329
328
  showToast = params.showToast !== undefined ? params.showToast : true;
330
329
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
331
330
  } else {
332
331
  console.error('batchAddCart() Invalid arguments!', args);
333
332
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
334
333
  showFailToast({
335
334
  title: msg,
336
335
  });
337
336
  return Promise.resolve({
338
337
  ok: false,
339
338
  msg,
340
339
  });
341
340
  }
342
341
  const addToWhereText = giftCard ? '购物清单' : '购物车';
343
342
  const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
344
343
  const failMsg = isLanguageForEn
345
344
  ? 'Please retry later'
346
345
  : `加入${addToWhereText}失败,请稍后重试!`;
347
346
  if (skuIds) {
348
347
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
349
348
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
350
349
  if (res?.ok) {
351
350
  if (showToast && !res?.isOpenApp)
352
351
  showSuccessToast({
353
352
  title: successMsg,
354
353
  })
355
354
  } else {
356
355
  showToast &&
357
356
  showFailToast({
358
357
  title: res?.errMsg || failMsg,
359
358
  })
360
359
  }
361
360
  return Promise.resolve(res)
362
361
  })
363
362
  .catch((e) => {
364
363
  console.log('调用加购方法异常=======>', e)
365
364
  return Promise.resolve({
366
365
  ok: false,
367
366
  msg: failMsg,
368
367
  })
369
368
  })
370
369
  } else {
371
370
  return Promise.resolve({
372
371
  ok: false,
373
372
  msg: failMsg,
374
373
  })
375
374
  }
376
375
  }
377
376
 
378
377
  async giftCardAddCart(skuList, num) {
379
378
  return this.gatewayReq('giftCardAddCart', {
380
379
  skuList,
381
380
  num: Number(num),
382
381
  });
383
382
  }
384
383
 
385
384
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
386
385
  return new Promise((resolve) => {
387
386
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
388
387
  if (productIdsArr.length > 0) {
389
388
  if (giftCard) {
390
389
  this.giftCardAddCart(productIdsArr, addCardNum)
391
390
  .then((res) => {
392
391
  if (res?.code === '0' && res?.result?.value) {
393
392
  resolve({
394
393
  ok: true,
395
394
  })
396
395
  } else {
397
396
  resolve({
398
397
  ok: false,
399
398
  msg: '加购失败,请稍后重试',
400
399
  })
401
400
  }
402
401
  })
403
402
  .catch((e) => {
404
403
  console.error('礼品卡加车失败: ', e)
405
404
  resolve({
406
405
  ok: false,
407
406
  msg: '加购失败,请稍后重试',
408
407
  });
409
408
  });
410
409
  } else if (isJdApp) {
411
410
  console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
412
411
  } else if (isMin) {
413
412
  console.log('==========>', '京购批量加车!')
414
413
  const productsAddCartList = productIdsArr.map((skuItem) => {
415
414
  return {
416
415
  skuId: skuItem,
417
416
  buyNum: addCardNum,
418
417
  }
419
418
  })
420
419
  global.wxAppBizInstance
421
420
  .addCart({ commArr: productsAddCartList })
422
421
  .then((res) => {
423
422
  console.log('dealCartSuccess: ', res)
424
423
  resolve({
425
424
  ok: true,
426
425
  msg: '已加入购物车!',
427
426
  data: res,
428
427
  })
429
428
  })
430
429
  .catch((e) => {
431
430
  console.log('京购小程序批量加车失败dealCartFail: ', e)
432
431
  resolve({
433
432
  ok: false,
434
433
  msg: '加购失败,请稍后重试',
435
434
  })
436
435
  })
437
436
  } else {
438
437
  console.log('==========>', 'M站批量加车!')
439
438
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
440
439
  resolve(res),
441
440
  )
442
441
  }
443
442
  } else {
444
443
  resolve({
445
444
  ok: false,
446
445
  msg: '加购sku不能为空',
447
446
  })
448
447
  }
449
448
  })
450
449
  }
451
450
 
452
451
  productAddToCart() {
453
452
  return Promise.resolve({
454
453
  ok: false,
455
454
  msg: 'productAddToCart暂不支持小程序',
456
455
  });
457
456
  }
458
457
  bMallGetUserInfo = () => {
459
458
  return getBMallUserInfo()
460
459
  }
461
460
  async bMallAddCart(params = {}) {
462
461
  console.warn('bMallAddCart 方法在微信京购小程序环境未经验证,请不要使用!');
463
462
  return await this.gatewayReq('bmall_cartAdd', params, {
464
463
  client: 'H5',
465
464
  clientVersion: '5.5.0',
466
465
  })
467
466
  }
468
467
  async bMallChangeCart(params = {}) {
469
468
  console.warn('bMallChangeCart 方法在微信京购小程序环境未经验证,请不要使用!');
470
469
  return await this.gatewayReq('bmall_cartChange', params, {
471
470
  client: 'H5',
472
471
  clientVersion: '5.5.0',
473
472
  })
474
473
  }
475
474
  async bMallRemoveCart(params = {}) {
476
475
  console.warn('bMallRemoveCart 方法在微信京购小程序环境未经验证,请不要使用!');
477
476
  return await this.gatewayReq(
478
477
  'bmall_cartRemove',
479
478
  params,
480
479
  {
481
480
  client: 'H5',
482
481
  clientVersion: '5.5.0',
483
482
  },
484
483
  )
485
484
  }
486
485
  async bMallGetOmittedProduct(params = {}) {
487
486
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
488
487
  client: 'H5',
489
488
  clientVersion: '5.5.0',
490
489
  })
491
490
  }
492
491
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
493
492
  const params = await getParams({ ...data, skuId, bMallTag, num })
494
493
  return await this.bMallAddCart(params)
495
494
  }
496
495
  async bMallGetSkuNumService(bMallTag = 1) {
497
496
  const params = await getParams({ bMallTag })
498
497
  delete params.operations
499
498
  return await this.bMallGetOmittedProduct(params)
500
499
  }
501
500
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
502
501
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
503
502
  return await this.bMallRemoveCart(params)
504
503
  }
505
504
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
506
505
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
507
506
  return await this.bMallChangeCart(params)
508
507
  }
509
508
 
510
509
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
511
510
  if (!needRequest && isH5 && window?.bMallCartData) {
512
511
  return window?.bMallCartData
513
512
  }
514
513
  const cartData = await this.bMallGetSkuNumService(bMallTag)
515
514
  let items
516
515
  if (cartData.ok && cartData.result) {
517
516
  items = cartData?.result?.items || {}
518
517
  }
519
518
  if (isH5) {
520
519
  window.bMallCartData = items
521
520
  }
522
521
  return items
523
522
  }
524
523
 
525
524
  async bMallCartHandle(goodItem, num) {
526
525
  try {
527
526
  const {
528
527
  skuUuid,
529
528
  limitUpper,
530
529
  limitLower,
531
530
  } = goodItem
532
531
  let cartNum = Number(num)
533
532
  if (limitLower && cartNum && cartNum < limitLower) {
534
533
  cartNum = limitLower
535
534
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
536
535
  cartNum = limitUpper
537
536
  }
538
537
  if (skuUuid && cartNum > 0) {
539
538
  return this.bMallChangeCartService({
540
539
  ...goodItem,
541
540
  skuUuid,
542
541
  num: cartNum,
543
542
  })
544
543
  } else if (!skuUuid && cartNum > 0) {
545
544
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
546
545
  } else if (skuUuid && !cartNum) {
547
546
  return this.bMallRemoveCartService({
548
547
  ...goodItem,
549
548
  skuUuid,
550
549
  num: cartNum,
551
550
  })
552
551
  } else {
553
552
  console.error('参数不全')
554
553
  return false
555
554
  }
556
555
  } catch (e) {
557
556
  console.error(e)
558
557
  }
559
558
  }
559
+ import Taro from '@tarojs/taro';
560
560
  isDynamic,
561
561
  isLanguageForEn,
562
562
  isJdApp,
563
563
  showSuccessToast,
564
564
  showFailToast,
565
565
  isPc,
566
566
  draInterfaceCustomReport,
567
567
  isAndroidDevice,
568
568
  draBusinessCustomReport,
569
569
  cookiesStr: '',
570
570
  requestHeaderContentType: {
571
571
  jsonHeader: {
572
572
  'content-type': 'application/json;charset=utf-8',
573
573
  },
574
574
  formDataHeader: {
575
575
  'content-type': 'application/x-www-form-urlencoded',
576
576
  },
577
577
  },
578
578
  requestBaseParam: {
579
579
  data: null,
580
580
  header: {
581
581
  'content-type': 'application/json;charset=utf-8',
582
582
  },
583
583
  },
584
584
  timeOut: 7000,
585
585
  apiClientParams: {
586
586
  appid: 'wx_mini_app',
587
587
  clientVersion: '11.0.0',
588
588
  client: 'wh5',
589
589
  area: '1_72_2799_0',
590
590
  uuid: '-1',
591
591
  loginType: '11',
592
592
  },
593
593
  public addressFetchInfo: {
594
594
  reqState: boolean;
595
595
  promiseInstance: null | Promise<any>;
596
596
  };
597
597
  public getPromotionConfig: {
598
598
  projectId: null | string | number;
599
599
  pageId: null | string | number;
600
600
  };
601
601
  public resInfo: ServiceInterFace.HttpRequestInfo;
602
602
  public api: ServiceInterFace.HttpApi;
603
603
  public isPageDomain: boolean;
604
604
  public verifyColorList: string[];
605
605
  constructor(opt) {
606
606
  this._init();
607
607
  this.addressFetchInfo = {
608
608
  reqState: false,
609
609
  promiseInstance: null,
610
610
  };
611
611
  this.getPromotionConfig = {
612
612
  projectId: null,
613
613
  pageId: null,
614
614
  };
615
615
  this._userAreaUpdateListen();
616
616
  this.resInfo = this._getResConfig(opt);
617
617
  this.api = api;
618
618
  this.isPageDomain = false;
619
619
  this.verifyColorList = [];
620
620
  }
621
621
 
622
622
  _init(): void {
623
623
  !isDynamic &&
624
624
  httpInterceptors.forEach((item) => {
625
625
  Taro.addInterceptor((chain) => item(chain));
626
626
  });
627
627
  }
628
628
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
629
629
  return Object.assign({}, DefaultConfig, opt);
630
630
  }
631
631
 
632
632
  _userAreaUpdateListen() {
633
633
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
634
634
  this.updateApiClientParamsResInfo(areaInfo);
635
635
  });
636
636
  }
637
637
  updateApiClientParamsResInfo(opt = {}) {
638
638
  const { area, realTimeArea, ...others } = opt;
639
639
  this.resInfo.apiClientParams = {
640
640
  ...this.resInfo.apiClientParams,
641
641
  ...others,
642
642
  };
643
643
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
644
644
  realTimeArea &&
645
645
  realTimeArea !== '' &&
646
646
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
647
647
  }
648
648
 
649
649
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
650
650
  if (functionId === 'receiveShopCoupon') {
651
651
  clientParams = Object.assign(
652
652
  {},
653
653
  {
654
654
  loginType: '1',
655
655
  loginWQBiz: WXAPP_BIZ_KEY,
656
656
  },
657
657
  clientParams,
658
658
  );
659
659
  }
660
660
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
661
661
  const getReqData = {
662
662
  functionId: functionId,
663
663
  body: JSON.stringify(bodyParams),
664
664
  t: Date.now(),
665
665
  ...apiClientParams,
666
666
  };
667
667
  return http
668
668
  .request({
669
669
  url: this.api.apiFunc,
670
670
  data: getReqData,
671
671
  isColorVerify: false,
672
672
  })
673
673
  .then((res: ServiceInterFace.RequestPromiseRes) => {
674
674
  const { statusCode, data, status, msg } = res;
675
675
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
676
676
  ok: true,
677
677
  };
678
678
  if ((statusCode === 200 || status === '0') && data) {
679
679
  changeRes = this.dealResponseFormatRes(data, getReqData);
680
680
  return changeRes;
681
681
  } else {
682
682
  draInterfaceCustomReport({
683
683
  ...getReqData,
684
684
  ...res,
685
685
  source: 'remote',
686
686
  });
687
687
  changeRes = {
688
688
  ...data,
689
689
  statusCode,
690
690
  status,
691
691
  msg,
692
692
  ok: false,
693
693
  };
694
694
  return changeRes;
695
695
  }
696
696
  })
697
697
  .catch((res) => {
698
698
  const propertyNames = Object.getOwnPropertyNames(res);
699
699
  const resObject = {};
700
700
  propertyNames.forEach((propertyName) => {
701
701
  resObject[propertyName] = res[propertyName];
702
702
  });
703
703
  draInterfaceCustomReport({
704
704
  ...getReqData,
705
705
  ...resObject,
706
706
  source: 'remote',
707
707
  });
708
708
  return {
709
709
  ...resObject,
710
710
  ok: false,
711
711
  } as ServiceInterFace.RequestResponseFormatRes;
712
712
  });
713
713
  }
714
714
 
715
715
  dealResponseFormatRes(data, reqData) {
716
716
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
717
717
  ok: true,
718
718
  };
719
719
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
720
720
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
721
721
  ? Number(data.subCode)
722
722
  : -1;
723
723
  if (
724
724
  data.success === true ||
725
725
  data.isSuccess ||
726
726
  resCode === 0 ||
727
727
  resCode === 200 ||
728
728
  subCode === 0
729
729
  ) {
730
730
  changeRes = {
731
731
  result: Object.prototype.hasOwnProperty.call(data, 'result')
732
732
  ? data.result
733
733
  : Object.prototype.hasOwnProperty.call(data, 'data')
734
734
  ? data.data
735
735
  : data,
736
736
  code: data.code ?? 200,
737
737
  ok: true,
738
738
  source: data,
739
739
  };
740
740
  return changeRes;
741
741
  } else {
742
742
  changeRes = {
743
743
  ...data,
744
744
  ok: false,
745
745
  };
746
746
  if (reqData && resCode !== 3) {
747
747
  draInterfaceCustomReport({
748
748
  ...reqData,
749
749
  ...data,
750
750
  source: 'remote',
751
751
  });
752
752
  }
753
753
  return changeRes;
754
754
  }
755
755
  }
756
756
 
757
757
  async receiveCoupon(param = {}, clientParams) {
758
758
  console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
759
759
  return await this.gatewayReq(
760
760
  'receiveShopCoupon',
761
761
  {
762
762
  operation: '3',
763
763
  ...param,
764
764
  },
765
765
  { ...clientParams },
766
766
  );
767
767
  }
768
768
 
769
769
  getCustomerCenterDispatch(params = {}) {
770
770
  return this.gatewayReq('customerCenterDispatch', params, {
771
771
  clientVersion: '9.2.0',
772
772
  client: 'H5',
773
773
  uuid: 88888,
774
774
  appid: 'shopmember_m_jd_com',
775
775
  });
776
776
  }
777
777
 
778
778
  batchAddCart(...args) {
779
779
  let skuIds, num, showToast, giftCard;
780
780
  if (['number', 'string'].includes(typeof args[0])) {
781
781
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
782
782
  } else if (typeof args[0] === 'object' && args[0] !== null) {
783
783
  const params = args[0];
784
784
  skuIds = params.skuIds;
785
785
  num = params.num || 1;
786
786
  showToast = params.showToast !== undefined ? params.showToast : true;
787
787
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
788
788
  } else {
789
789
  console.error('batchAddCart() Invalid arguments!', args);
790
790
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
791
791
  showFailToast({
792
792
  title: msg,
793
793
  });
794
794
  return Promise.resolve({
795
795
  ok: false,
796
796
  msg,
797
797
  });
798
798
  }
799
799
  const successMsg = giftCard
800
800
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
801
801
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
802
802
  const failMsg = giftCard
803
803
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
804
804
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
805
805
  if (skuIds) {
806
806
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
807
807
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
808
808
  if (res?.ok) {
809
809
  if (showToast && !res?.isOpenApp)
810
810
  showSuccessToast({
811
811
  title: successMsg,
812
812
  });
813
813
  } else {
814
814
  showToast &&
815
815
  showFailToast({
816
816
  title: res?.errMsg || failMsg,
817
817
  });
818
818
  }
819
819
  return Promise.resolve(res);
820
820
  })
821
821
  .catch((e) => {
822
822
  console.log('调用加购方法异常=======>', e);
823
823
  return Promise.resolve({
824
824
  ok: false,
825
825
  msg: failMsg,
826
826
  });
827
827
  });
828
828
  } else {
829
829
  return Promise.resolve({
830
830
  ok: false,
831
831
  msg: failMsg,
832
832
  });
833
833
  }
834
834
  }
835
835
 
836
836
  async giftCardAddCart(skuList, num) {
837
837
  const loginType = isPc ? { loginType: 3 } : {};
838
838
  return this.gatewayReq(
839
839
  'giftCardAddCart',
840
840
  {
841
841
  skuList,
842
842
  num: Number(num),
843
843
  },
844
844
  { ...loginType },
845
845
  );
846
846
  }
847
847
 
848
848
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
849
849
  return new Promise((resolve) => {
850
850
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
851
851
  if (productIdsArr.length > 0) {
852
852
  if (giftCard) {
853
853
  this.giftCardAddCart(productIdsArr, addCardNum)
854
854
  .then((res) => {
855
855
  if (res?.code === '0' && res?.result?.value) {
856
856
  resolve({
857
857
  ok: true,
858
858
  });
859
859
  } else {
860
860
  resolve({
861
861
  ok: false,
862
862
  msg: '加购失败,请稍后重试',
863
863
  });
864
864
  }
865
865
  })
866
866
  .catch((e) => {
867
867
  console.error('礼品卡加车失败: ', e);
868
868
  resolve({
869
869
  ok: false,
870
870
  msg: '加购失败,请稍后重试',
871
871
  });
872
872
  });
873
873
  } else if (isJdApp && isDynamic) {
874
874
  const productsAddCartList = productIdsArr.map((skuItem) => {
875
875
  const extFlag = {};
876
876
  return isAndroidDevice
877
877
  ? {
878
878
  sku: skuItem,
879
879
  num: addCardNum,
880
880
  extFlag,
881
881
  }
882
882
  : {
883
883
  productCode: skuItem,
884
884
  buyCount: addCardNum,
885
885
  extFlag,
886
886
  };
887
887
  });
888
888
  const addCartRouterParams = {
889
889
  url: isAndroidDevice ? `router://JDCartModule/addCartUniformWithUrl?wareList=${JSON.stringify(productsAddCartList)}&businessName=storeModel` : 'router://JDCartModule/batchAddService',
890
890
  params: isAndroidDevice ? {
891
891
  wareList: productsAddCartList,
892
892
  } : {
893
893
  sourceType: 'h5',
894
894
  sourceValue: '店铺批量加购',
895
895
  businessName: 'storeModel',
896
896
  isNewMode: '1',
897
897
  NotPassWebview: '1',
898
898
  products: productsAddCartList,
899
899
  }
900
900
  }
901
901
  Taro.JDRouter.callRouter({
902
902
  ...addCartRouterParams,
903
903
  success: (res) => {
904
904
  console.log('taro 动态化店铺批量加购成功结果', res);
905
905
  const { errno, errMsg, data } = res || {};
906
906
  const isOk = isAndroidDevice ? errno === 0 : errno === 0 && data?.code === 0
907
907
  if (isOk) {
908
908
  resolve({
909
909
  ok: true,
910
910
  msg: '已加入购物车!',
911
911
  });
912
912
  } else {
913
913
  resolve({
914
914
  ok: false,
915
915
  msg: '批量加车失败,请稍后重试',
916
916
  errMsg: data?.message || errMsg || "",
917
917
  });
918
918
  const reportData = {
919
919
  type: 'batchAddCart',
920
920
  subType: 'addCartFailByTaroDynamicCallIosNative',
921
921
  errMsg: 'taro 动态化 调用原生加车失败',
922
922
  platform: global.info?.sysInfo?.platform,
923
923
  originData: typeof res === 'object' ? JSON.stringify(res) : res,
924
924
  };
925
925
  draBusinessCustomReport(reportData);
926
926
  }
927
927
  },
928
928
  fail: (res) => {
929
929
  const data = {
930
930
  type: 'batchAddCart',
931
931
  subType: 'addCartFailByTaroDynamicCallIosNative',
932
932
  errMsg: 'taro 动态化 调用原生加车失败',
933
933
  platform: global.info?.sysInfo?.platform,
934
934
  originData: typeof res === 'object' ? JSON.stringify(res) : res,
935
935
  };
936
936
  draBusinessCustomReport(data);
937
937
  },
938
938
  });
939
939
  }
940
940
  } else {
941
941
  resolve({
942
942
  ok: false,
943
943
  msg: '加购sku不能为空',
944
944
  });
945
945
  }
946
946
  });
947
947
  }
948
948
 
949
949
  productAddToCart() {
950
950
  return Promise.resolve({
951
951
  ok: false,
952
952
  msg: 'productAddToCart暂不支持小程序',
953
953
  });
954
954
  }