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