@conecli/cone-render 0.8.39 → 0.8.41

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 (90) hide show
  1. package/README.md +7 -1
  2. package/dist/api/index.ts +1 -1
  3. package/dist/common/const.ts +1 -1
  4. package/dist/common/environmentType.ts +1 -0
  5. package/dist/common/index.h5.ts +1 -1
  6. package/dist/common/index.jd.ts +1 -1
  7. package/dist/common/index.ts +1 -1
  8. package/dist/common/index.weapp.ts +1 -1
  9. package/dist/common/jdplayerSdk.ts +1 -0
  10. package/dist/common/sgmCustomCode.ts +1 -0
  11. package/dist/common/token/token.jd.ts +1 -1
  12. package/dist/common/token/token.ts +1 -1
  13. package/dist/common/wxappApi.jd.ts +1 -0
  14. package/dist/components/ErrorBoundary.tsx +1 -1
  15. package/dist/components/base/CountDown/index.tsx +1 -1
  16. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  17. package/dist/components/base/CustomScrollView/index.module.scss +7 -0
  18. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  19. package/dist/components/base/CustomVideo/index.tsx +1 -1
  20. package/dist/components/base/Dialog/index.module.scss +5 -0
  21. package/dist/components/base/Dialog/index.tsx +1 -1
  22. package/dist/components/base/Exposure/index.h5.tsx +1 -1
  23. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  24. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  25. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  26. package/dist/components/base/InViewRender/index.tsx +1 -1
  27. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  28. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  29. package/dist/components/base/LazyLayoutLoad/index.weapp.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/NetworkDataError/const.ts +1 -1
  34. package/dist/components/base/NetworkDataError/index.module.scss +4 -0
  35. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  36. package/dist/components/base/Skeleton/index.tsx +1 -1
  37. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  38. package/dist/components/floorItem.jd.tsx +1 -1
  39. package/dist/components/floorItem.weapp.tsx +1 -1
  40. package/dist/components/isv/Floor/index.tsx +1 -1
  41. package/dist/components/remoteFloorItem.tsx +1 -1
  42. package/dist/interface/common.ts +1 -1
  43. package/dist/interface/component.ts +1 -1
  44. package/dist/interface/jumpEventReport.ts +1 -1
  45. package/dist/interface/service.ts +1 -1
  46. package/dist/interface/utils.ts +1 -1
  47. package/dist/jumpEventReport/base.ts +1 -1
  48. package/dist/jumpEventReport/const.ts +1 -1
  49. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  50. package/dist/jumpEventReport/index.h5.ts +1 -1
  51. package/dist/jumpEventReport/index.jd.ts +1 -1
  52. package/dist/jumpEventReport/index.weapp.ts +1 -1
  53. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  54. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  55. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  56. package/dist/jumpEventReport/web/report.ts +1 -1
  57. package/dist/jumpEventReport/web.base.ts +1 -1
  58. package/dist/jumpEventReport/web.jd.ts +1 -1
  59. package/dist/jumpEventReport/web.jdb.ts +1 -1
  60. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  61. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  62. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  63. package/dist/jumpEventReport/web.tjm.ts +1 -0
  64. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  65. package/dist/modules/ContainerFloorList/index.h5.module.scss +17 -1
  66. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  67. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  68. package/dist/open/api/environment.ts +1 -1
  69. package/dist/open/api/index.ts +1 -1
  70. package/dist/open/api/jump copy.ts +1 -1
  71. package/dist/open/api/shopMember.ts +1 -1
  72. package/dist/open/api/track.ts +1 -1
  73. package/dist/open/api/util.ts +1 -1
  74. package/dist/sass/app.h5.scss +39 -3
  75. package/dist/sass/base.scss +12 -0
  76. package/dist/service/requestServer.ts +1 -1
  77. package/dist/utils/connectNativeJsBridge.ts +1 -1
  78. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  79. package/dist/utils/draExceptionAndProfile.ts +1 -1
  80. package/dist/utils/h5Utils.ts +1 -1
  81. package/dist/utils/index.h5.ts +1 -1
  82. package/dist/utils/index.ts +1 -1
  83. package/dist/utils/index.weapp.ts +1 -1
  84. package/dist/utils/jm-common.js +1 -1
  85. package/dist/utils/sgmCodeUtils.ts +1 -0
  86. package/dist/utils/taroRenderUtil.ts +1 -0
  87. package/dist/utils/utils.ts +1 -1
  88. package/package.json +2 -1
  89. package/dist/components/base/Skeleton/old.tsx +0 -1
  90. package/dist/customHooks/useDocumentVisibilitychange.ts +0 -1
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  const { type, className, reportData, trackCallback } = props
3
2
  const checkReportData = Array.isArray(reportData)
4
3
  const [floorData, mInfo] = checkReportData ? reportData : []
5
4
  const getFloorPointClassName = `J_floor_${floorData?.uid}_index_${mInfo?.pos}`
6
5
  if (
7
6
  !taroJdBaseInfo.info.pageInfo.floorExposureInfo[
8
7
  getFloorPointClassName
9
8
  ]
10
9
  ){
11
10
  const createIntersectionObserver = new intersectionObserver({
12
11
  selector: `#J_floor_${floorData?.uid} >>> .${getFloorPointClassName}`,
13
12
  context: this,
14
13
  onFinal: (res) => {
15
14
  taroJdBaseInfo.info.pageInfo.floorExposureInfo[
16
15
  getFloorPointClassName
17
16
  ] = true
18
17
  console.log('小程序曝光埋点收到进入可视区域啦!', getFloorPointClassName, reportData, res)
19
18
  addReportData(reportData)
20
19
  typeof trackCallback === 'function' && trackCallback(reportData)
21
20
  createIntersectionObserver.disconnect()
22
21
  },
23
22
  })
24
23
  createIntersectionObserver.connect()
25
24
  }
26
25
  floorData &&
27
26
  mInfo && (
28
27
  {
29
28
  [exposureStyle['d-report-point']]: type === TrackType.point,
30
29
  },
31
30
  {
32
31
  [exposureStyle['d-report-floor']]: type === TrackType.floor,
33
32
  },
34
33
  getFloorPointClassName,
35
34
  reportData: null,
36
35
  trackCallback: null,
37
36
  type: TrackType.point,
37
+ import Taro from '@tarojs/taro'
38
38
  const { type, className, reportData, customReportDataKey, customReportDataFn, trackCallback } = props
39
39
  const isViewOnlineState =
40
40
  taroJdBaseInfo.info.pageInfo.dataType === BUSINESS_TYPE.ONLINE
41
41
  const isCustomReport = customReportDataKey && customReportDataFn
42
42
  const checkReportData = Array.isArray(reportData)
43
43
  const [floorData, mInfo] = checkReportData ? reportData : []
44
44
  const showRenderState = isCustomReport ? true : floorData && mInfo
45
45
  const getFloorPointClassName = isCustomReport ? `J_custom_${customReportDataKey}` : `J_floor_${floorData?.uid}_index_${mInfo?.pos}`
46
46
  const getTaroSelector = isCustomReport ? `#J_miniShopRoot >>> ${getFloorPointClassName}` : `#J_floor_${floorData?.uid} >>> .${getFloorPointClassName}`
47
47
  useEffect(() => {
48
48
  if (isViewOnlineState && reportData) {
49
49
  Taro.nextTick(() => {
50
50
  if (
51
51
  !taroJdBaseInfo.info.pageInfo.floorExposureInfo[
52
52
  getFloorPointClassName
53
53
  ]
54
54
  ){
55
55
  const createIntersectionObserver = new intersectionObserver({
56
56
  selector: getTaroSelector,
57
57
  context: this,
58
58
  onFinal: (res) => {
59
59
  taroJdBaseInfo.info.pageInfo.floorExposureInfo[
60
60
  getFloorPointClassName
61
61
  ] = true
62
62
  console.log('小程序曝光埋点收到进入可视区域啦!', getFloorPointClassName, reportData, res)
63
63
  if(!isCustomReport){
64
64
  addReportData(reportData)
65
65
  typeof trackCallback === 'function' && trackCallback(reportData)
66
66
  }else {
67
67
  typeof customReportDataFn === 'function' && customReportDataFn(customReportDataKey)
68
68
  }
69
69
  createIntersectionObserver.disconnect()
70
70
  },
71
71
  })
72
72
  createIntersectionObserver.connect()
73
73
  }
74
74
  })
75
75
  }
76
76
  }, [])
77
77
  return (showRenderState ? (
78
78
  <View
79
79
  className={classNames(
80
80
  {
81
81
  [exposureStyle['d-report-point']]: type === TrackType.point,
82
82
  },
83
83
  {
84
84
  [exposureStyle['d-report-floor']]: type === TrackType.floor,
85
85
  },
86
86
  getFloorPointClassName,
87
87
  className,
88
88
  )}
89
89
  />
90
90
  ) : null
91
91
  )
92
92
  return useMemo(() => {
93
93
  return <ExposureFloor {...props} />
94
94
  }, [])
95
95
  reportData: null,
96
96
  trackCallback: null,
97
97
  type: TrackType.point,
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  TaroEventType,
3
2
  WEBVIEW_STATE,
4
3
  M_H5_ROOT_ELE_NODE,
5
4
  latestFromNativeMsgStorage,
6
5
  getNativePageScrollRes,
7
6
  props: ComponentInterFace.InOrOutViewObserverProps,
8
7
  const {
9
8
  children,
10
9
  style,
11
10
  inViewCallback,
12
11
  outViewCallback,
13
12
  threshold = 0,
14
13
  } = props
15
14
  const [componentShowState, setComponentShowState] = useState(false)
16
15
  const componentObserverRef = useRef<HTMLElement | null>(null)
17
16
  const componentShowStateRef = useRef(false)
18
17
  const needShowHighVersion = isAppClassifyPage || (isH5AndJdShopViewH5Scroll && !(global.info.queryInfo?.downgraded && global.info.queryInfo.downgraded === "true"))
19
18
  const rootDom = isH5AndJdShopView && needShowHighVersion ? null : document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
20
19
  if (isH5AndJdShopView && !needShowHighVersion) {
21
20
  console.log('视频========属于app原生滚动')
22
21
  useEffect(() => {
23
22
  const latestRes =
24
23
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
25
24
  dealPageScrollInfo(latestRes)
26
25
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
27
26
  dealPageScrollInfo(res)
28
27
  })
29
28
  Taro.eventCenter.on(
30
29
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
31
30
  (state) => {
32
31
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
33
32
  },
34
33
  )
35
34
  return function cleanup() {
36
35
  Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, (res) => {
37
36
  dealPageScrollInfo(res)
38
37
  })
39
38
  Taro.eventCenter.off(
40
39
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
41
40
  (state) => {
42
41
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
43
42
  },
44
43
  )
45
44
  }
46
45
  }, [])
47
46
  useEffect(() => {
48
47
  if (componentShowState) {
49
48
  typeof inViewCallback === 'function' && inViewCallback()
50
49
  console.log('app=>in可视区域')
51
50
  } else {
52
51
  typeof outViewCallback === 'function' && outViewCallback()
53
52
  console.log('app=>out可视区域')
54
53
  }
55
54
  }, [componentShowState])
56
55
 
57
56
  const handleInOrOutView = (type: boolean) => {
58
57
  componentShowStateRef.current = type
59
58
  setComponentShowState(type)
60
59
  console.log('handleInOrOutView', type)
61
60
  }
62
61
 
63
62
  const dealPageScrollInfo = (res) => {
64
63
  console.log('dealPageScrollInfo===', res)
65
64
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
66
65
  if (
67
66
  typeof displayHeight === 'undefined' ||
68
67
  typeof offSetY === 'undefined'
69
68
  )
70
69
  return
71
70
  console.log(
72
71
  '处理后dealPageScrollInfo===displayHeight=offSetY',
73
72
  displayHeight,
74
73
  offSetY,
75
74
  )
76
75
  if (componentObserverRef.current) {
77
76
  const eleClientRect =
78
77
  componentObserverRef.current.getBoundingClientRect()
79
78
  const eleOffsetTop = Math.ceil(eleClientRect.top)
80
79
  const eleHeight = Math.ceil(eleClientRect.height)
81
80
  console.log(
82
81
  '==========================eleOffsetTop, eleHeight',
83
82
  eleOffsetTop,
84
83
  eleHeight,
85
84
  )
86
85
  if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
87
86
  const isOutView =
88
87
  offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
89
88
  displayHeight - (eleOffsetTop - offSetY) <
90
89
  Math.ceil(eleHeight * threshold)
91
90
  console.log(
92
91
  '比较isOutView',
93
92
  isOutView,
94
93
  offSetY,
95
94
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
96
95
  displayHeight - (eleOffsetTop - offSetY),
97
96
  Math.ceil(eleHeight * threshold),
98
97
  )
99
98
  handleInOrOutView(!isOutView)
100
99
  } else {
101
100
  const isInView =
102
101
  offSetY >
103
102
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
104
103
  offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
105
104
  console.log(
106
105
  '比较isInView',
107
106
  isInView,
108
107
  offSetY,
109
108
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
110
109
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
111
110
  )
112
111
  handleInOrOutView(isInView)
113
112
  }
114
113
  }
115
114
  }
116
115
  return (
117
116
  <View ref={componentObserverRef} style={style}>
118
117
  {children}
119
118
  </View>
120
119
  )
121
120
  } else {
122
121
  console.log('视频========h5滚动')
123
122
  const { ref, inView } = useInView({
124
123
  threshold,
125
124
  triggerOnce: false,
126
125
  root: rootDom || null,
127
126
  rootMargin: `0px 0px 0px 0px`,
128
127
  })
129
128
  useEffect(() => {
130
129
  if (inView) {
131
130
  typeof inViewCallback === 'function' && inViewCallback()
132
131
  console.log('其他h5=>in可视区域')
133
132
  } else {
134
133
  typeof outViewCallback === 'function' && outViewCallback()
135
134
  console.log('其他h5=>out可视区域')
136
135
  }
137
136
  }, [inView])
138
137
  return (
139
138
  <View ref={ref} style={style}>
140
139
  {children}
141
140
  </View>
142
141
  )
143
142
  }
144
143
  children: null,
145
144
  style: {},
146
145
  className: '',
147
146
  inViewCallback: null,
148
147
  outViewCallback: null,
149
148
  threshold: 0,
149
+ import Taro from '@tarojs/taro'
150
150
  isH5AndJdShopView,
151
151
  isH5AndJdShopViewH5Scroll,
152
152
  isAppClassifyPage,
153
153
  lodashThrottle,
154
154
  TaroEventType,
155
155
  WEBVIEW_STATE,
156
156
  M_H5_ROOT_ELE_NODE,
157
157
  latestFromNativeMsgStorage,
158
158
  getNativePageScrollRes,
159
159
  props: ComponentInterFace.InOrOutViewObserverProps,
160
160
  const {
161
161
  children,
162
162
  style,
163
163
  inViewCallback,
164
164
  outViewCallback,
165
165
  threshold = 0,
166
166
  } = props
167
167
  const [componentShowState, setComponentShowState] = useState(false)
168
168
  const componentObserverRef = useRef<HTMLElement | null>(null)
169
169
  const componentShowStateRef = useRef(false)
170
170
  const needShowHighVersion =
171
171
  isAppClassifyPage ||
172
172
  (isH5AndJdShopViewH5Scroll &&
173
173
  !(
174
174
  global.info.queryInfo?.downgraded &&
175
175
  global.info.queryInfo.downgraded === 'true'
176
176
  ))
177
177
  const rootDom =
178
178
  isH5AndJdShopView && needShowHighVersion
179
179
  ? null
180
180
  : document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
181
181
  if (isH5AndJdShopView && !needShowHighVersion) {
182
182
  console.log('视频========属于app原生滚动')
183
183
  useEffect(() => {
184
184
  const latestRes =
185
185
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
186
186
  dealPageScrollInfo(latestRes)
187
187
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
188
188
  dealPageScrollInfo(res)
189
189
  })
190
190
  Taro.eventCenter.on(
191
191
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
192
192
  state => {
193
193
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
194
194
  },
195
195
  )
196
196
  return function cleanup() {
197
197
  Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, res => {
198
198
  dealPageScrollInfo(res)
199
199
  })
200
200
  Taro.eventCenter.off(
201
201
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
202
202
  state => {
203
203
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
204
204
  },
205
205
  )
206
206
  }
207
207
  }, [])
208
208
  useEffect(() => {
209
209
  if (componentShowState) {
210
210
  typeof inViewCallback === 'function' && inViewCallback()
211
211
  console.log('app=>in可视区域')
212
212
  } else {
213
213
  typeof outViewCallback === 'function' && outViewCallback()
214
214
  console.log('app=>out可视区域')
215
215
  }
216
216
  }, [componentShowState])
217
217
 
218
218
  const handleInOrOutView = (type: boolean) => {
219
219
  componentShowStateRef.current = type
220
220
  setComponentShowState(type)
221
221
  console.log('handleInOrOutView', type)
222
222
  }
223
223
 
224
224
  const dealPageScrollInfo = res => {
225
225
  console.log('dealPageScrollInfo===', res)
226
226
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
227
227
  if (
228
228
  typeof displayHeight === 'undefined' ||
229
229
  typeof offSetY === 'undefined'
230
230
  )
231
231
  return
232
232
  console.log(
233
233
  '处理后dealPageScrollInfo===displayHeight=offSetY',
234
234
  displayHeight,
235
235
  offSetY,
236
236
  )
237
237
  if (componentObserverRef.current) {
238
238
  const eleClientRect = componentObserverRef.current.getBoundingClientRect()
239
239
  const eleOffsetTop = Math.ceil(eleClientRect.top)
240
240
  const eleHeight = Math.ceil(eleClientRect.height)
241
241
  console.log(
242
242
  '==========================eleOffsetTop, eleHeight',
243
243
  eleOffsetTop,
244
244
  eleHeight,
245
245
  )
246
246
  if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
247
247
  const isOutView =
248
248
  offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
249
249
  displayHeight - (eleOffsetTop - offSetY) <
250
250
  Math.ceil(eleHeight * threshold)
251
251
  console.log(
252
252
  '比较isOutView',
253
253
  isOutView,
254
254
  offSetY,
255
255
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
256
256
  displayHeight - (eleOffsetTop - offSetY),
257
257
  Math.ceil(eleHeight * threshold),
258
258
  )
259
259
  handleInOrOutView(!isOutView)
260
260
  } else {
261
261
  const isInView =
262
262
  offSetY >
263
263
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
264
264
  offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
265
265
  console.log(
266
266
  '比较isInView',
267
267
  isInView,
268
268
  offSetY,
269
269
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
270
270
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
271
271
  )
272
272
  handleInOrOutView(isInView)
273
273
  }
274
274
  }
275
275
  }
276
276
  return (
277
277
  <View ref={componentObserverRef} style={style}>
278
278
  {children}
279
279
  </View>
280
280
  )
281
281
  } else {
282
282
  console.log('视频========h5滚动')
283
283
  const { ref, inView } = useInView({
284
284
  delay: 100,
285
285
  threshold,
286
286
  triggerOnce: false,
287
287
  root: rootDom || null,
288
288
  rootMargin: `0px 0px 0px 0px`,
289
289
  })
290
290
  const throttledViewChanged: ViewChangeHandler = useCallback<
291
291
  ViewChangeHandler
292
292
  >(
293
293
  lodashThrottle(
294
294
  (inView: boolean) => {
295
295
  if (inView) {
296
296
  typeof inViewCallback === 'function' && inViewCallback()
297
297
  console.log('其他h5=>in可视区域')
298
298
  } else {
299
299
  typeof outViewCallback === 'function' && outViewCallback()
300
300
  console.log('其他h5=>out可视区域')
301
301
  }
302
302
  },
303
303
  300,
304
304
  { leading: false, trailing: true },
305
305
  ),
306
306
  [],
307
307
  )
308
308
  useEffect(() => {
309
309
  throttledViewChanged(inView)
310
310
  }, [inView])
311
311
  return (
312
312
  <View ref={ref} style={style}>
313
313
  {children}
314
314
  </View>
315
315
  )
316
316
  }
317
317
  children: null,
318
318
  style: {},
319
319
  className: '',
320
320
  inViewCallback: null,
321
321
  outViewCallback: null,
322
322
  threshold: 0,
@@ -1 +1 @@
1
- import Taro from '@tarojs/taro'
2
1
  TaroEventType,
3
2
  const {
4
3
  children,
5
4
  placeholder,
6
5
  height,
7
6
  className,
8
7
  inViewCallback
9
8
  } = props
10
9
  const [componentShowState, setComponentShowState] = useState(false)
11
10
  const [componentRenderShowState, setComponentRenderShowState] =
12
11
  useState(false)
13
12
  const componentLazyRef = useRef<HTMLElement | null>(null)
14
13
  const componentShowStateRef = useRef(false)
15
14
  const needShowHighVersion = isH5AndJdShopViewH5Scroll && !(global.info.queryInfo?.downgraded && global.info.queryInfo.downgraded === "true")
16
15
  const rootDom = isH5AndJdShopView && needShowHighVersion ? null : document.querySelector('#J_shopHomeRoot')
17
16
  if (isH5AndJdShopView && !needShowHighVersion) {
18
17
  useEffect(() => {
19
18
  const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
20
19
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
21
20
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
22
21
  !componentShowStateRef.current && dealPageScrollInfo(res)
23
22
  })
24
23
  }, [])
25
24
  useEffect(() => {
26
25
  if (componentShowState) {
27
26
  typeof inViewCallback === 'function' && inViewCallback()
28
27
  console.log('InViewRender -- 店铺H5 展示啦!')
29
28
  }
30
29
  }, [componentShowState])
31
30
 
32
31
  const dealPageScrollInfo = (res) => {
33
32
  console.log(
34
33
  '收到滚动信息和模块元素以及容器显示状态',
35
34
  res,
36
35
  typeof componentLazyRef.current,
37
36
  componentShowStateRef.current,
38
37
  )
39
38
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
40
39
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') return
41
40
  if (componentLazyRef.current) {
42
41
  const eleClientRect =
43
42
  componentLazyRef.current.getBoundingClientRect()
44
43
  const getContainerHeightOffSetY = displayHeight + offSetY
45
44
  const eleOffsetTop = Math.ceil(eleClientRect.top)
46
45
  if (!componentShowStateRef.current) {
47
46
  if (getContainerHeightOffSetY > eleOffsetTop) {
48
47
  componentShowStateRef.current = true
49
48
  setComponentShowState(true)
50
49
  Taro.nextTick(() => {
51
50
  setComponentRenderShowState(true)
52
51
  })
53
52
  }
54
53
  }
55
54
  }
56
55
  }
57
56
  return (
58
57
  <View
59
58
  ref={componentLazyRef}
60
59
  className={classNames(
61
60
  lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
62
61
  'd-app-floor-lazy-load',
63
62
  className
64
63
  )}
65
64
  style={{
66
65
  minHeight: `${componentRenderShowState ? 'auto' : height + (typeof height === 'number' ? 'px' : '')
67
66
  }`,
68
67
  backgroundColor: componentRenderShowState
69
68
  ? 'transparent'
70
69
  : '#ffffff',
71
70
  }}
72
71
  >
73
72
  {componentShowState ? children : placeholder}
74
73
  </View>
75
74
  )
76
75
  }else {
77
76
  const { ref, inView } = useInView({
78
77
  threshold: 0.5,
79
78
  triggerOnce: true,
80
79
  root: rootDom || null,
81
80
  rootMargin: `0px 0px 0px 0px`,
82
81
  delay: 300,
83
82
  })
84
83
  useEffect(() => {
85
84
  if (inView) {
86
85
  typeof inViewCallback === 'function' && inViewCallback()
87
86
  console.log('InViewRender -- 其它H5 展示啦!')
88
87
  }
89
88
  }, [inView])
90
89
  return (
91
90
  <View
92
91
  className={className}
93
92
  ref={ref}
94
93
  style={{
95
94
  minHeight: inView ? 'auto' : typeof height === 'number' ? `${height}px` : height,
96
95
  backgroundColor: 'transparent',
97
96
  }}
98
97
  >
99
98
  {inView ? children : placeholder}
100
99
  </View>
101
100
  )
102
101
  }
103
102
  children: null,
104
103
  placeholder: null,
105
104
  height: 1,
106
105
  className: '',
107
106
  lazyNodeClassName: '',
108
107
  inViewCallback: null,
108
+ import Taro from '@tarojs/taro'
109
109
  getNativePageScrollRes,
110
110
  latestFromNativeMsgStorage,
111
111
  const { children, placeholder, height, className, inViewCallback } = props
112
112
  const [componentShowState, setComponentShowState] = useState(false)
113
113
  const [componentRenderShowState, setComponentRenderShowState] = useState(
114
114
  false,
115
115
  )
116
116
  const componentLazyRef = useRef<HTMLElement | null>(null)
117
117
  const componentShowStateRef = useRef(false)
118
118
  const needShowHighVersion =
119
119
  isH5AndJdShopViewH5Scroll &&
120
120
  !(
121
121
  global.info.queryInfo?.downgraded &&
122
122
  global.info.queryInfo.downgraded === 'true'
123
123
  )
124
124
  const rootDom =
125
125
  isH5AndJdShopView && needShowHighVersion
126
126
  ? null
127
127
  : document.querySelector('#J_shopHomeRoot')
128
128
  if (isH5AndJdShopView && !needShowHighVersion && !isAppStowShop) {
129
129
  useEffect(() => {
130
130
  const latestRes =
131
131
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
132
132
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
133
133
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
134
134
  !componentShowStateRef.current && dealPageScrollInfo(res)
135
135
  })
136
136
  }, [])
137
137
  useEffect(() => {
138
138
  if (componentShowState) {
139
139
  typeof inViewCallback === 'function' && inViewCallback()
140
140
  }
141
141
  }, [componentShowState])
142
142
 
143
143
  const dealPageScrollInfo = res => {
144
144
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
145
145
  if (
146
146
  typeof displayHeight === 'undefined' ||
147
147
  typeof offSetY === 'undefined'
148
148
  )
149
149
  return
150
150
  if (componentLazyRef.current) {
151
151
  const eleClientRect = componentLazyRef.current.getBoundingClientRect()
152
152
  const getContainerHeightOffSetY = displayHeight + offSetY
153
153
  const eleOffsetTop = Math.ceil(eleClientRect.top)
154
154
  if (!componentShowStateRef.current) {
155
155
  if (getContainerHeightOffSetY > eleOffsetTop) {
156
156
  componentShowStateRef.current = true
157
157
  setComponentShowState(true)
158
158
  Taro.nextTick(() => {
159
159
  setComponentRenderShowState(true)
160
160
  })
161
161
  }
162
162
  }
163
163
  }
164
164
  }
165
165
  return (
166
166
  <View
167
167
  ref={componentLazyRef}
168
168
  className={classNames(
169
169
  lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
170
170
  'd-app-floor-lazy-load',
171
171
  className,
172
172
  )}
173
173
  style={{
174
174
  minHeight: `${
175
175
  componentRenderShowState
176
176
  ? 'auto'
177
177
  : height + (typeof height === 'number' ? 'px' : '')
178
178
  }`,
179
179
  backgroundColor: componentRenderShowState ? 'transparent' : '#ffffff',
180
180
  }}
181
181
  >
182
182
  {componentShowState ? children : placeholder}
183
183
  </View>
184
184
  )
185
185
  } else {
186
186
  const { ref, inView } = useInView({
187
187
  threshold: 0.5,
188
188
  triggerOnce: true,
189
189
  root: rootDom || null,
190
190
  rootMargin: `0px 0px 0px 0px`,
191
191
  delay: 300,
192
192
  })
193
193
  useEffect(() => {
194
194
  if (inView) {
195
195
  typeof inViewCallback === 'function' && inViewCallback()
196
196
  }
197
197
  }, [inView])
198
198
  return (
199
199
  <View
200
200
  className={className}
201
201
  ref={ref}
202
202
  style={{
203
203
  minHeight: inView
204
204
  ? 'auto'
205
205
  : typeof height === 'number'
206
206
  ? `${height}px`
207
207
  : height,
208
208
  backgroundColor: 'transparent',
209
209
  }}
210
210
  >
211
211
  {inView ? children : placeholder}
212
212
  </View>
213
213
  )
214
214
  }
215
215
  children: null,
216
216
  placeholder: null,
217
217
  height: 1,
218
218
  className: '',
219
219
  lazyNodeClassName: '',
220
220
  inViewCallback: null,