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