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