@conecli/cone-render 0.9.1-shop2.0 → 0.9.1-shop2.10

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 (98) 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 -0
  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/jssdk.ts +1 -0
  9. package/dist/common/pageType.ts +1 -0
  10. package/dist/common/sgmCustomCode.ts +1 -0
  11. package/dist/common/token/index.h5.ts +1 -1
  12. package/dist/common/token/token.jd.ts +1 -1
  13. package/dist/common/token/token.ts +1 -1
  14. package/dist/common/wxappApi.jd.ts +1 -0
  15. package/dist/components/ErrorBoundary.tsx +1 -1
  16. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  17. package/dist/components/base/CountDown/index.tsx +1 -1
  18. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  19. package/dist/components/base/CustomScrollView/index.module.scss +7 -0
  20. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  21. package/dist/components/base/Dialog/index.module.scss +5 -0
  22. package/dist/components/base/Dialog/index.tsx +1 -1
  23. package/dist/components/base/Exposure/index.h5.tsx +1 -1
  24. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  25. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  26. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  27. package/dist/components/base/InViewRender/index.tsx +1 -1
  28. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  29. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  30. package/dist/components/base/LazyLoadImage/const.ts +1 -1
  31. package/dist/components/base/LazyLoadImage/index.h5.module.scss +20 -20
  32. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  33. package/dist/components/base/MobileCommonHeader/index.module.scss +9 -0
  34. package/dist/components/base/MobileCommonHeader/index.tsx +1 -0
  35. package/dist/components/base/NetworkDataError/const.ts +1 -1
  36. package/dist/components/base/NetworkDataError/index.module.scss +4 -0
  37. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  38. package/dist/components/base/Price/Double/index.tsx +1 -1
  39. package/dist/components/base/Price/index.tsx +1 -1
  40. package/dist/components/decorate/DecorateFloorModule/index.module.scss +21 -2
  41. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  42. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  43. package/dist/components/floorItem.jd.tsx +1 -1
  44. package/dist/components/floorItem.tsx +1 -1
  45. package/dist/components/floorItem.weapp.tsx +1 -1
  46. package/dist/components/isv/Floor/index.tsx +1 -1
  47. package/dist/components/remoteFloorItem.tsx +1 -1
  48. package/dist/interface/common.ts +1 -1
  49. package/dist/interface/component.ts +1 -1
  50. package/dist/interface/jumpEventReport.ts +1 -1
  51. package/dist/interface/service.ts +1 -1
  52. package/dist/interface/utils.ts +1 -1
  53. package/dist/jumpEventReport/base.ts +1 -1
  54. package/dist/jumpEventReport/const.ts +1 -1
  55. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  56. package/dist/jumpEventReport/index.h5.ts +1 -1
  57. package/dist/jumpEventReport/index.jd.ts +1 -1
  58. package/dist/jumpEventReport/index.weapp.ts +1 -1
  59. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  60. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  61. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  62. package/dist/jumpEventReport/web/report.ts +1 -1
  63. package/dist/jumpEventReport/web.base.ts +1 -1
  64. package/dist/jumpEventReport/web.jd.ts +1 -1
  65. package/dist/jumpEventReport/web.jdb.ts +1 -1
  66. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  67. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  68. package/dist/jumpEventReport/web.pc.ts +1 -0
  69. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  70. package/dist/jumpEventReport/web.tjm.ts +1 -0
  71. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  72. package/dist/modules/ContainerFloorList/index.h5.module.scss +17 -1
  73. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  74. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  75. package/dist/open/api/environment.ts +1 -1
  76. package/dist/open/api/index.ts +1 -1
  77. package/dist/open/api/jump copy.ts +1 -1
  78. package/dist/open/api/shopMember.ts +1 -1
  79. package/dist/open/api/track.ts +1 -1
  80. package/dist/open/api/util.ts +1 -1
  81. package/dist/open/components/index.ts +1 -1
  82. package/dist/sass/app.h5.scss +39 -3
  83. package/dist/sass/base.scss +12 -0
  84. package/dist/service/fetchGateway.ts +1 -1
  85. package/dist/service/http/const.ts +1 -1
  86. package/dist/service/requestServer.ts +1 -1
  87. package/dist/utils/connectNativeJsBridge.ts +1 -1
  88. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  89. package/dist/utils/draExceptionAndProfile.ts +1 -1
  90. package/dist/utils/h5Utils.ts +1 -1
  91. package/dist/utils/index.h5.ts +1 -1
  92. package/dist/utils/index.ts +1 -1
  93. package/dist/utils/index.weapp.ts +1 -1
  94. package/dist/utils/jm-common.js +1 -1
  95. package/dist/utils/sgmCodeUtils.ts +1 -0
  96. package/dist/utils/taroRenderUtil.ts +1 -1
  97. package/dist/utils/utils.ts +1 -1
  98. package/package.json +1 -1
@@ -1 +1 @@
1
- import Taro, { useRouter } from "@tarojs/taro";
2
1
  SECTION_HOME_TAB_TYPE,
3
2
  SECTION_HOME_TAB_NAME_TYPE,
4
3
  TaroEventType,
5
4
  latestFromNativeMsgStorage,
6
5
  nativePageRegisterMessage,
7
6
  Message_Type,
8
7
  getNativePageScrollRes,
9
8
  const {
10
9
  children,
11
10
  containerId,
12
11
  type,
13
12
  placeholder,
14
13
  height,
15
14
  floorData = {},
16
15
  sectionType,
17
16
  lazyNodeClassName,
18
17
  } = props;
19
18
  const getRouterInfo = useRouter();
20
19
  const getQueryData = getRouterInfo?.params || {};
21
20
  const [componentShowState, setComponentShowState] = useState(false);
22
21
  const [componentRenderShowState, setComponentRenderShowState] =
23
22
  useState(false);
24
23
  const componentLazyRef = useRef<HTMLElement | null>(null);
25
24
  const componentShowStateRef = useRef(false);
26
25
  const needShowHighVersion =
27
26
  isH5AndJdShopViewH5Scroll &&
28
27
  !(
29
28
  global.info.queryInfo?.downgraded &&
30
29
  global.info.queryInfo.downgraded === "true"
31
30
  );
32
31
  const rootDom =
33
32
  isH5AndJdShopView && needShowHighVersion
34
33
  ? null
35
34
  : document.querySelector("#J_shopHomeRoot");
36
35
  const { ref, inView } = useInView({
37
36
  threshold: 0,
38
37
  triggerOnce: true,
39
38
  root: rootDom,
40
39
  rootMargin: `0px 0px ${window.innerHeight}px 0px`,
41
40
  });
42
41
  useEffect(() => {
43
42
  if (needShowHighVersion) return;
44
43
  if (type === LazyType.FLOOR) {
45
44
  const latestRes =
46
45
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {};
47
46
  !componentShowStateRef.current && dealPageScrollInfo(latestRes);
48
47
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
49
48
  !componentShowStateRef.current && dealPageScrollInfo(res);
50
49
  });
51
50
  }
52
51
  }, []);
53
52
  useEffect(() => {
54
53
  if (
55
54
  (!needShowHighVersion && componentShowState === true) ||
56
55
  (needShowHighVersion && inView && isH5AndJdShopView)
57
56
  ) {
58
57
  console.log(
59
58
  ">>>>>>>>>>>>>>>>>>> 楼层【id=" + containerId + "】已经渲染!"
60
59
  );
61
60
  const modularPackResultObj = formatPackResult(
62
61
  floorData?.floorExtInfo?.modularPackResult
63
62
  );
64
63
  const bundleUrl = getBundleUrl(modularPackResultObj);
65
64
  if (bundleUrl) {
66
65
  nativePageRegisterMessage(Message_Type.NATIVE_INJECT_JS_FILE, {
67
66
  data: {
68
67
  bundleUrl: [bundleUrl],
69
68
  },
70
69
  });
71
70
  }
72
71
  }
73
72
  }, [componentShowState, inView]);
74
73
 
75
74
  const dealPageScrollInfo = (res) => {
76
75
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {};
77
76
  if (typeof displayHeight === "undefined" || typeof offSetY === "undefined")
78
77
  return;
79
78
  if (componentLazyRef.current) {
80
79
  const eleClientRect = componentLazyRef.current.getBoundingClientRect();
81
80
  const getContainerHeightOffSetY = displayHeight + offSetY;
82
81
  const eleOffsetTop = Math.ceil(eleClientRect.top);
83
82
  const eleOffsetHeight = Math.ceil(eleClientRect.height);
84
83
  const eleOffsetTopHeight = eleOffsetTop + eleOffsetHeight;
85
84
  if (!componentShowStateRef.current) {
86
85
  if (getContainerHeightOffSetY > eleOffsetTop) {
87
86
  componentShowStateRef.current = true;
88
87
  setComponentShowState(true);
89
88
  Taro.nextTick(() => {
90
89
  setComponentRenderShowState(true);
91
90
  });
92
91
  }
93
92
  }
94
93
  }
95
94
  };
96
95
  return isH5AndJdShopView && !needShowHighVersion ? (
97
96
  <div
98
97
  id={`${containerId}_lazy`}
99
98
  ref={componentLazyRef}
100
99
  className={classNames(
101
100
  lazyLayoutLoadStyle["d-app-floor-lazy-layout-load"],
102
101
  "d-app-floor-lazy-load"
103
102
  )}
104
103
  style={{
105
104
  minHeight: `${componentRenderShowState ? "auto" : height + "px"}`,
106
105
  backgroundColor: componentRenderShowState ? "transparent" : "#ffffff",
107
106
  }}
108
107
  >
109
108
  {componentShowState ? children : placeholder}
110
109
  </div>
111
110
  ) : (
112
111
  <div
113
112
  id={`${containerId}_lazy`}
114
113
  className={classNames(
115
114
  lazyLayoutLoadStyle["d-mobile-floor-lazy-layout-load"],
116
115
  "d-mobile-floor-lazy-load"
117
116
  )}
118
117
  ref={ref}
119
118
  style={{
120
119
  minHeight: `${inView ? "auto" : height + "px"}`,
121
120
  backgroundColor: inView ? "transparent" : "#ffffff",
122
121
  }}
123
122
  >
124
123
  {inView ? children : placeholder}
125
124
  </div>
126
125
  );
127
126
  sectionType:
128
127
  SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN],
129
128
  type: LazyType.FLOOR,
130
129
  children: null,
131
130
  placeholder: null,
132
131
  height: 200,
133
132
  className: "",
134
133
  lazyNodeClassName: "",
134
+ import Taro, { useRouter } from "@tarojs/taro";
135
135
  SECTION_HOME_TAB_TYPE,
136
136
  SECTION_HOME_TAB_NAME_TYPE,
137
137
  TaroEventType,
138
138
  latestFromNativeMsgStorage,
139
139
  nativePageRegisterMessage,
140
140
  Message_Type,
141
141
  getNativePageScrollRes,
142
142
  const {
143
143
  children,
144
144
  containerId,
145
145
  type,
146
146
  placeholder,
147
147
  height,
148
148
  floorData = {},
149
149
  sectionType,
150
150
  lazyNodeClassName,
151
151
  } = props
152
152
  const getRouterInfo = useRouter()
153
153
  const getQueryData = getRouterInfo?.params || {}
154
154
  const [componentShowState, setComponentShowState] = useState(false)
155
155
  const [componentRenderShowState, setComponentRenderShowState] =
156
156
  useState(false)
157
157
  const componentLazyRef = useRef<HTMLElement | null>(null)
158
158
  const componentShowStateRef = useRef(false)
159
159
  const needShowHighVersion = isH5AndJdShopViewH5Scroll && !(global.info.queryInfo?.downgraded && global.info.queryInfo.downgraded === "true")
160
160
  const rootDom = isH5AndJdShopView && needShowHighVersion ? null : document.querySelector('#J_shopHomeRoot')
161
161
  const { ref, inView } = useInView({
162
162
  threshold: 0,
163
163
  triggerOnce: true,
164
164
  root: rootDom,
165
165
  rootMargin: `0px 0px ${window.innerHeight}px 0px`,
166
166
  })
167
167
  useEffect(() => {
168
168
  if(needShowHighVersion || !isH5AndJdShopView) return
169
169
  if (type === LazyType.FLOOR) {
170
170
  const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
171
171
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
172
172
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
173
173
  !componentShowStateRef.current && dealPageScrollInfo(res)
174
174
  })
175
175
  }
176
176
  }, [])
177
177
  useEffect(() => {
178
178
  if((!needShowHighVersion && componentShowState === true) ||
179
179
  (needShowHighVersion && inView && isH5AndJdShopView)
180
180
  ) {
181
181
  console.log('>>>>>>>>>>>>>>>>>>> 楼层【id=' + containerId + '】已经渲染!')
182
182
  const modularPackResult = floorData?.floorExtInfo?.modularPackResult
183
183
  const modularPackResultObj = typeof modularPackResult === 'string' ? JSON.parse(modularPackResult) : modularPackResult
184
184
  if (modularPackResultObj && modularPackResultObj.bundleUrl) {
185
185
  const { bundleUrl } = modularPackResultObj
186
186
  nativePageRegisterMessage(
187
187
  Message_Type.NATIVE_INJECT_JS_FILE,
188
188
  {
189
189
  data: {
190
190
  "bundleUrl": [bundleUrl]
191
191
  },
192
192
  },
193
193
  )
194
194
  }
195
195
  }
196
196
  }, [componentShowState,inView])
197
197
 
198
198
  const dealPageScrollInfo = (res) => {
199
199
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {};
200
200
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') {
201
201
  const shopId = floorData?.floorExtInfo?.shopId
202
202
  if(!lazyLayoutLoadErrorShopId[`${shopId}`]) {
203
203
  const opt = {
204
204
  msg: `店铺楼层懒加载失败。楼层顺序-floorIdx: ${floorData?.floorIdx}。`,
205
205
  uid: floorData?.uid,
206
206
  floorIdx: floorData?.floorIdx,
207
207
  shopId: shopId,
208
208
  moduleId: floorData?.moduleId,
209
209
  moduleName: floorData?.moduleName,
210
210
  middleTemplateId: floorData?.middleTemplateId,
211
211
  modularPackResult: typeof floorData?.floorExtInfo?.modularPackResult == 'string' ? JSON.parse(floorData?.floorExtInfo?.modularPackResult) : floorData?.floorExtInfo?.modularPackResult,
212
212
  }
213
213
  sgmCustomReport({
214
214
  code: 'lazyLayoutLoadError',
215
215
  msg: opt,
216
216
  })
217
217
  lazyLayoutLoadErrorShopId[`${shopId}`] = true
218
218
  }
219
219
  return
220
220
  }
221
221
  if (componentLazyRef.current) {
222
222
  const eleClientRect =
223
223
  componentLazyRef.current.getBoundingClientRect()
224
224
  const getContainerHeightOffSetY = displayHeight + offSetY
225
225
  const eleOffsetTop = Math.ceil(eleClientRect.top)
226
226
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
227
227
  const eleOffsetTopHeight = eleOffsetTop + eleOffsetHeight
228
228
  if (!componentShowStateRef.current) {
229
229
  if (getContainerHeightOffSetY > eleOffsetTop) {
230
230
  componentShowStateRef.current = true
231
231
  setComponentShowState(true)
232
232
  Taro.nextTick(() => {
233
233
  setComponentRenderShowState(true)
234
234
  })
235
235
  }
236
236
  }
237
237
  }
238
238
  }
239
239
  return isH5AndJdShopView && !needShowHighVersion ? (
240
240
  <div
241
241
  id={`${containerId}_lazy`}
242
242
  ref={componentLazyRef}
243
243
  className={classNames(
244
244
  lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
245
245
  'd-app-floor-lazy-load',
246
246
  )}
247
247
  style={{
248
248
  minHeight: `${
249
249
  componentRenderShowState ? 'auto' : height + 'px'
250
250
  }`,
251
251
  backgroundColor: componentRenderShowState
252
252
  ? 'transparent'
253
253
  : '#ffffff',
254
254
  }}
255
255
  >
256
256
  {componentShowState ? children : placeholder}
257
257
  </div>
258
258
  ) : (
259
259
  <div
260
260
  id={`${containerId}_lazy`}
261
261
  className={classNames(
262
262
  lazyLayoutLoadStyle["d-mobile-floor-lazy-layout-load"],
263
263
  "d-mobile-floor-lazy-load",
264
264
  lazyNodeClassName,
265
265
  )}
266
266
  ref={ref}
267
267
  style={{
268
268
  minHeight: `${inView ? 'auto' : height + 'px'}`,
269
269
  backgroundColor: inView ? 'transparent' : '#ffffff',
270
270
  }}
271
271
  >
272
272
  {inView ? children : placeholder}
273
273
  </div>
274
274
  );
275
275
  sectionType:
276
276
  SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN],
277
277
  type: LazyType.FLOOR,
278
278
  children: null,
279
279
  placeholder: null,
280
280
  height: 200,
281
281
  className: '',
282
282
  lazyNodeClassName: '',
@@ -1 +1 @@
1
- export const NetWorkTypeQuality = {
1
+ export const NetWorkTypeQuality = {
@@ -1,24 +1,24 @@
1
1
 
2
2
  .d-lazy-image,
3
3
  .d-app-lazy-image {
4
- //background: #F8F8F8 url("../../resoure/jd_logo_bg.png") center center/50% no-repeat;
5
- background: #fff
6
- url('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=')
7
- center center no-repeat;
8
- &.d-lazy-sku-image {
9
- background-image: url('https://img14.360buyimg.com/imagetools/jfs/t1/222907/25/7012/5824/61c4797cEbcd17c7f/6c76fc71e4fdb5a5.png');
10
- background-size: cover;
11
- }
12
- &.d-load-completed {
13
- background: none;
14
- }
15
- img {
16
- display: block;
17
- width: 100%;
18
- }
19
- &.d-hide-image-error {
20
- img {
21
- opacity: 0;
22
- }
23
- }
4
+ //background: #F8F8F8 url("../../resoure/jd_logo_bg.png") center center/50% no-repeat;
5
+ background: #fff
6
+ url('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=')
7
+ center center no-repeat;
8
+ &.d-lazy-sku-image {
9
+ background-image: url('https://img14.360buyimg.com/imagetools/jfs/t1/222907/25/7012/5824/61c4797cEbcd17c7f/6c76fc71e4fdb5a5.png');
10
+ background-size: cover;
11
+ }
12
+ &.d-load-completed {
13
+ background: none;
14
+ }
15
+ img {
16
+ display: block;
17
+ width: 100%;
18
+ }
19
+ &.d-hide-image-error {
20
+ img {
21
+ opacity: 0;
22
+ }
23
+ }
24
24
  }
@@ -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
  getNativePageScrollRes,
8
7
  latestFromNativeMsgStorage,
9
8
  const {
10
9
  src,
11
10
  lazyLoad,
12
11
  imagRenderingSet,
13
12
  width,
14
13
  height,
15
14
  className,
16
15
  isSkuImage,
17
16
  hideErrorImage,
18
17
  style,
19
18
  backgroundColor,
20
19
  errorSrc,
21
20
  onLoad,
22
21
  onError,
23
22
  ...otherOption
24
23
  } = props
25
24
  getNetWorkType === NetWorkTypeQuality.default &&
26
25
  (getNetWorkType = taroJdBaseInfo.info.sysInfo.netWorkType)
27
26
  const [loadSuccess, setLoadSuccess] = useState(false)
28
27
  const [imageErrState, setImageErrState] = useState(false)
29
28
  const [componentShowState, setComponentShowState] = useState(false)
30
29
  const [imgSrc, setImgSrc] = useState(src)
31
30
  const componentLazyRef = useRef<HTMLElement | null>(null)
32
31
  const componentShowStateRef = useRef(false)
33
32
  const needShowHighVersion =
34
33
  isH5AndJdShopViewH5Scroll &&
35
34
  !(
36
35
  global.info.queryInfo?.downgraded &&
37
36
  global.info.queryInfo.downgraded === 'true'
38
37
  )
39
38
  const { ref, inView } = useInView({
40
39
  threshold: 0,
41
40
  triggerOnce: true,
42
41
  root: null,
43
42
  rootMargin: `0px 0px ${window.innerHeight * 0.5}px 0px`,
44
43
  })
45
44
  const imageError = useCallback(
46
45
  (e) => {
47
46
  console.log('图片加载错误', e)
48
47
  errorSrc && setImgSrc(errorSrc)
49
48
  hideErrorImage && setImageErrState(true)
50
49
  typeof onError === 'function' && onError(e, src, props)
51
50
  },
52
51
  [src],
53
52
  )
54
53
 
55
54
  const imageLoad = useCallback(
56
55
  (_src, event) => {
57
56
  setLoadSuccess(true)
58
57
  typeof onLoad === 'function' && onLoad(event, src, props)
59
58
  },
60
59
  [src],
61
60
  )
62
61
 
63
62
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
64
63
  const changeStyle = {}
65
64
  width && (changeStyle['width'] = width)
66
65
  height && (changeStyle['height'] = height)
67
66
  backgroundColor && (changeStyle['backgroundColor'] = backgroundColor)
68
67
  return changeStyle
69
68
  }
70
69
  useEffect(() => {
71
70
  if (needShowHighVersion) return
72
71
  const latestRes =
73
72
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
74
73
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
75
74
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
76
75
  !componentShowStateRef.current && dealPageScrollInfo(res)
77
76
  })
78
77
  }, [])
79
78
 
80
79
  const dealPageScrollInfo = (res) => {
81
80
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
82
81
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined')
83
82
  return
84
83
  if (componentLazyRef.current) {
85
84
  const eleClientRect = componentLazyRef.current.getBoundingClientRect()
86
85
  const getContainerHeightOffSetY = displayHeight * 1.5 + offSetY
87
86
  const eleOffsetTop = Math.ceil(eleClientRect.top)
88
87
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
89
88
  if (!componentShowStateRef.current) {
90
89
  if (getContainerHeightOffSetY > eleOffsetTop) {
91
90
  componentShowStateRef.current = true
92
91
  setComponentShowState(true)
93
92
  }
94
93
  }
95
94
  }
96
95
  }
97
96
  <View
98
97
  ref={ componentLazyRef }
99
98
  className={classNames(
100
99
  imageStyle['d-app-lazy-image'],
101
100
  {
102
101
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
103
102
  },
104
103
  {
105
104
  [imageStyle['d-hide-image-error']]: imageErrState,
106
105
  },
107
106
  {
108
107
  [imageStyle['d-load-completed']]: loadSuccess,
109
108
  },
110
109
  {
111
110
  'd-imag-rendering-crisp-edges':
112
111
  !taroJdBaseInfo.info.pageInfo.isVipShop &&
113
112
  imagRenderingSet,
114
113
  },
115
114
  'J_html5ImageBg',
116
115
  className,
117
116
  )}
118
117
  style={{
119
118
  ...style,
120
119
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
121
120
  >
122
121
  {(componentShowState || lazyLoad === false) && <img
123
122
  src={getQualityImage(
124
123
  imgSrc,
125
124
  taroJdBaseInfo.info.pageInfo.isVipShop
126
125
  ? NetWorkTypeQuality['perfect']
127
126
  : NetWorkTypeQuality[getNetWorkType],
128
127
  )}
129
128
  onLoad={imageLoad.bind(this, imgSrc)}
130
129
  onError={imageError}
131
130
  />}
132
131
  </View>
133
132
  ) : (
134
133
  <Image
135
134
  style={{
136
135
  ...style,
137
136
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
138
137
  }}
139
138
  className={classNames(
140
139
  imageStyle['d-lazy-image'],
141
140
  {
142
141
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
143
142
  },
144
143
  {
145
144
  [imageStyle['d-hide-image-error']]: imageErrState,
146
145
  },
147
146
  {
148
147
  [imageStyle['d-load-completed']]: loadSuccess,
149
148
  },
150
149
  {
151
150
  'd-imag-rendering-crisp-edges': imagRenderingSet,
152
151
  },
153
152
  className,
154
153
  )}
155
154
  src={getQualityImage(
156
155
  imgSrc,
157
156
  NetWorkTypeQuality[getNetWorkType],
158
157
  )}
159
158
  lazyLoad={isChartH5 ? false : lazyLoad}
160
159
  onError={imageError}
161
160
  onLoad={imageLoad.bind(this, imgSrc)}
162
161
  {...otherOption}
163
162
  />
164
163
  )
165
164
  lazyLoad: true,
166
165
  isSkuImage: false,
167
166
  hideErrorImage: false,
168
167
  imagRenderingSet: true,
169
168
  src: null,
170
169
  style: null,
171
170
  width: null,
172
171
  height: null,
173
172
  backgroundColor: null,
174
173
  className: null,
175
174
  errorSrc: null,
176
175
  onLoad: null,
177
176
  onError: null,
177
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
178
178
  TaroEventType,
179
179
  getQualityImage,
180
180
  isH5AndJdShopView,
181
181
  isJdApp,
182
182
  isChartH5,
183
183
  isH5AndJdShopViewH5Scroll,
184
184
  isAppStowShop
185
185
  getNativePageScrollRes,
186
186
  latestFromNativeMsgStorage,
187
187
  const {
188
188
  src,
189
189
  lazyLoad,
190
190
  imagRenderingSet,
191
191
  width,
192
192
  height,
193
193
  className,
194
194
  isSkuImage,
195
195
  hideErrorImage,
196
196
  style,
197
197
  backgroundColor,
198
198
  errorSrc,
199
199
  onLoad,
200
200
  onError,
201
201
  ...otherOption
202
202
  } = props
203
203
  getNetWorkType === NetWorkTypeQuality.default &&
204
204
  (getNetWorkType = taroJdBaseInfo.info.sysInfo.netWorkType)
205
205
  const [loadSuccess, setLoadSuccess] = useState(false)
206
206
  const [imageErrState, setImageErrState] = useState(false)
207
207
  const [componentShowState, setComponentShowState] = useState(false)
208
208
  const [imgSrc, setImgSrc] = useState(src)
209
209
  const componentLazyRef = useRef<HTMLElement | null>(null)
210
210
  const componentShowStateRef = useRef(false)
211
211
  const needShowHighVersion =
212
212
  isH5AndJdShopViewH5Scroll &&
213
213
  !(
214
214
  global.info.queryInfo?.downgraded &&
215
215
  global.info.queryInfo.downgraded === 'true'
216
216
  )
217
217
  const imageError = useCallback(
218
218
  (e) => {
219
219
  console.log('图片加载错误', e)
220
220
  errorSrc && setImgSrc(errorSrc)
221
221
  hideErrorImage && setImageErrState(true)
222
222
  typeof onError === 'function' && onError(e, src, props)
223
223
  },
224
224
  [src],
225
225
  )
226
226
 
227
227
  const imageLoad = useCallback(
228
228
  (_src, event) => {
229
229
  setLoadSuccess(true)
230
230
  typeof onLoad === 'function' && onLoad(event, src, props)
231
231
  },
232
232
  [src],
233
233
  )
234
234
 
235
235
  const changeStyleIncludeWidthAndHeightAndBgColor = () => {
236
236
  const changeStyle = {}
237
237
  width && (changeStyle['width'] = width)
238
238
  height && (changeStyle['height'] = height)
239
239
  backgroundColor && (changeStyle['backgroundColor'] = backgroundColor)
240
240
  return changeStyle
241
241
  }
242
242
  useEffect(() => {
243
243
  if(needShowHighVersion) return
244
244
  const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
245
245
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
246
246
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
247
247
  !componentShowStateRef.current && dealPageScrollInfo(res)
248
248
  })
249
249
  }, [])
250
250
 
251
251
  const dealPageScrollInfo = (res) => {
252
252
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
253
253
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') return
254
254
  if (componentLazyRef.current) {
255
255
  const eleClientRect =
256
256
  componentLazyRef.current.getBoundingClientRect()
257
257
  const getContainerHeightOffSetY =
258
258
  displayHeight * 1.5 + offSetY
259
259
  const eleOffsetTop = Math.ceil(eleClientRect.top)
260
260
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
261
261
  if (!componentShowStateRef.current) {
262
262
  if (getContainerHeightOffSetY > eleOffsetTop) {
263
263
  componentShowStateRef.current = true
264
264
  setComponentShowState(true)
265
265
  }
266
266
  }
267
267
  }
268
268
  }
269
269
  return (
270
270
  (isH5AndJdShopView && global?.config?.needImageLazy !== false && !needShowHighVersion && !isAppStowShop) ? (
271
271
  <View
272
272
  ref={ componentLazyRef }
273
273
  className={classNames(
274
274
  imageStyle['d-app-lazy-image'],
275
275
  {
276
276
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
277
277
  },
278
278
  {
279
279
  [imageStyle['d-hide-image-error']]: imageErrState,
280
280
  },
281
281
  {
282
282
  [imageStyle['d-load-completed']]: loadSuccess,
283
283
  },
284
284
  {
285
285
  'd-imag-rendering-crisp-edges':
286
286
  !taroJdBaseInfo.info.pageInfo.isVipShop &&
287
287
  imagRenderingSet,
288
288
  },
289
289
  'J_html5ImageBg',
290
290
  className,
291
291
  )}
292
292
  style={{
293
293
  ...style,
294
294
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
295
295
  }}
296
296
  {...otherOption}
297
297
  >
298
298
  {(componentShowState || lazyLoad === false) && <img
299
299
  src={getQualityImage(
300
300
  imgSrc,
301
301
  taroJdBaseInfo.info.pageInfo.isVipShop
302
302
  ? NetWorkTypeQuality['perfect']
303
303
  : NetWorkTypeQuality[getNetWorkType],
304
304
  )}
305
305
  onLoad={imageLoad.bind(this, imgSrc)}
306
306
  onError={imageError}
307
307
  />}
308
308
  </View>
309
309
  ) : (
310
310
  <Image
311
311
  style={{
312
312
  ...style,
313
313
  ...changeStyleIncludeWidthAndHeightAndBgColor(),
314
314
  }}
315
315
  className={classNames(
316
316
  imageStyle['d-lazy-image'],
317
317
  {
318
318
  [imageStyle['d-lazy-sku-image']]: isSkuImage,
319
319
  },
320
320
  {
321
321
  [imageStyle['d-hide-image-error']]: imageErrState,
322
322
  },
323
323
  {
324
324
  [imageStyle['d-load-completed']]: loadSuccess,
325
325
  },
326
326
  {
327
327
  'd-imag-rendering-crisp-edges': imagRenderingSet,
328
328
  },
329
329
  className,
330
330
  )}
331
331
  src={getQualityImage(
332
332
  imgSrc,
333
333
  NetWorkTypeQuality[getNetWorkType],
334
334
  )}
335
335
  lazyLoad={isChartH5 ? false : lazyLoad}
336
336
  onError={imageError}
337
337
  onLoad={imageLoad.bind(this, imgSrc)}
338
338
  {...otherOption}
339
339
  />
340
340
  )
341
341
  )
342
342
  lazyLoad: true,
343
343
  isSkuImage: false,
344
344
  hideErrorImage: false,
345
345
  imagRenderingSet: true,
346
346
  src: null,
347
347
  style: null,
348
348
  width: null,
349
349
  height: null,
350
350
  backgroundColor: null,
351
351
  className: null,
352
352
  errorSrc: null,
353
353
  onLoad: null,
354
354
  onError: null,