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