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

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.
@@ -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
  sgmCustomReport,
9
8
  isImageOptimizeEnable,
10
9
  getNativePageScrollRes,
11
10
  latestFromNativeMsgStorage,
12
11
  '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='
13
12
  'https://img14.360buyimg.com/imagetools/jfs/t1/222907/25/7012/5824/61c4797cEbcd17c7f/6c76fc71e4fdb5a5.png'
14
13
  const {
15
14
  src,
16
15
  lazyLoad,
17
16
  imagRenderingSet,
18
17
  width,
19
18
  height,
20
19
  className,
21
20
  isSkuImage,
22
21
  hideErrorImage,
23
22
  style,
24
23
  backgroundColor,
25
24
  errorSrc,
26
25
  onLoad,
27
26
  onError,
28
27
  ...otherOption
29
28
  } = props
30
29
  getNetWorkType === NetWorkTypeQuality.default &&
31
30
  (getNetWorkType = taroJdBaseInfo.info.sysInfo.netWorkType)
32
31
  const [loadSuccess, setLoadSuccess] = useState(false)
33
32
  const [imageErrState, setImageErrState] = useState(false)
34
33
  const [componentShowState, setComponentShowState] = useState(false)
35
34
  const measureRef = useRef<HTMLElement | null>(null)
36
35
  const [measureComplete, setMeasureComplete] = useState(false)
37
36
  const [imgSrc, setImgSrc] = useState(src)
38
37
  const componentLazyRef = useRef<HTMLElement | null>(null)
39
38
  const componentShowStateRef = useRef(false)
40
39
  const requestSrcRef = useRef(src)
41
40
  const needShowHighVersion =
42
41
  isH5AndJdShopViewH5Scroll &&
43
42
  !(
44
43
  global.info.queryInfo?.downgraded &&
45
44
  global.info.queryInfo.downgraded === 'true'
46
45
  )
47
46
  const enableAvifOptimize = isImageOptimizeEnable()
48
47
 
49
48
  const getRequestSrc = useCallback(
50
49
  src => {
51
50
  const requestSrc = getQualityImage(imgSrc, {
52
51
  isSkuImage,
53
52
  size: measureRef?.current?.offsetWidth,
54
53
  })
55
54
  requestSrcRef.current = requestSrc
56
55
  return requestSrc
57
56
  },
58
57
  [src],
59
58
  )
60
59
  const imageError = useCallback(
61
60
  e => {
62
61
  console.log(' ==============> 图片加载错误', e)
63
62
  errorSrc && setImgSrc(errorSrc)
64
63
  hideErrorImage && setImageErrState(true)
65
64
  typeof onError === 'function' && onError(e, src, props)
66
65
  const { shopId, venderId } = global.info.queryInfo || {}
67
66
  sgmCustomReport({
68
67
  code: 'jshopViewImageLoadError',
69
68
  msg: {
70
69
  shopId,
71
70
  venderId,
72
71
  buildType,
73
72
  originSrc: src,
74
73
  requestSrc: requestSrcRef.current,
75
74
  },
76
75
  })
77
76
  },
78
77
  [src],
79
78
  )
80
79
 
81
80
  const imageLoad = useCallback(
82
81
  (_src, event) => {
83
82
  setLoadSuccess(true)
84
83
  typeof onLoad === 'function' && onLoad(event, src, props)
85
84
  },
86
85
  [src],
87
86
  )
88
87
 
89
88
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
90
89
  const changeStyle = {}
91
90
  width && (changeStyle['width'] = width)
92
91
  height && (changeStyle['height'] = height)
93
92
  backgroundColor && (changeStyle['backgroundColor'] = backgroundColor)
94
93
  return changeStyle
95
94
  }
96
95
  useEffect(() => {
97
96
  setMeasureComplete(true)
98
97
  if (needShowHighVersion) return
99
98
  const latestRes =
100
99
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
101
100
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
102
101
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
103
102
  !componentShowStateRef.current && dealPageScrollInfo(res)
104
103
  })
105
104
  }, [])
106
105
 
107
106
  const dealPageScrollInfo = res => {
108
107
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
109
108
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined')
110
109
  return
111
110
  if (measureRef.current) {
112
111
  const eleClientRect = measureRef.current.getBoundingClientRect()
113
112
  const getContainerHeightOffSetY = displayHeight * 1.5 + offSetY
114
113
  const eleOffsetTop = Math.ceil(eleClientRect.top)
115
114
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
116
115
  if (!componentShowStateRef.current) {
117
116
  if (getContainerHeightOffSetY > eleOffsetTop) {
118
117
  componentShowStateRef.current = true
119
118
  setComponentShowState(true)
120
119
  }
121
120
  }
122
121
  }
123
122
  }
124
123
  return isH5AndJdShopView &&
125
124
  global?.config?.needImageLazy !== false &&
126
125
  !needShowHighVersion &&
127
126
  !isAppStowShop ? (
128
127
  <View
129
128
  ref={measureRef}
130
129
  className={classNames(
131
130
  imageStyle['d-app-lazy-image'],
132
131
  {
133
132
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
134
133
  },
135
134
  {
136
135
  [imageStyle['d-hide-image-error']]: imageErrState,
137
136
  },
138
137
  {
139
138
  [imageStyle['d-load-completed']]: loadSuccess,
140
139
  },
141
140
  {
142
141
  'd-imag-rendering-crisp-edges':
143
142
  !taroJdBaseInfo.info.pageInfo.isVipShop && imagRenderingSet,
144
143
  },
145
144
  'J_html5ImageBg',
146
145
  className,
147
146
  )}
148
147
  style={{
149
148
  ...style,
150
149
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
151
150
  }}
152
151
  {...otherOption}
153
152
  >
154
153
  {(componentShowState || lazyLoad === false) && (
155
154
  <img
156
155
  src={getQualityImage(
157
156
  imgSrc,
158
157
  taroJdBaseInfo.info.pageInfo.isVipShop
159
158
  ? NetWorkTypeQuality['perfect']
160
159
  : NetWorkTypeQuality[getNetWorkType],
161
160
  )}
162
161
  onLoad={imageLoad.bind(this, imgSrc)}
163
162
  onError={imageError}
164
163
  />
165
164
  )}
166
165
  </View>
167
166
  ) : enableAvifOptimize ? (
168
167
  [
169
168
  measureComplete ? (
170
169
  <Image
171
170
  key={'realImage'}
172
171
  style={{
173
172
  ...style,
174
173
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
175
174
  }}
176
175
  className={classNames(
177
176
  imageStyle['d-lazy-image'],
178
177
  {
179
178
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
180
179
  },
181
180
  {
182
181
  [imageStyle['d-hide-image-error']]: imageErrState,
183
182
  },
184
183
  {
185
184
  [imageStyle['d-load-completed']]: loadSuccess,
186
185
  },
187
186
  {
188
187
  'd-imag-rendering-crisp-edges': imagRenderingSet,
189
188
  },
190
189
  className,
191
190
  )}
192
191
  src={getRequestSrc(imgSrc)}
193
192
  lazyLoad={isChartH5 ? false : lazyLoad}
194
193
  onError={imageError}
195
194
  onLoad={imageLoad.bind(this, imgSrc)}
196
195
  {...otherOption}
197
196
  />
198
197
  ) : (
199
198
  <Image
200
199
  key={'defaultImage'}
201
200
  style={{
202
201
  ...style,
203
202
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
204
203
  }}
205
204
  className={classNames(
206
205
  imageStyle['d-lazy-image'],
207
206
  {
208
207
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
209
208
  },
210
209
  {
211
210
  [imageStyle['d-hide-image-error']]: imageErrState,
212
211
  },
213
212
  {
214
213
  [imageStyle['d-load-completed']]: loadSuccess,
215
214
  },
216
215
  {
217
216
  'd-imag-rendering-crisp-edges': imagRenderingSet,
218
217
  },
219
218
  className,
220
219
  )}
221
220
  src={isSkuImage ? DEFAULT_SKU_SRC : DEFAULT_SRC}
222
221
  />
223
222
  ),
224
223
  loadSuccess ? null : <View key={'measureRef'} ref={measureRef}></View>,
225
224
  ]
226
225
  ) : (
227
226
  <Image
228
227
  style={{
229
228
  ...style,
230
229
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
231
230
  }}
232
231
  className={classNames(
233
232
  imageStyle['d-lazy-image'],
234
233
  {
235
234
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
236
235
  },
237
236
  {
238
237
  [imageStyle['d-hide-image-error']]: imageErrState,
239
238
  },
240
239
  {
241
240
  [imageStyle['d-load-completed']]: loadSuccess,
242
241
  },
243
242
  {
244
243
  'd-imag-rendering-crisp-edges': imagRenderingSet,
245
244
  },
246
245
  className,
247
246
  )}
248
247
  src={getQualityImage(imgSrc, NetWorkTypeQuality[getNetWorkType])}
249
248
  lazyLoad={isChartH5 ? false : lazyLoad}
250
249
  onError={imageError}
251
250
  onLoad={imageLoad.bind(this, imgSrc)}
252
251
  {...otherOption}
253
252
  />
254
253
  )
255
254
  lazyLoad: true,
256
255
  isSkuImage: false,
257
256
  hideErrorImage: false,
258
257
  imagRenderingSet: true,
259
258
  src: null,
260
259
  style: null,
261
260
  width: null,
262
261
  height: null,
263
262
  backgroundColor: null,
264
263
  className: null,
265
264
  errorSrc: null,
266
265
  onLoad: null,
267
266
  onError: null,
267
+ import React, { useCallback, useEffect, useRef, useState } from "react";
268
268
  getQualityImage,
269
269
  isH5AndJdShopView,
270
270
  isJdApp,
271
271
  isChartH5,
272
272
  isH5AndJdShopViewH5Scroll,
273
273
  isAppStowShop,
274
274
  getSgmCustomCode,
275
275
  sgmCustomReport,
276
276
  isImageOptimizeEnable,
277
277
  getNativePageScrollRes,
278
278
  latestFromNativeMsgStorage,
279
279
  "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=";
280
280
  "https://img14.360buyimg.com/imagetools/jfs/t1/222907/25/7012/5824/61c4797cEbcd17c7f/6c76fc71e4fdb5a5.png";
281
281
  const {
282
282
  src = null,
283
283
  lazyLoad = true,
284
284
  imagRenderingSet = true,
285
285
  width = null,
286
286
  height = null,
287
287
  className = null,
288
288
  isSkuImage = false,
289
289
  hideErrorImage = false,
290
290
  style = null,
291
291
  backgroundColor = null,
292
292
  errorSrc = null,
293
293
  onLoad = null,
294
294
  onError = null,
295
295
  ...otherOption
296
296
  } = props;
297
297
  getNetWorkType === NetWorkTypeQuality.default &&
298
298
  (getNetWorkType = global.info.sysInfo.netWorkType);
299
299
  const [loadSuccess, setLoadSuccess] = useState(false);
300
300
  const [imageErrState, setImageErrState] = useState(false);
301
301
  const [componentShowState, setComponentShowState] = useState(false);
302
302
  const measureRef = useRef<HTMLElement | null>(null);
303
303
  const [measureComplete, setMeasureComplete] = useState(false);
304
304
  const [imgSrc, setImgSrc] = useState(src);
305
305
  const [hasRetrySuccess, setHasRetrySuccess] = useState(false);
306
306
  const hasRetryRef = useRef(false);
307
307
  const componentShowStateRef = useRef(false);
308
308
  const requestSrcRef = useRef(src);
309
309
  const needShowHighVersion =
310
310
  isH5AndJdShopViewH5Scroll &&
311
311
  !(
312
312
  global.info.queryInfo?.downgraded &&
313
313
  global.info.queryInfo.downgraded === "true"
314
314
  );
315
315
  const enableAvifOptimize = isImageOptimizeEnable();
316
316
 
317
317
  const getRequestSrc = useCallback(
318
318
  (src) => {
319
319
  const requestSrc = getQualityImage(imgSrc, {
320
320
  isSkuImage,
321
321
  size: measureRef?.current?.offsetWidth,
322
322
  });
323
323
  requestSrcRef.current = requestSrc;
324
324
  return requestSrc;
325
325
  },
326
326
  [src]
327
327
  );
328
328
 
329
329
  const imageErrorRetry = (src) => {
330
330
  return new Promise((resolve, reject) => {
331
331
  if (fetch && window && window.Image) {
332
332
  fetch(src)
333
333
  .then((response) => {
334
334
  const { ok, status } = response;
335
335
  if (ok) {
336
336
  response.blob().then((blob) => {
337
337
  const url = URL.createObjectURL(blob);
338
338
  const img = new window.Image();
339
339
  img.src = url;
340
340
  img.onload = () => {
341
341
  resolve({
342
342
  ok: true,
343
343
  url,
344
344
  });
345
345
  setTimeout(() => {
346
346
  URL.revokeObjectURL(url);
347
347
  }, 1000);
348
348
  };
349
349
  img.onerror = () => {
350
350
  resolve({
351
351
  ok: false,
352
352
  text: "图片解析异常",
353
353
  type: "imageParseError",
354
354
  });
355
355
  URL.revokeObjectURL(url);
356
356
  };
357
357
  });
358
358
  } else {
359
359
  if (status === 404) {
360
360
  resolve({
361
361
  ok: false,
362
362
  text: "访问图片不存在",
363
363
  type: "noSuchUrlImage",
364
364
  });
365
365
  } else {
366
366
  resolve({
367
367
  ok: false,
368
368
  status: status,
369
369
  text: "其它图片问题",
370
370
  type: "otherImageError",
371
371
  });
372
372
  }
373
373
  }
374
374
  })
375
375
  .catch((error) => {
376
376
  resolve({
377
377
  ok: false,
378
378
  text: "网络异常",
379
379
  type: "networkError",
380
380
  });
381
381
  console.error("LazyLoadImage imageErrorRetry() error:", error);
382
382
  });
383
383
  } else {
384
384
  resolve({
385
385
  ok: false,
386
386
  text: "不支持重试",
387
387
  type: "notSupportRetry",
388
388
  });
389
389
  }
390
390
  });
391
391
  };
392
392
  const imageErrorHandle = useCallback(
393
393
  (e) => {
394
394
  console.log(" ==============> 图片加载错误", e);
395
395
  if (!hasRetryRef.current) {
396
396
  hasRetryRef.current = true;
397
397
  if (src) {
398
398
  try {
399
399
  imageErrorRetry(requestSrcRef.current).then((result) => {
400
400
  const { status, ok, text, type, url } = result || {};
401
401
  if (ok) {
402
402
  setImgSrc(url);
403
403
  setHasRetrySuccess(true);
404
404
  } else {
405
405
  errorSrc && setImgSrc(errorSrc);
406
406
  hideErrorImage && setImageErrState(true);
407
407
  typeof onError === "function" && onError(e, src, props);
408
408
  const { shopId, venderId } = global.info.queryInfo || {};
409
409
  sgmCustomReport({
410
410
  code: getSgmCustomCode(`${SgmCustomCode.IMAGE_LOAD}_${type}`),
411
411
  msg: {
412
412
  shopId,
413
413
  venderId,
414
414
  originSrc: src,
415
415
  requestSrc: requestSrcRef.current,
416
416
  status,
417
417
  text,
418
418
  },
419
419
  });
420
420
  }
421
421
  });
422
422
  } catch (e) {
423
423
  console.error("LazyLoadImage imageErrorHandle() error:", e);
424
424
  errorSrc && setImgSrc(errorSrc);
425
425
  hideErrorImage && setImageErrState(true);
426
426
  typeof onError === "function" && onError(e, src, props);
427
427
  }
428
428
  }
429
429
  }
430
430
  },
431
431
  [src, hasRetryRef.current]
432
432
  );
433
433
 
434
434
  const imageLoad = useCallback(
435
435
  (_src, event) => {
436
436
  setLoadSuccess(true);
437
437
  typeof onLoad === "function" && onLoad(event, src, props);
438
438
  },
439
439
  [src]
440
440
  );
441
441
 
442
442
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
443
443
  const changeStyle = {};
444
444
  width && (changeStyle["width"] = width);
445
445
  height && (changeStyle["height"] = height);
446
446
  backgroundColor && (changeStyle["backgroundColor"] = backgroundColor);
447
447
  return changeStyle;
448
448
  };
449
449
  useEffect(() => {
450
450
  setMeasureComplete(true);
451
451
  if (needShowHighVersion) return;
452
452
  const latestRes =
453
453
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {};
454
454
  !componentShowStateRef.current && dealPageScrollInfo(latestRes);
455
455
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
456
456
  !componentShowStateRef.current && dealPageScrollInfo(res);
457
457
  });
458
458
  }, []);
459
459
 
460
460
  const dealPageScrollInfo = (res) => {
461
461
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {};
462
462
  if (typeof displayHeight === "undefined" || typeof offSetY === "undefined")
463
463
  return;
464
464
  if (measureRef.current) {
465
465
  const eleClientRect = measureRef.current.getBoundingClientRect();
466
466
  const getContainerHeightOffSetY = displayHeight * 1.5 + offSetY;
467
467
  const eleOffsetTop = Math.ceil(eleClientRect.top);
468
468
  const eleOffsetHeight = Math.ceil(eleClientRect.height);
469
469
  if (!componentShowStateRef.current) {
470
470
  if (getContainerHeightOffSetY > eleOffsetTop) {
471
471
  componentShowStateRef.current = true;
472
472
  setComponentShowState(true);
473
473
  }
474
474
  }
475
475
  }
476
476
  };
477
477
  return isH5AndJdShopView &&
478
478
  global?.config?.needImageLazy !== false &&
479
479
  !needShowHighVersion &&
480
480
  !isAppStowShop ? (
481
481
  <View
482
482
  ref={measureRef}
483
483
  className={classNames(
484
484
  imageStyle["d-app-lazy-image"],
485
485
  {
486
486
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
487
487
  },
488
488
  {
489
489
  [imageStyle["d-hide-image-error"]]: imageErrState,
490
490
  },
491
491
  {
492
492
  [imageStyle["d-load-completed"]]: loadSuccess,
493
493
  },
494
494
  {
495
495
  "d-imag-rendering-crisp-edges":
496
496
  !global.info.pageInfo.isVipShop && imagRenderingSet,
497
497
  },
498
498
  "J_html5ImageBg",
499
499
  className
500
500
  )}
501
501
  style={{
502
502
  ...style,
503
503
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
504
504
  }}
505
505
  {...otherOption}
506
506
  >
507
507
  {(componentShowState || lazyLoad === false) && (
508
508
  <img
509
509
  src={getQualityImage(
510
510
  imgSrc,
511
511
  global.info.pageInfo.isVipShop
512
512
  ? NetWorkTypeQuality["perfect"]
513
513
  : NetWorkTypeQuality[getNetWorkType]
514
514
  )}
515
515
  onLoad={imageLoad.bind(this, imgSrc)}
516
516
  onError={imageErrorHandle}
517
517
  />
518
518
  )}
519
519
  </View>
520
520
  ) : enableAvifOptimize ? (
521
521
  [
522
522
  measureComplete ? (
523
523
  <Image
524
524
  key={hasRetrySuccess ? "realImageRetry" : "realImage"}
525
525
  style={{
526
526
  ...style,
527
527
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
528
528
  }}
529
529
  className={classNames(
530
530
  imageStyle["d-lazy-image"],
531
531
  {
532
532
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
533
533
  },
534
534
  {
535
535
  [imageStyle["d-hide-image-error"]]: imageErrState,
536
536
  },
537
537
  {
538
538
  [imageStyle["d-load-completed"]]: loadSuccess,
539
539
  },
540
540
  {
541
541
  "d-imag-rendering-crisp-edges": imagRenderingSet,
542
542
  },
543
543
  className
544
544
  )}
545
545
  src={hasRetrySuccess ? imgSrc : getRequestSrc(imgSrc)}
546
546
  lazyLoad={isChartH5 ? false : lazyLoad}
547
547
  onError={imageErrorHandle}
548
548
  onLoad={imageLoad.bind(this, imgSrc)}
549
549
  {...otherOption}
550
550
  />
551
551
  ) : (
552
552
  <Image
553
553
  key={"defaultImage"}
554
554
  style={{
555
555
  ...style,
556
556
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
557
557
  }}
558
558
  className={classNames(
559
559
  imageStyle["d-lazy-image"],
560
560
  {
561
561
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
562
562
  },
563
563
  {
564
564
  [imageStyle["d-hide-image-error"]]: imageErrState,
565
565
  },
566
566
  {
567
567
  [imageStyle["d-load-completed"]]: loadSuccess,
568
568
  },
569
569
  {
570
570
  "d-imag-rendering-crisp-edges": imagRenderingSet,
571
571
  },
572
572
  className
573
573
  )}
574
574
  src={isSkuImage ? DEFAULT_SKU_SRC : DEFAULT_SRC}
575
575
  />
576
576
  ),
577
577
  loadSuccess ? null : <View key={"measureRef"} ref={measureRef}></View>,
578
578
  ]
579
579
  ) : (
580
580
  <Image
581
581
  style={{
582
582
  ...style,
583
583
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
584
584
  }}
585
585
  className={classNames(
586
586
  imageStyle["d-lazy-image"],
587
587
  {
588
588
  [imageStyle["d-lazy-sku-image"]]: isSkuImage,
589
589
  },
590
590
  {
591
591
  [imageStyle["d-hide-image-error"]]: imageErrState,
592
592
  },
593
593
  {
594
594
  [imageStyle["d-load-completed"]]: loadSuccess,
595
595
  },
596
596
  {
597
597
  "d-imag-rendering-crisp-edges": imagRenderingSet,
598
598
  },
599
599
  className
600
600
  )}
601
601
  src={getQualityImage(imgSrc, NetWorkTypeQuality[getNetWorkType])}
602
602
  lazyLoad={isChartH5 ? false : lazyLoad}
603
603
  onError={imageErrorHandle}
604
604
  onLoad={imageLoad.bind(this, imgSrc)}
605
605
  {...otherOption}
606
606
  />
607
607
  );
@@ -1 +1 @@
1
- import React, {useCallback, useState} from 'react'
1
+ import React, { useCallback, useState } from 'react'
2
2
  const {
3
3
  src = null,
4
4
  lazyLoad = true,
5
5
  imagRenderingSet = true,
6
6
  width = null,
7
7
  height = null,
8
8
  className = null,
9
9
  isSkuImage = false,
10
10
  hideErrorImage = false,
11
11
  style = null,
12
12
  backgroundColor = null,
13
13
  errorSrc = null,
14
14
  onLoad = null,
15
15
  onError = null,
16
16
  ...otherOption
17
17
  } = props
18
18
  getNetWorkType === NetWorkTypeQuality.default &&
19
19
  (getNetWorkType = taroJdBaseInfo.info.sysInfo.netWorkType)
20
20
  const [loadSuccess, setLoadSuccess] = useState(false)
21
21
  const [imgSrc, setImgSrc] = useState(src)
22
22
  const [imageErrState, setImageErrState] = useState(false)
23
23
  const imageError = useCallback(
24
24
  (e) => {
25
25
  console.log('图片加载错误', e)
26
26
  errorSrc && setImgSrc(errorSrc)
27
27
  hideErrorImage && setImageErrState(true)
28
28
  typeof onError === 'function' && onError(e, src, props)
29
29
  },
30
30
  [src],
31
31
  )
32
32
 
33
33
  const imageLoad = useCallback(
34
34
  (event) => {
35
35
  setLoadSuccess(true)
36
36
  typeof onLoad === 'function' && onLoad(event, src, props)
37
37
  },
38
38
  [src],
39
39
  )
40
40
 
41
41
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
42
42
  const changeStyle = {}
43
43
  width && (changeStyle['width'] = width)
44
44
  height && (changeStyle['height'] = height)
45
45
  backgroundColor && (changeStyle['backgroundColor'] = backgroundColor)
46
46
  return changeStyle
47
47
  }
48
48
  return (
49
49
  <Image
50
50
  style={{
51
51
  ...style,
52
52
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
53
53
  }}
54
54
  className={classNames(
55
55
  imageStyle['d-lazy-image'],
56
56
  {
57
57
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
58
58
  },
59
59
  {
60
60
  [imageStyle['d-hide-image-error']]: imageErrState,
61
61
  },
62
62
  {
63
63
  [imageStyle['d-load-completed']]: loadSuccess,
64
64
  },
65
65
  {
66
66
  'd-imag-rendering-crisp-edges': imagRenderingSet,
67
67
  },
68
68
  className,
69
69
  )}
70
70
  src={getQualityImage(imgSrc, NetWorkTypeQuality[getNetWorkType])}
71
71
  lazyLoad={lazyLoad}
72
72
  onError={imageError}
73
73
  onLoad={imageLoad}
74
74
  {...otherOption}
75
75
  />
76
76
  )
@@ -7,3 +7,11 @@
7
7
  position: relative;
8
8
  }
9
9
  }
10
+ :global {
11
+ .d-mobile-header-sticky {
12
+ position: fixed;
13
+ top: 0;
14
+ width: 100%;
15
+ z-index: 999;
16
+ }
17
+ }