@conecli/cone-render 0.10.1-beta.4 → 0.10.1-beta.5

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 (50) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/index.h5.ts +1 -1
  4. package/dist/common/index.weapp.ts +1 -1
  5. package/dist/common/sgmCustomCode.ts +1 -1
  6. package/dist/components/ErrorBoundary.tsx +1 -1
  7. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  8. package/dist/components/base/CustomVideo/index.tsx +1 -1
  9. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  10. package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
  11. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  12. package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
  13. package/dist/components/base/LazyLoadImage/index.h5.module.scss +3 -0
  14. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  15. package/dist/components/base/MobileCommonHeader/index.tsx +1 -1
  16. package/dist/components/base/NetworkDataError/index.module.scss +3 -0
  17. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  18. package/dist/components/decorate/DecorateFloorModule/index.module.scss +11 -0
  19. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  20. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  21. package/dist/components/decorate/PlaceHolder/index.tsx +1 -1
  22. package/dist/components/floorItem.tsx +1 -1
  23. package/dist/components/remoteFloorItem.tsx +1 -1
  24. package/dist/interface/common.ts +1 -1
  25. package/dist/interface/component.ts +1 -1
  26. package/dist/interface/service.ts +1 -1
  27. package/dist/jumpEventReport/base.ts +1 -1
  28. package/dist/jumpEventReport/const.ts +1 -1
  29. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  30. package/dist/jumpEventReport/web.base.ts +1 -1
  31. package/dist/jumpEventReport/web.jd.ts +1 -1
  32. package/dist/modules/ContainerFloorList/index.h5.module.scss +1 -0
  33. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  34. package/dist/open/api/device.ts +1 -1
  35. package/dist/open/api/request.ts +1 -1
  36. package/dist/open/api/shopMember.ts +1 -1
  37. package/dist/open/api/util.ts +1 -1
  38. package/dist/open/components/index.ts +1 -1
  39. package/dist/sass/app.h5.scss +5 -0
  40. package/dist/sass/base.scss +45 -0
  41. package/dist/service/requestServer.ts +1 -1
  42. package/dist/utils/connectNativeJsBridge.ts +1 -1
  43. package/dist/utils/h5Utils.ts +1 -1
  44. package/dist/utils/index.h5.ts +1 -1
  45. package/dist/utils/index.ts +1 -1
  46. package/dist/utils/index.weapp.ts +1 -1
  47. package/dist/utils/sgmCodeUtils.ts +1 -1
  48. package/dist/utils/taroRenderUtil.ts +1 -1
  49. package/dist/utils/utils.ts +1 -1
  50. package/package.json +24 -23
@@ -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 = null,
17
16
  lazyLoad = true,
18
17
  imagRenderingSet = true,
19
18
  width = null,
20
19
  height = null,
21
20
  className = null,
22
21
  isSkuImage = false,
23
22
  hideErrorImage = false,
24
23
  style = null,
25
24
  backgroundColor = null,
26
25
  errorSrc = null,
27
26
  onLoad = null,
28
27
  onError = null,
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
  );
341
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
342
342
  getQualityImage,
343
343
  isH5AndJdShopView,
344
344
  isJdApp,
345
345
  isChartH5,
346
346
  isH5AndJdShopViewH5Scroll,
347
347
  isAppStowShop,
348
348
  getSgmCustomCode,
349
349
  sgmCustomReport,
350
350
  isImageOptimizeEnable,
351
351
  getAvifSupport,
352
352
  getWebpSupport,
353
353
  getNativePageScrollRes,
354
354
  latestFromNativeMsgStorage,
355
355
  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRFAAAAp3o92gAAAAF0Uk5TAEDm2GYAAAAKSURBVHicY2QAAAAEAAIhZK1qAAAAAElFTkSuQmCC";
356
356
  'https://img14.360buyimg.com/imagetools/jfs/t1/222907/25/7012/5824/61c4797cEbcd17c7f/6c76fc71e4fdb5a5.png'
357
357
  const {
358
358
  src = null,
359
359
  lazyLoad = true,
360
360
  imagRenderingSet = true,
361
361
  width = null,
362
362
  height = null,
363
363
  className = null,
364
364
  isSkuImage = false,
365
365
  hideErrorImage = false,
366
366
  style = null,
367
367
  backgroundColor = null,
368
368
  errorSrc = null,
369
369
  onLoad = null,
370
370
  onError = null,
371
371
  ...otherOption
372
372
  } = props
373
373
  getNetWorkType === NetWorkTypeQuality.default &&
374
374
  (getNetWorkType = global.info.sysInfo.netWorkType)
375
375
  const [loadSuccess, setLoadSuccess] = useState(false)
376
376
  const [imageErrState, setImageErrState] = useState(false)
377
377
  const [componentShowState, setComponentShowState] = useState(false)
378
378
  const measureRef = useRef<HTMLElement | null>(null)
379
379
  const [measureComplete, setMeasureComplete] = useState(false)
380
380
  const [imgSrc, setImgSrc] = useState(src)
381
381
  const [hasRetrySuccess, setHasRetrySuccess] = useState(false)
382
382
  const hasRetryRef = useRef(false)
383
383
  const componentShowStateRef = useRef(false)
384
384
  const requestSrcRef = useRef(src)
385
385
  const needShowHighVersion =
386
386
  isH5AndJdShopViewH5Scroll &&
387
387
  !(
388
388
  global.info.queryInfo?.downgraded &&
389
389
  global.info.queryInfo.downgraded === 'true'
390
390
  )
391
391
  const enableAvifOptimize = isImageOptimizeEnable()
392
392
  const avifSupport = getAvifSupport();
393
393
  const webpSupport = getWebpSupport();
394
394
 
395
395
  const getRequestSrc = useCallback(
396
396
  (src) => {
397
397
  const requestSrc = getQualityImage(imgSrc, {
398
398
  isSkuImage,
399
399
  size: measureRef?.current?.offsetWidth,
400
400
  })
401
401
  requestSrcRef.current = requestSrc
402
402
  return requestSrc
403
403
  },
404
404
  [src],
405
405
  )
406
406
 
407
407
  const imageErrorRetry = (src) => {
408
408
  return new Promise((resolve, reject) => {
409
409
  if (fetch && window && window.Image) {
410
410
  fetch(src)
411
411
  .then((response) => {
412
412
  const { ok, status } = response
413
413
  if (ok) {
414
414
  const originUrl = src.replace(/\.(jpe?g|png).*/, ".$1");
415
415
  response
416
416
  .blob()
417
417
  .then((blob) => {
418
418
  if (URL) {
419
419
  const url = URL.createObjectURL(blob);
420
420
  const img = new window.Image();
421
421
  img.src = url;
422
422
  img.onload = () => {
423
423
  reportSGM({
424
424
  status,
425
425
  text: "再次请求并且onload了",
426
426
  type: "retryAndOnload",
427
427
  requestSrc: src,
428
428
  resolveUrl: url,
429
429
  });
430
430
  resolve({
431
431
  ok: true,
432
432
  url,
433
433
  });
434
434
  setTimeout(() => {
435
435
  URL.revokeObjectURL(url);
436
436
  }, 2000);
437
437
  };
438
438
  img.onerror = () => {
439
439
  reportSGM({
440
440
  status,
441
441
  text: "图片解析异常",
442
442
  type: "imageParseError",
443
443
  requestSrc: src,
444
444
  });
445
445
  URL.revokeObjectURL(url);
446
446
  resolve({
447
447
  ok: true,
448
448
  url: originUrl,
449
449
  });
450
450
  };
451
451
  } else {
452
452
  resolve({
453
453
  ok: true,
454
454
  url: originUrl,
455
455
  });
456
456
  }
457
457
  })
458
458
  .catch((error) => {
459
459
  resolve({
460
460
  ok: true,
461
461
  url: originUrl,
462
462
  });
463
463
  console.error(
464
464
  "LazyLoadImage imageErrorRetry() error:",
465
465
  error
466
466
  );
467
467
  });
468
468
  } else {
469
469
  if (status === 404) {
470
470
  resolve({
471
471
  ok: false,
472
472
  text: '访问图片不存在',
473
473
  type: 'noSuchUrlImage',
474
474
  })
475
475
  } else {
476
476
  resolve({
477
477
  ok: false,
478
478
  status: status,
479
479
  text: '其它图片问题',
480
480
  type: 'otherImageError',
481
481
  })
482
482
  }
483
483
  }
484
484
  })
485
485
  .catch((error) => {
486
486
  resolve({
487
487
  ok: false,
488
488
  text: '网络异常',
489
489
  type: 'networkError',
490
490
  })
491
491
  console.error('LazyLoadImage imageErrorRetry() error:', error)
492
492
  })
493
493
  } else {
494
494
  resolve({
495
495
  ok: false,
496
496
  text: '不支持重试',
497
497
  type: 'notSupportRetry',
498
498
  })
499
499
  }
500
500
  })
501
501
  }
502
502
 
503
503
  const reportSGM = ({
504
504
  status,
505
505
  text,
506
506
  type,
507
507
  requestSrc = imgSrc,
508
508
  resolveUrl = "",
509
509
  }) => {
510
510
  const { shopId, venderId } = global.info.queryInfo || {};
511
511
  sgmCustomReport({
512
512
  code: getSgmCustomCode(`${SgmCustomCode.IMAGE_LOAD}_${type}`),
513
513
  msg: {
514
514
  avifSupport,
515
515
  webpSupport,
516
516
  shopId,
517
517
  venderId,
518
518
  originSrc: src,
519
519
  requestSrc,
520
520
  resolveUrl,
521
521
  status,
522
522
  text,
523
523
  },
524
524
  });
525
525
  };
526
526
  const imageErrorHandle = useCallback(
527
527
  (e) => {
528
528
  console.log(' ==============> 图片加载错误', e)
529
529
  if (!hasRetryRef.current) {
530
530
  hasRetryRef.current = true
531
531
  if (src) {
532
532
  try {
533
533
  imageErrorRetry(requestSrcRef.current).then((result) => {
534
534
  const { status, ok, text, type, url } = result || {}
535
535
  if (ok) {
536
536
  setImgSrc(url)
537
537
  setHasRetrySuccess(true)
538
538
  } else {
539
539
  errorSrc && setImgSrc(errorSrc)
540
540
  hideErrorImage && setImageErrState(true)
541
541
  typeof onError === 'function' && onError(e, src, props)
542
542
  reportSGM({
543
543
  status,
544
544
  text,
545
545
  type,
546
546
  requestSrc: requestSrcRef.current,
547
547
  });
548
548
  }
549
549
  })
550
550
  } catch (e) {
551
551
  console.error('LazyLoadImage imageErrorHandle() error:', e)
552
552
  errorSrc && setImgSrc(errorSrc)
553
553
  hideErrorImage && setImageErrState(true)
554
554
  typeof onError === 'function' && onError(e, src, props)
555
555
  }
556
556
  }
557
557
  } else {
558
558
  reportSGM({
559
559
  status: "",
560
560
  text: "渲染原始图片渲染异常",
561
561
  type: "renderOriginImageError",
562
562
  });
563
563
  if (imgSrc.includes("blob:")) {
564
564
  reportSGM({
565
565
  status: "",
566
566
  text: "渲染本地blob图片异常",
567
567
  type: "renderBlobImageError",
568
568
  });
569
569
  } else {
570
570
  reportSGM({
571
571
  status: "",
572
572
  text: "渲染本地非blob图片异常",
573
573
  type: "renderNoBlobImageError",
574
574
  });
575
575
  }
576
576
  }
577
577
  },
578
578
  [src, hasRetryRef.current],
579
579
  )
580
580
 
581
581
  const imageLoad = useCallback(
582
582
  (_src, event) => {
583
583
  setLoadSuccess(true)
584
584
  typeof onLoad === 'function' && onLoad(event, src, props)
585
585
  },
586
586
  [src],
587
587
  )
588
588
 
589
589
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
590
590
  const changeStyle = {}
591
591
  width && (changeStyle['width'] = width)
592
592
  height && (changeStyle['height'] = height)
593
593
  backgroundColor && (changeStyle['backgroundColor'] = backgroundColor)
594
594
  return changeStyle
595
595
  }
596
596
  useEffect(() => {
597
597
  setMeasureComplete(true)
598
598
  if (needShowHighVersion) return
599
599
  const latestRes =
600
600
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
601
601
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
602
602
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
603
603
  !componentShowStateRef.current && dealPageScrollInfo(res)
604
604
  })
605
605
  }, [])
606
606
 
607
607
  const dealPageScrollInfo = (res) => {
608
608
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
609
609
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined')
610
610
  return
611
611
  if (measureRef.current) {
612
612
  const eleClientRect = measureRef.current.getBoundingClientRect()
613
613
  const getContainerHeightOffSetY = displayHeight * 1.5 + offSetY
614
614
  const eleOffsetTop = Math.ceil(eleClientRect.top)
615
615
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
616
616
  if (!componentShowStateRef.current) {
617
617
  if (getContainerHeightOffSetY > eleOffsetTop) {
618
618
  componentShowStateRef.current = true
619
619
  setComponentShowState(true)
620
620
  }
621
621
  }
622
622
  }
623
623
  }
624
624
  return isH5AndJdShopView &&
625
625
  global?.config?.needImageLazy !== false &&
626
626
  !needShowHighVersion &&
627
627
  !isAppStowShop ? (
628
628
  <View
629
629
  ref={measureRef}
630
630
  className={classNames(
631
631
  imageStyle['d-app-lazy-image'],
632
632
  {
633
633
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
634
634
  },
635
635
  {
636
636
  [imageStyle['d-hide-image-error']]: imageErrState,
637
637
  },
638
638
  {
639
639
  [imageStyle['d-load-completed']]: loadSuccess,
640
640
  },
641
641
  {
642
642
  'd-imag-rendering-crisp-edges':
643
643
  !global.info.pageInfo.isVipShop && imagRenderingSet,
644
644
  },
645
645
  'J_html5ImageBg',
646
646
  className,
647
647
  )}
648
648
  style={{
649
649
  ...style,
650
650
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
651
651
  }}
652
652
  {...otherOption}
653
653
  >
654
654
  {(componentShowState || lazyLoad === false) && (
655
655
  <img
656
656
  src={getQualityImage(
657
657
  imgSrc,
658
658
  global.info.pageInfo.isVipShop
659
659
  ? NetWorkTypeQuality['perfect']
660
660
  : NetWorkTypeQuality[getNetWorkType],
661
661
  )}
662
662
  onLoad={imageLoad.bind(this, imgSrc)}
663
663
  onError={imageErrorHandle}
664
664
  />
665
665
  )}
666
666
  </View>
667
667
  ) : enableAvifOptimize ? (
668
668
  [
669
669
  measureComplete ? (
670
670
  <Image
671
671
  key={hasRetrySuccess ? 'realImageRetry' : 'realImage'}
672
672
  style={{
673
673
  ...style,
674
674
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
675
675
  }}
676
676
  className={classNames(
677
677
  imageStyle['d-lazy-image'],
678
678
  {
679
679
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
680
680
  },
681
681
  {
682
682
  [imageStyle['d-hide-image-error']]: imageErrState,
683
683
  },
684
684
  {
685
685
  [imageStyle['d-load-completed']]: loadSuccess,
686
686
  },
687
687
  {
688
688
  'd-imag-rendering-crisp-edges': imagRenderingSet,
689
689
  },
690
690
  className,
691
691
  )}
692
692
  src={hasRetrySuccess ? imgSrc : getRequestSrc(imgSrc)}
693
693
  lazyLoad={isChartH5 ? false : lazyLoad}
694
694
  onError={imageErrorHandle}
695
695
  onLoad={imageLoad.bind(this, imgSrc)}
696
696
  {...otherOption}
697
697
  />
698
698
  ) : (
699
699
  <Image
700
700
  key={'defaultImage'}
701
701
  style={{
702
702
  ...style,
703
703
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
704
704
  }}
705
705
  className={classNames(
706
706
  imageStyle['d-lazy-image'],
707
707
  {
708
708
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
709
709
  },
710
710
  {
711
711
  [imageStyle['d-hide-image-error']]: imageErrState,
712
712
  },
713
713
  {
714
714
  [imageStyle['d-load-completed']]: loadSuccess,
715
715
  },
716
716
  {
717
717
  'd-imag-rendering-crisp-edges': imagRenderingSet,
718
718
  },
719
719
  className,
720
720
  )}
721
721
  src={isSkuImage ? DEFAULT_SKU_SRC : DEFAULT_SRC}
722
722
  />
723
723
  ),
724
724
  loadSuccess ? null : <View key={'measureRef'} ref={measureRef}></View>,
725
725
  ]
726
726
  ) : (
727
727
  <Image
728
728
  style={{
729
729
  ...style,
730
730
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
731
731
  }}
732
732
  className={classNames(
733
733
  imageStyle['d-lazy-image'],
734
734
  {
735
735
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
736
736
  },
737
737
  {
738
738
  [imageStyle['d-hide-image-error']]: imageErrState,
739
739
  },
740
740
  {
741
741
  [imageStyle['d-load-completed']]: loadSuccess,
742
742
  },
743
743
  {
744
744
  'd-imag-rendering-crisp-edges': imagRenderingSet,
745
745
  },
746
746
  className,
747
747
  )}
748
748
  src={getQualityImage(imgSrc, NetWorkTypeQuality[getNetWorkType])}
749
749
  lazyLoad={isChartH5 ? false : lazyLoad}
750
750
  onError={imageErrorHandle}
751
751
  onLoad={imageLoad.bind(this, imgSrc)}
752
752
  {...otherOption}
753
753
  />
754
754
  )