@conecli/cone-render 0.9.1-shop2.4 → 0.9.1-shop2.40

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