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

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 (129) hide show
  1. package/README.md +1 -1
  2. package/dist/api/index.ts +1 -1
  3. package/dist/common/accessibility.h5.ts +1 -0
  4. package/dist/common/accessibility.ts +1 -0
  5. package/dist/common/const.ts +1 -1
  6. package/dist/common/index.h5.ts +1 -1
  7. package/dist/common/index.jd.ts +1 -1
  8. package/dist/common/index.ts +1 -1
  9. package/dist/common/index.weapp.ts +1 -1
  10. package/dist/common/jdplayerSdk.weapp.tsx +1 -0
  11. package/dist/common/jssdk.ts +1 -1
  12. package/dist/common/jssdk.weapp.ts +1 -0
  13. package/dist/common/pageType.ts +1 -1
  14. package/dist/common/token/index.h5.ts +1 -1
  15. package/dist/common/token/token.jd.ts +1 -1
  16. package/dist/common/wxappApi.ascf.ts +1 -0
  17. package/dist/common/wxappApi.ts +1 -1
  18. package/dist/components/ErrorBoundary.tsx +1 -1
  19. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  20. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  21. package/dist/components/base/CountDown/index.module.scss +49 -44
  22. package/dist/components/base/CountDown/index.tsx +1 -1
  23. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  24. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  25. package/dist/components/base/CustomVideo/index.tsx +1 -1
  26. package/dist/components/base/CustomVideo/index.weapp.tsx +1 -0
  27. package/dist/components/base/Dialog/index.module.scss +11 -0
  28. package/dist/components/base/ExposureSmart/index.h5.module.scss +12 -2
  29. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  30. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  31. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  32. package/dist/components/base/InOrOutViewObserver/index.weapp.tsx +1 -0
  33. package/dist/components/base/InViewRender/index.tsx +1 -1
  34. package/dist/components/base/ItemViewExposureSmart/index.module.scss +2 -2
  35. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  36. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  37. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  38. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  39. package/dist/components/base/MobileCommonHeader/index.weapp.tsx +1 -0
  40. package/dist/components/base/NetworkDataError/const.ts +1 -1
  41. package/dist/components/base/NetworkDataError/index.module.scss +118 -72
  42. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  43. package/dist/components/base/Price/Base/index.module.scss +12 -0
  44. package/dist/components/base/Price/Base/index.tsx +1 -1
  45. package/dist/components/base/Price/Double/index.module.scss +33 -1
  46. package/dist/components/base/Price/Double/index.tsx +1 -1
  47. package/dist/components/base/ShopLeGaoTag/index.h5.module.scss +35 -0
  48. package/dist/components/base/ShopLeGaoTag/index.h5.tsx +1 -0
  49. package/dist/components/base/ShopLeGaoTag/index.module.scss +33 -0
  50. package/dist/components/base/ShopLeGaoTag/index.tsx +1 -0
  51. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  52. package/dist/components/floorItem.tsx +1 -1
  53. package/dist/components/floorItem.weapp.tsx +1 -1
  54. package/dist/components/isv/Floor/index.tsx +1 -1
  55. package/dist/components/remoteFloorItem.tsx +1 -1
  56. package/dist/config/env.ts +1 -1
  57. package/dist/interface/common.ts +1 -1
  58. package/dist/interface/component.ts +1 -1
  59. package/dist/interface/jumpEventReport.ts +1 -1
  60. package/dist/interface/service.ts +1 -1
  61. package/dist/jumpEventReport/base.ts +1 -1
  62. package/dist/jumpEventReport/const.ts +1 -1
  63. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  64. package/dist/jumpEventReport/index.h5.ts +1 -1
  65. package/dist/jumpEventReport/index.jd.ts +1 -1
  66. package/dist/jumpEventReport/index.weapp.ts +1 -1
  67. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  68. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  69. package/dist/jumpEventReport/logEventConfig.h5.ts +1 -0
  70. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  71. package/dist/jumpEventReport/web/report.ts +1 -1
  72. package/dist/jumpEventReport/web.base.ts +1 -1
  73. package/dist/jumpEventReport/web.jd.ts +1 -1
  74. package/dist/jumpEventReport/web.jdb.ts +1 -1
  75. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  76. package/dist/jumpEventReport/web.jxwxapp.ts +1 -1
  77. package/dist/jumpEventReport/web.pc.ts +1 -1
  78. package/dist/jumpEventReport/web.tjapp.ts +1 -1
  79. package/dist/jumpEventReport/web.tjm.ts +1 -1
  80. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  81. package/dist/language/en_US.json +395 -0
  82. package/dist/language/zh_CN.json +395 -0
  83. package/dist/language/zh_HK.json +395 -0
  84. package/dist/libs/openShopBridge.js +161 -0
  85. package/dist/libs/openShopBridge.min.js +1 -0
  86. package/dist/libs/taroAppReport.js +2 -2
  87. package/dist/modules/ContainerFloorList/index.h5.module.scss +80 -53
  88. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  89. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  90. package/dist/modules/DecorateContainerFloorList/index.weapp.tsx +1 -0
  91. package/dist/open/api/environment.ts +1 -1
  92. package/dist/open/api/shopMember.ts +1 -1
  93. package/dist/open/api/shopMember.weapp.ts +1 -0
  94. package/dist/open/api/track.ts +1 -1
  95. package/dist/open/api/util.ts +1 -1
  96. package/dist/open/components/index.ts +1 -1
  97. package/dist/open/index.ts +1 -1
  98. package/dist/sass/app.h5.scss +278 -224
  99. package/dist/sass/base.scss +150 -145
  100. package/dist/service/fetchGateway.ts +1 -1
  101. package/dist/service/fetchGateway.weapp.ts +1 -0
  102. package/dist/service/fetchJsonp.weapp.ts +1 -0
  103. package/dist/service/http/colorSign.ts +1 -1
  104. package/dist/service/http/const.ts +1 -1
  105. package/dist/service/http/h5Http.ts +1 -1
  106. package/dist/service/http/httpInterceptors.weapp.ts +1 -0
  107. package/dist/service/requestServer.h5.ts +1 -1
  108. package/dist/service/requestServer.ts +1 -1
  109. package/dist/service/requestServer.weapp.ts +1 -0
  110. package/dist/utils/connectNativeJsBridge.ts +1 -1
  111. package/dist/utils/h5Utils.ts +1 -1
  112. package/dist/utils/harmonyCallRouter.h5.ts +1 -0
  113. package/dist/utils/harmonyCallRouter.ts +0 -0
  114. package/dist/utils/index.h5.ts +1 -1
  115. package/dist/utils/index.ts +1 -1
  116. package/dist/utils/index.weapp.ts +1 -1
  117. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  118. package/dist/utils/jumpExtMapUtil.ts +1 -0
  119. package/dist/utils/jumpExtMapUtil.weapp.ts +1 -0
  120. package/dist/utils/log.ts +1 -0
  121. package/dist/utils/sColor.ts +1 -0
  122. package/dist/utils/sColor.weapp.ts +1 -0
  123. package/dist/utils/utils.ts +1 -1
  124. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  125. package/dist/wxapp/common/user_info.js +1 -1
  126. package/package.json +162 -141
  127. package/dist/jumpEventReport/web/wqshop.report.ts +0 -1
  128. package/dist/utils/memberFormatUtils.js +0 -1
  129. package/dist/utils/priceUtils.js +0 -1
@@ -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
  draBusinessCustomReport,
623
623
  isJdApp,
624
624
  isIosDevice,
625
625
  isAndroidDevice,
626
626
  showSuccessToast,
627
627
  showFailToast,
628
628
  isH5,
629
629
  isWxMinAndWxapp,
630
630
  isMin,
631
631
  isPc,
632
632
  draInterfaceCustomReport,
633
633
  isHarmonyDevice,
634
634
  isAscfApp,
635
635
  callRouterIOS,
636
636
  callRouterAndroid,
637
637
  callRouterHarmony,
638
638
  sendNativePageToShowCartFloatBtn,
639
639
  cookiesStr: '',
640
640
  requestHeaderContentType: {
641
641
  jsonHeader: {
642
642
  'content-type': 'application/json;charset=utf-8',
643
643
  },
644
644
  formDataHeader: {
645
645
  'content-type': 'application/x-www-form-urlencoded',
646
646
  },
647
647
  },
648
648
  requestBaseParam: {
649
649
  data: null,
650
650
  header: {
651
651
  'content-type': 'application/json;charset=utf-8',
652
652
  },
653
653
  },
654
654
  timeOut: 7000,
655
655
  apiClientParams: {
656
656
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
657
657
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
658
658
  area: '1_72_2799_0',
659
659
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
660
660
  window.screen?.height * devicePixelRatio,
661
661
  )}`,
662
662
  uuid: UUID,
663
663
  },
664
664
  window.shopGlobalSwitch?.useNativeHarmonyAddCartJdAppVersion;
665
665
  nativeHarmonyAddCartJdAppVersion && jdAppVersionCompare(nativeHarmonyAddCartJdAppVersion) >= 0;
666
666
  public addressFetchInfo: {
667
667
  reqState: boolean;
668
668
  promiseInstance: null | Promise<any>;
669
669
  };
670
670
  public getPromotionConfig: {
671
671
  projectId: null | string | number;
672
672
  pageId: null | string | number;
673
673
  };
674
674
  public resInfo: ServiceInterFace.HttpRequestInfo;
675
675
  public api: ServiceInterFace.HttpApi;
676
676
  public isPageDomain: boolean;
677
677
  public verifyColorList: string[];
678
678
  private isShowJdShopCartFloatBtn: boolean;
679
679
  constructor(opt) {
680
680
  this._init();
681
681
  this.addressFetchInfo = {
682
682
  reqState: false,
683
683
  promiseInstance: null,
684
684
  };
685
685
  this.getPromotionConfig = {
686
686
  projectId: null,
687
687
  pageId: null,
688
688
  };
689
689
  this._userAreaUpdateListen();
690
690
  this.resInfo = this._getResConfig(opt);
691
691
  this.api = api;
692
692
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
693
693
  this.verifyColorList = [
694
694
  ...MobileVerifyColorList,
695
695
  ...AppVerifyColorList,
696
696
  ...JshopxVerifyColorList,
697
697
  ...BMallVerifyColorList,
698
698
  ];
699
699
  this.isShowJdShopCartFloatBtn =
700
700
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
701
701
  }
702
702
  _init(): void {
703
703
  httpInterceptors.forEach((item) => {
704
704
  Taro.addInterceptor((chain) => item(chain));
705
705
  });
706
706
  }
707
707
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
708
708
  return Object.assign({}, DefaultConfig, opt);
709
709
  }
710
710
 
711
711
  _userAreaUpdateListen() {
712
712
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
713
713
  this.updateApiClientParamsResInfo(areaInfo);
714
714
  console.log(
715
715
  'cone-render收到原生端获取传来的四级地址信息',
716
716
  areaInfo,
717
717
  '更新后的接口底层信息',
718
718
  this.resInfo.apiClientParams,
719
719
  );
720
720
  });
721
721
  }
722
722
  updateApiClientParamsResInfo(opt = {}) {
723
723
  const { area, realTimeArea, ...others } = opt;
724
724
  this.resInfo.apiClientParams = {
725
725
  ...this.resInfo.apiClientParams,
726
726
  ...others,
727
727
  };
728
728
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
729
729
  realTimeArea &&
730
730
  realTimeArea !== '' &&
731
731
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
732
732
  }
733
733
 
734
734
  checkFunctionIdToReturnAppId(functionId) {
735
735
  if (JshopxColorFunctionIdList.includes(functionId)) {
736
736
  return APPID.JSHOPX_COLOR_APPID;
737
737
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
738
738
  return APPID.PAGES_COLOR_APPID;
739
739
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
740
740
  return APPID.SHOP_MEMBER_COLOR_APPID;
741
741
  } else if (B2BColorFunctionIdList.includes(functionId)) {
742
742
  return APPID.B2B_COLOR_APPID;
743
743
  } else if (isPc) {
744
744
  return APPID.MALL_COLOR_APPID;
745
745
  } else {
746
746
  return APPID.SHOP_COLOR_APPID;
747
747
  }
748
748
  }
749
749
 
750
750
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
751
751
  if (
752
752
  functionId === 'receiveShopCoupon' &&
753
753
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
754
754
  isWxMinAndWxapp)
755
755
  ) {
756
756
  clientParams = Object.assign(
757
757
  {},
758
758
  {
759
759
  loginType: isAscfApp ? '2' : '1',
760
760
  loginWQBiz: WXAPP_BIZ_KEY,
761
761
  },
762
762
  clientParams,
763
763
  );
764
764
  }
765
765
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
766
766
  typeof apiClientParams.appid === 'undefined' &&
767
767
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
768
768
  const isColorVerify = this.verifyColorList.includes(functionId);
769
769
  const getReqData = {
770
770
  functionId: functionId,
771
771
  body: JSON.stringify(bodyParams),
772
772
  t: Date.now(),
773
773
  ...apiClientParams,
774
774
  };
775
775
  return http
776
776
  .request({
777
777
  url: this.api.apiFunc,
778
778
  data: getReqData,
779
779
  isColorVerify,
780
780
  })
781
781
  .then((res: ServiceInterFace.RequestPromiseRes) => {
782
782
  const { statusCode, data, status, msg } = res;
783
783
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
784
784
  ok: true,
785
785
  };
786
786
  if ((statusCode === 200 || status === '0') && data) {
787
787
  changeRes = this.dealResponseFormatRes(data);
788
788
  return changeRes;
789
789
  } else {
790
790
  changeRes = {
791
791
  ...data,
792
792
  statusCode,
793
793
  status,
794
794
  msg,
795
795
  ok: false,
796
796
  };
797
797
  return changeRes;
798
798
  }
799
799
  })
800
800
  .catch((res) => {
801
801
  const propertyNames = Object.getOwnPropertyNames(res);
802
802
  const resObject = {};
803
803
  propertyNames.forEach((propertyName) => {
804
804
  resObject[propertyName] = res[propertyName];
805
805
  });
806
806
  draInterfaceCustomReport({
807
807
  eventName: 'apiStatusCode',
808
808
  errorName: `shop_${functionId}_error`,
809
809
  errorMessage: `接口返回statusCode为${res?.statusCode || res?.status}`,
810
810
  url: this.api.apiFunc,
811
811
  source: 'remote',
812
812
  requestType: res?.requestType,
813
813
  functionId: getReqData?.functionId,
814
814
  appid: getReqData?.appid,
815
815
  client: getReqData?.client,
816
816
  clientVersion: getReqData?.clientVersion,
817
817
  statusCode: res?.statusCode,
818
818
  status: res?.status,
819
819
  statusText: res?.statusText,
820
820
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
821
821
  originReqDataStr: JSON.stringify(getReqData),
822
822
  });
823
823
  return {
824
824
  ...resObject,
825
825
  ok: false,
826
826
  } as ServiceInterFace.RequestResponseFormatRes;
827
827
  });
828
828
  }
829
829
 
830
830
  dealResponseFormatRes(data) {
831
831
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
832
832
  ok: true,
833
833
  };
834
834
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
835
835
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
836
836
  ? Number(data.subCode)
837
837
  : -1;
838
838
  if (
839
839
  data.success === true ||
840
840
  data.isSuccess ||
841
841
  resCode === 0 ||
842
842
  resCode === 200 ||
843
843
  subCode === 0
844
844
  ) {
845
845
  changeRes = {
846
846
  result: Object.prototype.hasOwnProperty.call(data, 'result')
847
847
  ? data.result
848
848
  : Object.prototype.hasOwnProperty.call(data, 'data')
849
849
  ? data.data
850
850
  : data,
851
851
  code: data.code ?? 200,
852
852
  ok: true,
853
853
  source: data,
854
854
  };
855
855
  return changeRes;
856
856
  } else {
857
857
  changeRes = {
858
858
  ...data,
859
859
  ok: false,
860
860
  };
861
861
  return changeRes;
862
862
  }
863
863
  }
864
864
 
865
865
  async receiveCoupon(param = {}, clientParams) {
866
866
  const loginType = isPc ? { loginType: 3 } : {};
867
867
  return await this.gatewayReq(
868
868
  'receiveShopCoupon',
869
869
  {
870
870
  operation: '3',
871
871
  ...param,
872
872
  },
873
873
  { ...loginType, ...clientParams },
874
874
  );
875
875
  }
876
876
 
877
877
  getCustomerCenterDispatch(params = {}) {
878
878
  return this.gatewayReq('customerCenterDispatch', params, {
879
879
  clientVersion: '9.2.0',
880
880
  client: 'H5',
881
881
  uuid: 88888,
882
882
  appid: 'shopmember_m_jd_com',
883
883
  });
884
884
  }
885
885
 
886
886
  batchAddCart(...args) {
887
887
  let skuIds, num, showToast, giftCard, extFlag;
888
888
  if (['number', 'string'].includes(typeof args[0])) {
889
889
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
890
890
  } else if (typeof args[0] === 'object' && args[0] !== null) {
891
891
  const params = args[0];
892
892
  skuIds = params.skuIds;
893
893
  num = params.num || 1;
894
894
  showToast = params.showToast !== undefined ? params.showToast : true;
895
895
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
896
896
  extFlag = params.extFlag !== undefined ? params.extFlag : null;
897
897
  } else {
898
898
  try {
899
899
  const data = {
900
900
  eventName: 'business',
901
901
  errorName: 'shop_batchAddCart_error',
902
902
  errorMessage: '入参不合法',
903
903
  extraData: JSON.stringify(args),
904
904
  };
905
905
  draBusinessCustomReport(data);
906
906
  } catch (e) {
907
907
  console.error('draBusinessCustomReport error:', e);
908
908
  }
909
909
  const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
910
910
  showFailToast({
911
911
  title: msg,
912
912
  });
913
913
  return Promise.resolve({
914
914
  ok: false,
915
915
  msg,
916
916
  });
917
917
  }
918
918
  const successMsg = giftCard
919
919
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
920
920
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
921
921
  const failMsg = giftCard
922
922
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
923
923
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
924
924
  if (skuIds) {
925
925
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard, extFlag })
926
926
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
927
927
  if (res?.ok) {
928
928
  showToast &&
929
929
  !res?.isOpenApp &&
930
930
  showSuccessToast({
931
931
  title: successMsg,
932
932
  });
933
933
  this.isShowJdShopCartFloatBtn &&
934
934
  sendNativePageToShowCartFloatBtn({
935
935
  isShow: true,
936
936
  });
937
937
  } else {
938
938
  showToast &&
939
939
  showFailToast({
940
940
  title: res?.errMsg || failMsg,
941
941
  });
942
942
  }
943
943
  return Promise.resolve(res);
944
944
  })
945
945
  .catch((e) => {
946
946
  console.log('调用加购方法异常=======>', e);
947
947
  return Promise.resolve({
948
948
  ok: false,
949
949
  msg: failMsg,
950
950
  });
951
951
  });
952
952
  } else {
953
953
  try {
954
954
  const data = {
955
955
  eventName: 'business',
956
956
  errorName: 'shop_batchAddCart_error',
957
957
  errorMessage: '没有传入合法的skuIds',
958
958
  };
959
959
  draBusinessCustomReport(data);
960
960
  } catch (e) {
961
961
  console.error('draBusinessCustomReport error:', e);
962
962
  }
963
963
  return Promise.resolve({
964
964
  ok: false,
965
965
  msg: failMsg,
966
966
  });
967
967
  }
968
968
  }
969
969
 
970
970
  async giftCardAddCart(skuList, num) {
971
971
  const loginType = isPc ? { loginType: 3 } : {};
972
972
  return this.gatewayReq(
973
973
  'giftCardAddCart',
974
974
  {
975
975
  skuList,
976
976
  num: Number(num),
977
977
  },
978
978
  { ...loginType },
979
979
  );
980
980
  }
981
981
 
982
982
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard, extFlag }) {
983
983
  return new Promise((resolve) => {
984
984
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
985
985
  if (productIdsArr.length > 0) {
986
986
  if (giftCard) {
987
987
  this.giftCardAddCart(productIdsArr, addCardNum)
988
988
  .then((res) => {
989
989
  if (res?.code === '0' && res?.result?.value) {
990
990
  resolve({
991
991
  ok: true,
992
992
  });
993
993
  } else {
994
994
  try {
995
995
  const data = {
996
996
  eventName: 'business',
997
997
  errorName: 'shop_batchAddCart_error',
998
998
  errorMessage: '礼品卡加车接口返回加车失败标识',
999
999
  };
1000
1000
  draBusinessCustomReport(data);
1001
1001
  } catch (e) {
1002
1002
  console.error('draBusinessCustomReport error:', e);
1003
1003
  }
1004
1004
  resolve({
1005
1005
  ok: false,
1006
1006
  msg: '加购失败,请稍后重试',
1007
1007
  });
1008
1008
  }
1009
1009
  })
1010
1010
  .catch((e) => {
1011
1011
  console.error('礼品卡加车失败: ', e);
1012
1012
  resolve({
1013
1013
  ok: false,
1014
1014
  msg: '加购失败,请稍后重试',
1015
1015
  });
1016
1016
  });
1017
1017
  } else if (
1018
1018
  isJdApp &&
1019
1019
  (!isHarmonyDevice || (isHarmonyDevice && useNativeHarmonyAddCartJd))
1020
1020
  ) {
1021
1021
  const nativeAddCartCallBack = `nativeBatchAddCart${
1022
1022
  Date.now() + Number(productIdsArr[0]) + Number(addCardNum)
1023
1023
  }`;
1024
1024
  console.log(
1025
1025
  '==========>',
1026
1026
  '使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
1027
1027
  nativeAddCartCallBack,
1028
1028
  );
1029
1029
  if (!window[nativeAddCartCallBack]) {
1030
1030
  window[nativeAddCartCallBack] = (res) => {
1031
1031
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
1032
1032
  console.info(
1033
1033
  '获取批量加车原始数据',
1034
1034
  res,
1035
1035
  '====转换后的json数据为===',
1036
1036
  getMessageJsonData,
1037
1037
  );
1038
1038
  try {
1039
1039
  if (isAndroidDevice) {
1040
1040
  const isOk = getMessageJsonData?.status === '0';
1041
1041
  isOk
1042
1042
  ? resolve({
1043
1043
  ok: true,
1044
1044
  msg: '已加入购物车!',
1045
1045
  })
1046
1046
  : resolve({
1047
1047
  ok: false,
1048
1048
  msg: '加购失败,请稍后重试',
1049
1049
  errMsg: getMessageJsonData?.data?.message ?? '',
1050
1050
  });
1051
1051
  if (!isOk) {
1052
1052
  const data = {
1053
1053
  eventName: 'business',
1054
1054
  errorName: 'shop_batchAddCart_error',
1055
1055
  errorMessage: 'H5调用Android原生加车失败',
1056
1056
  };
1057
1057
  draBusinessCustomReport(data);
1058
1058
  }
1059
1059
  } else if (isIosDevice) {
1060
1060
  const isOk =
1061
1061
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
1062
1062
  isOk
1063
1063
  ? resolve({
1064
1064
  ok: true,
1065
1065
  msg: '已加入购物车!',
1066
1066
  })
1067
1067
  : resolve({
1068
1068
  ok: false,
1069
1069
  msg: '批量加车失败,请稍后重试',
1070
1070
  errMsg: getMessageJsonData?.data?.message ?? '',
1071
1071
  });
1072
1072
  if (!isOk) {
1073
1073
  const data = {
1074
1074
  eventName: 'business',
1075
1075
  errorName: 'shop_batchAddCart_error',
1076
1076
  errorMessage: 'H5调用IOS原生加车失败',
1077
1077
  };
1078
1078
  draBusinessCustomReport(data);
1079
1079
  }
1080
1080
  } else if (isHarmonyDevice) {
1081
1081
  const isOk =
1082
1082
  getMessageJsonData?.data?.code === 0 &&
1083
1083
  getMessageJsonData?.data?.response?.resultCode === 0;
1084
1084
  isOk
1085
1085
  ? resolve({
1086
1086
  ok: true,
1087
1087
  msg: '已加入购物车!',
1088
1088
  })
1089
1089
  : resolve({
1090
1090
  ok: false,
1091
1091
  msg: '加购失败,请稍后重试',
1092
1092
  errMsg: getMessageJsonData?.data?.message ?? '',
1093
1093
  });
1094
1094
  if (!isOk) {
1095
1095
  const data = {
1096
1096
  eventName: 'business',
1097
1097
  errorName: 'shop_batchAddCart_error',
1098
1098
  errorMessage: 'H5调用Harmony原生加车失败',
1099
1099
  };
1100
1100
  draBusinessCustomReport(data);
1101
1101
  }
1102
1102
  } else {
1103
1103
  resolve({
1104
1104
  ok: false,
1105
1105
  msg: '加购失败,请稍后重试',
1106
1106
  });
1107
1107
  const data = {
1108
1108
  eventName: 'business',
1109
1109
  errorName: 'shop_batchAddCart_error',
1110
1110
  errorMessage: 'H5调用未知原生加车失败',
1111
1111
  };
1112
1112
  draBusinessCustomReport(data);
1113
1113
  }
1114
1114
  } catch (e) {
1115
1115
  resolve({
1116
1116
  ok: false,
1117
1117
  msg: '加购失败,请稍后重试',
1118
1118
  });
1119
1119
  console.warn('批量加车转换数据异常', e);
1120
1120
  const data = {
1121
1121
  eventName: 'business',
1122
1122
  errorName: 'shop_batchAddCart_error',
1123
1123
  errorMessage: '批量加车转换数据异常',
1124
1124
  };
1125
1125
  draBusinessCustomReport(data);
1126
1126
  }
1127
1127
  window[nativeAddCartCallBack] = null;
1128
1128
  };
1129
1129
  }
1130
1130
  const productsAddCartList = productIdsArr.map((skuItem) => {
1131
1131
  const adInfos = getAdInfoBySkuId(skuItem);
1132
1132
  let allExtFlag = typeof extFlag === 'object' ? extFlag : {};
1133
1133
  if (adInfos) {
1134
1134
  allExtFlag = Object.assign({}, allExtFlag, { adInfos });
1135
1135
  }
1136
1136
  let item = null;
1137
1137
  if (isAndroidDevice) {
1138
1138
  item = {
1139
1139
  sku: skuItem,
1140
1140
  num: addCardNum,
1141
1141
  extFlag: allExtFlag,
1142
1142
  };
1143
1143
  } else if (isIosDevice) {
1144
1144
  item = {
1145
1145
  productCode: skuItem,
1146
1146
  buyCount: addCardNum,
1147
1147
  extFlag: allExtFlag,
1148
1148
  };
1149
1149
  } else if (isHarmonyDevice) {
1150
1150
  item = {
1151
1151
  sourceType: 'native',
1152
1152
  sourceValue: 'shop',
1153
1153
  productCode: skuItem,
1154
1154
  buyCount: addCardNum,
1155
1155
  extFlag: allExtFlag,
1156
1156
  };
1157
1157
  }
1158
1158
  return item;
1159
1159
  });
1160
1160
  if (isAndroidDevice) {
1161
1161
  const androidProductsStr = JSON.stringify(productsAddCartList);
1162
1162
  callRouterAndroid({
1163
1163
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
1164
1164
  routerParam: {
1165
1165
  wareList: productsAddCartList,
1166
1166
  },
1167
1167
  callBackName: nativeAddCartCallBack,
1168
1168
  });
1169
1169
  } else if (isIosDevice) {
1170
1170
  if (isLowAppVer) {
1171
1171
  const lowVersionAppList = productIdsArr.map((skuItem) => {
1172
1172
  return {
1173
1173
  sku: skuItem,
1174
1174
  num: addCardNum,
1175
1175
  };
1176
1176
  });
1177
1177
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
1178
1178
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
1179
1179
  jump.side.jdJumpToWeb(url, {});
1180
1180
  resolve({
1181
1181
  ok: true,
1182
1182
  isOpenApp: true,
1183
1183
  msg: '加购完成, 加购结果请点击购物车确认',
1184
1184
  });
1185
1185
  } else {
1186
1186
  callRouterIOS({
1187
1187
  routerURL: 'router://JDCartModule/batchAddService',
1188
1188
  routerParam: {
1189
1189
  sourceType: 'h5',
1190
1190
  sourceValue: '店铺批量加购',
1191
1191
  businessName: 'storeModel',
1192
1192
  isNewMode: '1',
1193
1193
  NotPassWebview: '1',
1194
1194
  products: productsAddCartList,
1195
1195
  },
1196
1196
  callBackName: nativeAddCartCallBack,
1197
1197
  });
1198
1198
  }
1199
1199
  } else if (isHarmonyDevice) {
1200
1200
  callRouterHarmony({
1201
1201
  routerURL: 'router://JDCartModule/batchAddService',
1202
1202
  routerParam: {
1203
1203
  sourceType: 'native',
1204
1204
  sourceValue: 'shop',
1205
1205
  products: productsAddCartList,
1206
1206
  },
1207
1207
  callBackName: nativeAddCartCallBack,
1208
1208
  });
1209
1209
  }
1210
1210
  } else if (isMin) {
1211
1211
  console.log('==========>', '京购批量加车!');
1212
1212
  const productsAddCartList = productIdsArr.map((skuItem) => {
1213
1213
  return {
1214
1214
  skuId: skuItem,
1215
1215
  buyNum: addCardNum,
1216
1216
  };
1217
1217
  });
1218
1218
  global.wxAppBizInstance
1219
1219
  .addCart({ commArr: productsAddCartList })
1220
1220
  .then((res) => {
1221
1221
  console.log('dealCartSuccess: ', res);
1222
1222
  resolve({
1223
1223
  ok: true,
1224
1224
  msg: '已加入购物车!',
1225
1225
  data: res,
1226
1226
  });
1227
1227
  })
1228
1228
  .catch((e) => {
1229
1229
  console.log('京购小程序批量加车失败dealCartFail: ', e);
1230
1230
  resolve({
1231
1231
  ok: false,
1232
1232
  msg: '加购失败,请稍后重试',
1233
1233
  });
1234
1234
  const data = {
1235
1235
  eventName: 'business',
1236
1236
  errorName: 'shop_batchAddCart_error',
1237
1237
  errorMessage: 'H5调用小程序加车失败',
1238
1238
  };
1239
1239
  draBusinessCustomReport(data);
1240
1240
  });
1241
1241
  } else {
1242
1242
  console.log('==========>', '使用M站批量加车!');
1243
1243
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
1244
1244
  }
1245
1245
  } else {
1246
1246
  resolve({
1247
1247
  ok: false,
1248
1248
  msg: '加购sku不能为空',
1249
1249
  });
1250
1250
  const data = {
1251
1251
  eventName: 'business',
1252
1252
  errorName: 'shop_batchAddCart_error',
1253
1253
  errorMessage: '加购sku不能为空',
1254
1254
  };
1255
1255
  draBusinessCustomReport(data);
1256
1256
  }
1257
1257
  });
1258
1258
  }
1259
1259
 
1260
1260
  productAddToCart(skuIdsStr, num) {
1261
1261
  return new Promise((resolve) => {
1262
1262
  if (window.AddcartToolObj) {
1263
1263
  window.AddcartToolObj.addCart({
1264
1264
  skuId: skuIdsStr,
1265
1265
  num,
1266
1266
  source: 'sjdpyw',
1267
1267
  actId: '1',
1268
1268
  loginType: isAscfApp ? '2' : window?.isJingGouMiniViewState ? '11' : isPc ? '3' : '2',
1269
1269
  sucFun(res) {
1270
1270
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
1271
1271
  if (res.errId === '0' && res.cartJson) {
1272
1272
  resolve({
1273
1273
  ok: true,
1274
1274
  msg: '已加入购物车!',
1275
1275
  ...res,
1276
1276
  });
1277
1277
  } else {
1278
1278
  if (res.errId === '13') {
1279
1279
  global.doLogin();
1280
1280
  } else {
1281
1281
  resolve({
1282
1282
  ok: false,
1283
1283
  msg: '加购失败,请稍后重试',
1284
1284
  ...res,
1285
1285
  });
1286
1286
  const data = {
1287
1287
  eventName: 'business',
1288
1288
  errorName: 'shop_batchAddCart_error',
1289
1289
  errorMessage: 'H5调用M站加车失败',
1290
1290
  };
1291
1291
  draBusinessCustomReport(data);
1292
1292
  }
1293
1293
  }
1294
1294
  },
1295
1295
  failFun(err) {
1296
1296
  console.log('fail', err);
1297
1297
  resolve({
1298
1298
  ok: false,
1299
1299
  msg: '加购失败,请稍后重试',
1300
1300
  ...err,
1301
1301
  });
1302
1302
  const data = {
1303
1303
  eventName: 'business',
1304
1304
  errorName: 'shop_batchAddCart_error',
1305
1305
  errorMessage: 'H5调用M站加车失败',
1306
1306
  };
1307
1307
  draBusinessCustomReport(data);
1308
1308
  },
1309
1309
  });
1310
1310
  } else {
1311
1311
  resolve({
1312
1312
  ok: false,
1313
1313
  msg: '购物车方法检查异常',
1314
1314
  });
1315
1315
  const data = {
1316
1316
  eventName: 'business',
1317
1317
  errorName: 'shop_batchAddCart_error',
1318
1318
  errorMessage: 'H5调用M站加车检查依赖方法异常',
1319
1319
  };
1320
1320
  draBusinessCustomReport(data);
1321
1321
  }
1322
1322
  });
1323
1323
  }
1324
1324
  bMallGetUserInfo = () => {
1325
1325
  return getBMallUserInfo();
1326
1326
  };
1327
1327
  async bMallAddCart(params = {}) {
1328
1328
  return await this.gatewayReq('bmall_cartAdd', params, {
1329
1329
  client: 'H5',
1330
1330
  clientVersion: '5.5.0',
1331
1331
  });
1332
1332
  }
1333
1333
  async bMallChangeCart(params = {}) {
1334
1334
  return await this.gatewayReq('bmall_cartChange', params, {
1335
1335
  client: 'H5',
1336
1336
  clientVersion: '5.5.0',
1337
1337
  });
1338
1338
  }
1339
1339
  async bMallRemoveCart(params = {}) {
1340
1340
  return await this.gatewayReq(
1341
1341
  'bmall_cartRemove',
1342
1342
  params,
1343
1343
  {
1344
1344
  client: 'H5',
1345
1345
  clientVersion: '5.5.0',
1346
1346
  },
1347
1347
  );
1348
1348
  }
1349
1349
  async bMallGetOmittedProduct(params = {}) {
1350
1350
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1351
1351
  client: 'H5',
1352
1352
  clientVersion: '5.5.0',
1353
1353
  });
1354
1354
  }
1355
1355
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1356
1356
  const params = await getParams({ ...data, skuId, bMallTag, num });
1357
1357
  return await this.bMallAddCart(params);
1358
1358
  }
1359
1359
  async bMallGetSkuNumService(bMallTag = 1) {
1360
1360
  const params = await getParams({ bMallTag });
1361
1361
  delete params.operations;
1362
1362
  return await this.bMallGetOmittedProduct(params);
1363
1363
  }
1364
1364
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1365
1365
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1366
1366
  return await this.bMallRemoveCart(params);
1367
1367
  }
1368
1368
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1369
1369
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1370
1370
  return await this.bMallChangeCart(params);
1371
1371
  }
1372
1372
 
1373
1373
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1374
1374
  if (!needRequest && isH5 && window?.bMallCartData) {
1375
1375
  return window?.bMallCartData;
1376
1376
  }
1377
1377
  const cartData = await this.bMallGetSkuNumService(bMallTag);
1378
1378
  let items;
1379
1379
  if (cartData.ok && cartData.result) {
1380
1380
  items = cartData?.result?.items || {};
1381
1381
  }
1382
1382
  if (isH5) {
1383
1383
  window.bMallCartData = items;
1384
1384
  }
1385
1385
  return items;
1386
1386
  }
1387
1387
 
1388
1388
  async bMallCartHandle(goodItem, num) {
1389
1389
  try {
1390
1390
  const {
1391
1391
  skuUuid,
1392
1392
  limitUpper,
1393
1393
  limitLower,
1394
1394
  } = goodItem;
1395
1395
  let cartNum = Number(num);
1396
1396
  if (limitLower && cartNum && cartNum < limitLower) {
1397
1397
  cartNum = limitLower;
1398
1398
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1399
1399
  cartNum = limitUpper;
1400
1400
  }
1401
1401
  if (skuUuid && cartNum > 0) {
1402
1402
  return this.bMallChangeCartService({
1403
1403
  ...goodItem,
1404
1404
  skuUuid,
1405
1405
  num: cartNum,
1406
1406
  });
1407
1407
  } else if (!skuUuid && cartNum > 0) {
1408
1408
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
1409
1409
  } else if (skuUuid && !cartNum) {
1410
1410
  return this.bMallRemoveCartService({
1411
1411
  ...goodItem,
1412
1412
  skuUuid,
1413
1413
  num: cartNum,
1414
1414
  });
1415
1415
  } else {
1416
1416
  console.error('参数不全');
1417
1417
  return false;
1418
1418
  }
1419
1419
  } catch (e) {
1420
1420
  console.error(e);
1421
1421
  }
1422
1422
  }