@conecli/cone-render 0.8.34 → 0.8.35
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.
- package/dist/common/const.ts +1 -1
- package/dist/common/index.h5.ts +1 -1
- package/dist/common/index.jd.ts +1 -1
- package/dist/common/index.ts +1 -1
- package/dist/common/index.weapp.ts +1 -1
- package/dist/components/base/CustomScrollView/index.tsx +1 -1
- package/dist/components/base/ExposureSmart/const.ts +1 -0
- package/dist/components/base/ExposureSmart/index.h5.module.scss +18 -4
- package/dist/components/base/ExposureSmart/index.h5.tsx +1 -1
- package/dist/components/base/ExposureSmart/index.module.scss +20 -9
- package/dist/components/base/ExposureSmart/index.tsx +1 -1
- package/dist/components/base/ExposureSmart/reporter.tsx +1 -1
- package/dist/components/base/InOrOutViewObserver/index.tsx +1 -1
- package/dist/components/base/InViewRender/index.tsx +1 -1
- package/dist/components/base/InViewRender/index.weapp.tsx +1 -1
- package/dist/components/base/ItemViewExposureSmart/index.module.scss +8 -0
- package/dist/components/base/ItemViewExposureSmart/index.tsx +1 -0
- package/dist/components/base/LazyLayoutLoad/index.tsx +1 -1
- package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
- package/dist/components/base/NetworkDataError/const.ts +1 -1
- package/dist/components/base/NetworkDataError/index.module.scss +4 -1
- package/dist/components/decorate/DecorateFloorModule/index.tsx +1 -1
- package/dist/interface/common.ts +1 -1
- package/dist/jumpEventReport/base.ts +1 -1
- package/dist/jumpEventReport/createReportFloorData.ts +1 -1
- package/dist/jumpEventReport/index.h5.ts +1 -1
- package/dist/jumpEventReport/index.weapp.ts +1 -1
- package/dist/jumpEventReport/web/report.ts +1 -1
- package/dist/jumpEventReport/web.base.ts +1 -1
- package/dist/jumpEventReport/web.jd.ts +1 -1
- package/dist/jumpEventReport/web.jdb.ts +1 -1
- package/dist/jumpEventReport/web.jdjch.ts +1 -0
- package/dist/libs/taroAppReport.js +2 -2
- package/dist/modules/ContainerFloorList/index.h5.module.scss +10 -1
- package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
- package/dist/open/api/device.ts +1 -1
- package/dist/open/api/track.ts +1 -1
- package/dist/open/api/util.ts +1 -1
- package/dist/open/components/index.ts +1 -1
- package/dist/service/bMallConst.ts +1 -1
- package/dist/utils/connectNativeJsBridge.ts +1 -1
- package/dist/utils/connectNativeJsBridge.weapp.ts +1 -1
- package/dist/utils/h5Utils.ts +1 -1
- package/dist/utils/index.h5.ts +1 -1
- package/dist/utils/index.ts +1 -1
- package/dist/utils/index.weapp.ts +1 -1
- package/dist/utils/intersectionObserver.ts +1 -1
- package/dist/utils/jm-common.js +1 -1
- package/dist/utils/utils.ts +1 -1
- package/package.json +1 -1
- /package/dist/service/{bMallConst.wxapp.ts → bMallConst.weapp.ts} +0 -0
- /package/dist/service/http/{colorSign.wxapp.ts → colorSign.weapp.ts} +0 -0
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
//坑位曝光
|
|
3
|
+
.d-report-point {
|
|
4
|
+
position: absolute;
|
|
5
|
+
top: 0;
|
|
6
|
+
left: 0;
|
|
7
|
+
right: 0;
|
|
8
|
+
bottom: 0;
|
|
6
9
|
opacity: 0;
|
|
7
10
|
pointer-events: none;
|
|
11
|
+
z-index: -1;
|
|
12
|
+
}
|
|
13
|
+
//楼层曝光
|
|
14
|
+
.d-report-floor {
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: 0;
|
|
17
|
+
left: 0;
|
|
18
|
+
right: 0;
|
|
19
|
+
height: 1px;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
z-index: -1;
|
|
8
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
2
1
|
const inViewCallback = () => {
|
|
3
2
|
console.log('埋点收到进入可视区域的回到啦!', reportData)
|
|
4
3
|
addReportData(reportData)
|
|
5
4
|
}
|
|
6
5
|
exposureStyle.root,
|
|
7
6
|
className,
|
|
8
7
|
)} height={'100%'} inViewCallback={inViewCallback}></InViewRender>
|
|
8
|
+
import React, { useMemo } from 'react'
|
|
9
9
|
const { type, className, reportData, trackCallback, markPoint } = props
|
|
10
10
|
const isViewOnlineState =
|
|
11
11
|
taroJdBaseInfo.info.pageInfo.dataType === BUSINESS_TYPE.ONLINE
|
|
12
12
|
const inViewCallback = () => {
|
|
13
13
|
console.log('埋点收到进入可视区域的回到啦!', reportData)
|
|
14
14
|
addReportData(reportData)
|
|
15
15
|
typeof trackCallback === 'function' && trackCallback(reportData)
|
|
16
16
|
}
|
|
17
17
|
let chartPointClassName = ""
|
|
18
18
|
|
|
19
19
|
if(isChartH5 && markPoint && Array.isArray(reportData)){
|
|
20
20
|
const [floorData, mInfo] = reportData
|
|
21
21
|
if(floorData && mInfo && mInfo.hasOwnProperty('pos') ){
|
|
22
22
|
chartPointClassName = track.getFloorPointIndexClassName(floorData, mInfo.pos)
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
return isViewOnlineState && reportData
|
|
26
26
|
? <InViewRender className={classNames(
|
|
27
27
|
{
|
|
28
28
|
[exposureStyle['d-report-point']]: type === TrackType.point,
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
[exposureStyle['d-report-floor']]: type === TrackType.floor,
|
|
32
32
|
},
|
|
33
33
|
className,
|
|
34
34
|
chartPointClassName
|
|
35
35
|
)} height={'100%'} inViewCallback={inViewCallback}></InViewRender>
|
|
36
36
|
: null
|
|
37
37
|
return useMemo(() => {
|
|
38
38
|
return <Exposure {...props} />
|
|
39
39
|
}, [])
|
|
40
40
|
reportData: null,
|
|
41
41
|
trackCallback: null,
|
|
42
42
|
type: TrackType.point,
|
|
43
43
|
markPoint: false
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
//坑位曝光
|
|
3
|
+
.d-report-point {
|
|
4
|
+
position: absolute;
|
|
5
|
+
top: 0;
|
|
6
|
+
left: 0;
|
|
7
|
+
right: 0;
|
|
8
|
+
bottom: 0;
|
|
9
|
+
opacity: 0;
|
|
10
|
+
pointer-events: none;
|
|
11
|
+
z-index: -1;
|
|
12
|
+
}
|
|
13
|
+
//楼层曝光
|
|
14
|
+
.d-report-floor {
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: 0;
|
|
17
|
+
left: 0;
|
|
18
|
+
right: 0;
|
|
19
|
+
height: 1px;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
z-index: -1;
|
|
11
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
2
|
const { type, className, reportData, trackCallback } = props
|
|
3
3
|
const checkReportData = Array.isArray(reportData)
|
|
4
4
|
const [floorData, mInfo] = checkReportData ? reportData : []
|
|
5
5
|
const getFloorPointClassName = `J_floor_${floorData?.uid}_index_${mInfo?.pos}`
|
|
6
6
|
if (
|
|
7
7
|
!taroJdBaseInfo.info.pageInfo.floorExposureInfo[
|
|
8
8
|
getFloorPointClassName
|
|
9
9
|
]
|
|
10
10
|
){
|
|
11
11
|
const createIntersectionObserver = new intersectionObserver({
|
|
12
12
|
selector: `#J_floor_${floorData?.uid} >>> .${getFloorPointClassName}`,
|
|
13
13
|
context: this,
|
|
14
14
|
onFinal: (res) => {
|
|
15
15
|
taroJdBaseInfo.info.pageInfo.floorExposureInfo[
|
|
16
16
|
getFloorPointClassName
|
|
17
17
|
] = true
|
|
18
18
|
console.log('小程序曝光埋点收到进入可视区域啦!', getFloorPointClassName, reportData, res)
|
|
19
19
|
addReportData(reportData)
|
|
20
20
|
typeof trackCallback === 'function' && trackCallback(reportData)
|
|
21
21
|
createIntersectionObserver.disconnect()
|
|
22
22
|
},
|
|
23
23
|
})
|
|
24
24
|
createIntersectionObserver.connect()
|
|
25
25
|
}
|
|
26
26
|
floorData &&
|
|
27
27
|
mInfo && (
|
|
28
28
|
{
|
|
29
29
|
[exposureStyle['d-report-point']]: type === TrackType.point,
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
[exposureStyle['d-report-floor']]: type === TrackType.floor,
|
|
33
33
|
},
|
|
34
34
|
getFloorPointClassName,
|
|
35
35
|
reportData: null,
|
|
36
36
|
trackCallback: null,
|
|
37
37
|
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 isOverMax = arrTask.length >= 10
|
|
5
4
|
const hasData = arrTask.length > 0
|
|
6
5
|
if(hasData && (isTimeout || isOverMax)){
|
|
7
6
|
const reduceData = connactData(arrTask)
|
|
8
7
|
track.reportExposureEventLog(reduceData)
|
|
9
8
|
floorTask.arr = []
|
|
10
9
|
floorTask.startWaitTime = 0
|
|
11
10
|
clearTimeout(floorTask.timer)
|
|
12
11
|
}
|
|
13
12
|
const initData = JSON.parse(JSON.stringify(arr[0]))
|
|
14
13
|
if(initData.jsonParam.etModelInfo) {
|
|
15
14
|
initData.jsonParam.logBaseInfo = []
|
|
16
15
|
initData.jsonParam.etModelInfo.lstms = []
|
|
17
16
|
return arr.reduce((acc, cur) => {
|
|
18
17
|
cur.jsonParam.etModelInfo.lstms[0].la_p = cur.jsonParam.logBaseInfo.mInfo?.pos
|
|
19
18
|
acc.jsonParam.logBaseInfo.push(cur.jsonParam.logBaseInfo)
|
|
20
19
|
acc.jsonParam.etModelInfo.lstms.push(cur.jsonParam.etModelInfo.lstms)
|
|
21
20
|
return acc
|
|
22
21
|
}, initData)
|
|
23
22
|
} else {
|
|
24
23
|
return arr.reduce((acc) => {
|
|
25
24
|
return acc
|
|
26
25
|
})
|
|
27
26
|
}
|
|
28
27
|
if(!Array.isArray(data)){
|
|
29
28
|
console.log('坑位曝光埋点原始数据参类型错误,期望是数组,实际是:', data)
|
|
30
29
|
return
|
|
31
30
|
}
|
|
32
31
|
const [floorData, mInfo, etModelInfo] = data
|
|
33
32
|
if(floorData && mInfo && etModelInfo){
|
|
34
33
|
try {
|
|
35
34
|
const reportJson = track.getIsvExposureInfo(floorData, mInfo, etModelInfo)
|
|
36
35
|
console.log('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
|
if (isH5AndJdShopView) {
|
|
19
18
|
useEffect(() => {
|
|
20
19
|
const latestRes =
|
|
21
20
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
|
|
22
21
|
dealPageScrollInfo(latestRes)
|
|
23
22
|
Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
|
|
24
23
|
dealPageScrollInfo(res)
|
|
25
24
|
})
|
|
26
25
|
Taro.eventCenter.on(
|
|
27
26
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
28
27
|
(state) => {
|
|
29
28
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
30
29
|
},
|
|
31
30
|
)
|
|
32
31
|
return function cleanup() {
|
|
33
32
|
Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, (res) => {
|
|
34
33
|
dealPageScrollInfo(res)
|
|
35
34
|
})
|
|
36
35
|
Taro.eventCenter.off(
|
|
37
36
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
38
37
|
(state) => {
|
|
39
38
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
40
39
|
},
|
|
41
40
|
)
|
|
42
41
|
}
|
|
43
42
|
}, [])
|
|
44
43
|
useEffect(() => {
|
|
45
44
|
if (componentShowState) {
|
|
46
45
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
47
46
|
console.log('app=>in可视区域')
|
|
48
47
|
} else {
|
|
49
48
|
typeof outViewCallback === 'function' && outViewCallback()
|
|
50
49
|
console.log('app=>out可视区域')
|
|
51
50
|
}
|
|
52
51
|
}, [componentShowState])
|
|
53
52
|
|
|
54
53
|
const handleInOrOutView = (type: boolean) => {
|
|
55
54
|
componentShowStateRef.current = type
|
|
56
55
|
setComponentShowState(type)
|
|
57
56
|
console.log('handleInOrOutView', type)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
const dealPageScrollInfo = (res) => {
|
|
61
60
|
console.log('dealPageScrollInfo===', res)
|
|
62
61
|
const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
|
|
63
62
|
if (
|
|
64
63
|
typeof displayHeight === 'undefined' ||
|
|
65
64
|
typeof offSetY === 'undefined'
|
|
66
65
|
)
|
|
67
66
|
return
|
|
68
67
|
console.log(
|
|
69
68
|
'处理后dealPageScrollInfo===displayHeight=offSetY',
|
|
70
69
|
displayHeight,
|
|
71
70
|
offSetY,
|
|
72
71
|
)
|
|
73
72
|
if (componentObserverRef.current) {
|
|
74
73
|
const eleClientRect =
|
|
75
74
|
componentObserverRef.current.getBoundingClientRect()
|
|
76
75
|
const eleOffsetTop = Math.ceil(eleClientRect.top)
|
|
77
76
|
const eleHeight = Math.ceil(eleClientRect.height)
|
|
78
77
|
console.log(
|
|
79
78
|
'==========================eleOffsetTop, eleHeight',
|
|
80
79
|
eleOffsetTop,
|
|
81
80
|
eleHeight,
|
|
82
81
|
)
|
|
83
82
|
if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
|
|
84
83
|
const isOutView =
|
|
85
84
|
offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
|
|
86
85
|
displayHeight - (eleOffsetTop - offSetY) <
|
|
87
86
|
Math.ceil(eleHeight * threshold)
|
|
88
87
|
console.log(
|
|
89
88
|
'比较isOutView',
|
|
90
89
|
isOutView,
|
|
91
90
|
offSetY,
|
|
92
91
|
eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
|
|
93
92
|
displayHeight - (eleOffsetTop - offSetY),
|
|
94
93
|
Math.ceil(eleHeight * threshold),
|
|
95
94
|
)
|
|
96
95
|
handleInOrOutView(!isOutView)
|
|
97
96
|
} else {
|
|
98
97
|
const isInView =
|
|
99
98
|
offSetY >
|
|
100
99
|
eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
|
|
101
100
|
offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
|
|
102
101
|
console.log(
|
|
103
102
|
'比较isInView',
|
|
104
103
|
isInView,
|
|
105
104
|
offSetY,
|
|
106
105
|
eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
|
|
107
106
|
eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
|
|
108
107
|
)
|
|
109
108
|
handleInOrOutView(isInView)
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
return (
|
|
114
113
|
<View ref={componentObserverRef} style={style}>
|
|
115
114
|
{children}
|
|
116
115
|
</View>
|
|
117
116
|
)
|
|
118
117
|
} else {
|
|
119
118
|
const rootDom = document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
|
|
120
119
|
const { ref, inView } = useInView({
|
|
121
120
|
threshold,
|
|
122
121
|
triggerOnce: false,
|
|
123
122
|
root: rootDom || null,
|
|
124
123
|
rootMargin: `0px 0px 0px 0px`,
|
|
125
124
|
})
|
|
126
125
|
useEffect(() => {
|
|
127
126
|
if (inView) {
|
|
128
127
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
129
128
|
console.log('其他h5=>in可视区域')
|
|
130
129
|
} else {
|
|
131
130
|
typeof outViewCallback === 'function' && outViewCallback()
|
|
132
131
|
console.log('其他h5=>out可视区域')
|
|
133
132
|
}
|
|
134
133
|
}, [inView])
|
|
135
134
|
return (
|
|
136
135
|
<View ref={ref} style={style}>
|
|
137
136
|
{children}
|
|
138
137
|
</View>
|
|
139
138
|
)
|
|
140
139
|
}
|
|
141
140
|
children: null,
|
|
142
141
|
style: {},
|
|
143
142
|
className: '',
|
|
144
143
|
inViewCallback: null,
|
|
145
144
|
outViewCallback: null,
|
|
146
145
|
threshold: 0,
|
|
146
|
+
import Taro from '@tarojs/taro'
|
|
147
147
|
TaroEventType,
|
|
148
148
|
WEBVIEW_STATE,
|
|
149
149
|
M_H5_ROOT_ELE_NODE,
|
|
150
150
|
latestFromNativeMsgStorage,
|
|
151
151
|
getNativePageScrollRes,
|
|
152
152
|
props: ComponentInterFace.InOrOutViewObserverProps,
|
|
153
153
|
const {
|
|
154
154
|
children,
|
|
155
155
|
style,
|
|
156
156
|
inViewCallback,
|
|
157
157
|
outViewCallback,
|
|
158
158
|
threshold = 0,
|
|
159
159
|
} = props
|
|
160
160
|
const [componentShowState, setComponentShowState] = useState(false)
|
|
161
161
|
const componentObserverRef = useRef<HTMLElement | null>(null)
|
|
162
162
|
const componentShowStateRef = useRef(false)
|
|
163
163
|
const needShowHighVersion = isH5AndJdShopViewH5Scroll && !(global.info.queryInfo?.downgraded && global.info.queryInfo.downgraded === "true")
|
|
164
164
|
const rootDom = isH5AndJdShopView && needShowHighVersion ? null : document.querySelector(`${M_H5_ROOT_ELE_NODE}`)
|
|
165
165
|
if (isH5AndJdShopView && !needShowHighVersion) {
|
|
166
166
|
useEffect(() => {
|
|
167
167
|
const latestRes =
|
|
168
168
|
latestFromNativeMsgStorage[TaroEventType.PAGE_SCROLL] || {}
|
|
169
169
|
dealPageScrollInfo(latestRes)
|
|
170
170
|
Taro.eventCenter.on(TaroEventType.PAGE_SCROLL, (res) => {
|
|
171
171
|
dealPageScrollInfo(res)
|
|
172
172
|
})
|
|
173
173
|
Taro.eventCenter.on(
|
|
174
174
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
175
175
|
(state) => {
|
|
176
176
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
177
177
|
},
|
|
178
178
|
)
|
|
179
179
|
return function cleanup() {
|
|
180
180
|
Taro.eventCenter.off(TaroEventType.PAGE_SCROLL, (res) => {
|
|
181
181
|
dealPageScrollInfo(res)
|
|
182
182
|
})
|
|
183
183
|
Taro.eventCenter.off(
|
|
184
184
|
TaroEventType.PAGE_DOCUMENT_VISIBILITY_CHANGE,
|
|
185
185
|
(state) => {
|
|
186
186
|
state === WEBVIEW_STATE.NOT_VISIBLE && handleInOrOutView(false)
|
|
187
187
|
},
|
|
188
188
|
)
|
|
189
189
|
}
|
|
190
190
|
}, [])
|
|
191
191
|
useEffect(() => {
|
|
192
192
|
if (componentShowState) {
|
|
193
193
|
typeof inViewCallback === 'function' && inViewCallback()
|
|
194
194
|
console.log('app=>in可视区域')
|
|
195
195
|
} else {
|
|
196
196
|
typeof outViewCallback === 'function' && outViewCallback()
|
|
197
197
|
console.log('app=>out可视区域')
|
|
198
198
|
}
|
|
199
199
|
}, [componentShowState])
|
|
200
200
|
|
|
201
201
|
const handleInOrOutView = (type: boolean) => {
|
|
202
202
|
componentShowStateRef.current = type
|
|
203
203
|
setComponentShowState(type)
|
|
204
204
|
console.log('handleInOrOutView', type)
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
const dealPageScrollInfo = (res) => {
|
|
208
208
|
console.log('dealPageScrollInfo===', res)
|
|
209
209
|
const { displayHeight, offSetY } = getNativePageScrollRes(res) || {}
|
|
210
210
|
if (
|
|
211
211
|
typeof displayHeight === 'undefined' ||
|
|
212
212
|
typeof offSetY === 'undefined'
|
|
213
213
|
)
|
|
214
214
|
return
|
|
215
215
|
console.log(
|
|
216
216
|
'处理后dealPageScrollInfo===displayHeight=offSetY',
|
|
217
217
|
displayHeight,
|
|
218
218
|
offSetY,
|
|
219
219
|
)
|
|
220
220
|
if (componentObserverRef.current) {
|
|
221
221
|
const eleClientRect =
|
|
222
222
|
componentObserverRef.current.getBoundingClientRect()
|
|
223
223
|
const eleOffsetTop = Math.ceil(eleClientRect.top)
|
|
224
224
|
const eleHeight = Math.ceil(eleClientRect.height)
|
|
225
225
|
console.log(
|
|
226
226
|
'==========================eleOffsetTop, eleHeight',
|
|
227
227
|
eleOffsetTop,
|
|
228
228
|
eleHeight,
|
|
229
229
|
)
|
|
230
230
|
if (eleOffsetTop >= 0 && eleOffsetTop < displayHeight) {
|
|
231
231
|
const isOutView =
|
|
232
232
|
offSetY > eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)) ||
|
|
233
233
|
displayHeight - (eleOffsetTop - offSetY) <
|
|
234
234
|
Math.ceil(eleHeight * threshold)
|
|
235
235
|
console.log(
|
|
236
236
|
'比较isOutView',
|
|
237
237
|
isOutView,
|
|
238
238
|
offSetY,
|
|
239
239
|
eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
|
|
240
240
|
displayHeight - (eleOffsetTop - offSetY),
|
|
241
241
|
Math.ceil(eleHeight * threshold),
|
|
242
242
|
)
|
|
243
243
|
handleInOrOutView(!isOutView)
|
|
244
244
|
} else {
|
|
245
245
|
const isInView =
|
|
246
246
|
offSetY >
|
|
247
247
|
eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold) &&
|
|
248
248
|
offSetY < eleOffsetTop + Math.ceil(eleHeight * (1 - threshold))
|
|
249
249
|
console.log(
|
|
250
250
|
'比较isInView',
|
|
251
251
|
isInView,
|
|
252
252
|
offSetY,
|
|
253
253
|
eleOffsetTop - displayHeight + Math.ceil(eleHeight * threshold),
|
|
254
254
|
eleOffsetTop + Math.ceil(eleHeight * (1 - threshold)),
|
|
255
255
|
)
|
|
256
256
|
handleInOrOutView(isInView)
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
return (
|
|
261
261
|
<View ref={componentObserverRef} style={style}>
|
|
262
262
|
{children}
|
|
263
263
|
</View>
|
|
264
264
|
)
|
|
265
265
|
} else {
|
|
266
266
|
const { ref, inView } = useInView({
|
|
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,
|