@conecli/cone-render 0.10.1-shop-beta.11 → 0.10.1-shop-beta.13

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 (78) hide show
  1. package/README.md +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/index.dynamic.ts +1 -0
  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/token/index.h5.ts +1 -1
  10. package/dist/common/wxappApi.ts +1 -1
  11. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  12. package/dist/components/base/CountDown/index.tsx +1 -1
  13. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  14. package/dist/components/base/Dialog/index.dynamic.module.scss +126 -0
  15. package/dist/components/base/Dialog/index.dynamic.tsx +1 -0
  16. package/dist/components/base/DynamicTest/index.dynamic.module.scss +15 -0
  17. package/dist/components/base/DynamicTest/index.module.scss +16 -0
  18. package/dist/components/base/DynamicTest/index.tsx +1 -0
  19. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  20. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  21. package/dist/components/base/JdLoading/index.module.scss +2 -0
  22. package/dist/components/base/JdLoading/index.tsx +1 -1
  23. package/dist/components/base/LazyLoadImage/index.tsx +1 -1
  24. package/dist/components/base/NetworkDataError/const.ts +1 -1
  25. package/dist/components/base/NetworkDataError/index.module.scss +116 -70
  26. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  27. package/dist/components/base/Price/Base/index.dynamic.module.scss +63 -0
  28. package/dist/components/base/Price/Base/index.dynamic.tsx +1 -0
  29. package/dist/components/base/Price/Base/index.module.scss +6 -0
  30. package/dist/components/base/Price/Base/index.tsx +1 -1
  31. package/dist/components/base/Price/Double/index.dynamic.module.scss +172 -0
  32. package/dist/components/base/Price/Double/index.dynamic.tsx +1 -0
  33. package/dist/components/base/Price/Double/index.module.scss +6 -0
  34. package/dist/components/base/Price/Double/index.tsx +1 -1
  35. package/dist/components/debug/DebugLayout/index.module.scss +2 -2
  36. package/dist/config/env.ts +1 -1
  37. package/dist/interface/common.ts +1 -1
  38. package/dist/interface/component.ts +1 -1
  39. package/dist/interface/jumpEventReport.ts +1 -1
  40. package/dist/jumpEventReport/const.ts +1 -1
  41. package/dist/jumpEventReport/index.dynamic.ts +1 -0
  42. package/dist/jumpEventReport/index.h5.ts +1 -1
  43. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  44. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  45. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  46. package/dist/jumpEventReport/web.base.ts +1 -1
  47. package/dist/jumpEventReport/web.jd.ts +1 -1
  48. package/dist/language/zh_CN.json +162 -0
  49. package/dist/open/api/index.ts +1 -1
  50. package/dist/open/api/shopMember.dynamic.ts +1 -0
  51. package/dist/open/api/shopMember.ts +1 -1
  52. package/dist/open/components/index.dynamic.ts +1 -0
  53. package/dist/open/components/index.ts +1 -1
  54. package/dist/sass/app.dynamic.scss +306 -0
  55. package/dist/service/fetchGateway.h5.ts +1 -0
  56. package/dist/service/fetchGateway.ts +1 -1
  57. package/dist/service/fetchGateway.weapp.ts +1 -1
  58. package/dist/service/fetchJsonp.h5.ts +1 -0
  59. package/dist/service/fetchJsonp.ts +1 -1
  60. package/dist/service/http/colorSign.dynamic.ts +1 -0
  61. package/dist/service/http/http.ts +1 -1
  62. package/dist/service/requestServer.h5.ts +1 -1
  63. package/dist/service/requestServer.ts +1 -1
  64. package/dist/service/requestServer.weapp.ts +1 -1
  65. package/dist/utils/connectNativeJsBridge.dynamic.ts +1 -0
  66. package/dist/utils/connectNativeJsBridge.ts +1 -1
  67. package/dist/utils/h5Utils.ts +1 -1
  68. package/dist/utils/index.h5.ts +1 -1
  69. package/dist/utils/index.ts +1 -1
  70. package/dist/utils/index.weapp.ts +1 -1
  71. package/dist/utils/intersectionObserver.ts +1 -1
  72. package/dist/utils/jumpExtMapUtil.ts +1 -0
  73. package/dist/utils/log.ts +1 -0
  74. package/dist/utils/utils.ts +1 -1
  75. package/dist/wxapp/common/address_api/address_api_v2.js +1 -0
  76. package/dist/wxapp/common/user_info.js +1 -1
  77. package/package.json +51 -31
  78. /package/dist/utils/{jumpExtMapUtil.js → jumpExtMapUtil.h5.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
  isLanguageForEn,
13
12
  isJdApp,
14
13
  showSuccessToast,
15
14
  showFailToast,
16
15
  isH5,
17
16
  isWxMinAndWxapp,
18
17
  isMin,
19
18
  isPc,
20
19
  cookiesStr: '',
21
20
  requestHeaderContentType: {
22
21
  jsonHeader: {
23
22
  'content-type': 'application/json;charset=utf-8',
24
23
  },
25
24
  formDataHeader: {
26
25
  'content-type': 'application/x-www-form-urlencoded',
27
26
  },
28
27
  },
29
28
  requestBaseParam: {
30
29
  data: null,
31
30
  header: {
32
31
  'content-type': 'application/json;charset=utf-8',
33
32
  },
34
33
  },
35
34
  timeOut: 7000,
36
35
  apiClientParams: {
37
36
  appid: 'wx_mini_app',
38
37
  clientVersion: '11.0.0',
39
38
  client: 'wh5',
40
39
  area: '1_72_2799_0',
41
40
  screen: `${Math.ceil(getSystemInfo?.screenWidth * devicePixelRatio)}*${Math.ceil(
42
41
  getSystemInfo?.screenHeight * devicePixelRatio,
43
42
  )}`,
44
43
  uuid: UUID,
45
44
  loginType: '11',
46
45
  },
47
46
  public addressFetchInfo: {
48
47
  reqState: boolean;
49
48
  promiseInstance: null | Promise<any>;
50
49
  };
51
50
  public getPromotionConfig: {
52
51
  projectId: null | string | number;
53
52
  pageId: null | string | number;
54
53
  };
55
54
  public resInfo: ServiceInterFace.HttpRequestInfo;
56
55
  public api: ServiceInterFace.HttpApi;
57
56
  public isPageDomain: boolean;
58
57
  public verifyColorList: string[];
59
58
  constructor(opt) {
60
59
  this._init();
61
60
  this.addressFetchInfo = {
62
61
  reqState: false,
63
62
  promiseInstance: null,
64
63
  };
65
64
  this.getPromotionConfig = {
66
65
  projectId: null,
67
66
  pageId: null,
68
67
  };
69
68
  this._userAreaUpdateListen();
70
69
  this.resInfo = this._getResConfig(opt);
71
70
  this.api = api;
72
71
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
73
72
  this.verifyColorList = [
74
73
  ...MobileVerifyColorList,
75
74
  ...AppVerifyColorList,
76
75
  ...JshopxVerifyColorList,
77
76
  ...BMallVerifyColorList,
78
77
  ];
79
78
  }
80
79
  _init(): void {
81
80
  httpInterceptors.forEach((item) => {
82
81
  Taro.addInterceptor((chain) => item(chain));
83
82
  });
84
83
  }
85
84
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
86
85
  return Object.assign({}, DefaultConfig, opt);
87
86
  }
88
87
 
89
88
  _userAreaUpdateListen() {
90
89
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (area) => {
91
90
  this.updateApiClientParamsResInfo({
92
91
  area,
93
92
  });
94
93
  });
95
94
  }
96
95
  updateApiClientParamsResInfo(opt = {}) {
97
96
  this.resInfo.apiClientParams = {
98
97
  ...this.resInfo.apiClientParams,
99
98
  ...opt,
100
99
  };
101
100
  }
102
101
 
103
102
  checkFunctionIdToReturnAppId(functionId) {
104
103
  if (JshopxColorFunctionIdList.includes(functionId)) {
105
104
  return APPID.JSHOPX_COLOR_APPID;
106
105
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
107
106
  return APPID.PAGES_COLOR_APPID;
108
107
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
109
108
  return APPID.SHOP_MEMBER_COLOR_APPID;
110
109
  } else if (B2BColorFunctionIdList.includes(functionId)) {
111
110
  return APPID.B2B_COLOR_APPID;
112
111
  } else if (isPc) {
113
112
  return APPID.MALL_COLOR_APPID;
114
113
  } else {
115
114
  return APPID.SHOP_COLOR_APPID;
116
115
  }
117
116
  }
118
117
 
119
118
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
120
119
  if (
121
120
  functionId === 'receiveShopCoupon'
122
121
  ) {
123
122
  clientParams = Object.assign(
124
123
  {},
125
124
  {
126
125
  loginType: '1',
127
126
  loginWQBiz: WXAPP_BIZ_KEY,
128
127
  },
129
128
  clientParams,
130
129
  );
131
130
  }
132
131
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
133
132
  const isColorVerify = this.verifyColorList.includes(functionId);
134
133
  const getReqData = {
135
134
  functionId: functionId,
136
135
  body: JSON.stringify(bodyParams),
137
136
  t: Date.now(),
138
137
  ...apiClientParams,
139
138
  };
140
139
  return http
141
140
  .request({
142
141
  url: this.api.apiFunc,
143
142
  data: getReqData,
144
143
  isColorVerify,
145
144
  })
146
145
  .then((res: ServiceInterFace.RequestPromiseRes) => {
147
146
  const { statusCode, data } = res;
148
147
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
149
148
  ok: true,
150
149
  };
151
150
  if (statusCode === 200 && data) {
152
151
  const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
153
152
  ? Number(res.data.code)
154
153
  : -1;
155
154
  const subCode = Object.prototype.hasOwnProperty.call(res.data, 'subCode')
156
155
  ? Number(res.data.subCode)
157
156
  : -1;
158
157
  if (
159
158
  data.success === true ||
160
159
  data.isSuccess ||
161
160
  resCode === 0 ||
162
161
  resCode === 200 ||
163
162
  subCode === 0
164
163
  ) {
165
164
  changeRes = {
166
165
  result: Object.prototype.hasOwnProperty.call(data, 'result')
167
166
  ? data.result
168
167
  : Object.prototype.hasOwnProperty.call(data, 'data')
169
168
  ? data.data
170
169
  : data,
171
170
  code: data.code || 200,
172
171
  ok: true,
173
172
  source: data,
174
173
  };
175
174
  return changeRes;
176
175
  } else {
177
176
  changeRes = {
178
177
  ...data,
179
178
  ok: false,
180
179
  statusCode: res.statusCode,
181
180
  };
182
181
  return changeRes;
183
182
  }
184
183
  } else {
185
184
  changeRes = {
186
185
  ...data,
187
186
  ok: false,
188
187
  statusCode: res.statusCode,
189
188
  };
190
189
  return changeRes;
191
190
  }
192
191
  })
193
192
  .catch((res) => {
194
193
  return {
195
194
  ...res,
196
195
  ok: false,
197
196
  } as ServiceInterFace.RequestResponseFormatRes;
198
197
  });
199
198
  }
200
199
 
201
200
  async receiveCoupon(param = {}, clientParams) {
202
201
  console.warn("receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!")
203
202
  return await this.gatewayReq(
204
203
  'receiveShopCoupon',
205
204
  {
206
205
  operation: '3',
207
206
  ...param,
208
207
  },
209
208
  { ...clientParams },
210
209
  );
211
210
  }
212
211
 
213
212
  getCustomerCenterDispatch(params = {}) {
214
213
  return this.gatewayReq('customerCenterDispatch', params, {
215
214
  clientVersion: '9.2.0',
216
215
  client: 'H5',
217
216
  uuid: 88888,
218
217
  appid: 'shopmember_m_jd_com',
219
218
  });
220
219
  }
221
220
 
222
221
  batchAddCart(...args) {
223
222
  let skuIds, num, showToast, giftCard;
224
223
  if (['number', 'string'].includes(typeof args[0])) {
225
224
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
226
225
  } else if (typeof args[0] === 'object' && args[0] !== null) {
227
226
  const params = args[0];
228
227
  skuIds = params.skuIds;
229
228
  num = params.num || 1;
230
229
  showToast = params.showToast !== undefined ? params.showToast : true;
231
230
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
232
231
  } else {
233
232
  console.error('batchAddCart() Invalid arguments!', args)
234
233
  const msg = isLanguageForEn? 'Please retry later': '加入购物车失败,请稍后重试!'
235
234
  showFailToast({
236
235
  title: msg,
237
236
  });
238
237
  return Promise.resolve({
239
238
  ok: false,
240
239
  msg,
241
240
  });
242
241
  }
243
242
  const addToWhereText = giftCard? '购物清单': '购物车'
244
243
  const successMsg = isLanguageForEn? 'Success': `加入${addToWhereText}成功`
245
244
  const failMsg = isLanguageForEn? 'Please retry later': `加入${addToWhereText}失败,请稍后重试!`
246
245
  if (skuIds) {
247
246
  return this._addShopGoodCart(`${skuIds}`, `${num}`, {giftCard})
248
247
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
249
248
  if (res?.ok) {
250
249
  if (showToast && !res?.isOpenApp)
251
250
  showSuccessToast({
252
251
  title: successMsg,
253
252
  })
254
253
  } else {
255
254
  showToast &&
256
255
  showFailToast({
257
256
  title: res?.errMsg || failMsg,
258
257
  })
259
258
  }
260
259
  return Promise.resolve(res);
261
260
  })
262
261
  .catch((e) => {
263
262
  console.log('调用加购方法异常=======>', e);
264
263
  return Promise.resolve({
265
264
  ok: false,
266
265
  msg: failMsg,
267
266
  })
268
267
  })
269
268
  } else {
270
269
  return Promise.resolve({
271
270
  ok: false,
272
271
  msg: failMsg,
273
272
  })
274
273
  }
275
274
  }
276
275
  return this.gatewayReq(
277
276
  'giftCardAddCart',
278
277
  {
279
278
  skuList,
280
279
  num: Number(num)
281
280
  },
282
281
  );
283
282
  }
284
283
 
285
284
  _addShopGoodCart(skuIdsStr, addCardNum = '1', {giftCard}) {
286
285
  return new Promise((resolve) => {
287
286
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
288
287
  if (productIdsArr.length > 0) {
289
288
  if(giftCard){
290
289
  this.giftCardAddCart(productIdsArr, addCardNum).then((res) => {
291
290
  if(res?.code === '0' && res?.result?.value){
292
291
  resolve({
293
292
  ok: true,
294
293
  })
295
294
  }else{
296
295
  resolve({
297
296
  ok: false,
298
297
  msg: '加购失败,请稍后重试',
299
298
  });
300
299
  }
301
300
  }).catch((e) => {
302
301
  console.error('礼品卡加车失败: ', e);
303
302
  resolve({
304
303
  ok: false,
305
304
  msg: '加购失败,请稍后重试',
306
305
  });
307
306
  });
308
307
  }else if (isJdApp) {
309
308
  console.log('==========>', 'app原生批量加车!,小程序端暂不涉及')
310
309
  } else if (isMin) {
311
310
  console.log('==========>', '京购批量加车!');
312
311
  const productsAddCartList = productIdsArr.map((skuItem) => {
313
312
  return {
314
313
  skuId: skuItem,
315
314
  buyNum: addCardNum,
316
315
  };
317
316
  });
318
317
  global.wxAppBizInstance
319
318
  .addCart({ commArr: productsAddCartList })
320
319
  .then((res) => {
321
320
  console.log('dealCartSuccess: ', res);
322
321
  resolve({
323
322
  ok: true,
324
323
  msg: '已加入购物车!',
325
324
  data: res,
326
325
  });
327
326
  })
328
327
  .catch((e) => {
329
328
  console.log('京购小程序批量加车失败dealCartFail: ', e);
330
329
  resolve({
331
330
  ok: false,
332
331
  msg: '加购失败,请稍后重试',
333
332
  });
334
333
  });
335
334
  } else {
336
335
  console.log('==========>', 'M站批量加车!');
337
336
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
338
337
  }
339
338
  } else {
340
339
  resolve({
341
340
  ok: false,
342
341
  msg: '加购sku不能为空',
343
342
  });
344
343
  }
345
344
  });
346
345
  }
347
346
 
348
347
  productAddToCart() {
349
348
  return Promise.resolve({
350
349
  ok: false,
351
350
  msg: 'productAddToCart暂不支持小程序',
352
351
  });
353
352
  }
354
353
  bMallGetUserInfo = () => {
355
354
  return getBMallUserInfo();
356
355
  };
357
356
  async bMallAddCart(params = {}) {
358
357
  console.warn("bMallAddCart 方法在微信京购小程序环境未经验证,请不要使用!")
359
358
  return await this.gatewayReq('bmall_cartAdd', params, {
360
359
  client: 'H5',
361
360
  clientVersion: '5.5.0',
362
361
  });
363
362
  }
364
363
  async bMallChangeCart(params = {}) {
365
364
  console.warn("bMallChangeCart 方法在微信京购小程序环境未经验证,请不要使用!")
366
365
  return await this.gatewayReq('bmall_cartChange', params, {
367
366
  client: 'H5',
368
367
  clientVersion: '5.5.0',
369
368
  });
370
369
  }
371
370
  async bMallRemoveCart(params = {}) {
372
371
  console.warn("bMallRemoveCart 方法在微信京购小程序环境未经验证,请不要使用!")
373
372
  return await this.gatewayReq(
374
373
  'bmall_cartRemove',
375
374
  params,
376
375
  {
377
376
  client: 'H5',
378
377
  clientVersion: '5.5.0',
379
378
  },
380
379
  );
381
380
  }
382
381
  async bMallGetOmittedProduct(params = {}) {
383
382
  return await this.gatewayReq('bmall_getOmittedProduct', params, {
384
383
  client: 'H5',
385
384
  clientVersion: '5.5.0',
386
385
  });
387
386
  }
388
387
  async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
389
388
  const params = await getParams({ ...data, skuId, bMallTag, num });
390
389
  return await this.bMallAddCart(params);
391
390
  }
392
391
  async bMallGetSkuNumService(bMallTag = 1) {
393
392
  const params = await getParams({ bMallTag });
394
393
  delete params.operations;
395
394
  return await this.bMallGetOmittedProduct(params);
396
395
  }
397
396
  async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
398
397
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
399
398
  return await this.bMallRemoveCart(params);
400
399
  }
401
400
  async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
402
401
  let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
403
402
  return await this.bMallChangeCart(params);
404
403
  }
405
404
 
406
405
  async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
407
406
  if (!needRequest && isH5 && window?.bMallCartData) {
408
407
  return window?.bMallCartData;
409
408
  }
410
409
  const cartData = await this.bMallGetSkuNumService(bMallTag);
411
410
  let items;
412
411
  if (cartData.ok && cartData.result) {
413
412
  items = cartData?.result?.items || {};
414
413
  }
415
414
  if (isH5) {
416
415
  window.bMallCartData = items;
417
416
  }
418
417
  return items;
419
418
  }
420
419
 
421
420
  async bMallCartHandle(goodItem, num) {
422
421
  try {
423
422
  const {
424
423
  skuUuid,
425
424
  limitUpper,
426
425
  limitLower,
427
426
  } = goodItem;
428
427
  let cartNum = Number(num);
429
428
  if (limitLower && cartNum && cartNum < limitLower) {
430
429
  cartNum = limitLower;
431
430
  } else if (limitUpper && cartNum && cartNum > limitUpper) {
432
431
  cartNum = limitUpper;
433
432
  }
434
433
  if (skuUuid && cartNum > 0) {
435
434
  return this.bMallChangeCartService({
436
435
  ...goodItem,
437
436
  skuUuid,
438
437
  num: cartNum,
439
438
  });
440
439
  } else if (!skuUuid && cartNum > 0) {
441
440
  return this.bMallAddCartService({ ...goodItem, num: cartNum });
442
441
  } else if (skuUuid && !cartNum) {
443
442
  return this.bMallRemoveCartService({
444
443
  ...goodItem,
445
444
  skuUuid,
446
445
  num: cartNum,
447
446
  });
448
447
  } else {
449
448
  console.error('参数不全');
450
449
  return false;
451
450
  }
452
451
  } catch (e) {
453
452
  console.error(e);
454
453
  }
455
454
  }
455
+ import Taro from '@tarojs/taro';
456
456
  APPID,
457
457
  JshopxColorFunctionIdList,
458
458
  PagesColorFunctionIdList,
459
459
  PAGES_DOMAIN,
460
460
  B2BColorFunctionIdList,
461
461
  MobileVerifyColorList,
462
462
  AppVerifyColorList,
463
463
  JshopxVerifyColorList,
464
464
  BMallVerifyColorList,
465
465
  shopMemberColorFunctionIdList,
466
466
  isLanguageForEn,
467
467
  isJdApp,
468
468
  showSuccessToast,
469
469
  showFailToast,
470
470
  isH5,
471
471
  isMin,
472
472
  isPc,
473
473
  cookiesStr: '',
474
474
  requestHeaderContentType: {
475
475
  jsonHeader: {
476
476
  'content-type': 'application/json;charset=utf-8',
477
477
  },
478
478
  formDataHeader: {
479
479
  'content-type': 'application/x-www-form-urlencoded',
480
480
  },
481
481
  },
482
482
  requestBaseParam: {
483
483
  data: null,
484
484
  header: {
485
485
  'content-type': 'application/json;charset=utf-8',
486
486
  },
487
487
  },
488
488
  timeOut: 7000,
489
489
  apiClientParams: {
490
490
  appid: 'wx_mini_app',
491
491
  clientVersion: '11.0.0',
492
492
  client: 'wh5',
493
493
  area: '1_72_2799_0',
494
494
  screen: `${Math.ceil(getSystemInfo?.screenWidth * devicePixelRatio)}*${Math.ceil(
495
495
  getSystemInfo?.screenHeight * devicePixelRatio,
496
496
  )}`,
497
497
  uuid: "-1",
498
498
  loginType: '11',
499
499
  },
500
500
  public addressFetchInfo: {
501
501
  reqState: boolean;
502
502
  promiseInstance: null | Promise<any>;
503
503
  };
504
504
  public getPromotionConfig: {
505
505
  projectId: null | string | number;
506
506
  pageId: null | string | number;
507
507
  };
508
508
  public resInfo: ServiceInterFace.HttpRequestInfo;
509
509
  public api: ServiceInterFace.HttpApi;
510
510
  public isPageDomain: boolean;
511
511
  public verifyColorList: string[];
512
512
  constructor(opt) {
513
513
  this._init();
514
514
  this.addressFetchInfo = {
515
515
  reqState: false,
516
516
  promiseInstance: null,
517
517
  };
518
518
  this.getPromotionConfig = {
519
519
  projectId: null,
520
520
  pageId: null,
521
521
  };
522
522
  this._userAreaUpdateListen();
523
523
  this.resInfo = this._getResConfig(opt);
524
524
  this.api = api;
525
525
  this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
526
526
  this.verifyColorList = [
527
527
  ...MobileVerifyColorList,
528
528
  ...AppVerifyColorList,
529
529
  ...JshopxVerifyColorList,
530
530
  ...BMallVerifyColorList,
531
531
  ];
532
532
  }
533
533
  _init(): void {
534
534
  httpInterceptors.forEach((item) => {
535
535
  Taro.addInterceptor((chain) => item(chain));
536
536
  });
537
537
  }
538
538
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
539
539
  return Object.assign({}, DefaultConfig, opt);
540
540
  }
541
541
 
542
542
  _userAreaUpdateListen() {
543
543
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
544
544
  this.updateApiClientParamsResInfo(areaInfo);
545
545
  });
546
546
  }
547
547
  updateApiClientParamsResInfo(opt = {}) {
548
548
  const { area, realTimeArea, ...others } = opt;
549
549
  this.resInfo.apiClientParams = {
550
550
  ...this.resInfo.apiClientParams,
551
551
  ...others,
552
552
  };
553
553
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
554
554
  realTimeArea &&
555
555
  realTimeArea !== '' &&
556
556
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
557
557
  }
558
558
 
559
559
  checkFunctionIdToReturnAppId(functionId) {
560
560
  if (JshopxColorFunctionIdList.includes(functionId)) {
561
561
  return APPID.JSHOPX_COLOR_APPID;
562
562
  } else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
563
563
  return APPID.PAGES_COLOR_APPID;
564
564
  } else if (shopMemberColorFunctionIdList.includes(functionId)) {
565
565
  return APPID.SHOP_MEMBER_COLOR_APPID;
566
566
  } else if (B2BColorFunctionIdList.includes(functionId)) {
567
567
  return APPID.B2B_COLOR_APPID;
568
568
  } else if (isPc) {
569
569
  return APPID.MALL_COLOR_APPID;
570
570
  } else {
571
571
  return APPID.SHOP_COLOR_APPID;
572
572
  }
573
573
  }
574
574
 
575
575
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
576
576
  if (functionId === 'receiveShopCoupon') {
577
577
  clientParams = Object.assign(
578
578
  {},
579
579
  {
580
580
  loginType: '1',
581
581
  loginWQBiz: WXAPP_BIZ_KEY,
582
582
  },
583
583
  clientParams,
584
584
  );
585
585
  }
586
586
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
587
587
  const isColorVerify = this.verifyColorList.includes(functionId);
588
588
  const getReqData = {
589
589
  functionId: functionId,
590
590
  body: JSON.stringify(bodyParams),
591
591
  t: Date.now(),
592
592
  ...apiClientParams,
593
593
  };
594
594
  return http
595
595
  .request({
596
596
  url: this.api.apiFunc,
597
597
  data: getReqData,
598
598
  isColorVerify,
599
599
  })
600
600
  .then((res: ServiceInterFace.RequestPromiseRes) => {
601
601
  const { statusCode, data } = res;
602
602
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
603
603
  ok: true,
604
604
  };
605
605
  if (statusCode === 200 && data) {
606
606
  const resCode = Object.prototype.hasOwnProperty.call(res.data, 'code')
607
607
  ? Number(res.data.code)
608
608
  : -1;
609
609
  const subCode = Object.prototype.hasOwnProperty.call(res.data, 'subCode')
610
610
  ? Number(res.data.subCode)
611
611
  : -1;
612
612
  if (
613
613
  data.success === true ||
614
614
  data.isSuccess ||
615
615
  resCode === 0 ||
616
616
  resCode === 200 ||
617
617
  subCode === 0
618
618
  ) {
619
619
  changeRes = {
620
620
  result: Object.prototype.hasOwnProperty.call(data, 'result')
621
621
  ? data.result
622
622
  : Object.prototype.hasOwnProperty.call(data, 'data')
623
623
  ? data.data
624
624
  : data,
625
625
  code: data.code || 200,
626
626
  ok: true,
627
627
  source: data,
628
628
  };
629
629
  return changeRes;
630
630
  } else {
631
631
  changeRes = {
632
632
  ...data,
633
633
  ok: false,
634
634
  statusCode: res.statusCode,
635
635
  };
636
636
  return changeRes;
637
637
  }
638
638
  } else {
639
639
  changeRes = {
640
640
  ...data,
641
641
  ok: false,
642
642
  statusCode: res.statusCode,
643
643
  };
644
644
  return changeRes;
645
645
  }
646
646
  })
647
647
  .catch((res) => {
648
648
  return {
649
649
  ...res,
650
650
  ok: false,
651
651
  } as ServiceInterFace.RequestResponseFormatRes;
652
652
  });
653
653
  }
654
654
 
655
655
  async receiveCoupon(param = {}, clientParams) {
656
656
  console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
657
657
  return await this.gatewayReq(
658
658
  'receiveShopCoupon',
659
659
  {
660
660
  operation: '3',
661
661
  ...param,
662
662
  },
663
663
  { ...clientParams },
664
664
  );
665
665
  }
666
666
 
667
667
  getCustomerCenterDispatch(params = {}) {
668
668
  return this.gatewayReq('customerCenterDispatch', params, {
669
669
  clientVersion: '9.2.0',
670
670
  client: 'H5',
671
671
  uuid: 88888,
672
672
  appid: 'shopmember_m_jd_com',
673
673
  });
674
674
  }
675
675
 
676
676
  batchAddCart(...args) {
677
677
  let skuIds, num, showToast, giftCard;
678
678
  if (['number', 'string'].includes(typeof args[0])) {
679
679
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
680
680
  } else if (typeof args[0] === 'object' && args[0] !== null) {
681
681
  const params = args[0];
682
682
  skuIds = params.skuIds;
683
683
  num = params.num || 1;
684
684
  showToast = params.showToast !== undefined ? params.showToast : true;
685
685
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
686
686
  } else {
687
687
  console.error('batchAddCart() Invalid arguments!', args);
688
688
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
689
689
  showFailToast({
690
690
  title: msg,
691
691
  });
692
692
  return Promise.resolve({
693
693
  ok: false,
694
694
  msg,
695
695
  });
696
696
  }
697
697
  const addToWhereText = giftCard ? '购物清单' : '购物车';
698
698
  const successMsg = isLanguageForEn ? 'Success' : `加入${addToWhereText}成功`;
699
699
  const failMsg = isLanguageForEn
700
700
  ? 'Please retry later'
701
701
  : `加入${addToWhereText}失败,请稍后重试!`;
702
702
  if (skuIds) {
703
703
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
704
704
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
705
705
  if (res?.ok) {
706
706
  if (showToast && !res?.isOpenApp)
707
707
  showSuccessToast({
708
708
  title: successMsg,
709
709
  });
710
710
  } else {
711
711
  showToast &&
712
712
  showFailToast({
713
713
  title: res?.errMsg || failMsg,
714
714
  });
715
715
  }
716
716
  return Promise.resolve(res);
717
717
  })
718
718
  .catch((e) => {
719
719
  console.log('调用加购方法异常=======>', e);
720
720
  return Promise.resolve({
721
721
  ok: false,
722
722
  msg: failMsg,
723
723
  });
724
724
  });
725
725
  } else {
726
726
  return Promise.resolve({
727
727
  ok: false,
728
728
  msg: failMsg,
729
729
  });
730
730
  }
731
731
  }
732
732
 
733
733
  async giftCardAddCart(skuList, num) {
734
734
  return this.gatewayReq('giftCardAddCart', {
735
735
  skuList,
736
736
  num: Number(num),
737
737
  });
738
738
  }
739
739
 
740
740
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
741
741
  return new Promise((resolve) => {
742
742
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
743
743
  if (productIdsArr.length > 0) {
744
744
  if (giftCard) {
745
745
  this.giftCardAddCart(productIdsArr, addCardNum)
746
746
  .then((res) => {
747
747
  if (res?.code === '0' && res?.result?.value) {
748
748
  resolve({
749
749
  ok: true,
750
750
  });
751
751
  } else {
752
752
  resolve({
753
753
  ok: false,
754
754
  msg: '加购失败,请稍后重试',
755
755
  });
756
756
  }
757
757
  })
758
758
  .catch((e) => {
759
759
  console.error('礼品卡加车失败: ', e);
760
760
  resolve({
761
761
  ok: false,
762
762
  msg: '加购失败,请稍后重试',
763
763
  });
764
764
  });
765
765
  } else if (isJdApp) {
766
766
  console.log('==========>', 'app原生批量加车!,小程序端暂不涉及');
767
767
  } else if (isMin) {
768
768
  console.log('==========>', '京购批量加车!');
769
769
  const productsAddCartList = productIdsArr.map((skuItem) => {
770
770
  return {
771
771
  skuId: skuItem,
772
772
  buyNum: addCardNum,
773
773
  };
774
774
  });
775
775
  global.wxAppBizInstance
776
776
  .addCart({ commArr: productsAddCartList })
777
777
  .then((res) => {
778
778
  console.log('dealCartSuccess: ', res);
779
779
  resolve({
780
780
  ok: true,
781
781
  msg: '已加入购物车!',
782
782
  data: res,
783
783
  });
784
784
  })
785
785
  .catch((e) => {
786
786
  console.log('京购小程序批量加车失败dealCartFail: ', e);
787
787
  resolve({
788
788
  ok: false,
789
789
  msg: '加购失败,请稍后重试',
790
790
  });
791
791
  });
792
792
  } else {
793
793
  console.log('==========>', 'M站批量加车!');
794
794
  return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
795
795
  }
796
796
  } else {
797
797
  resolve({
798
798
  ok: false,
799
799
  msg: '加购sku不能为空',
800
800
  });
801
801
  }
802
802
  });
803
803
  }
804
804
 
805
805
  productAddToCart() {
806
806
  return Promise.resolve({
807
807
  ok: false,
808
808
  msg: 'productAddToCart暂不支持小程序',
809
809
  });
810
810
  }