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

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 (84) 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/pageType.ts +1 -1
  9. package/dist/common/sgmCustomCode.ts +1 -1
  10. package/dist/components/ErrorBoundary.tsx +1 -1
  11. package/dist/components/base/CountDown/index.module.scss +49 -44
  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/CustomVideo/common.ts +1 -0
  15. package/dist/components/base/CustomVideo/index.tsx +1 -1
  16. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  17. package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
  18. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  19. package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
  20. package/dist/components/base/LazyLoadImage/index.h5.module.scss +11 -3
  21. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  22. package/dist/components/base/LazyLoadImage/index.tsx +1 -1
  23. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  24. package/dist/components/base/NetworkDataError/index.module.scss +3 -0
  25. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  26. package/dist/components/base/Price/Base/index.tsx +1 -1
  27. package/dist/components/base/Price/Double/index.module.scss +8 -0
  28. package/dist/components/base/Price/Double/index.tsx +1 -1
  29. package/dist/components/decorate/DecorateFloorModule/index.module.scss +11 -0
  30. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  31. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  32. package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
  33. package/dist/components/floorItem.jd.tsx +1 -1
  34. package/dist/components/floorItem.tsx +1 -1
  35. package/dist/components/floorItem.weapp.tsx +1 -1
  36. package/dist/components/isv/Floor/index.tsx +1 -1
  37. package/dist/components/remoteFloorItem.tsx +1 -1
  38. package/dist/interface/common.ts +1 -1
  39. package/dist/interface/component.ts +1 -1
  40. package/dist/interface/jumpEventReport.ts +1 -1
  41. package/dist/interface/service.ts +1 -1
  42. package/dist/jumpEventReport/base.ts +1 -1
  43. package/dist/jumpEventReport/const.ts +1 -1
  44. package/dist/jumpEventReport/index.jd.ts +1 -1
  45. package/dist/jumpEventReport/index.weapp.ts +1 -1
  46. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  47. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  48. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  49. package/dist/jumpEventReport/web.base.ts +1 -1
  50. package/dist/jumpEventReport/web.jd.ts +1 -1
  51. package/dist/jumpEventReport/web.jdb.ts +1 -1
  52. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  53. package/dist/jumpEventReport/web.jxwxapp.ts +1 -1
  54. package/dist/jumpEventReport/web.pc.ts +1 -1
  55. package/dist/jumpEventReport/web.tjapp.ts +1 -1
  56. package/dist/jumpEventReport/web.tjm.ts +1 -1
  57. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  58. package/dist/modules/ContainerFloorList/index.h5.module.scss +1 -0
  59. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  60. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  61. package/dist/open/api/device.ts +1 -1
  62. package/dist/open/api/request.ts +1 -1
  63. package/dist/open/api/shopMember.ts +1 -1
  64. package/dist/open/api/util.ts +1 -1
  65. package/dist/open/components/index.ts +1 -1
  66. package/dist/sass/app.h5.scss +5 -0
  67. package/dist/sass/base.scss +183 -137
  68. package/dist/service/fetchGateway.ts +1 -1
  69. package/dist/service/http/colorSign.ts +1 -1
  70. package/dist/service/http/h5Http.ts +1 -0
  71. package/dist/service/http/index.h5.ts +1 -0
  72. package/dist/service/requestServer.h5.ts +1 -0
  73. package/dist/service/requestServer.ts +1 -1
  74. package/dist/utils/connectNativeJsBridge.ts +1 -1
  75. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  76. package/dist/utils/h5Utils.ts +1 -1
  77. package/dist/utils/index.h5.ts +1 -1
  78. package/dist/utils/index.ts +1 -1
  79. package/dist/utils/index.weapp.ts +1 -1
  80. package/dist/utils/sgmCodeUtils.ts +1 -1
  81. package/dist/utils/taroRenderUtil.ts +1 -1
  82. package/dist/utils/utils.ts +1 -1
  83. package/package.json +35 -29
  84. package/dist/utils/memberFormatUtils.js +0 -1
@@ -1 +1 @@
1
- import React, { useCallback, useEffect, useRef, useState } from "react";
2
1
  getQualityImage,
3
2
  isH5AndJdShopView,
4
3
  isJdApp,
5
4
  isChartH5,
6
5
  isH5AndJdShopViewH5Scroll,
7
6
  isAppStowShop,
8
7
  getSgmCustomCode,
9
8
  sgmCustomReport,
10
9
  isImageOptimizeEnable,
11
10
  getNativePageScrollRes,
12
11
  latestFromNativeMsgStorage,
13
12
  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAAAeCAMAAABT0xOcAAAAe1BMVEUAAADx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fELy0NOAAAAKHRSTlMApwmfFtYm9rWveHDm70yJHYJaD2k8IeIr6pY2X0HHfsGRZDHdu1XNmO+CqgAAAu9JREFUSMfNlNmymzAQRAchkCUhdrMZbLze/v8vjIRMKN8kRR7ykFNeVIPV9Ewj039P1TR8+eILjL7RdLFFJUO8QMS7ZmyDJvZ0nDYGY+aKKDSJpY3OwWX6uFUEY/peCNEbY4Rp6AABixFYkLQRAK3VOmAjUrawMt1GrfWtXD7rlFF3uiA6HV/p0TF1tBECEVskYe+7qqW08mqT1jruneu21/72JfHoSZ7faj2bJu6mOlgEa3qjEXKeL/ACV1s5YSbqYP6stXUeX2FZnV3wuBSZqnVWqDNCIvaFRzZIiGAIw+CS/1brQCslgOQdUBoW10C2EFJei7AkygOlAnmGeMprJq/NjhZpAIrepOpOte2Oq9EXjupIMVoiXduQ9rTo7KsODhxJYaAGuJPjgRvdkRD1KP9CawRwettyF5SbVLZ49ZbuMJxGW93XisXPKA/oXNMDEReJT6N0OfZ2V4RqX4tFQPbOQbntwrl8oXCOQmu2hVosSr6j5QcW+uvukZJP37CWzL7tQs2lH8B53Nd6eq192N/72mdfa52XhdXPx6zcXKYgikLXbaNP66M27edoAO2X+RkQ9tVRhoWC6IZkCZAbHHa1SgDHNdHDsbrLr0ojKTkfDWp6+WPh1APakMAXbVrb6B/Mn+311zlETJZOCJYChttWxedUIyvyi9bLt+J4IPcLvVYypBNaDG5TguCzmct3rUkAPSdHJRLyDEjXQ6Un3GZQBamxaU09gJg+/r+4gqV0uzixXjBfLnDzixrjhDJGNoDXXqvK76OEJaO3L1bx/FQOCSxqcfJVUWiXCydEPowHeIqaZnf3wmvNRsBiC28ttEnS+1oy+lNtOMVAzayZCwsQ5ESNREgvKKuNjjI/ewNHr9Y4N5Is98llx2U8iOQXcKczhDwAM6ObayaanfWDDwhJcMvpU8ucr6+cPji5a8+UEVMCMNo97tLm0MU2uoMmi850yrc8s8Khyzuj7+Q6U7GPMCt8mOtGljP6l/wAUcBZ6lceL/8AAAAASUVORK5CYII=";
14
13
  "https://img14.360buyimg.com/imagetools/jfs/t1/222907/25/7012/5824/61c4797cEbcd17c7f/6c76fc71e4fdb5a5.png";
15
14
  const {
16
15
  src,
17
16
  lazyLoad,
18
17
  imagRenderingSet,
19
18
  width,
20
19
  height,
21
20
  className,
22
21
  isSkuImage,
23
22
  hideErrorImage,
24
23
  style,
25
24
  backgroundColor,
26
25
  errorSrc,
27
26
  onLoad,
28
27
  onError,
29
28
  ...otherOption
30
29
  } = props;
31
30
  getNetWorkType === NetWorkTypeQuality.default &&
32
31
  (getNetWorkType = global.info.sysInfo.netWorkType);
33
32
  const [loadSuccess, setLoadSuccess] = useState(false);
34
33
  const [imageErrState, setImageErrState] = useState(false);
35
34
  const [componentShowState, setComponentShowState] = useState(false);
36
35
  const measureRef = useRef<HTMLElement | null>(null);
37
36
  const [measureComplete, setMeasureComplete] = useState(false);
38
37
  const [imgSrc, setImgSrc] = useState(src);
39
38
  const [hasRetrySuccess, setHasRetrySuccess] = useState(false);
40
39
  const hasRetryRef = useRef(false);
41
40
  const componentShowStateRef = useRef(false);
42
41
  const requestSrcRef = useRef(src);
43
42
  const needShowHighVersion =
44
43
  isH5AndJdShopViewH5Scroll &&
45
44
  !(
46
45
  global.info.queryInfo?.downgraded &&
47
46
  global.info.queryInfo.downgraded === "true"
48
47
  );
49
48
  const enableAvifOptimize = isImageOptimizeEnable();
50
49
 
51
50
  const getRequestSrc = useCallback(
52
51
  (src) => {
53
52
  const requestSrc = getQualityImage(imgSrc, {
54
53
  isSkuImage,
55
54
  size: measureRef?.current?.offsetWidth,
56
55
  });
57
56
  requestSrcRef.current = requestSrc;
58
57
  return requestSrc;
59
58
  },
60
59
  [src]
61
60
  );
62
61
 
63
62
  const imageErrorRetry = (src) => {
64
63
  return new Promise((resolve, reject) => {
65
64
  if (fetch && window && window.Image) {
66
65
  fetch(src)
67
66
  .then((response) => {
68
67
  const { ok, status } = response;
69
68
  if (ok) {
70
69
  response.blob().then((blob) => {
71
70
  const url = URL.createObjectURL(blob);
72
71
  const img = new window.Image();
73
72
  img.src = url;
74
73
  img.onload = () => {
75
74
  resolve({
76
75
  ok: true,
77
76
  url,
78
77
  });
79
78
  setTimeout(() => {
80
79
  URL.revokeObjectURL(url);
81
80
  }, 1000);
82
81
  };
83
82
  img.onerror = () => {
84
83
  resolve({
85
84
  ok: false,
86
85
  text: "图片解析异常",
87
86
  type: "imageParseError",
88
87
  });
89
88
  URL.revokeObjectURL(url);
90
89
  };
91
90
  });
92
91
  } else {
93
92
  if (status === 404) {
94
93
  resolve({
95
94
  ok: false,
96
95
  text: "访问图片不存在",
97
96
  type: "noSuchUrlImage",
98
97
  });
99
98
  } else {
100
99
  resolve({
101
100
  ok: false,
102
101
  status: status,
103
102
  text: "其它图片问题",
104
103
  type: "otherImageError",
105
104
  });
106
105
  }
107
106
  }
108
107
  })
109
108
  .catch((error) => {
110
109
  resolve({
111
110
  ok: false,
112
111
  text: "网络异常",
113
112
  type: "networkError",
114
113
  });
115
114
  console.error("LazyLoadImage imageErrorRetry() error:", error);
116
115
  });
117
116
  } else {
118
117
  resolve({
119
118
  ok: false,
120
119
  text: "不支持重试",
121
120
  type: "notSupportRetry",
122
121
  });
123
122
  }
124
123
  });
125
124
  };
126
125
  const imageErrorHandle = useCallback(
127
126
  (e) => {
128
127
  console.log(" ==============> 图片加载错误", e);
129
128
  if (!hasRetryRef.current) {
130
129
  hasRetryRef.current = true;
131
130
  if (src) {
132
131
  try {
133
132
  imageErrorRetry(requestSrcRef.current).then((result) => {
134
133
  const { status, ok, text, type, url } = result || {};
135
134
  if (ok) {
136
135
  setImgSrc(url);
137
136
  setHasRetrySuccess(true);
138
137
  } else {
139
138
  errorSrc && setImgSrc(errorSrc);
140
139
  hideErrorImage && setImageErrState(true);
141
140
  typeof onError === "function" && onError(e, src, props);
142
141
  const { shopId, venderId } = global.info.queryInfo || {};
143
142
  sgmCustomReport({
144
143
  code: getSgmCustomCode(`${SgmCustomCode.IMAGE_LOAD}_${type}`),
145
144
  msg: {
146
145
  shopId,
147
146
  venderId,
148
147
  originSrc: src,
149
148
  requestSrc: requestSrcRef.current,
150
149
  status,
151
150
  text,
152
151
  },
153
152
  });
154
153
  }
155
154
  });
156
155
  } catch (e) {
157
156
  console.error("LazyLoadImage imageErrorHandle() error:", e);
158
157
  errorSrc && setImgSrc(errorSrc);
159
158
  hideErrorImage && setImageErrState(true);
160
159
  typeof onError === "function" && onError(e, src, props);
161
160
  }
162
161
  }
163
162
  }
164
163
  },
165
164
  [src, hasRetryRef.current]
166
165
  );
167
166
 
168
167
  const imageLoad = useCallback(
169
168
  (_src, event) => {
170
169
  setLoadSuccess(true);
171
170
  typeof onLoad === "function" && onLoad(event, src, props);
172
171
  },
173
172
  [src]
174
173
  );
175
174
 
176
175
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
177
176
  const changeStyle = {};
178
177
  width && (changeStyle["width"] = width);
179
178
  height && (changeStyle["height"] = height);
180
179
  backgroundColor && (changeStyle["backgroundColor"] = backgroundColor);
181
180
  return changeStyle;
182
181
  };
183
182
  useEffect(() => {
184
183
  setMeasureComplete(true);
185
184
  if (needShowHighVersion) return;
186
185
  const latestRes =
187
186
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {};
188
187
  !componentShowStateRef.current && dealPageScrollInfo(latestRes);
189
188
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
190
189
  !componentShowStateRef.current && dealPageScrollInfo(res);
191
190
  });
192
191
  }, []);
193
192
 
194
193
  const dealPageScrollInfo = (res) => {
195
194
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {};
196
195
  if (typeof displayHeight === "undefined" || typeof offSetY === "undefined")
197
196
  return;
198
197
  if (measureRef.current) {
199
198
  const eleClientRect = measureRef.current.getBoundingClientRect();
200
199
  const getContainerHeightOffSetY = displayHeight * 1.5 + offSetY;
201
200
  const eleOffsetTop = Math.ceil(eleClientRect.top);
202
201
  const eleOffsetHeight = Math.ceil(eleClientRect.height);
203
202
  if (!componentShowStateRef.current) {
204
203
  if (getContainerHeightOffSetY > eleOffsetTop) {
205
204
  componentShowStateRef.current = true;
206
205
  setComponentShowState(true);
207
206
  }
208
207
  }
209
208
  }
210
209
  };
211
210
  return isH5AndJdShopView &&
212
211
  global?.config?.needImageLazy !== false &&
213
212
  !needShowHighVersion &&
214
213
  !isAppStowShop ? (
215
214
  <View
216
215
  ref={measureRef}
217
216
  className={classNames(
218
217
  imageStyle["d-app-lazy-image"],
219
218
  {
220
219
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
221
220
  },
222
221
  {
223
222
  [imageStyle["d-hide-image-error"]]: imageErrState,
224
223
  },
225
224
  {
226
225
  [imageStyle["d-load-completed"]]: loadSuccess,
227
226
  },
228
227
  {
229
228
  "d-imag-rendering-crisp-edges":
230
229
  !global.info.pageInfo.isVipShop && imagRenderingSet,
231
230
  },
232
231
  "J_html5ImageBg",
233
232
  className
234
233
  )}
235
234
  style={{
236
235
  ...style,
237
236
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
238
237
  }}
239
238
  {...otherOption}
240
239
  >
241
240
  {(componentShowState || lazyLoad === false) && (
242
241
  <img
243
242
  src={getQualityImage(
244
243
  imgSrc,
245
244
  global.info.pageInfo.isVipShop
246
245
  ? NetWorkTypeQuality["perfect"]
247
246
  : NetWorkTypeQuality[getNetWorkType]
248
247
  )}
249
248
  onLoad={imageLoad.bind(this, imgSrc)}
250
249
  onError={imageErrorHandle}
251
250
  />
252
251
  )}
253
252
  </View>
254
253
  ) : enableAvifOptimize ? (
255
254
  [
256
255
  measureComplete ? (
257
256
  <Image
258
257
  key={hasRetrySuccess ? "realImageRetry" : "realImage"}
259
258
  style={{
260
259
  ...style,
261
260
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
262
261
  }}
263
262
  className={classNames(
264
263
  imageStyle["d-lazy-image"],
265
264
  {
266
265
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
267
266
  },
268
267
  {
269
268
  [imageStyle["d-hide-image-error"]]: imageErrState,
270
269
  },
271
270
  {
272
271
  [imageStyle["d-load-completed"]]: loadSuccess,
273
272
  },
274
273
  {
275
274
  "d-imag-rendering-crisp-edges": imagRenderingSet,
276
275
  },
277
276
  className
278
277
  )}
279
278
  src={hasRetrySuccess ? imgSrc : getRequestSrc(imgSrc)}
280
279
  lazyLoad={isChartH5 ? false : lazyLoad}
281
280
  onError={imageErrorHandle}
282
281
  onLoad={imageLoad.bind(this, imgSrc)}
283
282
  {...otherOption}
284
283
  />
285
284
  ) : (
286
285
  <Image
287
286
  key={"defaultImage"}
288
287
  style={{
289
288
  ...style,
290
289
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
291
290
  }}
292
291
  className={classNames(
293
292
  imageStyle["d-lazy-image"],
294
293
  {
295
294
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
296
295
  },
297
296
  {
298
297
  [imageStyle["d-hide-image-error"]]: imageErrState,
299
298
  },
300
299
  {
301
300
  [imageStyle["d-load-completed"]]: loadSuccess,
302
301
  },
303
302
  {
304
303
  "d-imag-rendering-crisp-edges": imagRenderingSet,
305
304
  },
306
305
  className
307
306
  )}
308
307
  src={isSkuImage ? DEFAULT_SKU_SRC : DEFAULT_SRC}
309
308
  />
310
309
  ),
311
310
  loadSuccess ? null : <View key={"measureRef"} ref={measureRef}></View>,
312
311
  ]
313
312
  ) : (
314
313
  <Image
315
314
  style={{
316
315
  ...style,
317
316
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
318
317
  }}
319
318
  className={classNames(
320
319
  imageStyle["d-lazy-image"],
321
320
  {
322
321
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
323
322
  },
324
323
  {
325
324
  [imageStyle["d-hide-image-error"]]: imageErrState,
326
325
  },
327
326
  {
328
327
  [imageStyle["d-load-completed"]]: loadSuccess,
329
328
  },
330
329
  {
331
330
  "d-imag-rendering-crisp-edges": imagRenderingSet,
332
331
  },
333
332
  className
334
333
  )}
335
334
  src={getQualityImage(imgSrc, NetWorkTypeQuality[getNetWorkType])}
336
335
  lazyLoad={isChartH5 ? false : lazyLoad}
337
336
  onError={imageErrorHandle}
338
337
  onLoad={imageLoad.bind(this, imgSrc)}
339
338
  {...otherOption}
340
339
  />
341
340
  );
342
341
  lazyLoad: true,
343
342
  isSkuImage: false,
344
343
  hideErrorImage: false,
345
344
  imagRenderingSet: true,
346
345
  src: null,
347
346
  style: null,
348
347
  width: null,
349
348
  height: null,
350
349
  backgroundColor: null,
351
350
  className: null,
352
351
  errorSrc: null,
353
352
  onLoad: null,
354
353
  onError: null,
354
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
355
355
  getQualityImage,
356
356
  isH5AndJdShopView,
357
357
  isChartH5,
358
358
  isH5AndJdShopViewH5Scroll,
359
359
  isAppStowShop,
360
360
  getSgmCustomCode,
361
361
  sgmCustomReport,
362
362
  isImageOptimizeEnable,
363
363
  getAvifSupport,
364
364
  getWebpSupport,
365
365
  getNativePageScrollRes,
366
366
  latestFromNativeMsgStorage,
367
367
  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRFAAAAp3o92gAAAAF0Uk5TAEDm2GYAAAAKSURBVHicY2QAAAAEAAIhZK1qAAAAAElFTkSuQmCC'
368
368
  'https://img14.360buyimg.com/imagetools/jfs/t1/222907/25/7012/5824/61c4797cEbcd17c7f/6c76fc71e4fdb5a5.png'
369
369
  const styleSheets = document.styleSheets
370
370
  const internalStyleSheets = []
371
371
  for (let i = 0; i < styleSheets.length; i++) {
372
372
  const sheet = styleSheets[i]
373
373
  const ownerNode = sheet.ownerNode
374
374
  if (ownerNode && ownerNode.nodeName === 'STYLE') {
375
375
  internalStyleSheets.push(sheet)
376
376
  }
377
377
  }
378
378
  console.warn(
379
379
  '🚗 ~~ file: index.h5.tsx:47 ~~ getRuleBySelector() ~~ selector:',
380
380
  selector,
381
381
  )
382
382
  for (let i = 0; i < internalStyleSheets.length; i++) {
383
383
  try {
384
384
  const sheet = internalStyleSheets[i]
385
385
  const rules = sheet.cssRules || sheet.rules
386
386
  for (const rule of rules) {
387
387
  if (rule?.selectorText?.match(new RegExp(selector + '$'))) {
388
388
  return rule
389
389
  }
390
390
  }
391
391
  } catch (e) {
392
392
  console.warn('因安全限制无法访问样式表:', e)
393
393
  }
394
394
  }
395
395
  return null
396
396
  const {
397
397
  src = null,
398
398
  lazyLoad = true,
399
399
  imagRenderingSet = true,
400
400
  width = null,
401
401
  height = null,
402
402
  className = null,
403
403
  isSkuImage = false,
404
404
  hideErrorImage = false,
405
405
  style = null,
406
406
  backgroundColor = null,
407
407
  errorSrc = null,
408
408
  onLoad = null,
409
409
  onError = null,
410
410
  ...otherOption
411
411
  } = props
412
412
  getNetWorkType === NetWorkTypeQuality.default &&
413
413
  (getNetWorkType = global.info.sysInfo.netWorkType)
414
414
  const [loadSuccess, setLoadSuccess] = useState(false)
415
415
  const [imageErrState, setImageErrState] = useState(false)
416
416
  const [componentShowState, setComponentShowState] = useState(false)
417
417
  const measureRef = useRef<HTMLElement | null>(null)
418
418
  const [measureComplete, setMeasureComplete] = useState(false)
419
419
  const [imgSrc, setImgSrc] = useState(src)
420
420
  const [hasRetrySuccess, setHasRetrySuccess] = useState(false)
421
421
  const hasRetryRef = useRef(false)
422
422
  const componentShowStateRef = useRef(false)
423
423
  const requestSrcRef = useRef(src)
424
424
  const needShowHighVersion =
425
425
  isH5AndJdShopViewH5Scroll &&
426
426
  !(
427
427
  global.info.queryInfo?.downgraded &&
428
428
  global.info.queryInfo.downgraded === 'true'
429
429
  )
430
430
  const enableAvifOptimize = isImageOptimizeEnable()
431
431
  const isVipShop = global?.info?.pageInfo?.isVipShop
432
432
  const avifSupport = getAvifSupport()
433
433
  const webpSupport = getWebpSupport()
434
434
 
435
435
  const getRequestSrc = useCallback(
436
436
  (src) => {
437
437
  const requestSrc = getQualityImage(imgSrc, {
438
438
  isSkuImage,
439
439
  size: measureRef?.current?.getBoundingClientRect()?.width,
440
440
  })
441
441
  requestSrcRef.current = requestSrc
442
442
  return requestSrc
443
443
  },
444
444
  [src],
445
445
  )
446
446
 
447
447
  const imageErrorRetry = (src) => {
448
448
  return new Promise((resolve, reject) => {
449
449
  if (fetch && window && window.Image) {
450
450
  fetch(src)
451
451
  .then((response) => {
452
452
  const { ok, status } = response
453
453
  if (ok) {
454
454
  const originUrl = src.replace(/\.(jpe?g|png).*/, '.$1')
455
455
  response
456
456
  .blob()
457
457
  .then((blob) => {
458
458
  if (URL) {
459
459
  const url = URL.createObjectURL(blob)
460
460
  const img = new window.Image()
461
461
  img.src = url
462
462
  img.onload = () => {
463
463
  reportSGM({
464
464
  status,
465
465
  text: '再次请求并且onload了',
466
466
  type: 'retryAndOnload',
467
467
  requestSrc: src,
468
468
  resolveUrl: url,
469
469
  })
470
470
  resolve({
471
471
  ok: true,
472
472
  url,
473
473
  })
474
474
  setTimeout(() => {
475
475
  URL.revokeObjectURL(url)
476
476
  }, 2000)
477
477
  }
478
478
  img.onerror = () => {
479
479
  reportSGM({
480
480
  status,
481
481
  text: '图片解析异常',
482
482
  type: 'imageParseError',
483
483
  requestSrc: src,
484
484
  })
485
485
  URL.revokeObjectURL(url)
486
486
  resolve({
487
487
  ok: true,
488
488
  url: originUrl,
489
489
  })
490
490
  }
491
491
  } else {
492
492
  resolve({
493
493
  ok: true,
494
494
  url: originUrl,
495
495
  })
496
496
  }
497
497
  })
498
498
  .catch((error) => {
499
499
  resolve({
500
500
  ok: true,
501
501
  url: originUrl,
502
502
  })
503
503
  console.error('LazyLoadImage imageErrorRetry() error:', error)
504
504
  })
505
505
  } else {
506
506
  if (status === 404) {
507
507
  resolve({
508
508
  ok: false,
509
509
  text: '访问图片不存在',
510
510
  type: 'noSuchUrlImage',
511
511
  })
512
512
  } else {
513
513
  resolve({
514
514
  ok: false,
515
515
  status: status,
516
516
  text: '其它图片问题',
517
517
  type: 'otherImageError',
518
518
  })
519
519
  }
520
520
  }
521
521
  })
522
522
  .catch((error) => {
523
523
  resolve({
524
524
  ok: false,
525
525
  text: '网络异常',
526
526
  type: 'networkError',
527
527
  })
528
528
  console.error('LazyLoadImage imageErrorRetry() error:', error)
529
529
  })
530
530
  } else {
531
531
  resolve({
532
532
  ok: false,
533
533
  text: '不支持重试',
534
534
  type: 'notSupportRetry',
535
535
  })
536
536
  }
537
537
  })
538
538
  }
539
539
 
540
540
  const reportSGM = ({
541
541
  status,
542
542
  text,
543
543
  type,
544
544
  requestSrc = imgSrc,
545
545
  resolveUrl = '',
546
546
  }) => {
547
547
  const { shopId, venderId } = global.info.queryInfo || {}
548
548
  sgmCustomReport({
549
549
  code: getSgmCustomCode(`${SgmCustomCode.IMAGE_LOAD}_${type}`),
550
550
  msg: {
551
551
  avifSupport,
552
552
  webpSupport,
553
553
  shopId,
554
554
  venderId,
555
555
  originSrc: src,
556
556
  requestSrc,
557
557
  resolveUrl,
558
558
  status,
559
559
  text,
560
560
  },
561
561
  })
562
562
  }
563
563
  const imageErrorHandle = useCallback(
564
564
  (e) => {
565
565
  console.log(' ==============> 图片加载错误', e)
566
566
  if (!hasRetryRef.current) {
567
567
  hasRetryRef.current = true
568
568
  if (src) {
569
569
  try {
570
570
  imageErrorRetry(requestSrcRef.current).then((result) => {
571
571
  const { status, ok, text, type, url } = result || {}
572
572
  if (ok) {
573
573
  setImgSrc(url)
574
574
  setHasRetrySuccess(true)
575
575
  } else {
576
576
  errorSrc && setImgSrc(errorSrc)
577
577
  hideErrorImage && setImageErrState(true)
578
578
  typeof onError === 'function' && onError(e, src, props)
579
579
  reportSGM({
580
580
  status,
581
581
  text,
582
582
  type,
583
583
  requestSrc: requestSrcRef.current,
584
584
  })
585
585
  }
586
586
  })
587
587
  } catch (e) {
588
588
  console.error('LazyLoadImage imageErrorHandle() error:', e)
589
589
  errorSrc && setImgSrc(errorSrc)
590
590
  hideErrorImage && setImageErrState(true)
591
591
  typeof onError === 'function' && onError(e, src, props)
592
592
  }
593
593
  }
594
594
  } else {
595
595
  reportSGM({
596
596
  status: '',
597
597
  text: '渲染原始图片渲染异常',
598
598
  type: 'renderOriginImageError',
599
599
  })
600
600
  if (imgSrc.includes('blob:')) {
601
601
  reportSGM({
602
602
  status: '',
603
603
  text: '渲染本地blob图片异常',
604
604
  type: 'renderBlobImageError',
605
605
  })
606
606
  } else {
607
607
  reportSGM({
608
608
  status: '',
609
609
  text: '渲染本地非blob图片异常',
610
610
  type: 'renderNoBlobImageError',
611
611
  })
612
612
  }
613
613
  }
614
614
  },
615
615
  [src, hasRetryRef.current],
616
616
  )
617
617
 
618
618
  const imageLoad = useCallback(
619
619
  (_src, event) => {
620
620
  setLoadSuccess(true)
621
621
  typeof onLoad === 'function' && onLoad(event, src, props)
622
622
  },
623
623
  [src],
624
624
  )
625
625
 
626
626
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
627
627
  const changeStyle = {}
628
628
  width && (changeStyle['width'] = width)
629
629
  height && (changeStyle['height'] = height)
630
630
  backgroundColor && (changeStyle['backgroundColor'] = backgroundColor)
631
631
  return changeStyle
632
632
  }
633
633
  useEffect(() => {
634
634
  try {
635
635
  const { mode } = otherOption
636
636
  if (mode && mode === 'heightFix') {
637
637
  className?.split(/\s/)?.forEach((item) => {
638
638
  const userDefinedClass = getRuleBySelector('.' + item)
639
639
  const userDefinedHeight = userDefinedClass?.style?.height
640
640
  if (userDefinedHeight === '' || userDefinedHeight === 'auto') {
641
641
  console.warn(
642
642
  "🚗 ~~ 发现一例用户使用图片组件设置了 mode='heightFix' 并且没有定义一个具体高度:",
643
643
  userDefinedHeight,
644
644
  {
645
645
  code: getSgmCustomCode(`imageUsageCheck`),
646
646
  msg: {
647
647
  userDefinedClass: item,
648
648
  userDefinedHeight,
649
649
  },
650
650
  },
651
651
  )
652
652
  sgmCustomReport({
653
653
  code: getSgmCustomCode(`imageUsageCheck`),
654
654
  msg: {
655
655
  userDefinedClass: item,
656
656
  userDefinedHeight,
657
657
  },
658
658
  })
659
659
  }
660
660
  })
661
661
  }
662
662
  } catch (e) {
663
663
  console.warn('imageUsageCheck error:', e)
664
664
  }
665
665
  setMeasureComplete(true)
666
666
  if (needShowHighVersion) return
667
667
  const latestRes =
668
668
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
669
669
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
670
670
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
671
671
  !componentShowStateRef.current && dealPageScrollInfo(res)
672
672
  })
673
673
  }, [])
674
674
 
675
675
  const dealPageScrollInfo = (res) => {
676
676
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
677
677
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined')
678
678
  return
679
679
  if (measureRef.current) {
680
680
  const eleClientRect = measureRef.current.getBoundingClientRect()
681
681
  const getContainerHeightOffSetY = displayHeight * 1.5 + offSetY
682
682
  const eleOffsetTop = Math.ceil(eleClientRect.top)
683
683
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
684
684
  if (!componentShowStateRef.current) {
685
685
  if (getContainerHeightOffSetY > eleOffsetTop) {
686
686
  componentShowStateRef.current = true
687
687
  setComponentShowState(true)
688
688
  }
689
689
  }
690
690
  }
691
691
  }
692
692
  return isH5AndJdShopView &&
693
693
  global?.config?.needImageLazy !== false &&
694
694
  !needShowHighVersion &&
695
695
  !isAppStowShop ? (
696
696
  <View
697
697
  ref={measureRef}
698
698
  className={classNames(
699
699
  imageStyle['d-app-lazy-image'],
700
700
  {
701
701
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
702
702
  },
703
703
  {
704
704
  [imageStyle['d-hide-image-error']]: imageErrState,
705
705
  },
706
706
  {
707
707
  [imageStyle['d-load-completed']]: loadSuccess,
708
708
  },
709
709
  {
710
710
  'd-imag-rendering-crisp-edges':
711
711
  !isVipShop && imagRenderingSet,
712
712
  },
713
713
  'J_html5ImageBg',
714
714
  className,
715
715
  )}
716
716
  style={{
717
717
  ...style,
718
718
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
719
719
  }}
720
720
  {...otherOption}
721
721
  >
722
722
  {(componentShowState || lazyLoad === false) && (
723
723
  <img
724
724
  src={getQualityImage(
725
725
  imgSrc,
726
726
  isVipShop
727
727
  ? NetWorkTypeQuality['perfect']
728
728
  : NetWorkTypeQuality[getNetWorkType],
729
729
  )}
730
730
  onLoad={imageLoad.bind(this, imgSrc)}
731
731
  onError={imageErrorHandle}
732
732
  />
733
733
  )}
734
734
  </View>
735
735
  ) : enableAvifOptimize ? (
736
736
  [
737
737
  measureComplete ? (
738
738
  <Image
739
739
  key={hasRetrySuccess ? 'realImageRetry' : 'realImage'}
740
740
  style={{
741
741
  ...style,
742
742
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
743
743
  }}
744
744
  className={classNames(
745
745
  imageStyle['d-lazy-image'],
746
746
  {
747
747
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
748
748
  },
749
749
  {
750
750
  [imageStyle['d-hide-image-error']]: imageErrState,
751
751
  },
752
752
  {
753
753
  [imageStyle['d-load-completed']]: loadSuccess,
754
754
  },
755
755
  {
756
756
  'd-imag-rendering-crisp-edges': imagRenderingSet,
757
757
  },
758
758
  {
759
759
  [imageStyle["d-no-jd-dog"]]: isVipShop && !isSkuImage,
760
760
  },
761
761
  className,
762
762
  )}
763
763
  src={hasRetrySuccess ? imgSrc : getRequestSrc(imgSrc)}
764
764
  lazyLoad={isChartH5 ? false : lazyLoad}
765
765
  onError={imageErrorHandle}
766
766
  onLoad={imageLoad.bind(this, imgSrc)}
767
767
  {...otherOption}
768
768
  />
769
769
  ) : (
770
770
  <Image
771
771
  key="defaultImage"
772
772
  style={{
773
773
  ...style,
774
774
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
775
775
  }}
776
776
  className={classNames(
777
777
  imageStyle['d-lazy-image'],
778
778
  {
779
779
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
780
780
  },
781
781
  {
782
782
  [imageStyle['d-hide-image-error']]: imageErrState,
783
783
  },
784
784
  {
785
785
  [imageStyle['d-load-completed']]: loadSuccess,
786
786
  },
787
787
  {
788
788
  'd-imag-rendering-crisp-edges': imagRenderingSet,
789
789
  },
790
790
  {
791
791
  [imageStyle["d-no-jd-dog"]]: isVipShop && !isSkuImage,
792
792
  },
793
793
  className,
794
794
  )}
795
795
  src={isSkuImage ? DEFAULT_SKU_SRC : DEFAULT_SRC}
796
796
  />
797
797
  ),
798
798
  loadSuccess ? null : <View key="measureRef" ref={measureRef}></View>,
799
799
  ]
800
800
  ) : (
801
801
  <Image
802
802
  style={{
803
803
  ...style,
804
804
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
805
805
  }}
806
806
  className={classNames(
807
807
  imageStyle['d-lazy-image'],
808
808
  {
809
809
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
810
810
  },
811
811
  {
812
812
  [imageStyle['d-hide-image-error']]: imageErrState,
813
813
  },
814
814
  {
815
815
  [imageStyle['d-load-completed']]: loadSuccess,
816
816
  },
817
817
  {
818
818
  'd-imag-rendering-crisp-edges': imagRenderingSet,
819
819
  },
820
820
  className,
821
821
  )}
822
822
  src={getQualityImage(imgSrc, NetWorkTypeQuality[getNetWorkType])}
823
823
  lazyLoad={isChartH5 ? false : lazyLoad}
824
824
  onError={imageErrorHandle}
825
825
  onLoad={imageLoad.bind(this, imgSrc)}
826
826
  {...otherOption}
827
827
  />
828
828
  )