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