@conecli/cone-render 0.10.1-beta.4 → 0.10.1-beta.5

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