@conecli/cone-render 0.10.1-isv2.1 → 0.10.1-isv2.4

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 (111) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/environmentType.ts +1 -1
  4. package/dist/common/index.h5.ts +1 -1
  5. package/dist/common/index.jd.ts +1 -1
  6. package/dist/common/index.ts +1 -1
  7. package/dist/common/index.weapp.ts +1 -1
  8. package/dist/common/jssdk.ts +1 -1
  9. package/dist/common/pageType.ts +1 -1
  10. package/dist/common/sgmCustomCode.ts +1 -1
  11. package/dist/common/token/index.h5.ts +1 -1
  12. package/dist/common/token/token.jd.ts +1 -1
  13. package/dist/common/wxappApi.ts +1 -1
  14. package/dist/components/ErrorBoundary.tsx +1 -1
  15. package/dist/components/base/CommonFloorHead/index.module.scss +126 -111
  16. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  17. package/dist/components/base/CountDown/index.module.scss +49 -44
  18. package/dist/components/base/CountDown/index.tsx +1 -1
  19. package/dist/components/base/CustomScrollView/index-back.tsx +1 -0
  20. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  21. package/dist/components/base/CustomVideo/common.ts +1 -0
  22. package/dist/components/base/CustomVideo/index.tsx +1 -1
  23. package/dist/components/base/Dialog/index.module.scss +11 -0
  24. package/dist/components/base/ExposureSmart/index.h5.module.scss +12 -2
  25. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  26. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  27. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  28. package/dist/components/base/InViewRender/index.tsx +1 -1
  29. package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
  30. package/dist/components/base/ItemViewExposureSmart/index.module.scss +2 -2
  31. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  32. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  33. package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
  34. package/dist/components/base/LazyLoadImage/index.h5.module.scss +11 -3
  35. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  36. package/dist/components/base/LazyLoadImage/index.tsx +1 -1
  37. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  38. package/dist/components/base/NetworkDataError/index.module.scss +3 -0
  39. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  40. package/dist/components/base/Price/Base/index.tsx +1 -1
  41. package/dist/components/base/Price/Double/index.module.scss +8 -0
  42. package/dist/components/base/Price/Double/index.tsx +1 -1
  43. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  44. package/dist/components/decorate/DecorateFloorModule/index.module.scss +11 -0
  45. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  46. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  47. package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
  48. package/dist/components/floorItem.jd.tsx +1 -1
  49. package/dist/components/floorItem.tsx +1 -1
  50. package/dist/components/floorItem.weapp.tsx +1 -1
  51. package/dist/components/isv/Floor/index.tsx +1 -1
  52. package/dist/components/remoteFloorItem.tsx +1 -1
  53. package/dist/interface/common.ts +1 -1
  54. package/dist/interface/component.ts +1 -1
  55. package/dist/interface/jumpEventReport.ts +1 -1
  56. package/dist/interface/service.ts +1 -1
  57. package/dist/jumpEventReport/base.ts +1 -1
  58. package/dist/jumpEventReport/const.ts +1 -1
  59. package/dist/jumpEventReport/index.jd.ts +1 -1
  60. package/dist/jumpEventReport/index.weapp.ts +1 -1
  61. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  62. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  63. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  64. package/dist/jumpEventReport/web/report.ts +1 -1
  65. package/dist/jumpEventReport/web.base.ts +1 -1
  66. package/dist/jumpEventReport/web.jd.ts +1 -1
  67. package/dist/jumpEventReport/web.jdb.ts +1 -1
  68. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  69. package/dist/jumpEventReport/web.jxwxapp.ts +1 -1
  70. package/dist/jumpEventReport/web.pc.ts +1 -1
  71. package/dist/jumpEventReport/web.tjapp.ts +1 -1
  72. package/dist/jumpEventReport/web.tjm.ts +1 -1
  73. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  74. package/dist/libs/taroAppReport.js +2 -2
  75. package/dist/modules/ContainerFloorList/index.h5.module.scss +66 -52
  76. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  77. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  78. package/dist/open/api/device.ts +1 -1
  79. package/dist/open/api/environment.ts +1 -1
  80. package/dist/open/api/request.ts +1 -1
  81. package/dist/open/api/shopMember.ts +1 -1
  82. package/dist/open/api/util.ts +1 -1
  83. package/dist/open/components/index.ts +1 -1
  84. package/dist/sass/app.h5.scss +275 -221
  85. package/dist/sass/base.scss +183 -137
  86. package/dist/service/fetchGateway.ts +1 -1
  87. package/dist/service/fetchGateway.weapp.ts +1 -0
  88. package/dist/service/http/colorSign.ts +1 -1
  89. package/dist/service/http/const.ts +1 -1
  90. package/dist/service/http/h5Http.ts +1 -0
  91. package/dist/service/http/index.h5.ts +1 -0
  92. package/dist/service/requestServer.h5.ts +1 -0
  93. package/dist/service/requestServer.ts +1 -1
  94. package/dist/service/requestServer.weapp.ts +1 -0
  95. package/dist/utils/connectNativeJsBridge.ts +1 -1
  96. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  97. package/dist/utils/h5Utils.ts +1 -1
  98. package/dist/utils/index.h5.ts +1 -1
  99. package/dist/utils/index.ts +1 -1
  100. package/dist/utils/index.weapp.ts +1 -1
  101. package/dist/utils/jumpExtMapUtil.h5.ts +1 -0
  102. package/dist/utils/jumpExtMapUtil.ts +1 -0
  103. package/dist/utils/log.ts +1 -0
  104. package/dist/utils/sColor.js +1 -0
  105. package/dist/utils/sgmCodeUtils.ts +1 -1
  106. package/dist/utils/taroRenderUtil.ts +1 -1
  107. package/dist/utils/utils.ts +1 -1
  108. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  109. package/dist/wxapp/common/user_info.js +1 -1
  110. package/package.json +158 -135
  111. package/dist/utils/memberFormatUtils.js +0 -1
@@ -0,0 +1 @@
1
+ import Taro from '@tarojs/taro';
2
  APPID,
1
3
  JshopxColorFunctionIdList,
2
4
  PagesColorFunctionIdList,
3
5
  PAGES_DOMAIN,
4
6
  B2BColorFunctionIdList,
5
7
  MobileVerifyColorList,
6
8
  AppVerifyColorList,
7
9
  JshopxVerifyColorList,
8
10
  BMallVerifyColorList,
9
11
  shopMemberColorFunctionIdList,
10
12
  draBusinessCustomReport,
11
13
  isLanguageForEn,
12
14
  isJdApp,
13
15
  isIosDevice,
14
16
  isAndroidDevice,
15
17
  isJdAndHarmonyDevice,
16
18
  showSuccessToast,
17
19
  showFailToast,
18
20
  isH5,
19
21
  isWxMinAndWxapp,
20
22
  isMin,
21
23
  isPc,
22
24
  draInterfaceCustomReport,
23
25
  callRouterIOS,
24
26
  callRouterAndroid,
25
27
  sendNativePageToShowCartFloatBtn,
26
28
  cookiesStr: '',
27
29
  requestHeaderContentType: {
28
30
  jsonHeader: {
29
31
  'content-type': 'application/json;charset=utf-8',
30
32
  },
31
33
  formDataHeader: {
32
34
  'content-type': 'application/x-www-form-urlencoded',
33
35
  },
34
36
  },
35
37
  requestBaseParam: {
36
38
  data: null,
37
39
  header: {
38
40
  'content-type': 'application/json;charset=utf-8',
39
41
  },
40
42
  },
41
43
  timeOut: 7000,
42
44
  apiClientParams: {
43
45
  clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
44
46
  client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
45
47
  area: '1_72_2799_0',
46
48
  screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
47
49
  window.screen?.height * devicePixelRatio,
48
50
  )}`,
49
51
  uuid: UUID,
50
52
  },
51
53
  public addressFetchInfo: {
52
54
  reqState: boolean;
53
55
  promiseInstance: null | Promise<any>;
54
56
  };
55
57
  public getPromotionConfig: {
56
58
  projectId: null | string | number;
57
59
  pageId: null | string | number;
58
60
  };
59
61
  public resInfo: ServiceInterFace.HttpRequestInfo;
60
62
  public api: ServiceInterFace.HttpApi;
61
63
  public isPageDomain: boolean;
62
64
  public verifyColorList: string[];
63
65
  private isShowJdShopCartFloatBtn: boolean;
64
66
  constructor(opt) {
65
67
  this._init();
66
68
  this.addressFetchInfo = {
67
69
  reqState: false,
68
70
  promiseInstance: null,
69
71
  };
70
72
  this.getPromotionConfig = {
71
73
  projectId: null,
72
74
  pageId: null,
73
75
  };
74
76
  this._userAreaUpdateListen();
75
77
  this.resInfo = this._getResConfig(opt);
76
78
  this.api = api;
77
79
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
78
80
  this.verifyColorList = [
79
81
  ...MobileVerifyColorList,
80
82
  ...AppVerifyColorList,
81
83
  ...JshopxVerifyColorList,
82
84
  ...BMallVerifyColorList,
83
85
  ];
84
86
  this.isShowJdShopCartFloatBtn =
85
87
  jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
86
88
  }
87
89
  _init(): void {
88
90
  httpInterceptors.forEach((item) => {
89
91
  Taro.addInterceptor((chain) => item(chain));
90
92
  });
91
93
  }
92
94
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
93
95
  return Object.assign({}, DefaultConfig, opt);
94
96
  }
95
97
 
96
98
  _userAreaUpdateListen() {
97
99
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
98
100
  this.updateApiClientParamsResInfo(areaInfo);
99
101
  console.log(
100
102
  'cone-render收到原生端获取传来的四级地址信息',
101
103
  areaInfo,
102
104
  '更新后的接口底层信息',
103
105
  this.resInfo.apiClientParams,
104
106
  );
105
107
  });
106
108
  }
107
109
  updateApiClientParamsResInfo(opt = {}) {
108
110
  const { area, realTimeArea, ...others } = opt;
109
111
  this.resInfo.apiClientParams = {
110
112
  ...this.resInfo.apiClientParams,
111
113
  ...others,
112
114
  };
113
115
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
114
116
  realTimeArea &&
115
117
  realTimeArea !== '' &&
116
118
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
117
119
  }
118
120
 
119
121
  checkFunctionIdToReturnAppId(functionId) {
120
122
  if (JshopxColorFunctionIdList.includes(functionId)) {
121
123
  return APPID.JSHOPX_COLOR_APPID;
122
124
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
123
125
  return APPID.PAGES_COLOR_APPID;
124
126
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
125
127
  return APPID.SHOP_MEMBER_COLOR_APPID;
126
128
  } else if (B2BColorFunctionIdList.includes(functionId)) {
127
129
  return APPID.B2B_COLOR_APPID;
128
130
  } else if (isPc) {
129
131
  return APPID.MALL_COLOR_APPID;
130
132
  } else {
131
133
  return APPID.SHOP_COLOR_APPID;
132
134
  }
133
135
  }
134
136
 
135
137
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
136
138
  if (
137
139
  functionId === 'receiveShopCoupon' &&
138
140
  ((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
139
141
  isWxMinAndWxapp)
140
142
  ) {
141
143
  clientParams = Object.assign(
142
144
  {},
143
145
  {
144
146
  loginType: '1',
145
147
  loginWQBiz: WXAPP_BIZ_KEY,
146
148
  },
147
149
  clientParams,
148
150
  );
149
151
  }
150
152
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
151
153
  typeof apiClientParams.appid === 'undefined' &&
152
154
  (apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
153
155
  const isColorVerify = this.verifyColorList.includes(functionId);
154
156
  const getReqData = {
155
157
  functionId: functionId,
156
158
  body: JSON.stringify(bodyParams),
157
159
  t: Date.now(),
158
160
  ...apiClientParams,
159
161
  };
160
162
  return http
161
163
  .request({
162
164
  url: this.api.apiFunc,
163
165
  data: getReqData,
164
166
  isColorVerify,
165
167
  })
166
168
  .then((res: ServiceInterFace.RequestPromiseRes) => {
167
169
  const { statusCode, data, status, msg } = res;
168
170
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
169
171
  ok: true,
170
172
  };
171
173
  if ((statusCode === 200 || status === '0') && data) {
172
174
  changeRes = this.dealResponseFormatRes(data);
173
175
  return changeRes;
174
176
  } else {
175
177
  changeRes = {
176
178
  ...data,
177
179
  statusCode,
178
180
  status,
179
181
  msg,
180
182
  ok: false,
181
183
  };
182
184
  return changeRes;
183
185
  }
184
186
  })
185
187
  .catch((res) => {
186
188
  const propertyNames = Object.getOwnPropertyNames(res);
187
189
  const resObject = {};
188
190
  propertyNames.forEach((propertyName) => {
189
191
  resObject[propertyName] = res[propertyName];
190
192
  });
191
193
  draInterfaceCustomReport({
192
194
  subMsg:
193
195
  '接口请求异常,进入catch逻辑,例如h5请求神盾(反爬、小号、风控)或加固拦截返回status为403等',
194
196
  url: this.api.apiFunc,
195
197
  source: 'remote',
196
198
  requestType: res?.requestType,
197
199
  errorType: 'catchError',
198
200
  functionId: getReqData?.functionId,
199
201
  appid: getReqData?.appid,
200
202
  client: getReqData?.client,
201
203
  clientVersion: getReqData?.clientVersion,
202
204
  statusCode: res?.statusCode,
203
205
  status: res?.status,
204
206
  statusText: res?.statusText,
205
207
  code: res?.data?.code || res?.data?.subCode,
206
208
  errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
207
209
  originReqDataStr: JSON.stringify(getReqData),
208
210
  originResDataStr: JSON.stringify(res, propertyNames),
209
211
  });
210
212
  return {
211
213
  ...resObject,
212
214
  ok: false,
213
215
  } as ServiceInterFace.RequestResponseFormatRes;
214
216
  });
215
217
  }
216
218
 
217
219
  dealResponseFormatRes(data) {
218
220
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
219
221
  ok: true,
220
222
  };
221
223
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
222
224
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
223
225
  ? Number(data.subCode)
224
226
  : -1;
225
227
  if (
226
228
  data.success === true ||
227
229
  data.isSuccess ||
228
230
  resCode === 0 ||
229
231
  resCode === 200 ||
230
232
  subCode === 0
231
233
  ) {
232
234
  changeRes = {
233
235
  result: Object.prototype.hasOwnProperty.call(data, 'result')
234
236
  ? data.result
235
237
  : Object.prototype.hasOwnProperty.call(data, 'data')
236
238
  ? data.data
237
239
  : data,
238
240
  code: data.code ?? 200,
239
241
  ok: true,
240
242
  source: data,
241
243
  };
242
244
  return changeRes;
243
245
  } else {
244
246
  changeRes = {
245
247
  ...data,
246
248
  ok: false,
247
249
  };
248
250
  return changeRes;
249
251
  }
250
252
  }
251
253
 
252
254
  async receiveCoupon(param = {}, clientParams) {
253
255
  const loginType = isPc ? { loginType: 3 } : {};
254
256
  return await this.gatewayReq(
255
257
  'receiveShopCoupon',
256
258
  {
257
259
  operation: '3',
258
260
  ...param,
259
261
  },
260
262
  { ...loginType, ...clientParams },
261
263
  );
262
264
  }
263
265
 
264
266
  getCustomerCenterDispatch(params = {}) {
265
267
  return this.gatewayReq('customerCenterDispatch', params, {
266
268
  clientVersion: '9.2.0',
267
269
  client: 'H5',
268
270
  uuid: 88888,
269
271
  appid: 'shopmember_m_jd_com',
270
272
  });
271
273
  }
272
274
 
273
275
  batchAddCart(...args) {
274
276
  let skuIds, num, showToast, giftCard;
275
277
  if (['number', 'string'].includes(typeof args[0])) {
276
278
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
277
279
  } else if (typeof args[0] === 'object' && args[0] !== null) {
278
280
  const params = args[0];
279
281
  skuIds = params.skuIds;
280
282
  num = params.num || 1;
281
283
  showToast = params.showToast !== undefined ? params.showToast : true;
282
284
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
283
285
  } else {
284
286
  console.error('batchAddCart() Invalid arguments!', args);
285
287
  try {
286
288
  const data = {
287
289
  type: 'batchAddCart',
288
290
  subType: 'invalidInputParameter',
289
291
  errMsg: '入参不合法',
290
292
  originData: args,
291
293
  };
292
294
  draBusinessCustomReport(data);
293
295
  } catch (e) {
294
296
  console.error('draBusinessCustomReport error:', e);
295
297
  }
296
298
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
297
299
  showFailToast({
298
300
  title: msg,
299
301
  });
300
302
  return Promise.resolve({
301
303
  ok: false,
302
304
  msg,
303
305
  });
304
306
  }
305
307
  const addToWhereText = giftCard ? '购物清单' : '购物车';
306
308
  const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
307
309
  const failMsg = isLanguageForEn
308
310
  ? 'Please retry later'
309
311
  : `加入${addToWhereText}失败,请稍后重试!`;
310
312
  if (skuIds) {
311
313
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
312
314
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
313
315
  if (res?.ok) {
314
316
  showToast &&
315
317
  !res?.isOpenApp &&
316
318
  showSuccessToast({
317
319
  title: successMsg,
318
320
  });
319
321
  this.isShowJdShopCartFloatBtn &&
320
322
  sendNativePageToShowCartFloatBtn({
321
323
  isShow: true,
322
324
  });
323
325
  } else {
324
326
  showToast &&
325
327
  showFailToast({
326
328
  title: res?.errMsg || failMsg,
327
329
  });
328
330
  }
329
331
  return Promise.resolve(res);
330
332
  })
331
333
  .catch((e) => {
332
334
  console.log('调用加购方法异常=======>', e);
333
335
  return Promise.resolve({
334
336
  ok: false,
335
337
  msg: failMsg,
336
338
  });
337
339
  });
338
340
  } else {
339
341
  try {
340
342
  const data = {
341
343
  type: 'batchAddCart',
342
344
  subType: 'invalidInputParameter',
343
345
  errMsg: '没有传入合法的skuIds',
344
346
  originData: skuIds,
345
347
  };
346
348
  draBusinessCustomReport(data);
347
349
  } catch (e) {
348
350
  console.error('draBusinessCustomReport error:', e);
349
351
  }
350
352
  return Promise.resolve({
351
353
  ok: false,
352
354
  msg: failMsg,
353
355
  });
354
356
  }
355
357
  }
356
358
 
357
359
  async giftCardAddCart(skuList, num) {
358
360
  const loginType = isPc ? { loginType: 3 } : {};
359
361
  return this.gatewayReq(
360
362
  'giftCardAddCart',
361
363
  {
362
364
  skuList,
363
365
  num: Number(num),
364
366
  },
365
367
  { ...loginType },
366
368
  );
367
369
  }
368
370
 
369
371
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
370
372
  return new Promise((resolve) => {
371
373
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
372
374
  if (productIdsArr.length > 0) {
373
375
  if (giftCard) {
374
376
  this.giftCardAddCart(productIdsArr, addCardNum)
375
377
  .then((res) => {
376
378
  if (res?.code === '0' && res?.result?.value) {
377
379
  resolve({
378
380
  ok: true,
379
381
  });
380
382
  } else {
381
383
  try {
382
384
  const data = {
383
385
  type: 'batchAddCart',
384
386
  subType: 'addCartFailByGiftCard',
385
387
  errMsg: '礼品卡加车接口返回加车失败标识',
386
388
  originData: res,
387
389
  };
388
390
  draBusinessCustomReport(data);
389
391
  } catch (e) {
390
392
  console.error('draBusinessCustomReport error:', e);
391
393
  }
392
394
  resolve({
393
395
  ok: false,
394
396
  msg: '加购失败,请稍后重试',
395
397
  });
396
398
  }
397
399
  })
398
400
  .catch((e) => {
399
401
  console.error('礼品卡加车失败: ', e);
400
402
  resolve({
401
403
  ok: false,
402
404
  msg: '加购失败,请稍后重试',
403
405
  });
404
406
  });
405
407
  } else if (isJdApp && !isJdAndHarmonyDevice) {
406
408
  const nativeAddCartCallBack = `nativeBatchAddCart${Date.now() + Number(productIdsArr[0]) + Number(addCardNum)}`;
407
409
  console.log(
408
410
  '==========>',
409
411
  '原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
410
412
  nativeAddCartCallBack,
411
413
  );
412
414
  if (!window[nativeAddCartCallBack]) {
413
415
  window[nativeAddCartCallBack] = (res) => {
414
416
  const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
415
417
  console.info(
416
418
  '获取批量加车原始数据',
417
419
  res,
418
420
  '====转换后的json数据为===',
419
421
  getMessageJsonData,
420
422
  );
421
423
  try {
422
424
  if (isAndroidDevice) {
423
425
  const isOk = getMessageJsonData?.status === '0';
424
426
  isOk
425
427
  ? resolve({
426
428
  ok: true,
427
429
  msg: '已加入购物车!',
428
430
  })
429
431
  : resolve({
430
432
  ok: false,
431
433
  msg: '加购失败,请稍后重试',
432
434
  errMsg: getMessageJsonData?.data?.message ?? '',
433
435
  });
434
436
  if (!isOk) {
435
437
  const data = {
436
438
  type: 'batchAddCart',
437
439
  subType: 'addCartFailByH5CallAndroidNative',
438
440
  errMsg: 'H5调用安卓原生加车失败',
439
441
  originData: getMessageJsonData,
440
442
  };
441
443
  draBusinessCustomReport(data);
442
444
  }
443
445
  } else if (isIosDevice) {
444
446
  const isOk =
445
447
  getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
446
448
  isOk
447
449
  ? resolve({
448
450
  ok: true,
449
451
  msg: '已加入购物车!',
450
452
  })
451
453
  : resolve({
452
454
  ok: false,
453
455
  msg: '批量加车失败,请稍后重试',
454
456
  errMsg: getMessageJsonData?.data?.message ?? '',
455
457
  });
456
458
  if (!isOk) {
457
459
  const data = {
458
460
  type: 'batchAddCart',
459
461
  subType: 'addCartFailByH5CallIosNative',
460
462
  errMsg: 'H5调用IOS原生加车失败',
461
463
  originData: getMessageJsonData,
462
464
  };
463
465
  draBusinessCustomReport(data);
464
466
  }
465
467
  } else {
466
468
  resolve({
467
469
  ok: false,
468
470
  msg: '加购失败,请稍后重试',
469
471
  });
470
472
  const data = {
471
473
  type: 'batchAddCart',
472
474
  subType: 'addCartFailByH5CallUnknownNative',
473
475
  errMsg: 'H5调用未知原生加车失败',
474
476
  };
475
477
  draBusinessCustomReport(data);
476
478
  }
477
479
  } catch (e) {
478
480
  resolve({
479
481
  ok: false,
480
482
  msg: '加购失败,请稍后重试',
481
483
  });
482
484
  console.warn('批量加车转换数据异常', e);
483
485
  const data = {
484
486
  type: 'batchAddCart',
485
487
  subType: 'addCartFailByTransformData',
486
488
  errMsg: '批量加车转换数据异常',
487
489
  originData: e,
488
490
  };
489
491
  draBusinessCustomReport(data);
490
492
  }
491
493
  window[nativeAddCartCallBack] = null;
492
494
  };
493
495
  }
494
496
  const productsAddCartList = productIdsArr.map((skuItem) => {
495
497
  const adInfos = getAdInfoBySkuId(skuItem);
496
498
  const extFlag = adInfos ? { adInfos } : {};
497
499
  return isAndroidDevice
498
500
  ? {
499
501
  sku: skuItem,
500
502
  num: addCardNum,
501
503
  extFlag,
502
504
  }
503
505
  : {
504
506
  productCode: skuItem,
505
507
  buyCount: addCardNum,
506
508
  extFlag,
507
509
  };
508
510
  });
509
511
  if (isAndroidDevice) {
510
512
  const androidProductsStr = JSON.stringify(productsAddCartList);
511
513
  callRouterAndroid({
512
514
  routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
513
515
  routerParam: {
514
516
  wareList: productsAddCartList,
515
517
  },
516
518
  callBackName: nativeAddCartCallBack,
517
519
  });
518
520
  } else if (isIosDevice) {
519
521
  if (isLowAppVer) {
520
522
  const lowVersionAppList = productIdsArr.map((skuItem) => {
521
523
  return {
522
524
  sku: skuItem,
523
525
  num: addCardNum,
524
526
  };
525
527
  });
526
528
  const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
527
529
  const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
528
530
  jump.side.jdJumpToWeb(url, {});
529
531
  resolve({
530
532
  ok: true,
531
533
  isOpenApp: true,
532
534
  msg: '加购完成, 加购结果请点击购物车确认',
533
535
  });
534
536
  } else {
535
537
  callRouterIOS({
536
538
  routerURL: 'router://JDCartModule/batchAddService',
537
539
  routerParam: {
538
540
  sourceType: 'h5',
539
541
  sourceValue: '店铺批量加购',
540
542
  businessName: 'storeModel',
541
543
  isNewMode: '1',
542
544
  NotPassWebview: '1',
543
545
  products: productsAddCartList,
544
546
  },
545
547
  callBackName: nativeAddCartCallBack,
546
548
  });
547
549
  }
548
550
  }
549
551
  } else if (isMin) {
550
552
  console.log('==========>', '京购批量加车!');
551
553
  const productsAddCartList = productIdsArr.map((skuItem) => {
552
554
  return {
553
555
  skuId: skuItem,
554
556
  buyNum: addCardNum,
555
557
  };
556
558
  });
557
559
  global.wxAppBizInstance
558
560
  .addCart({ commArr: productsAddCartList })
559
561
  .then((res) => {
560
562
  console.log('dealCartSuccess: ', res);
561
563
  resolve({
562
564
  ok: true,
563
565
  msg: '已加入购物车!',
564
566
  data: res,
565
567
  });
566
568
  })
567
569
  .catch((e) => {
568
570
  console.log('京购小程序批量加车失败dealCartFail: ', e);
569
571
  resolve({
570
572
  ok: false,
571
573
  msg: '加购失败,请稍后重试',
572
574
  });
573
575
  const data = {
574
576
  type: 'batchAddCart',
575
577
  subType: 'addCartFailByH5CallMini',
576
578
  errMsg: 'H5调用小程序加车失败',
577
579
  originData: e,
578
580
  };
579
581
  draBusinessCustomReport(data);
580
582
  });
581
583
  } else {
582
584
  console.log('==========>', 'M站批量加车!');
583
585
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
584
586
  }
585
587
  } else {
586
588
  resolve({
587
589
  ok: false,
588
590
  msg: '加购sku不能为空',
589
591
  });
590
592
  const data = {
591
593
  type: 'batchAddCart',
592
594
  subType: 'addCartFailNoSku',
593
595
  errMsg: '加购sku不能为空',
594
596
  originData: skuIdsStr,
595
597
  };
596
598
  draBusinessCustomReport(data);
597
599
  }
598
600
  });
599
601
  }
600
602
 
601
603
  productAddToCart(skuIdsStr, num) {
602
604
  return new Promise((resolve) => {
603
605
  if (window.AddcartToolObj) {
604
606
  window.AddcartToolObj.addCart({
605
607
  skuId: skuIdsStr,
606
608
  num,
607
609
  source: 'sjdpyw',
608
610
  actId: '1',
609
611
  loginType: window?.isJingGouMiniViewState ? '11' : '2',
610
612
  sucFun(res) {
611
613
  console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
612
614
  if (res.errId === '0' && res.cartJson) {
613
615
  resolve({
614
616
  ok: true,
615
617
  msg: '已加入购物车!',
616
618
  ...res,
617
619
  });
618
620
  } else {
619
621
  if (res.errId === '13') {
620
622
  global.doLogin();
621
623
  } else {
622
624
  resolve({
623
625
  ok: false,
624
626
  msg: '加购失败,请稍后重试',
625
627
  ...res,
626
628
  });
627
629
  const data = {
628
630
  type: 'batchAddCart',
629
631
  subType: 'addCartFailByH5CallM',
630
632
  errMsg: 'H5调用M站加车失败',
631
633
  originData: res,
632
634
  };
633
635
  draBusinessCustomReport(data);
634
636
  }
635
637
  }
636
638
  },
637
639
  failFun(err) {
638
640
  console.log('fail', err);
639
641
  resolve({
640
642
  ok: false,
641
643
  msg: '加购失败,请稍后重试',
642
644
  ...err,
643
645
  });
644
646
  const data = {
645
647
  type: 'batchAddCart',
646
648
  subType: 'addCartFailByH5CallM',
647
649
  errMsg: 'H5调用M站加车失败',
648
650
  originData: err,
649
651
  };
650
652
  draBusinessCustomReport(data);
651
653
  },
652
654
  });
653
655
  } else {
654
656
  resolve({
655
657
  ok: false,
656
658
  msg: '购物车方法检查异常',
657
659
  });
658
660
  const data = {
659
661
  type: 'batchAddCart',
660
662
  subType: 'addCartFailByH5CallM',
661
663
  errMsg: 'H5调用M站加车检查依赖方法异常',
662
664
  };
663
665
  draBusinessCustomReport(data);
664
666
  }
665
667
  });
666
668
  }
667
669
  bMallGetUserInfo = () => {
668
670
  return getBMallUserInfo();
669
671
  };
670
672
  async bMallAddCart(params = {}) {
671
673
  return await this.gatewayReq('bmall_cartAdd', params, {
672
674
  client: 'H5',
673
675
  clientVersion: '5.5.0',
674
676
  });
675
677
  }
676
678
  async bMallChangeCart(params = {}) {
677
679
  return await this.gatewayReq('bmall_cartChange', params, {
678
680
  client: 'H5',
679
681
  clientVersion: '5.5.0',
680
682
  });
681
683
  }
682
684
  async bMallRemoveCart(params = {}) {
683
685
  return await this.gatewayReq(
684
686
  'bmall_cartRemove',
685
687
  params,
686
688
  {
687
689
  client: 'H5',
688
690
  clientVersion: '5.5.0',
689
691
  },
690
692
  );
691
693
  }
692
694
  async bMallGetOmittedProduct(params = {}) {
693
695
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
694
696
  client: 'H5',
695
697
  clientVersion: '5.5.0',
696
698
  });
697
699
  }
698
700
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
699
701
  const params = await getParams({ ...data, skuId, bMallTag, num });
700
702
  return await this.bMallAddCart(params);
701
703
  }
702
704
  async bMallGetSkuNumService(bMallTag = 1) {
703
705
  const params = await getParams({ bMallTag });
704
706
  delete params.operations;
705
707
  return await this.bMallGetOmittedProduct(params);
706
708
  }
707
709
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
708
710
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
709
711
  return await this.bMallRemoveCart(params);
710
712
  }
711
713
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
712
714
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
713
715
  return await this.bMallChangeCart(params);
714
716
  }
715
717
 
716
718
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
717
719
  if (!needRequest && isH5 && window?.bMallCartData) {
718
720
  return window?.bMallCartData;
719
721
  }
720
722
  const cartData = await this.bMallGetSkuNumService(bMallTag);
721
723
  let items;
722
724
  if (cartData.ok && cartData.result) {
723
725
  items = cartData?.result?.items || {};
724
726
  }
725
727
  if (isH5) {
726
728
  window.bMallCartData = items;
727
729
  }
728
730
  return items;
729
731
  }
730
732
 
731
733
  async bMallCartHandle(goodItem, num) {
732
734
  try {
733
735
  const {
734
736
  skuUuid,
735
737
  limitUpper,
736
738
  limitLower,
737
739
  } = goodItem;
738
740
  let cartNum = Number(num);
739
741
  if (limitLower && cartNum && cartNum < limitLower) {
740
742
  cartNum = limitLower;
741
743
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
742
744
  cartNum = limitUpper;
743
745
  }
744
746
  if (skuUuid && cartNum > 0) {
745
747
  return this.bMallChangeCartService({
746
748
  ...goodItem,
747
749
  skuUuid,
748
750
  num: cartNum,
749
751
  });
750
752
  } else if (!skuUuid && cartNum > 0) {
751
753
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
752
754
  } else if (skuUuid && !cartNum) {
753
755
  return this.bMallRemoveCartService({
754
756
  ...goodItem,
755
757
  skuUuid,
756
758
  num: cartNum,
757
759
  });
758
760
  } else {
759
761
  console.error('参数不全');
760
762
  return false;
761
763
  }
762
764
  } catch (e) {
763
765
  console.error(e);
764
766
  }
765
767
  }