@conecli/cone-render 0.8.44 → 0.8.46-beta.0

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