@conecli/cone-render 0.8.38 → 0.8.40

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 (117) 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/jssdk.ts +1 -0
  11. package/dist/common/pageType.ts +1 -0
  12. package/dist/common/sgmCustomCode.ts +1 -0
  13. package/dist/common/token/index.h5.ts +1 -1
  14. package/dist/common/token/token.jd.ts +1 -1
  15. package/dist/common/token/token.ts +1 -1
  16. package/dist/common/wxappApi.jd.ts +1 -0
  17. package/dist/common/wxappApi.ts +1 -1
  18. package/dist/components/ErrorBoundary.tsx +1 -1
  19. package/dist/components/base/CommonFloorHead/index.tsx +1 -1
  20. package/dist/components/base/CountDown/index.tsx +1 -1
  21. package/dist/components/base/CustomScrollView/index.jd.tsx +1 -0
  22. package/dist/components/base/CustomScrollView/index.module.scss +7 -0
  23. package/dist/components/base/CustomScrollView/index.tsx +1 -1
  24. package/dist/components/base/CustomVideo/index.tsx +1 -1
  25. package/dist/components/base/Dialog/index.module.scss +5 -0
  26. package/dist/components/base/Dialog/index.tsx +1 -1
  27. package/dist/components/base/Exposure/index.h5.tsx +1 -1
  28. package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
  29. package/dist/components/base/ExposureSmart/index.tsx +1 -1
  30. package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
  31. package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
  32. package/dist/components/base/InViewRender/index.tsx +1 -1
  33. package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -1
  34. package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
  35. package/dist/components/base/LazyLayoutLoad/index.weapp.tsx +1 -1
  36. package/dist/components/base/LazyLoadImage/const.ts +1 -1
  37. package/dist/components/base/LazyLoadImage/index.h5.module.scss +20 -20
  38. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  39. package/dist/components/base/MobileCommonHeader/index.module.scss +9 -0
  40. package/dist/components/base/MobileCommonHeader/index.tsx +1 -0
  41. package/dist/components/base/NetworkDataError/const.ts +1 -1
  42. package/dist/components/base/NetworkDataError/index.module.scss +4 -0
  43. package/dist/components/base/NetworkDataError/index.tsx +1 -1
  44. package/dist/components/base/Price/Double/index.tsx +1 -1
  45. package/dist/components/base/Price/index.tsx +1 -1
  46. package/dist/components/base/Skeleton/index.tsx +1 -1
  47. package/dist/components/decorate/DecorateFloorModule/index.module.scss +21 -2
  48. package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
  49. package/dist/components/decorate/EmptyFloorModule/index.tsx +1 -1
  50. package/dist/components/floorItem.jd.tsx +1 -1
  51. package/dist/components/floorItem.tsx +1 -1
  52. package/dist/components/floorItem.weapp.tsx +1 -1
  53. package/dist/components/isv/Floor/index.tsx +1 -1
  54. package/dist/components/remoteFloorItem.tsx +1 -1
  55. package/dist/interface/common.ts +1 -1
  56. package/dist/interface/component.ts +1 -1
  57. package/dist/interface/jumpEventReport.ts +1 -1
  58. package/dist/interface/service.ts +1 -1
  59. package/dist/interface/utils.ts +1 -1
  60. package/dist/jumpEventReport/base.ts +1 -1
  61. package/dist/jumpEventReport/const.ts +1 -1
  62. package/dist/jumpEventReport/createReportFloorData.ts +1 -1
  63. package/dist/jumpEventReport/index.h5.ts +1 -1
  64. package/dist/jumpEventReport/index.jd.ts +1 -1
  65. package/dist/jumpEventReport/index.weapp.ts +1 -1
  66. package/dist/jumpEventReport/jdJumpJdApp.ts +1 -1
  67. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  68. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  69. package/dist/jumpEventReport/web/report.ts +1 -1
  70. package/dist/jumpEventReport/web.base.ts +1 -1
  71. package/dist/jumpEventReport/web.jd.ts +1 -1
  72. package/dist/jumpEventReport/web.jdb.ts +1 -1
  73. package/dist/jumpEventReport/web.jdjch.ts +1 -1
  74. package/dist/jumpEventReport/web.jxwxapp.ts +1 -0
  75. package/dist/jumpEventReport/web.pc.ts +1 -0
  76. package/dist/jumpEventReport/web.tjapp.ts +1 -0
  77. package/dist/jumpEventReport/web.tjm.ts +1 -0
  78. package/dist/jumpEventReport/web.wxapp.ts +1 -1
  79. package/dist/modules/ContainerFloorList/index.h5.module.scss +17 -1
  80. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  81. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  82. package/dist/open/api/environment.ts +1 -1
  83. package/dist/open/api/index.ts +1 -1
  84. package/dist/open/api/jump copy.ts +1 -1
  85. package/dist/open/api/shopMember.ts +1 -1
  86. package/dist/open/api/track.ts +1 -1
  87. package/dist/open/api/util.ts +1 -1
  88. package/dist/open/components/index.ts +1 -1
  89. package/dist/sass/app.h5.scss +39 -3
  90. package/dist/sass/base.scss +12 -0
  91. package/dist/service/fetchGateway.ts +1 -1
  92. package/dist/service/http/const.ts +1 -1
  93. package/dist/service/requestServer.ts +1 -1
  94. package/dist/utils/connectNativeJsBridge.ts +1 -1
  95. package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
  96. package/dist/utils/draExceptionAndProfile.ts +1 -1
  97. package/dist/utils/h5Utils.ts +1 -1
  98. package/dist/utils/index.h5.ts +1 -1
  99. package/dist/utils/index.ts +1 -1
  100. package/dist/utils/index.weapp.ts +1 -1
  101. package/dist/utils/jm-common.js +1 -1
  102. package/dist/utils/sgmCodeUtils.ts +1 -0
  103. package/dist/utils/taroRenderUtil.ts +1 -0
  104. package/dist/utils/utils.ts +1 -1
  105. package/dist/wxapp/api/helper.js +1 -0
  106. package/dist/wxapp/components/launch-app/index.js +1 -0
  107. package/dist/wxapp/components/launch-app/index.json +5 -0
  108. package/dist/wxapp/components/launch-app/index.wxml +0 -0
  109. package/dist/wxapp/components/launch-app/index.wxss +0 -0
  110. package/dist/wxapp/components/subscribe-guider/helper.js +1 -0
  111. package/dist/wxapp/components/subscribe-guider/index.js +1 -0
  112. package/dist/wxapp/components/subscribe-guider/index.json +5 -0
  113. package/dist/wxapp/components/subscribe-guider/index.wxml +0 -0
  114. package/dist/wxapp/components/subscribe-guider/index.wxss +0 -0
  115. package/package.json +2 -1
  116. package/dist/components/base/Skeleton/old.tsx +0 -1
  117. 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 track from '../../../open/api/track'
2
1
  const {arr : arrTask, startWaitTime} = floorTask
3
2
  const isTimeout = startWaitTime != 0 && (Date.now() - startWaitTime >= 1000)
4
3
  const arrTaskNum = arrTask.length;
5
4
  const isOverMax = arrTaskNum >= 10
6
5
  const hasData = arrTaskNum > 0
7
6
  if(hasData && (isTimeout || isOverMax)){
8
7
  const reduceData = connactData(arrTask)
9
8
  track.reportExposureEventLog(reduceData)
10
9
  floorTask.arr = []
11
10
  floorTask.startWaitTime = 0
12
11
  clearTimeout(floorTask.timer)
13
12
  }
14
13
  const initData = JSON.parse(JSON.stringify(arr[0]))
15
14
  if(initData.jsonParam.etModelInfo) {
16
15
  initData.jsonParam.logBaseInfo = []
17
16
  initData.jsonParam.etModelInfo.lstms = []
18
17
  return arr.reduce((acc, cur) => {
19
18
  acc.jsonParam.logBaseInfo.push(cur.jsonParam.logBaseInfo)
20
19
  return acc
21
20
  }, initData)
22
21
  } else {
23
22
  return arr.reduce((acc) => {
24
23
  return acc
25
24
  })
26
25
  }
27
26
  if(!Array.isArray(data)){
28
27
  console.log('坑位曝光埋点原始数据参类型错误,期望是数组,实际是:', data)
29
28
  return
30
29
  }
31
30
  const [floorData, mInfo, etModelInfo] = data
32
31
  if(floorData && mInfo && etModelInfo){
33
32
  const isIsvReportModule = isvReportModuleTypeList.includes(floorData?.floorExtInfo?.moduleFlag)
34
33
  try {
35
34
  const reportJson = track.getExposureInfo(floorData, mInfo, etModelInfo,true, isIsvReportModule)
36
35
  console.log(`${floorData?.floorExtInfo?.moduleFlag}===reportJson===`,reportJson)
37
36
  const { floorIdx } = floorData
38
37
  if(!task[floorIdx]){
39
38
  task[floorIdx] = {
40
39
  arr: [],
41
40
  startWaitTime: 0,
42
41
  timer : 0
43
42
  }
44
43
  }
45
44
  const floorTask = task[floorIdx]
46
45
  if(floorTask.arr.length === 0){
47
46
  floorTask.startWaitTime = Date.now()
48
47
  }
49
48
  if(reportJson){
50
49
  floorTask.arr.push(reportJson)
51
50
  clearTimeout(floorTask.timer)
52
51
  floorTask.timer = setTimeout(() => {
53
52
  check(floorTask)
54
53
  }, 1000)
55
54
  check(floorTask)
56
55
  }
57
56
  }catch (e) {
58
57
  {
59
58
  console.log('坑位曝光埋点出错啦',e)
60
59
  }
61
60
  }
62
61
  }else{
63
62
  console.log('坑位曝光埋点原始数据参数缺失,期望是[floorData, mInfo, etModelInfo],实际是:', data)
64
63
  }
64
+ import track from '../../../open/api/track'
65
65
  const {arr : arrTask, startWaitTime} = floorTask
66
66
  const isTimeout = startWaitTime != 0 && (Date.now() - startWaitTime >= 1000)
67
67
  const arrTaskNum = arrTask.length;
68
68
  const isOverMax = arrTaskNum >= 10
69
69
  const hasData = arrTaskNum > 0
70
70
  if(hasData && (isTimeout || isOverMax)){
71
71
  const reduceData = connactData(arrTask)
72
72
  track.reportExposureEventLog(reduceData)
73
73
  floorTask.arr = []
74
74
  floorTask.startWaitTime = 0
75
75
  clearTimeout(floorTask.timer)
76
76
  }
77
77
  const initData = JSON.parse(JSON.stringify(arr[0]))
78
78
  if(initData.jsonParam.etModelInfo) {
79
79
  initData.jsonParam.logBaseInfo = []
80
80
  initData.jsonParam.etModelInfo.lstms = []
81
81
  return arr.reduce((acc, cur) => {
82
82
  acc.jsonParam.logBaseInfo.push(cur.jsonParam.logBaseInfo)
83
83
  return acc
84
84
  }, initData)
85
85
  } else {
86
86
  return arr.reduce((acc) => {
87
87
  return acc
88
88
  })
89
89
  }
90
90
  if(!Array.isArray(data)){
91
91
  console.log('坑位曝光埋点原始数据参类型错误,期望是数组,实际是:', data)
92
92
  return
93
93
  }
94
94
  const [floorData, mInfo, etModelInfo] = data
95
95
  if(floorData && mInfo && etModelInfo){
96
96
  const isIsvReportModule = isvReportModuleTypeList.includes(floorData?.floorExtInfo?.moduleFlag)
97
97
  try {
98
98
  const reportJson = track.getExposureInfo(floorData, mInfo, etModelInfo,true, isIsvReportModule)
99
99
  console.log(`${floorData?.floorExtInfo?.moduleFlag}===reportJson===`,reportJson)
100
100
  const { floorIdx } = floorData
101
101
  if(!task[floorIdx]){
102
102
  task[floorIdx] = {
103
103
  arr: [],
104
104
  startWaitTime: 0,
105
105
  timer : 0
106
106
  }
107
107
  }
108
108
  const floorTask = task[floorIdx]
109
109
  if(floorTask.arr.length === 0){
110
110
  floorTask.startWaitTime = Date.now()
111
111
  }
112
112
  if(reportJson){
113
113
  floorTask.arr.push(reportJson)
114
114
  clearTimeout(floorTask.timer)
115
115
  floorTask.timer = setTimeout(() => {
116
116
  check(floorTask)
117
117
  }, 1000)
118
118
  check(floorTask)
119
119
  }
120
120
  }catch (e) {
121
121
  {
122
122
  console.log('坑位曝光埋点出错啦',e)
123
123
  }
124
124
  }
125
125
  }else{
126
126
  console.log('坑位曝光埋点原始数据参数缺失,期望是[floorData, mInfo, etModelInfo],实际是:', data)
127
127
  }
@@ -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 = 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
  useEffect(() => {
22
21
  const latestRes =
23
22
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
24
23
  dealPageScrollInfo(latestRes)
25
24
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
26
25
  dealPageScrollInfo(res)
27
26
  })
28
27
  Taro.eventCenter.on(
29
28
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
30
29
  (state) => {
31
30
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
32
31
  },
33
32
  )
34
33
  return function cleanup() {
35
34
  Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, (res) => {
36
35
  dealPageScrollInfo(res)
37
36
  })
38
37
  Taro.eventCenter.off(
39
38
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
40
39
  (state) => {
41
40
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
42
41
  },
43
42
  )
44
43
  }
45
44
  }, [])
46
45
  useEffect(() => {
47
46
  if (componentShowState) {
48
47
  typeof inViewCallback === 'function' && inViewCallback()
49
48
  console.log('app=>in可视区域')
50
49
  } else {
51
50
  typeof outViewCallback === 'function' && outViewCallback()
52
51
  console.log('app=>out可视区域')
53
52
  }
54
53
  }, [componentShowState])
55
54
 
56
55
  const handleInOrOutView = (type: boolean) => {
57
56
  componentShowStateRef.current = type
58
57
  setComponentShowState(type)
59
58
  console.log('handleInOrOutView', type)
60
59
  }
61
60
 
62
61
  const dealPageScrollInfo = (res) => {
63
62
  console.log('dealPageScrollInfo===', res)
64
63
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
65
64
  if (
66
65
  typeof displayHeight === 'undefined' ||
67
66
  typeof offSetY === 'undefined'
68
67
  )
69
68
  return
70
69
  console.log(
71
70
  '处理后dealPageScrollInfo===displayHeight=offSetY',
72
71
  displayHeight,
73
72
  offSetY,
74
73
  )
75
74
  if (componentObserverRef.current) {
76
75
  const eleClientRect =
77
76
  componentObserverRef.current.getBoundingClientRect()
78
77
  const eleOffsetTop = Math.ceil(eleClientRect.top)
79
78
  const eleHeight = Math.ceil(eleClientRect.height)
80
79
  console.log(
81
80
  '==========================eleOffsetTop, eleHeight',
82
81
  eleOffsetTop,
83
82
  eleHeight,
84
83
  )
85
84
  if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
86
85
  const isOutView =
87
86
  offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
88
87
  displayHeight - (eleOffsetTop - offSetY) <
89
88
  Math.ceil(eleHeight * threshold)
90
89
  console.log(
91
90
  '比较isOutView',
92
91
  isOutView,
93
92
  offSetY,
94
93
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
95
94
  displayHeight - (eleOffsetTop - offSetY),
96
95
  Math.ceil(eleHeight * threshold),
97
96
  )
98
97
  handleInOrOutView(!isOutView)
99
98
  } else {
100
99
  const isInView =
101
100
  offSetY >
102
101
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
103
102
  offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
104
103
  console.log(
105
104
  '比较isInView',
106
105
  isInView,
107
106
  offSetY,
108
107
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
109
108
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
110
109
  )
111
110
  handleInOrOutView(isInView)
112
111
  }
113
112
  }
114
113
  }
115
114
  return (
116
115
  <View ref={componentObserverRef} style={style}>
117
116
  {children}
118
117
  </View>
119
118
  )
120
119
  } else {
121
120
  const { ref, inView } = useInView({
122
121
  threshold,
123
122
  triggerOnce: false,
124
123
  root: rootDom || null,
125
124
  rootMargin: `0px 0px 0px 0px`,
126
125
  })
127
126
  useEffect(() => {
128
127
  if (inView) {
129
128
  typeof inViewCallback === 'function' && inViewCallback()
130
129
  console.log('其他h5=>in可视区域')
131
130
  } else {
132
131
  typeof outViewCallback === 'function' && outViewCallback()
133
132
  console.log('其他h5=>out可视区域')
134
133
  }
135
134
  }, [inView])
136
135
  return (
137
136
  <View ref={ref} style={style}>
138
137
  {children}
139
138
  </View>
140
139
  )
141
140
  }
142
141
  children: null,
143
142
  style: {},
144
143
  className: '',
145
144
  inViewCallback: null,
146
145
  outViewCallback: null,
147
146
  threshold: 0,
147
+ import Taro from '@tarojs/taro'
148
148
  isH5AndJdShopView,
149
149
  isH5AndJdShopViewH5Scroll,
150
150
  isAppClassifyPage,
151
151
  lodashThrottle,
152
152
  TaroEventType,
153
153
  WEBVIEW_STATE,
154
154
  M_H5_ROOT_ELE_NODE,
155
155
  latestFromNativeMsgStorage,
156
156
  getNativePageScrollRes,
157
157
  props: ComponentInterFace.InOrOutViewObserverProps,
158
158
  const {
159
159
  children,
160
160
  style,
161
161
  inViewCallback,
162
162
  outViewCallback,
163
163
  threshold = 0,
164
164
  } = props
165
165
  const [componentShowState, setComponentShowState] = useState(false)
166
166
  const componentObserverRef = useRef<HTMLElement | null>(null)
167
167
  const componentShowStateRef = useRef(false)
168
168
  const needShowHighVersion =
169
169
  isAppClassifyPage ||
170
170
  (isH5AndJdShopViewH5Scroll &&
171
171
  !(
172
172
  global.info.queryInfo?.downgraded &&
173
173
  global.info.queryInfo.downgraded === 'true'
174
174
  ))
175
175
  const rootDom =
176
176
  isH5AndJdShopView && needShowHighVersion
177
177
  ? null
178
178
  : document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
179
179
  if (isH5AndJdShopView && !needShowHighVersion) {
180
180
  console.log('视频========属于app原生滚动')
181
181
  useEffect(() => {
182
182
  const latestRes =
183
183
  latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
184
184
  dealPageScrollInfo(latestRes)
185
185
  Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, res => {
186
186
  dealPageScrollInfo(res)
187
187
  })
188
188
  Taro.eventCenter.on(
189
189
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
190
190
  state => {
191
191
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
192
192
  },
193
193
  )
194
194
  return function cleanup() {
195
195
  Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, res => {
196
196
  dealPageScrollInfo(res)
197
197
  })
198
198
  Taro.eventCenter.off(
199
199
  TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
200
200
  state => {
201
201
  state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
202
202
  },
203
203
  )
204
204
  }
205
205
  }, [])
206
206
  useEffect(() => {
207
207
  if (componentShowState) {
208
208
  typeof inViewCallback === 'function' && inViewCallback()
209
209
  console.log('app=>in可视区域')
210
210
  } else {
211
211
  typeof outViewCallback === 'function' && outViewCallback()
212
212
  console.log('app=>out可视区域')
213
213
  }
214
214
  }, [componentShowState])
215
215
 
216
216
  const handleInOrOutView = (type: boolean) => {
217
217
  componentShowStateRef.current = type
218
218
  setComponentShowState(type)
219
219
  console.log('handleInOrOutView', type)
220
220
  }
221
221
 
222
222
  const dealPageScrollInfo = res => {
223
223
  console.log('dealPageScrollInfo===', res)
224
224
  const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
225
225
  if (
226
226
  typeof displayHeight === 'undefined' ||
227
227
  typeof offSetY === 'undefined'
228
228
  )
229
229
  return
230
230
  console.log(
231
231
  '处理后dealPageScrollInfo===displayHeight=offSetY',
232
232
  displayHeight,
233
233
  offSetY,
234
234
  )
235
235
  if (componentObserverRef.current) {
236
236
  const eleClientRect = componentObserverRef.current.getBoundingClientRect()
237
237
  const eleOffsetTop = Math.ceil(eleClientRect.top)
238
238
  const eleHeight = Math.ceil(eleClientRect.height)
239
239
  console.log(
240
240
  '==========================eleOffsetTop, eleHeight',
241
241
  eleOffsetTop,
242
242
  eleHeight,
243
243
  )
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
  console.log(
250
250
  '比较isOutView',
251
251
  isOutView,
252
252
  offSetY,
253
253
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
254
254
  displayHeight - (eleOffsetTop - offSetY),
255
255
  Math.ceil(eleHeight * threshold),
256
256
  )
257
257
  handleInOrOutView(!isOutView)
258
258
  } else {
259
259
  const isInView =
260
260
  offSetY >
261
261
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
262
262
  offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
263
263
  console.log(
264
264
  '比较isInView',
265
265
  isInView,
266
266
  offSetY,
267
267
  eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
268
268
  eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
269
269
  )
270
270
  handleInOrOutView(isInView)
271
271
  }
272
272
  }
273
273
  }
274
274
  return (
275
275
  <View ref={componentObserverRef} style={style}>
276
276
  {children}
277
277
  </View>
278
278
  )
279
279
  } else {
280
280
  console.log('视频========h5滚动')
281
281
  const { ref, inView } = useInView({
282
282
  delay: 100,
283
283
  threshold,
284
284
  triggerOnce: false,
285
285
  root: rootDom || null,
286
286
  rootMargin: `0px 0px 0px 0px`,
287
287
  })
288
288
  const throttledViewChanged: ViewChangeHandler = useCallback<
289
289
  ViewChangeHandler
290
290
  >(
291
291
  lodashThrottle(
292
292
  (inView: boolean) => {
293
293
  if (inView) {
294
294
  typeof inViewCallback === 'function' && inViewCallback()
295
295
  console.log('其他h5=>in可视区域')
296
296
  } else {
297
297
  typeof outViewCallback === 'function' && outViewCallback()
298
298
  console.log('其他h5=>out可视区域')
299
299
  }
300
300
  },
301
301
  300,
302
302
  { leading: false, trailing: true },
303
303
  ),
304
304
  [],
305
305
  )
306
306
  useEffect(() => {
307
307
  throttledViewChanged(inView)
308
308
  }, [inView])
309
309
  return (
310
310
  <View ref={ref} style={style}>
311
311
  {children}
312
312
  </View>
313
313
  )
314
314
  }
315
315
  children: null,
316
316
  style: {},
317
317
  className: '',
318
318
  inViewCallback: null,
319
319
  outViewCallback: null,
320
320
  threshold: 0,