@conecli/cone-render 0.10.1-isv2.2 → 0.10.1-isv3.1

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 (123) 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.tsx +1 -1
  22. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  23. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  24. package/dist/components/base/CustomVideo/index.tsx +1 -1
  25. package/dist/components/base/CustomVideo/index.weapp.tsx +1 -0
  26. package/dist/components/base/Dialog/index.module.scss +11 -0
  27. package/dist/components/base/ExposureSmart/index.h5.module.scss +12 -2
  28. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  29. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  30. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  31. package/dist/components/base/InOrOutViewObserver/index.weapp.tsx +1 -0
  32. package/dist/components/base/InViewRender/index.tsx +1 -1
  33. package/dist/components/base/ItemViewExposureSmart/index.module.scss +2 -2
  34. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  35. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  36. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  37. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  38. package/dist/components/base/MobileCommonHeader/index.weapp.tsx +1 -0
  39. package/dist/components/base/NetworkDataError/const.ts +1 -1
  40. package/dist/components/base/NetworkDataError/index.module.scss +118 -72
  41. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  42. package/dist/components/base/Price/Base/index.module.scss +12 -0
  43. package/dist/components/base/Price/Base/index.tsx +1 -1
  44. package/dist/components/base/Price/Double/index.module.scss +25 -1
  45. package/dist/components/base/Price/Double/index.tsx +1 -1
  46. package/dist/components/base/ShopLeGaoTag/index.h5.module.scss +35 -0
  47. package/dist/components/base/ShopLeGaoTag/index.h5.tsx +1 -0
  48. package/dist/components/base/ShopLeGaoTag/index.module.scss +33 -0
  49. package/dist/components/base/ShopLeGaoTag/index.tsx +1 -0
  50. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  51. package/dist/components/floorItem.tsx +1 -1
  52. package/dist/components/floorItem.weapp.tsx +1 -1
  53. package/dist/components/isv/Floor/index.tsx +1 -1
  54. package/dist/components/remoteFloorItem.tsx +1 -1
  55. package/dist/config/env.ts +1 -1
  56. package/dist/interface/common.ts +1 -1
  57. package/dist/interface/component.ts +1 -1
  58. package/dist/interface/jumpEventReport.ts +1 -1
  59. package/dist/interface/service.ts +1 -1
  60. package/dist/jumpEventReport/base.ts +1 -1
  61. package/dist/jumpEventReport/const.ts +1 -1
  62. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  63. package/dist/jumpEventReport/index.h5.ts +1 -1
  64. package/dist/jumpEventReport/index.jd.ts +1 -1
  65. package/dist/jumpEventReport/index.weapp.ts +1 -1
  66. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  67. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  68. package/dist/jumpEventReport/logEventConfig.h5.ts +1 -0
  69. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  70. package/dist/jumpEventReport/web/report.ts +1 -1
  71. package/dist/jumpEventReport/web.base.ts +1 -1
  72. package/dist/jumpEventReport/web.jd.ts +1 -1
  73. package/dist/jumpEventReport/web.pc.ts +1 -1
  74. package/dist/jumpEventReport/web.tjm.ts +1 -1
  75. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  76. package/dist/language/en_US.json +395 -0
  77. package/dist/language/zh_CN.json +395 -0
  78. package/dist/language/zh_HK.json +395 -0
  79. package/dist/libs/openShopBridge.js +161 -0
  80. package/dist/libs/openShopBridge.min.js +1 -0
  81. package/dist/libs/taroAppReport.js +2 -2
  82. package/dist/modules/ContainerFloorList/index.h5.module.scss +80 -53
  83. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  84. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  85. package/dist/modules/DecorateContainerFloorList/index.weapp.tsx +1 -0
  86. package/dist/open/api/environment.ts +1 -1
  87. package/dist/open/api/shopMember.ts +1 -1
  88. package/dist/open/api/shopMember.weapp.ts +1 -0
  89. package/dist/open/api/track.ts +1 -1
  90. package/dist/open/api/util.ts +1 -1
  91. package/dist/open/components/index.ts +1 -1
  92. package/dist/open/index.ts +1 -1
  93. package/dist/sass/app.h5.scss +278 -224
  94. package/dist/sass/base.scss +8 -4
  95. package/dist/service/fetchGateway.ts +1 -1
  96. package/dist/service/fetchGateway.weapp.ts +1 -0
  97. package/dist/service/fetchJsonp.weapp.ts +1 -0
  98. package/dist/service/http/colorSign.ts +1 -1
  99. package/dist/service/http/const.ts +1 -1
  100. package/dist/service/http/h5Http.ts +1 -1
  101. package/dist/service/http/httpInterceptors.weapp.ts +1 -0
  102. package/dist/service/requestServer.h5.ts +1 -1
  103. package/dist/service/requestServer.ts +1 -1
  104. package/dist/service/requestServer.weapp.ts +1 -0
  105. package/dist/utils/connectNativeJsBridge.ts +1 -1
  106. package/dist/utils/h5Utils.ts +1 -1
  107. package/dist/utils/harmonyCallRouter.h5.ts +1 -0
  108. package/dist/utils/harmonyCallRouter.ts +0 -0
  109. package/dist/utils/index.h5.ts +1 -1
  110. package/dist/utils/index.ts +1 -1
  111. package/dist/utils/index.weapp.ts +1 -1
  112. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  113. package/dist/utils/jumpExtMapUtil.ts +1 -0
  114. package/dist/utils/jumpExtMapUtil.weapp.ts +1 -0
  115. package/dist/utils/log.ts +1 -0
  116. package/dist/utils/sColor.ts +1 -0
  117. package/dist/utils/sColor.weapp.ts +1 -0
  118. package/dist/utils/utils.ts +1 -1
  119. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  120. package/dist/wxapp/common/user_info.js +1 -1
  121. package/package.json +164 -141
  122. package/dist/jumpEventReport/web/wqshop.report.ts +0 -1
  123. 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
  area && area !== "" && this.updateApiClientParamsResInfo({
99
98
  area,
100
99
  })
101
100
  console.log("cone-render收到原生端获取传来的四级地址信息",area,"更新后的接口底层信息", this.resInfo.apiClientParams)
102
101
  })
103
102
  }
104
103
  updateApiClientParamsResInfo(opt = {}) {
105
104
  const { area, ...others} = opt
106
105
  this.resInfo.apiClientParams = {
107
106
  ...this.resInfo.apiClientParams,
108
107
  ...others
109
108
  }
110
109
  if(area){
111
110
  this.resInfo.apiClientParams.area = area
112
111
  }
113
112
  }
114
113
 
115
114
  checkFunctionIdToReturnAppId(functionId) {
116
115
  if (JshopxColorFunctionIdList.includes(functionId)) {
117
116
  return APPID.JSHOPX_COLOR_APPID
118
117
  } else if (
119
118
  this.isPageDomain &&
120
119
  PagesColorFunctionIdList.includes(functionId)
121
120
  ) {
122
121
  return APPID.PAGES_COLOR_APPID
123
122
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
124
123
  return APPID.SHOP_MEMBER_COLOR_APPID
125
124
  } else if (B2BColorFunctionIdList.includes(functionId)) {
126
125
  return APPID.B2B_COLOR_APPID
127
126
  } else if (isPc) {
128
127
  return APPID.MALL_COLOR_APPID
129
128
  } else {
130
129
  return APPID.SHOP_COLOR_APPID
131
130
  }
132
131
  }
133
132
 
134
133
  gatewayReq(
135
134
  functionId: string,
136
135
  bodyParams = {},
137
136
  clientParams = {},
138
137
  ): Promise<any> {
139
138
  if (
140
139
  functionId === 'receiveShopCoupon' &&
141
140
  ((isH5 &&
142
141
  (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
143
142
  isWxMinAndWxapp)
144
143
  ) {
145
144
  clientParams = Object.assign(
146
145
  {},
147
146
  {
148
147
  loginType: '1',
149
148
  loginWQBiz: WXAPP_BIZ_KEY,
150
149
  },
151
150
  clientParams,
152
151
  )
153
152
  }
154
153
  const apiClientParams = Object.assign(
155
154
  {},
156
155
  this.resInfo.apiClientParams,
157
156
  clientParams,
158
157
  )
159
158
  typeof apiClientParams.appid === 'undefined' &&
160
159
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId))
161
160
  const isColorVerify = this.verifyColorList.includes(functionId)
162
161
  const getReqData = {
163
162
  functionId: functionId,
164
163
  body: JSON.stringify(bodyParams),
165
164
  t: Date.now(),
166
165
  ...apiClientParams,
167
166
  }
168
167
  return http
169
168
  .request({
170
169
  url: this.api.apiFunc,
171
170
  data: getReqData,
172
171
  isColorVerify,
173
172
  })
174
173
  .then((res: ServiceInterFace.RequestPromiseRes) => {
175
174
  const { statusCode, data, status, msg } = res
176
175
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
177
176
  ok: true,
178
177
  }
179
178
  if ((statusCode === 200 || status === '0') && data) {
180
179
  changeRes = this.dealResponseFormatRes(data)
181
180
  return changeRes
182
181
  } else {
183
182
  changeRes = {
184
183
  ...data,
185
184
  statusCode,
186
185
  status,
187
186
  msg,
188
187
  ok: false,
189
188
  }
190
189
  return changeRes
191
190
  }
192
191
  })
193
192
  .catch((res) => {
194
193
  const propertyNames = Object.getOwnPropertyNames(res);
195
194
  const resObject = {};
196
195
  propertyNames.forEach((propertyName) => {
197
196
  resObject[propertyName] = res[propertyName];
198
197
  });
199
198
  draInterfaceCustomReport({
200
199
  subMsg:
201
200
  '接口请求异常,进入catch逻辑,例如h5请求神盾(反爬、小号、风控)或加固拦截返回status为403等',
202
201
  url: this.api.apiFunc,
203
202
  source: 'remote',
204
203
  requestType: res?.requestType,
205
204
  errorType: 'catchError',
206
205
  functionId: getReqData?.functionId,
207
206
  appid: getReqData?.appid,
208
207
  client: getReqData?.client,
209
208
  clientVersion: getReqData?.clientVersion,
210
209
  statusCode: res?.statusCode,
211
210
  status: res?.status,
212
211
  statusText: res?.statusText,
213
212
  code: res?.data?.code || res?.data?.subCode,
214
213
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
215
214
  originReqDataStr: JSON.stringify(getReqData),
216
215
  originResDataStr: JSON.stringify(res, propertyNames),
217
216
  });
218
217
  return {
219
218
  ...resObject,
220
219
  ok: false,
221
220
  } as ServiceInterFace.RequestResponseFormatRes;
222
221
  })
223
222
  }
224
223
 
225
224
  dealResponseFormatRes(data) {
226
225
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
227
226
  ok: true,
228
227
  }
229
228
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
230
229
  ? Number(data.code)
231
230
  : -1
232
231
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
233
232
  ? Number(data.subCode)
234
233
  : -1
235
234
  if (
236
235
  data.success === true ||
237
236
  data.isSuccess ||
238
237
  resCode === 0 ||
239
238
  resCode === 200 ||
240
239
  subCode === 0
241
240
  ) {
242
241
  changeRes = {
243
242
  result: Object.prototype.hasOwnProperty.call(data, 'result')
244
243
  ? data.result
245
244
  : Object.prototype.hasOwnProperty.call(data, 'data')
246
245
  ? data.data
247
246
  : data,
248
247
  code: data.code ?? 200,
249
248
  ok: true,
250
249
  source: data,
251
250
  }
252
251
  return changeRes
253
252
  } else {
254
253
  changeRes = {
255
254
  ...data,
256
255
  ok: false,
257
256
  }
258
257
  return changeRes
259
258
  }
260
259
  }
261
260
 
262
261
  async receiveCoupon(param = {}, clientParams) {
263
262
  const loginType = isPc ? { loginType: 3 } : {}
264
263
  return await this.gatewayReq(
265
264
  'receiveShopCoupon',
266
265
  {
267
266
  operation: '3',
268
267
  ...param,
269
268
  },
270
269
  { ...loginType, ...clientParams },
271
270
  )
272
271
  }
273
272
 
274
273
  getCustomerCenterDispatch(params = {}) {
275
274
  return this.gatewayReq('customerCenterDispatch', params, {
276
275
  clientVersion: '9.2.0',
277
276
  client: 'H5',
278
277
  uuid: 88888,
279
278
  appid: 'shopmember_m_jd_com',
280
279
  })
281
280
  }
282
281
 
283
282
  batchAddCart(skuIdsStr, num = 1, showToast = true) {
284
283
  if (skuIdsStr) {
285
284
  return this._addShopGoodCart(`${skuIdsStr}`, `${num}`)
286
285
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
287
286
  if (res?.ok) {
288
287
  if (showToast && !res?.isOpenApp)
289
288
  showSuccessToast({
290
289
  title: '加入购物车成功',
291
290
  })
292
291
  } else {
293
292
  showToast &&
294
293
  showFailToast({
295
294
  title: res?.errMsg || '加入购物车失败,请稍后重试!',
296
295
  })
297
296
  }
298
297
  return Promise.resolve(res)
299
298
  })
300
299
  .catch((e) => {
301
300
  console.log('调用加购方法异常=======>', e)
302
301
  return Promise.resolve({
303
302
  ok: false,
304
303
  msg: '加入购物车失败,请稍后重试!',
305
304
  })
306
305
  })
307
306
  } else {
308
307
  return Promise.resolve({
309
308
  ok: false,
310
309
  msg: '加入购物车失败,请稍后重试!',
311
310
  })
312
311
  }
313
312
  }
314
313
 
315
314
  _addShopGoodCart(skuIdsStr, addCardNum = '1') {
316
315
  return new Promise((resolve) => {
317
316
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : []
318
317
  if (productIdsArr.length > 0) {
319
318
  if (isJdApp) {
320
319
  console.log('==========>', '原生批量加车!')
321
320
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now()}`
322
321
  if (!window[nativeAddCartCallBack]) {
323
322
  window[nativeAddCartCallBack] = (res) => {
324
323
  const getMessageJsonData =
325
324
  typeof res === 'string' ? JSON.parse(res) : res
326
325
  console.info(
327
326
  '获取批量加车原始数据',
328
327
  res,
329
328
  '====转换后的json数据为===',
330
329
  getMessageJsonData,
331
330
  )
332
331
  try {
333
332
  if (isAndroidDevice) {
334
333
  getMessageJsonData?.status === '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 if (isIosDevice) {
344
343
  getMessageJsonData?.status === '0' &&
345
344
  getMessageJsonData?.data?.code === 0
346
345
  ? resolve({
347
346
  ok: true,
348
347
  msg: '已加入购物车!',
349
348
  })
350
349
  : resolve({
351
350
  ok: false,
352
351
  msg: '批量加车失败,请稍后重试',
353
352
  })
354
353
  } else {
355
354
  resolve({
356
355
  ok: false,
357
356
  msg: '加购失败,请稍后重试',
358
357
  })
359
358
  }
360
359
  } catch (e) {
361
360
  resolve({
362
361
  ok: false,
363
362
  msg: '加购失败,请稍后重试',
364
363
  })
365
364
  console.warn('批量加车转换数据异常', e)
366
365
  }
367
366
  window[nativeAddCartCallBack] = null
368
367
  }
369
368
  }
370
369
  const productsAddCartList = productIdsArr.map((skuItem) => {
371
370
  return isAndroidDevice
372
371
  ? {
373
372
  sku: skuItem,
374
373
  num: addCardNum,
375
374
  }
376
375
  : {
377
376
  productCode: skuItem,
378
377
  buyCount: addCardNum,
379
378
  }
380
379
  })
381
380
  if (isAndroidDevice) {
382
381
  const androidProductsStr = JSON.stringify(productsAddCartList)
383
382
  callRouterAndroid({
384
383
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
385
384
  routerParam: {
386
385
  wareList: productsAddCartList,
387
386
  },
388
387
  callBackName: nativeAddCartCallBack,
389
388
  })
390
389
  } else if (isIosDevice) {
391
390
  if (isLowAppVer) {
392
391
  const lowVersionAppList = productIdsArr.map((skuItem) => {
393
392
  return {
394
393
  sku: skuItem,
395
394
  num: addCardNum,
396
395
  }
397
396
  })
398
397
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList)
399
398
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`
400
399
  jump.side.jdJumpToWeb(url, {})
401
400
  resolve({
402
401
  ok: true,
403
402
  isOpenApp: true,
404
403
  msg: '加购完成, 加购结果请点击购物车确认',
405
404
  })
406
405
  } else {
407
406
  callRouterIOS({
408
407
  routerURL: 'router://JDCartModule/batchAddService',
409
408
  routerParam: {
410
409
  sourceType: 'h5',
411
410
  sourceValue: '店铺批量加购',
412
411
  businessName: 'storeModel',
413
412
  isNewMode: '1',
414
413
  NotPassWebview: '1',
415
414
  products: productsAddCartList,
416
415
  },
417
416
  callBackName: nativeAddCartCallBack,
418
417
  })
419
418
  }
420
419
  }
421
420
  } else if (isMin) {
422
421
  console.log('==========>', '京购批量加车!')
423
422
  const productsAddCartList = productIdsArr.map((skuItem) => {
424
423
  return {
425
424
  skuId: skuItem,
426
425
  buyNum: addCardNum,
427
426
  }
428
427
  })
429
428
  global.wxAppBizInstance
430
429
  .addCart({ commArr: productsAddCartList })
431
430
  .then((res) => {
432
431
  console.log('dealCartSuccess: ', res)
433
432
  resolve({
434
433
  ok: true,
435
434
  msg: '已加入购物车!',
436
435
  data: res,
437
436
  })
438
437
  })
439
438
  .catch((e) => {
440
439
  console.log('京购小程序批量加车失败dealCartFail: ', e)
441
440
  resolve({
442
441
  ok: false,
443
442
  msg: '加购失败,请稍后重试',
444
443
  })
445
444
  })
446
445
  } else {
447
446
  console.log('==========>', 'M站批量加车!')
448
447
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) =>
449
448
  resolve(res),
450
449
  )
451
450
  }
452
451
  } else {
453
452
  resolve({
454
453
  ok: false,
455
454
  msg: '加购sku不能为空',
456
455
  })
457
456
  }
458
457
  })
459
458
  }
460
459
 
461
460
  productAddToCart(skuIdsStr, num) {
462
461
  return new Promise((resolve) => {
463
462
  if (window.AddcartToolObj) {
464
463
  window.AddcartToolObj.addCart({
465
464
  skuId: skuIdsStr,
466
465
  num,
467
466
  source: 'sjdpyw',
468
467
  actId: '1',
469
468
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
470
469
  sucFun(res) {
471
470
  console.log(
472
471
  'ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0',
473
472
  res,
474
473
  )
475
474
  if (res.errId === '0' && res.cartJson) {
476
475
  resolve({
477
476
  ok: true,
478
477
  msg: '已加入购物车!',
479
478
  ...res,
480
479
  })
481
480
  } else {
482
481
  if (res.errId === '13') {
483
482
  global.doLogin()
484
483
  } else {
485
484
  resolve({
486
485
  ok: false,
487
486
  msg: '加购失败,请稍后重试',
488
487
  ...res,
489
488
  })
490
489
  }
491
490
  }
492
491
  },
493
492
  failFun(err) {
494
493
  console.log('fail', err)
495
494
  resolve({
496
495
  ok: false,
497
496
  msg: '加购失败,请稍后重试',
498
497
  ...err,
499
498
  })
500
499
  },
501
500
  })
502
501
  } else {
503
502
  resolve({
504
503
  ok: false,
505
504
  msg: '购物车方法检查异常',
506
505
  })
507
506
  }
508
507
  })
509
508
  }
510
509
  bMallGetUserInfo = () => {
511
510
  return getBMallUserInfo()
512
511
  }
513
512
  async bMallAddCart(params = {}) {
514
513
  return await this.gatewayReq('bmall_cartAdd', params, {
515
514
  client: 'H5',
516
515
  clientVersion: '5.5.0',
517
516
  })
518
517
  }
519
518
  async bMallChangeCart(params = {}) {
520
519
  return await this.gatewayReq('bmall_cartChange', params, {
521
520
  client: 'H5',
522
521
  clientVersion: '5.5.0',
523
522
  })
524
523
  }
525
524
  async bMallRemoveCart(params = {}) {
526
525
  return await this.gatewayReq(
527
526
  'bmall_cartRemove',
528
527
  params,
529
528
  {
530
529
  client: 'H5',
531
530
  clientVersion: '5.5.0',
532
531
  },
533
532
  )
534
533
  }
535
534
  async bMallGetOmittedProduct(params = {}) {
536
535
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
537
536
  client: 'H5',
538
537
  clientVersion: '5.5.0',
539
538
  })
540
539
  }
541
540
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
542
541
  const params = await getParams({ ...data, skuId, bMallTag, num })
543
542
  return await this.bMallAddCart(params)
544
543
  }
545
544
  async bMallGetSkuNumService(bMallTag = 1) {
546
545
  const params = await getParams({ bMallTag })
547
546
  delete params.operations
548
547
  return await this.bMallGetOmittedProduct(params)
549
548
  }
550
549
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
551
550
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
552
551
  return await this.bMallRemoveCart(params)
553
552
  }
554
553
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
555
554
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid })
556
555
  return await this.bMallChangeCart(params)
557
556
  }
558
557
 
559
558
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
560
559
  if (!needRequest && isH5 && window?.bMallCartData) {
561
560
  return window?.bMallCartData
562
561
  }
563
562
  const cartData = await this.bMallGetSkuNumService(bMallTag)
564
563
  let items
565
564
  if (cartData.ok && cartData.result) {
566
565
  items = cartData?.result?.items || {}
567
566
  }
568
567
  if (isH5) {
569
568
  window.bMallCartData = items
570
569
  }
571
570
  return items
572
571
  }
573
572
 
574
573
  async bMallCartHandle(goodItem, num) {
575
574
  try {
576
575
  const {
577
576
  skuUuid,
578
577
  limitUpper,
579
578
  limitLower,
580
579
  } = goodItem
581
580
  let cartNum = Number(num)
582
581
  if (limitLower && cartNum && cartNum < limitLower) {
583
582
  cartNum = limitLower
584
583
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
585
584
  cartNum = limitUpper
586
585
  }
587
586
  if (skuUuid && cartNum > 0) {
588
587
  return this.bMallChangeCartService({
589
588
  ...goodItem,
590
589
  skuUuid,
591
590
  num: cartNum,
592
591
  })
593
592
  } else if (!skuUuid && cartNum > 0) {
594
593
  return this.bMallAddCartService({ ...goodItem, num: cartNum })
595
594
  } else if (skuUuid && !cartNum) {
596
595
  return this.bMallRemoveCartService({
597
596
  ...goodItem,
598
597
  skuUuid,
599
598
  num: cartNum,
600
599
  })
601
600
  } else {
602
601
  console.error('参数不全')
603
602
  return false
604
603
  }
605
604
  } catch (e) {
606
605
  console.error(e)
607
606
  }
608
607
  }
608
+ import Taro from '@tarojs/taro';
609
609
  APPID,
610
610
  JshopxColorFunctionIdList,
611
611
  PagesColorFunctionIdList,
612
612
  PAGES_DOMAIN,
613
613
  B2BColorFunctionIdList,
614
614
  MobileVerifyColorList,
615
615
  AppVerifyColorList,
616
616
  JshopxVerifyColorList,
617
617
  BMallVerifyColorList,
618
618
  shopMemberColorFunctionIdList,
619
619
  draBusinessCustomReport,
620
620
  isJdApp,
621
621
  isIosDevice,
622
622
  isAndroidDevice,
623
623
  showSuccessToast,
624
624
  showFailToast,
625
625
  isH5,
626
626
  isWxMinAndWxapp,
627
627
  isMin,
628
628
  isPc,
629
629
  draInterfaceCustomReport,
630
630
  isHarmonyDevice,
631
631
  isAscfApp,
632
632
  callRouterIOS,
633
633
  callRouterAndroid,
634
634
  callRouterHarmony,
635
635
  sendNativePageToShowCartFloatBtn,
636
636
  cookiesStr: '',
637
637
  requestHeaderContentType: {
638
638
  jsonHeader: {
639
639
  'content-type': 'application/json;charset=utf-8',
640
640
  },
641
641
  formDataHeader: {
642
642
  'content-type': 'application/x-www-form-urlencoded',
643
643
  },
644
644
  },
645
645
  requestBaseParam: {
646
646
  data: null,
647
647
  header: {
648
648
  'content-type': 'application/json;charset=utf-8',
649
649
  },
650
650
  },
651
651
  timeOut: 7000,
652
652
  apiClientParams: {
653
653
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
654
654
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
655
655
  area: '1_72_2799_0',
656
656
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
657
657
  window.screen?.height * devicePixelRatio,
658
658
  )}`,
659
659
  uuid: UUID,
660
660
  },
661
661
  window.shopGlobalSwitch?.useNativeHarmonyAddCartJdAppVersion;
662
662
  nativeHarmonyAddCartJdAppVersion && jdAppVersionCompare(nativeHarmonyAddCartJdAppVersion) >= 0;
663
663
  public addressFetchInfo: {
664
664
  reqState: boolean;
665
665
  promiseInstance: null | Promise<any>;
666
666
  };
667
667
  public getPromotionConfig: {
668
668
  projectId: null | string | number;
669
669
  pageId: null | string | number;
670
670
  };
671
671
  public resInfo: ServiceInterFace.HttpRequestInfo;
672
672
  public api: ServiceInterFace.HttpApi;
673
673
  public isPageDomain: boolean;
674
674
  public verifyColorList: string[];
675
675
  private isShowJdShopCartFloatBtn: boolean;
676
676
  constructor(opt) {
677
677
  this._init();
678
678
  this.addressFetchInfo = {
679
679
  reqState: false,
680
680
  promiseInstance: null,
681
681
  };
682
682
  this.getPromotionConfig = {
683
683
  projectId: null,
684
684
  pageId: null,
685
685
  };
686
686
  this._userAreaUpdateListen();
687
687
  this.resInfo = this._getResConfig(opt);
688
688
  this.api = api;
689
689
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
690
690
  this.verifyColorList = [
691
691
  ...MobileVerifyColorList,
692
692
  ...AppVerifyColorList,
693
693
  ...JshopxVerifyColorList,
694
694
  ...BMallVerifyColorList,
695
695
  ];
696
696
  this.isShowJdShopCartFloatBtn =
697
697
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
698
698
  }
699
699
  _init(): void {
700
700
  httpInterceptors.forEach((item) => {
701
701
  Taro.addInterceptor((chain) => item(chain));
702
702
  });
703
703
  }
704
704
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
705
705
  return Object.assign({}, DefaultConfig, opt);
706
706
  }
707
707
 
708
708
  _userAreaUpdateListen() {
709
709
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
710
710
  this.updateApiClientParamsResInfo(areaInfo);
711
711
  console.log(
712
712
  'cone-render收到原生端获取传来的四级地址信息',
713
713
  areaInfo,
714
714
  '更新后的接口底层信息',
715
715
  this.resInfo.apiClientParams,
716
716
  );
717
717
  });
718
718
  }
719
719
  updateApiClientParamsResInfo(opt = {}) {
720
720
  const { area, realTimeArea, ...others } = opt;
721
721
  this.resInfo.apiClientParams = {
722
722
  ...this.resInfo.apiClientParams,
723
723
  ...others,
724
724
  };
725
725
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
726
726
  realTimeArea &&
727
727
  realTimeArea !== '' &&
728
728
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
729
729
  }
730
730
 
731
731
  checkFunctionIdToReturnAppId(functionId) {
732
732
  if (JshopxColorFunctionIdList.includes(functionId)) {
733
733
  return APPID.JSHOPX_COLOR_APPID;
734
734
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
735
735
  return APPID.PAGES_COLOR_APPID;
736
736
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
737
737
  return APPID.SHOP_MEMBER_COLOR_APPID;
738
738
  } else if (B2BColorFunctionIdList.includes(functionId)) {
739
739
  return APPID.B2B_COLOR_APPID;
740
740
  } else if (isPc) {
741
741
  return APPID.MALL_COLOR_APPID;
742
742
  } else {
743
743
  return APPID.SHOP_COLOR_APPID;
744
744
  }
745
745
  }
746
746
 
747
747
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
748
748
  if (
749
749
  functionId === 'receiveShopCoupon' &&
750
750
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
751
751
  isWxMinAndWxapp)
752
752
  ) {
753
753
  clientParams = Object.assign(
754
754
  {},
755
755
  {
756
756
  loginType: isAscfApp ? '2' : '1',
757
757
  loginWQBiz: WXAPP_BIZ_KEY,
758
758
  },
759
759
  clientParams,
760
760
  );
761
761
  }
762
762
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
763
763
  typeof apiClientParams.appid === 'undefined' &&
764
764
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
765
765
  const isColorVerify = this.verifyColorList.includes(functionId);
766
766
  const getReqData = {
767
767
  functionId: functionId,
768
768
  body: JSON.stringify(bodyParams),
769
769
  t: Date.now(),
770
770
  ...apiClientParams,
771
771
  };
772
772
  return http
773
773
  .request({
774
774
  url: this.api.apiFunc,
775
775
  data: getReqData,
776
776
  isColorVerify,
777
777
  })
778
778
  .then((res: ServiceInterFace.RequestPromiseRes) => {
779
779
  const { statusCode, data, status, msg } = res;
780
780
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
781
781
  ok: true,
782
782
  };
783
783
  if ((statusCode === 200 || status === '0') && data) {
784
784
  changeRes = this.dealResponseFormatRes(data);
785
785
  return changeRes;
786
786
  } else {
787
787
  changeRes = {
788
788
  ...data,
789
789
  statusCode,
790
790
  status,
791
791
  msg,
792
792
  ok: false,
793
793
  };
794
794
  return changeRes;
795
795
  }
796
796
  })
797
797
  .catch((res) => {
798
798
  const propertyNames = Object.getOwnPropertyNames(res);
799
799
  const resObject = {};
800
800
  propertyNames.forEach((propertyName) => {
801
801
  resObject[propertyName] = res[propertyName];
802
802
  });
803
803
  draInterfaceCustomReport({
804
804
  eventName: 'apiStatusCode',
805
805
  errorName: `shop_${functionId}_error`,
806
806
  errorMessage: `接口返回statusCode为${res?.statusCode || res?.status}`,
807
807
  url: this.api.apiFunc,
808
808
  source: 'remote',
809
809
  requestType: res?.requestType,
810
810
  functionId: getReqData?.functionId,
811
811
  appid: getReqData?.appid,
812
812
  client: getReqData?.client,
813
813
  clientVersion: getReqData?.clientVersion,
814
814
  statusCode: res?.statusCode,
815
815
  status: res?.status,
816
816
  statusText: res?.statusText,
817
817
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
818
818
  originReqDataStr: JSON.stringify(getReqData),
819
819
  });
820
820
  return {
821
821
  ...resObject,
822
822
  ok: false,
823
823
  } as ServiceInterFace.RequestResponseFormatRes;
824
824
  });
825
825
  }
826
826
 
827
827
  dealResponseFormatRes(data) {
828
828
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
829
829
  ok: true,
830
830
  };
831
831
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
832
832
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
833
833
  ? Number(data.subCode)
834
834
  : -1;
835
835
  if (
836
836
  data.success === true ||
837
837
  data.isSuccess ||
838
838
  resCode === 0 ||
839
839
  resCode === 200 ||
840
840
  subCode === 0
841
841
  ) {
842
842
  changeRes = {
843
843
  result: Object.prototype.hasOwnProperty.call(data, 'result')
844
844
  ? data.result
845
845
  : Object.prototype.hasOwnProperty.call(data, 'data')
846
846
  ? data.data
847
847
  : data,
848
848
  code: data.code ?? 200,
849
849
  ok: true,
850
850
  source: data,
851
851
  };
852
852
  return changeRes;
853
853
  } else {
854
854
  changeRes = {
855
855
  ...data,
856
856
  ok: false,
857
857
  };
858
858
  return changeRes;
859
859
  }
860
860
  }
861
861
 
862
862
  async receiveCoupon(param = {}, clientParams) {
863
863
  const loginType = isPc ? { loginType: 3 } : {};
864
864
  return await this.gatewayReq(
865
865
  'receiveShopCoupon',
866
866
  {
867
867
  operation: '3',
868
868
  ...param,
869
869
  },
870
870
  { ...loginType, ...clientParams },
871
871
  );
872
872
  }
873
873
 
874
874
  getCustomerCenterDispatch(params = {}) {
875
875
  return this.gatewayReq('customerCenterDispatch', params, {
876
876
  clientVersion: '9.2.0',
877
877
  client: 'H5',
878
878
  uuid: 88888,
879
879
  appid: 'shopmember_m_jd_com',
880
880
  });
881
881
  }
882
882
 
883
883
  batchAddCart(...args) {
884
884
  let skuIds, num, showToast, giftCard, extFlag;
885
885
  if (['number', 'string'].includes(typeof args[0])) {
886
886
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
887
887
  } else if (typeof args[0] === 'object' && args[0] !== null) {
888
888
  const params = args[0];
889
889
  skuIds = params.skuIds;
890
890
  num = params.num || 1;
891
891
  showToast = params.showToast !== undefined ? params.showToast : true;
892
892
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
893
893
  extFlag = params.extFlag !== undefined ? params.extFlag : null;
894
894
  } else {
895
895
  try {
896
896
  const data = {
897
897
  eventName: 'business',
898
898
  errorName: 'shop_batchAddCart_error',
899
899
  errorMessage: '入参不合法',
900
900
  extraData: JSON.stringify(args),
901
901
  };
902
902
  draBusinessCustomReport(data);
903
903
  } catch (e) {
904
904
  console.error('draBusinessCustomReport error:', e);
905
905
  }
906
906
  const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
907
907
  showFailToast({
908
908
  title: msg,
909
909
  });
910
910
  return Promise.resolve({
911
911
  ok: false,
912
912
  msg,
913
913
  });
914
914
  }
915
915
  const successMsg = giftCard
916
916
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
917
917
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
918
918
  const failMsg = giftCard
919
919
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
920
920
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
921
921
  if (skuIds) {
922
922
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard, extFlag })
923
923
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
924
924
  if (res?.ok) {
925
925
  showToast &&
926
926
  !res?.isOpenApp &&
927
927
  showSuccessToast({
928
928
  title: successMsg,
929
929
  });
930
930
  this.isShowJdShopCartFloatBtn &&
931
931
  sendNativePageToShowCartFloatBtn({
932
932
  isShow: true,
933
933
  });
934
934
  } else {
935
935
  showToast &&
936
936
  showFailToast({
937
937
  title: res?.errMsg || failMsg,
938
938
  });
939
939
  }
940
940
  return Promise.resolve(res);
941
941
  })
942
942
  .catch((e) => {
943
943
  console.log('调用加购方法异常=======>', e);
944
944
  return Promise.resolve({
945
945
  ok: false,
946
946
  msg: failMsg,
947
947
  });
948
948
  });
949
949
  } else {
950
950
  try {
951
951
  const data = {
952
952
  eventName: 'business',
953
953
  errorName: 'shop_batchAddCart_error',
954
954
  errorMessage: '没有传入合法的skuIds',
955
955
  };
956
956
  draBusinessCustomReport(data);
957
957
  } catch (e) {
958
958
  console.error('draBusinessCustomReport error:', e);
959
959
  }
960
960
  return Promise.resolve({
961
961
  ok: false,
962
962
  msg: failMsg,
963
963
  });
964
964
  }
965
965
  }
966
966
 
967
967
  async giftCardAddCart(skuList, num) {
968
968
  const loginType = isPc ? { loginType: 3 } : {};
969
969
  return this.gatewayReq(
970
970
  'giftCardAddCart',
971
971
  {
972
972
  skuList,
973
973
  num: Number(num),
974
974
  },
975
975
  { ...loginType },
976
976
  );
977
977
  }
978
978
 
979
979
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard, extFlag }) {
980
980
  return new Promise((resolve) => {
981
981
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
982
982
  if (productIdsArr.length > 0) {
983
983
  if (giftCard) {
984
984
  this.giftCardAddCart(productIdsArr, addCardNum)
985
985
  .then((res) => {
986
986
  if (res?.code === '0' && res?.result?.value) {
987
987
  resolve({
988
988
  ok: true,
989
989
  });
990
990
  } else {
991
991
  try {
992
992
  const data = {
993
993
  eventName: 'business',
994
994
  errorName: 'shop_batchAddCart_error',
995
995
  errorMessage: '礼品卡加车接口返回加车失败标识',
996
996
  };
997
997
  draBusinessCustomReport(data);
998
998
  } catch (e) {
999
999
  console.error('draBusinessCustomReport error:', e);
1000
1000
  }
1001
1001
  resolve({
1002
1002
  ok: false,
1003
1003
  msg: '加购失败,请稍后重试',
1004
1004
  });
1005
1005
  }
1006
1006
  })
1007
1007
  .catch((e) => {
1008
1008
  console.error('礼品卡加车失败: ', e);
1009
1009
  resolve({
1010
1010
  ok: false,
1011
1011
  msg: '加购失败,请稍后重试',
1012
1012
  });
1013
1013
  });
1014
1014
  } else if (
1015
1015
  isJdApp &&
1016
1016
  (!isHarmonyDevice || (isHarmonyDevice && useNativeHarmonyAddCartJd))
1017
1017
  ) {
1018
1018
  const nativeAddCartCallBack = `nativeBatchAddCart${
1019
1019
  Date.now() + Number(productIdsArr[0]) + Number(addCardNum)
1020
1020
  }`;
1021
1021
  console.log(
1022
1022
  '==========>',
1023
1023
  '使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
1024
1024
  nativeAddCartCallBack,
1025
1025
  );
1026
1026
  if (!window[nativeAddCartCallBack]) {
1027
1027
  window[nativeAddCartCallBack] = (res) => {
1028
1028
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
1029
1029
  console.info(
1030
1030
  '获取批量加车原始数据',
1031
1031
  res,
1032
1032
  '====转换后的json数据为===',
1033
1033
  getMessageJsonData,
1034
1034
  );
1035
1035
  try {
1036
1036
  if (isAndroidDevice) {
1037
1037
  const isOk = getMessageJsonData?.status === '0';
1038
1038
  isOk
1039
1039
  ? resolve({
1040
1040
  ok: true,
1041
1041
  msg: '已加入购物车!',
1042
1042
  })
1043
1043
  : resolve({
1044
1044
  ok: false,
1045
1045
  msg: '加购失败,请稍后重试',
1046
1046
  errMsg: getMessageJsonData?.data?.message ?? '',
1047
1047
  });
1048
1048
  if (!isOk) {
1049
1049
  const data = {
1050
1050
  eventName: 'business',
1051
1051
  errorName: 'shop_batchAddCart_error',
1052
1052
  errorMessage: 'H5调用Android原生加车失败',
1053
1053
  };
1054
1054
  draBusinessCustomReport(data);
1055
1055
  }
1056
1056
  } else if (isIosDevice) {
1057
1057
  const isOk =
1058
1058
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
1059
1059
  isOk
1060
1060
  ? resolve({
1061
1061
  ok: true,
1062
1062
  msg: '已加入购物车!',
1063
1063
  })
1064
1064
  : resolve({
1065
1065
  ok: false,
1066
1066
  msg: '批量加车失败,请稍后重试',
1067
1067
  errMsg: getMessageJsonData?.data?.message ?? '',
1068
1068
  });
1069
1069
  if (!isOk) {
1070
1070
  const data = {
1071
1071
  eventName: 'business',
1072
1072
  errorName: 'shop_batchAddCart_error',
1073
1073
  errorMessage: 'H5调用IOS原生加车失败',
1074
1074
  };
1075
1075
  draBusinessCustomReport(data);
1076
1076
  }
1077
1077
  } else if (isHarmonyDevice) {
1078
1078
  const isOk =
1079
1079
  getMessageJsonData?.data?.code === 0 &&
1080
1080
  getMessageJsonData?.data?.response?.resultCode === 0;
1081
1081
  isOk
1082
1082
  ? resolve({
1083
1083
  ok: true,
1084
1084
  msg: '已加入购物车!',
1085
1085
  })
1086
1086
  : resolve({
1087
1087
  ok: false,
1088
1088
  msg: '加购失败,请稍后重试',
1089
1089
  errMsg: getMessageJsonData?.data?.message ?? '',
1090
1090
  });
1091
1091
  if (!isOk) {
1092
1092
  const data = {
1093
1093
  eventName: 'business',
1094
1094
  errorName: 'shop_batchAddCart_error',
1095
1095
  errorMessage: 'H5调用Harmony原生加车失败',
1096
1096
  };
1097
1097
  draBusinessCustomReport(data);
1098
1098
  }
1099
1099
  } else {
1100
1100
  resolve({
1101
1101
  ok: false,
1102
1102
  msg: '加购失败,请稍后重试',
1103
1103
  });
1104
1104
  const data = {
1105
1105
  eventName: 'business',
1106
1106
  errorName: 'shop_batchAddCart_error',
1107
1107
  errorMessage: 'H5调用未知原生加车失败',
1108
1108
  };
1109
1109
  draBusinessCustomReport(data);
1110
1110
  }
1111
1111
  } catch (e) {
1112
1112
  resolve({
1113
1113
  ok: false,
1114
1114
  msg: '加购失败,请稍后重试',
1115
1115
  });
1116
1116
  console.warn('批量加车转换数据异常', e);
1117
1117
  const data = {
1118
1118
  eventName: 'business',
1119
1119
  errorName: 'shop_batchAddCart_error',
1120
1120
  errorMessage: '批量加车转换数据异常',
1121
1121
  };
1122
1122
  draBusinessCustomReport(data);
1123
1123
  }
1124
1124
  window[nativeAddCartCallBack] = null;
1125
1125
  };
1126
1126
  }
1127
1127
  const productsAddCartList = productIdsArr.map((skuItem) => {
1128
1128
  const adInfos = getAdInfoBySkuId(skuItem);
1129
1129
  let allExtFlag = typeof extFlag === 'object' ? extFlag : {};
1130
1130
  if (adInfos) {
1131
1131
  allExtFlag = Object.assign({}, allExtFlag, { adInfos });
1132
1132
  }
1133
1133
  let item = null;
1134
1134
  if (isAndroidDevice) {
1135
1135
  item = {
1136
1136
  sku: skuItem,
1137
1137
  num: addCardNum,
1138
1138
  extFlag: allExtFlag,
1139
1139
  };
1140
1140
  } else if (isIosDevice) {
1141
1141
  item = {
1142
1142
  productCode: skuItem,
1143
1143
  buyCount: addCardNum,
1144
1144
  extFlag: allExtFlag,
1145
1145
  };
1146
1146
  } else if (isHarmonyDevice) {
1147
1147
  item = {
1148
1148
  sourceType: 'native',
1149
1149
  sourceValue: 'shop',
1150
1150
  productCode: skuItem,
1151
1151
  buyCount: addCardNum,
1152
1152
  extFlag: allExtFlag,
1153
1153
  };
1154
1154
  }
1155
1155
  return item;
1156
1156
  });
1157
1157
  if (isAndroidDevice) {
1158
1158
  const androidProductsStr = JSON.stringify(productsAddCartList);
1159
1159
  callRouterAndroid({
1160
1160
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
1161
1161
  routerParam: {
1162
1162
  wareList: productsAddCartList,
1163
1163
  },
1164
1164
  callBackName: nativeAddCartCallBack,
1165
1165
  });
1166
1166
  } else if (isIosDevice) {
1167
1167
  if (isLowAppVer) {
1168
1168
  const lowVersionAppList = productIdsArr.map((skuItem) => {
1169
1169
  return {
1170
1170
  sku: skuItem,
1171
1171
  num: addCardNum,
1172
1172
  };
1173
1173
  });
1174
1174
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
1175
1175
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
1176
1176
  jump.side.jdJumpToWeb(url, {});
1177
1177
  resolve({
1178
1178
  ok: true,
1179
1179
  isOpenApp: true,
1180
1180
  msg: '加购完成, 加购结果请点击购物车确认',
1181
1181
  });
1182
1182
  } else {
1183
1183
  callRouterIOS({
1184
1184
  routerURL: 'router://JDCartModule/batchAddService',
1185
1185
  routerParam: {
1186
1186
  sourceType: 'h5',
1187
1187
  sourceValue: '店铺批量加购',
1188
1188
  businessName: 'storeModel',
1189
1189
  isNewMode: '1',
1190
1190
  NotPassWebview: '1',
1191
1191
  products: productsAddCartList,
1192
1192
  },
1193
1193
  callBackName: nativeAddCartCallBack,
1194
1194
  });
1195
1195
  }
1196
1196
  } else if (isHarmonyDevice) {
1197
1197
  callRouterHarmony({
1198
1198
  routerURL: 'router://JDCartModule/batchAddService',
1199
1199
  routerParam: {
1200
1200
  sourceType: 'native',
1201
1201
  sourceValue: 'shop',
1202
1202
  products: productsAddCartList,
1203
1203
  },
1204
1204
  callBackName: nativeAddCartCallBack,
1205
1205
  });
1206
1206
  }
1207
1207
  } else if (isMin) {
1208
1208
  console.log('==========>', '京购批量加车!');
1209
1209
  const productsAddCartList = productIdsArr.map((skuItem) => {
1210
1210
  return {
1211
1211
  skuId: skuItem,
1212
1212
  buyNum: addCardNum,
1213
1213
  };
1214
1214
  });
1215
1215
  global.wxAppBizInstance
1216
1216
  .addCart({ commArr: productsAddCartList })
1217
1217
  .then((res) => {
1218
1218
  console.log('dealCartSuccess: ', res);
1219
1219
  resolve({
1220
1220
  ok: true,
1221
1221
  msg: '已加入购物车!',
1222
1222
  data: res,
1223
1223
  });
1224
1224
  })
1225
1225
  .catch((e) => {
1226
1226
  console.log('京购小程序批量加车失败dealCartFail: ', e);
1227
1227
  resolve({
1228
1228
  ok: false,
1229
1229
  msg: '加购失败,请稍后重试',
1230
1230
  });
1231
1231
  const data = {
1232
1232
  eventName: 'business',
1233
1233
  errorName: 'shop_batchAddCart_error',
1234
1234
  errorMessage: 'H5调用小程序加车失败',
1235
1235
  };
1236
1236
  draBusinessCustomReport(data);
1237
1237
  });
1238
1238
  } else {
1239
1239
  console.log('==========>', '使用M站批量加车!');
1240
1240
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
1241
1241
  }
1242
1242
  } else {
1243
1243
  resolve({
1244
1244
  ok: false,
1245
1245
  msg: '加购sku不能为空',
1246
1246
  });
1247
1247
  const data = {
1248
1248
  eventName: 'business',
1249
1249
  errorName: 'shop_batchAddCart_error',
1250
1250
  errorMessage: '加购sku不能为空',
1251
1251
  };
1252
1252
  draBusinessCustomReport(data);
1253
1253
  }
1254
1254
  });
1255
1255
  }
1256
1256
 
1257
1257
  productAddToCart(skuIdsStr, num) {
1258
1258
  return new Promise((resolve) => {
1259
1259
  if (window.AddcartToolObj) {
1260
1260
  window.AddcartToolObj.addCart({
1261
1261
  skuId: skuIdsStr,
1262
1262
  num,
1263
1263
  source: 'sjdpyw',
1264
1264
  actId: '1',
1265
1265
  loginType: isAscfApp ? '2' : window?.isJingGouMiniViewState ? '11' : isPc ? '3' : '2',
1266
1266
  sucFun(res) {
1267
1267
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
1268
1268
  if (res.errId === '0' && res.cartJson) {
1269
1269
  resolve({
1270
1270
  ok: true,
1271
1271
  msg: '已加入购物车!',
1272
1272
  ...res,
1273
1273
  });
1274
1274
  } else {
1275
1275
  if (res.errId === '13') {
1276
1276
  global.doLogin();
1277
1277
  } else {
1278
1278
  resolve({
1279
1279
  ok: false,
1280
1280
  msg: '加购失败,请稍后重试',
1281
1281
  ...res,
1282
1282
  });
1283
1283
  const data = {
1284
1284
  eventName: 'business',
1285
1285
  errorName: 'shop_batchAddCart_error',
1286
1286
  errorMessage: 'H5调用M站加车失败',
1287
1287
  };
1288
1288
  draBusinessCustomReport(data);
1289
1289
  }
1290
1290
  }
1291
1291
  },
1292
1292
  failFun(err) {
1293
1293
  console.log('fail', err);
1294
1294
  resolve({
1295
1295
  ok: false,
1296
1296
  msg: '加购失败,请稍后重试',
1297
1297
  ...err,
1298
1298
  });
1299
1299
  const data = {
1300
1300
  eventName: 'business',
1301
1301
  errorName: 'shop_batchAddCart_error',
1302
1302
  errorMessage: 'H5调用M站加车失败',
1303
1303
  };
1304
1304
  draBusinessCustomReport(data);
1305
1305
  },
1306
1306
  });
1307
1307
  } else {
1308
1308
  resolve({
1309
1309
  ok: false,
1310
1310
  msg: '购物车方法检查异常',
1311
1311
  });
1312
1312
  const data = {
1313
1313
  eventName: 'business',
1314
1314
  errorName: 'shop_batchAddCart_error',
1315
1315
  errorMessage: 'H5调用M站加车检查依赖方法异常',
1316
1316
  };
1317
1317
  draBusinessCustomReport(data);
1318
1318
  }
1319
1319
  });
1320
1320
  }
1321
1321
  bMallGetUserInfo = () => {
1322
1322
  return getBMallUserInfo();
1323
1323
  };
1324
1324
  async bMallAddCart(params = {}) {
1325
1325
  return await this.gatewayReq('bmall_cartAdd', params, {
1326
1326
  client: 'H5',
1327
1327
  clientVersion: '5.5.0',
1328
1328
  });
1329
1329
  }
1330
1330
  async bMallChangeCart(params = {}) {
1331
1331
  return await this.gatewayReq('bmall_cartChange', params, {
1332
1332
  client: 'H5',
1333
1333
  clientVersion: '5.5.0',
1334
1334
  });
1335
1335
  }
1336
1336
  async bMallRemoveCart(params = {}) {
1337
1337
  return await this.gatewayReq(
1338
1338
  'bmall_cartRemove',
1339
1339
  params,
1340
1340
  {
1341
1341
  client: 'H5',
1342
1342
  clientVersion: '5.5.0',
1343
1343
  },
1344
1344
  );
1345
1345
  }
1346
1346
  async bMallGetOmittedProduct(params = {}) {
1347
1347
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
1348
1348
  client: 'H5',
1349
1349
  clientVersion: '5.5.0',
1350
1350
  });
1351
1351
  }
1352
1352
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
1353
1353
  const params = await getParams({ ...data, skuId, bMallTag, num });
1354
1354
  return await this.bMallAddCart(params);
1355
1355
  }
1356
1356
  async bMallGetSkuNumService(bMallTag = 1) {
1357
1357
  const params = await getParams({ bMallTag });
1358
1358
  delete params.operations;
1359
1359
  return await this.bMallGetOmittedProduct(params);
1360
1360
  }
1361
1361
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1362
1362
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1363
1363
  return await this.bMallRemoveCart(params);
1364
1364
  }
1365
1365
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
1366
1366
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
1367
1367
  return await this.bMallChangeCart(params);
1368
1368
  }
1369
1369
 
1370
1370
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
1371
1371
  if (!needRequest && isH5 && window?.bMallCartData) {
1372
1372
  return window?.bMallCartData;
1373
1373
  }
1374
1374
  const cartData = await this.bMallGetSkuNumService(bMallTag);
1375
1375
  let items;
1376
1376
  if (cartData.ok && cartData.result) {
1377
1377
  items = cartData?.result?.items || {};
1378
1378
  }
1379
1379
  if (isH5) {
1380
1380
  window.bMallCartData = items;
1381
1381
  }
1382
1382
  return items;
1383
1383
  }
1384
1384
 
1385
1385
  async bMallCartHandle(goodItem, num) {
1386
1386
  try {
1387
1387
  const {
1388
1388
  skuUuid,
1389
1389
  limitUpper,
1390
1390
  limitLower,
1391
1391
  } = goodItem;
1392
1392
  let cartNum = Number(num);
1393
1393
  if (limitLower && cartNum && cartNum < limitLower) {
1394
1394
  cartNum = limitLower;
1395
1395
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
1396
1396
  cartNum = limitUpper;
1397
1397
  }
1398
1398
  if (skuUuid && cartNum > 0) {
1399
1399
  return this.bMallChangeCartService({
1400
1400
  ...goodItem,
1401
1401
  skuUuid,
1402
1402
  num: cartNum,
1403
1403
  });
1404
1404
  } else if (!skuUuid && cartNum > 0) {
1405
1405
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
1406
1406
  } else if (skuUuid && !cartNum) {
1407
1407
  return this.bMallRemoveCartService({
1408
1408
  ...goodItem,
1409
1409
  skuUuid,
1410
1410
  num: cartNum,
1411
1411
  });
1412
1412
  } else {
1413
1413
  console.error('参数不全');
1414
1414
  return false;
1415
1415
  }
1416
1416
  } catch (e) {
1417
1417
  console.error(e);
1418
1418
  }
1419
1419
  }