@conecli/cone-render 0.9.1-shop2.8 → 0.10.1-beta.0

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 (56) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/assets/icon_blue_info.svg +1 -0
  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/wxappApi.jd.ts +1 -0
  12. package/dist/components/ErrorBoundary.tsx +1 -1
  13. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  14. package/dist/components/base/CustomScrollView/index.module.scss +7 -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/LazyLayoutLoad/index.tsx +1 -1
  18. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  19. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  20. package/dist/components/debug/DebugLayout/index.module.scss +67 -0
  21. package/dist/components/debug/DebugLayout/index.tsx +1 -0
  22. package/dist/components/debug/DebugLayout/utils.ts +1 -0
  23. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  24. package/dist/components/floorItem.jd.tsx +1 -1
  25. package/dist/components/floorItem.weapp.tsx +1 -1
  26. package/dist/components/isv/Floor/index.tsx +1 -1
  27. package/dist/components/remoteFloorItem.tsx +1 -1
  28. package/dist/interface/common.ts +1 -1
  29. package/dist/interface/component.ts +1 -1
  30. package/dist/interface/jumpEventReport.ts +1 -1
  31. package/dist/interface/service.ts +1 -1
  32. package/dist/interface/utils.ts +1 -1
  33. package/dist/jumpEventReport/base.ts +1 -1
  34. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  35. package/dist/jumpEventReport/index.h5.ts +1 -1
  36. package/dist/jumpEventReport/index.jd.ts +1 -1
  37. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  38. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  39. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  40. package/dist/jumpEventReport/web.tjm.ts +1 -0
  41. package/dist/open/api/environment.ts +1 -1
  42. package/dist/open/api/index.ts +1 -1
  43. package/dist/open/api/track.ts +1 -1
  44. package/dist/sass/app.h5.scss +5 -0
  45. package/dist/service/requestServer.ts +1 -1
  46. package/dist/utils/connectNativeJsBridge.ts +1 -1
  47. package/dist/utils/draExceptionAndProfile.ts +1 -1
  48. package/dist/utils/h5Utils.ts +1 -1
  49. package/dist/utils/index.h5.ts +1 -1
  50. package/dist/utils/index.ts +1 -1
  51. package/dist/utils/index.weapp.ts +1 -1
  52. package/dist/utils/jm-common.js +1 -1
  53. package/dist/utils/sgmCodeUtils.ts +1 -0
  54. package/dist/utils/utils.ts +1 -1
  55. package/package.json +42 -39
  56. package/dist/customHooks/useDocumentVisibilitychange.ts +0 -1
@@ -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
  TaroEventType,
154
154
  WEBVIEW_STATE,
155
155
  M_H5_ROOT_ELE_NODE,
156
156
  latestFromNativeMsgStorage,
157
157
  getNativePageScrollRes,
158
158
  props: ComponentInterFace.InOrOutViewObserverProps,
159
159
  const {
160
160
  children,
161
161
  style,
162
162
  inViewCallback,
163
163
  outViewCallback,
164
164
  threshold = 0,
165
165
  } = props
166
166
  const [componentShowState, setComponentShowState] = useState(false)
167
167
  const componentObserverRef = useRef<HTMLElement | null>(null)
168
168
  const componentShowStateRef = useRef(false)
169
169
  const needShowHighVersion =
170
170
  isAppClassifyPage ||
171
171
  (isH5AndJdShopViewH5Scroll &&
172
172
  !(
173
173
  global.info.queryInfo?.downgraded &&
174
174
  global.info.queryInfo.downgraded === 'true'
175
175
  ))
176
176
  const rootDom =
177
177
  isH5AndJdShopView && needShowHighVersion
178
178
  ? null
179
179
  : document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
180
180
  if (isH5AndJdShopView && !needShowHighVersion) {
181
181
  console.log('视频========属于app原生滚动')
182
182
  useEffect(() => {
183
183
  const latestRes =
184
184
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
185
185
  dealPageScrollInfo(latestRes)
186
186
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
187
187
  dealPageScrollInfo(res)
188
188
  })
189
189
  Taro.eventCenter.on(
190
190
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
191
191
  state => {
192
192
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
193
193
  },
194
194
  )
195
195
  return function cleanup() {
196
196
  Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, res => {
197
197
  dealPageScrollInfo(res)
198
198
  })
199
199
  Taro.eventCenter.off(
200
200
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
201
201
  state => {
202
202
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
203
203
  },
204
204
  )
205
205
  }
206
206
  }, [])
207
207
  useEffect(() => {
208
208
  if (componentShowState) {
209
209
  typeof inViewCallback === 'function' && inViewCallback()
210
210
  console.log('app=>in可视区域')
211
211
  } else {
212
212
  typeof outViewCallback === 'function' && outViewCallback()
213
213
  console.log('app=>out可视区域')
214
214
  }
215
215
  }, [componentShowState])
216
216
 
217
217
  const handleInOrOutView = (type: boolean) => {
218
218
  componentShowStateRef.current = type
219
219
  setComponentShowState(type)
220
220
  console.log('handleInOrOutView', type)
221
221
  }
222
222
 
223
223
  const dealPageScrollInfo = res => {
224
224
  console.log('dealPageScrollInfo===', res)
225
225
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
226
226
  if (
227
227
  typeof displayHeight === 'undefined' ||
228
228
  typeof offSetY === 'undefined'
229
229
  )
230
230
  return
231
231
  console.log(
232
232
  '处理后dealPageScrollInfo===displayHeight=offSetY',
233
233
  displayHeight,
234
234
  offSetY,
235
235
  )
236
236
  if (componentObserverRef.current) {
237
237
  const eleClientRect = componentObserverRef.current.getBoundingClientRect()
238
238
  const eleOffsetTop = Math.ceil(eleClientRect.top)
239
239
  const eleHeight = Math.ceil(eleClientRect.height)
240
240
  console.log(
241
241
  '==========================eleOffsetTop, eleHeight',
242
242
  eleOffsetTop,
243
243
  eleHeight,
244
244
  )
245
245
  if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
246
246
  const isOutView =
247
247
  offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
248
248
  displayHeight - (eleOffsetTop - offSetY) <
249
249
  Math.ceil(eleHeight * threshold)
250
250
  console.log(
251
251
  '比较isOutView',
252
252
  isOutView,
253
253
  offSetY,
254
254
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
255
255
  displayHeight - (eleOffsetTop - offSetY),
256
256
  Math.ceil(eleHeight * threshold),
257
257
  )
258
258
  handleInOrOutView(!isOutView)
259
259
  } else {
260
260
  const isInView =
261
261
  offSetY >
262
262
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
263
263
  offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
264
264
  console.log(
265
265
  '比较isInView',
266
266
  isInView,
267
267
  offSetY,
268
268
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
269
269
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
270
270
  )
271
271
  handleInOrOutView(isInView)
272
272
  }
273
273
  }
274
274
  }
275
275
  return (
276
276
  <View ref={componentObserverRef} style={style}>
277
277
  {children}
278
278
  </View>
279
279
  )
280
280
  } else {
281
281
  console.log('视频========h5滚动')
282
282
  const { ref, inView } = useInView({
283
283
  delay: 100,
284
284
  threshold,
285
285
  triggerOnce: false,
286
286
  root: rootDom || null,
287
287
  rootMargin: `0px 0px 0px 0px`,
288
288
  })
289
289
  useEffect(() => {
290
290
  if (inView) {
291
291
  typeof inViewCallback === 'function' && inViewCallback()
292
292
  console.log('其他h5=>in可视区域')
293
293
  } else {
294
294
  typeof outViewCallback === 'function' && outViewCallback()
295
295
  console.log('其他h5=>out可视区域')
296
296
  }
297
297
  }, [inView])
298
298
  return (
299
299
  <View ref={ref} style={style}>
300
300
  {children}
301
301
  </View>
302
302
  )
303
303
  }
304
304
  children: null,
305
305
  style: {},
306
306
  className: '',
307
307
  inViewCallback: null,
308
308
  outViewCallback: null,
309
309
  threshold: 0,
@@ -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 = isH5AndJdShopViewH5Scroll && !(global.info.queryInfo?.downgraded && global.info.queryInfo.downgraded === "true")
27
26
  const rootDom = isH5AndJdShopView && needShowHighVersion ? null : document.querySelector('#J_shopHomeRoot')
28
27
  const { ref, inView } = useInView({
29
28
  threshold: 0,
30
29
  triggerOnce: true,
31
30
  root: rootDom,
32
31
  rootMargin: `0px 0px ${window.innerHeight}px 0px`,
33
32
  })
34
33
  useEffect(() => {
35
34
  if(needShowHighVersion || !isH5AndJdShopView) return
36
35
  if (type === LazyType.FLOOR) {
37
36
  const latestRes = latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
38
37
  !componentShowStateRef.current && dealPageScrollInfo(latestRes)
39
38
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
40
39
  !componentShowStateRef.current && dealPageScrollInfo(res)
41
40
  })
42
41
  }
43
42
  }, [])
44
43
  useEffect(() => {
45
44
  if((!needShowHighVersion && componentShowState === true) ||
46
45
  (needShowHighVersion && inView && isH5AndJdShopView)
47
46
  ) {
48
47
  console.log('>>>>>>>>>>>>>>>>>>> 楼层【id=' + containerId + '】已经渲染!')
49
48
  const modularPackResult = floorData?.floorExtInfo?.modularPackResult
50
49
  const modularPackResultObj = typeof modularPackResult === 'string' ? JSON.parse(modularPackResult) : modularPackResult
51
50
  if (modularPackResultObj && modularPackResultObj.bundleUrl) {
52
51
  const { bundleUrl } = modularPackResultObj
53
52
  nativePageRegisterMessage(
54
53
  Message_Type.NATIVE_INJECT_JS_FILE,
55
54
  {
56
55
  data: {
57
56
  "bundleUrl": [bundleUrl]
58
57
  },
59
58
  },
60
59
  )
61
60
  }
62
61
  }
63
62
  }, [componentShowState,inView])
64
63
 
65
64
  const dealPageScrollInfo = (res) => {
66
65
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {};
67
66
  if (typeof displayHeight === 'undefined' || typeof offSetY === 'undefined') {
68
67
  const shopId = floorData?.floorExtInfo?.shopId
69
68
  if(!lazyLayoutLoadErrorShopId[`${shopId}`]) {
70
69
  const opt = {
71
70
  msg: `店铺楼层懒加载失败。楼层顺序-floorIdx: ${floorData?.floorIdx}。`,
72
71
  uid: floorData?.uid,
73
72
  floorIdx: floorData?.floorIdx,
74
73
  shopId: shopId,
75
74
  moduleId: floorData?.moduleId,
76
75
  moduleName: floorData?.moduleName,
77
76
  middleTemplateId: floorData?.middleTemplateId,
78
77
  modularPackResult: typeof floorData?.floorExtInfo?.modularPackResult == 'string' ? JSON.parse(floorData?.floorExtInfo?.modularPackResult) : floorData?.floorExtInfo?.modularPackResult,
79
78
  }
80
79
  sgmCustomReport({
81
80
  code: 'lazyLayoutLoadError',
82
81
  msg: opt,
83
82
  })
84
83
  lazyLayoutLoadErrorShopId[`${shopId}`] = true
85
84
  }
86
85
  return
87
86
  }
88
87
  if (componentLazyRef.current) {
89
88
  const eleClientRect =
90
89
  componentLazyRef.current.getBoundingClientRect()
91
90
  const getContainerHeightOffSetY = displayHeight + offSetY
92
91
  const eleOffsetTop = Math.ceil(eleClientRect.top)
93
92
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
94
93
  const eleOffsetTopHeight = eleOffsetTop + eleOffsetHeight
95
94
  if (!componentShowStateRef.current) {
96
95
  if (getContainerHeightOffSetY > eleOffsetTop) {
97
96
  componentShowStateRef.current = true
98
97
  setComponentShowState(true)
99
98
  Taro.nextTick(() => {
100
99
  setComponentRenderShowState(true)
101
100
  })
102
101
  }
103
102
  }
104
103
  }
105
104
  }
106
105
  return isH5AndJdShopView && !needShowHighVersion ? (
107
106
  <div
108
107
  id={`${containerId}_lazy`}
109
108
  ref={componentLazyRef}
110
109
  className={classNames(
111
110
  lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
112
111
  'd-app-floor-lazy-load',
113
112
  )}
114
113
  style={{
115
114
  minHeight: `${
116
115
  componentRenderShowState ? 'auto' : height + 'px'
117
116
  }`,
118
117
  backgroundColor: componentRenderShowState
119
118
  ? 'transparent'
120
119
  : '#ffffff',
121
120
  }}
122
121
  >
123
122
  {componentShowState ? children : placeholder}
124
123
  </div>
125
124
  ) : (
126
125
  <div
127
126
  id={`${containerId}_lazy`}
128
127
  className={classNames(
129
128
  lazyLayoutLoadStyle["d-mobile-floor-lazy-layout-load"],
130
129
  "d-mobile-floor-lazy-load",
131
130
  lazyNodeClassName,
132
131
  )}
133
132
  ref={ref}
134
133
  style={{
135
134
  minHeight: `${inView ? 'auto' : height + 'px'}`,
136
135
  backgroundColor: inView ? 'transparent' : '#ffffff',
137
136
  }}
138
137
  >
139
138
  {inView ? children : placeholder}
140
139
  </div>
141
140
  );
142
141
  sectionType:
143
142
  SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN],
144
143
  type: LazyType.FLOOR,
145
144
  children: null,
146
145
  placeholder: null,
147
146
  height: 200,
148
147
  className: '',
149
148
  lazyNodeClassName: '',
149
+ import Taro, { useRouter } from '@tarojs/taro'
150
150
  isH5AndJdShopView,
151
151
  isH5AndJdShopViewH5Scroll,
152
152
  sgmCustomReport,
153
153
  getSgmCustomCode,
154
154
  SECTION_HOME_TAB_TYPE,
155
155
  SECTION_HOME_TAB_NAME_TYPE,
156
156
  TaroEventType,
157
157
  latestFromNativeMsgStorage,
158
158
  nativePageRegisterMessage,
159
159
  Message_Type,
160
160
  getNativePageScrollRes,
161
161
  const {
162
162
  children,
163
163
  containerId,
164
164
  type,
165
165
  placeholder,
166
166
  height,
167
167
  floorData = {},
168
168
  sectionType,
169
169
  lazyNodeClassName,
170
170
  } = props
171
171
  const getRouterInfo = useRouter()
172
172
  const getQueryData = getRouterInfo?.params || {}
173
173
  const [componentShowState, setComponentShowState] = useState(false)
174
174
  const [componentRenderShowState, setComponentRenderShowState] = useState(
175
175
  false,
176
176
  )
177
177
  const componentLazyRef = useRef<HTMLElement | null>(null)
178
178
  const componentShowStateRef = useRef(false)
179
179
  const needShowHighVersion =
180
180
  isH5AndJdShopViewH5Scroll &&
181
181
  !(
182
182
  global.info.queryInfo?.downgraded &&
183
183
  global.info.queryInfo.downgraded === 'true'
184
184
  )
185
185
  const rootDom =
186
186
  isH5AndJdShopView && needShowHighVersion
187
187
  ? null
188
188
  : document.querySelector('#J_shopHomeRoot')
189
189
  const { ref, inView } = useInView({
190
190
  threshold: 0,
191
191
  triggerOnce: true,
192
192
  root: rootDom,
193
193
  rootMargin: `0px 0px ${window.innerHeight}px 0px`,
194
194
  })
195
195
  useEffect(() => {
196
196
  if (needShowHighVersion || !isH5AndJdShopView) return
197
197
  if (type === LazyType.FLOOR) {
198
198
  const latestRes =
199
199
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
200
200
  !componentShowStateRef.current && dealPageScrollInfo(latestRes, false)
201
201
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
202
202
  !componentShowStateRef.current && dealPageScrollInfo(res, true)
203
203
  })
204
204
  }
205
205
  }, [])
206
206
  useEffect(() => {
207
207
  if (
208
208
  (!needShowHighVersion && componentShowState === true) ||
209
209
  (needShowHighVersion && inView && isH5AndJdShopView)
210
210
  ) {
211
211
  console.log(
212
212
  '>>>>>>>>>>>>>>>>>>> 楼层【id=' + containerId + '】已经渲染!',
213
213
  )
214
214
  const modularPackResult = floorData?.floorExtInfo?.modularPackResult
215
215
  const modularPackResultObj =
216
216
  typeof modularPackResult === 'string'
217
217
  ? JSON.parse(modularPackResult)
218
218
  : modularPackResult
219
219
  if (modularPackResultObj && modularPackResultObj.bundleUrl) {
220
220
  const { bundleUrl } = modularPackResultObj
221
221
  nativePageRegisterMessage(Message_Type.NATIVE_INJECT_JS_FILE, {
222
222
  data: {
223
223
  bundleUrl: [bundleUrl],
224
224
  },
225
225
  })
226
226
  }
227
227
  }
228
228
  }, [componentShowState, inView])
229
229
 
230
230
  const dealPageScrollInfo = (res, pageScrollTrigger) => {
231
231
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
232
232
  if (
233
233
  typeof displayHeight === 'undefined' ||
234
234
  typeof offSetY === 'undefined'
235
235
  ) {
236
236
  const shopId = floorData?.floorExtInfo?.shopId
237
237
  if (!lazyLayoutLoadErrorShopId[`${shopId}`] && pageScrollTrigger) {
238
238
  const opt = {
239
239
  msg: `店铺楼层懒加载失败。楼层顺序-floorIdx: ${floorData?.floorIdx}。`,
240
240
  uid: floorData?.uid,
241
241
  floorIdx: floorData?.floorIdx,
242
242
  shopId: shopId,
243
243
  moduleId: floorData?.moduleId,
244
244
  moduleName: floorData?.moduleName,
245
245
  middleTemplateId: floorData?.middleTemplateId,
246
246
  modularPackResult:
247
247
  typeof floorData?.floorExtInfo?.modularPackResult == 'string'
248
248
  ? JSON.parse(floorData?.floorExtInfo?.modularPackResult)
249
249
  : floorData?.floorExtInfo?.modularPackResult,
250
250
  }
251
251
  sgmCustomReport({
252
252
  code: getSgmCustomCode(SgmCustomCode.FLOORLAZYLOAD_DATA),
253
253
  msg: opt,
254
254
  })
255
255
  lazyLayoutLoadErrorShopId[`${shopId}`] = true
256
256
  }
257
257
  return
258
258
  }
259
259
  if (componentLazyRef.current) {
260
260
  const eleClientRect = componentLazyRef.current.getBoundingClientRect()
261
261
  const getContainerHeightOffSetY = displayHeight + offSetY
262
262
  const eleOffsetTop = Math.ceil(eleClientRect.top)
263
263
  const eleOffsetHeight = Math.ceil(eleClientRect.height)
264
264
  const eleOffsetTopHeight = eleOffsetTop + eleOffsetHeight
265
265
  if (!componentShowStateRef.current) {
266
266
  if (getContainerHeightOffSetY > eleOffsetTop) {
267
267
  componentShowStateRef.current = true
268
268
  setComponentShowState(true)
269
269
  Taro.nextTick(() => {
270
270
  setComponentRenderShowState(true)
271
271
  })
272
272
  }
273
273
  }
274
274
  }
275
275
  }
276
276
  return isH5AndJdShopView && !needShowHighVersion ? (
277
277
  <div
278
278
  id={`${containerId}_lazy`}
279
279
  ref={componentLazyRef}
280
280
  className={classNames(
281
281
  lazyLayoutLoadStyle['d-app-floor-lazy-layout-load'],
282
282
  'd-app-floor-lazy-load',
283
283
  )}
284
284
  style={{
285
285
  minHeight: `${componentRenderShowState ? 'auto' : height + 'px'}`,
286
286
  backgroundColor: componentRenderShowState ? 'transparent' : '#ffffff',
287
287
  }}
288
288
  >
289
289
  {componentShowState ? children : placeholder}
290
290
  </div>
291
291
  ) : (
292
292
  <div
293
293
  id={`${containerId}_lazy`}
294
294
  className={classNames(
295
295
  lazyLayoutLoadStyle['d-mobile-floor-lazy-layout-load'],
296
296
  'd-mobile-floor-lazy-load',
297
297
  lazyNodeClassName,
298
298
  )}
299
299
  ref={ref}
300
300
  style={{
301
301
  minHeight: `${inView ? 'auto' : height + 'px'}`,
302
302
  backgroundColor: inView ? 'transparent' : '#ffffff',
303
303
  }}
304
304
  >
305
305
  {inView ? children : placeholder}
306
306
  </div>
307
307
  )
308
308
  sectionType:
309
309
  SECTION_HOME_TAB_NAME_TYPE[SECTION_HOME_TAB_TYPE.HOME_WELL_CHOSEN],
310
310
  type: LazyType.FLOOR,
311
311
  children: null,
312
312
  placeholder: null,
313
313
  height: 200,
314
314
  className: '',
315
315
  lazyNodeClassName: '',