@conecli/cone-render 0.10.1-shop3.13 → 0.10.1-shop3.131

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