Authored by 李奇

组件特殊情况处理

... ... @@ -29,18 +29,16 @@
visible: false,
waitingReport: [],
isVisible: false,
pagePrefix: yoho.isiOS ? 'i' : (yoho.isAndroid ? 'a' : 'h5')
appPrefix: yoho.isiOS ? 'i' : (yoho.isAndroid ? 'a' : 'h5')
};
},
methods: {
record(visible) {
// 元素由不可见变为可见则记录,否则不记录
if (!this.isVisiable && visible) {
const param = {
P_NAME: `${this.pagePrefix}${this.pageName}` || '', // 页面名称
P_NAME: `${this.appPrefix}${this.pageName}` || '', // 页面名称
P_PARAM: this.pageParam || '', // 页面参数
I_INDEX: this.index, // 内部item的序号
PRD_SKN: this.productSkn // 商品SKN (可选)
... ...
... ... @@ -28,6 +28,15 @@
},
methods: {
checkReport() {
// 顶部区域可能切换显示和隐藏所以动态获取
const topRect = document.querySelector(`.${this.topClassName}`).getBoundingClientRect();
// 可见区域顶部距离视口的上边的距离
this.viewArea.top = topRect.bottom;
// 可见区域底部距离视口的上边的距离
this.viewArea.bottom = window.screen.height;
let children = _.filter(this.$children, child => {
return child.$options.name === 'ExposureItem'
});
... ... @@ -47,19 +56,10 @@
},
mounted() {
let timer = setInterval(() => {
const filterRect = document.querySelector(`.${this.topClassName}`).getBoundingClientRect();
// 可见区域顶部距离视口的上边的距离
this.viewArea.top = filterRect.bottom;
// 可见区域底部距离视口的上边的距离
this.viewArea.bottom = window.screen.height;
this.$scrollEl = window;
this.scrollEvent = util.throttle(500, this.checkReport);
if (this.$scrollEl) {
this.$scrollEl.addEventListener('scroll', this.scrollEvent);
}
if (this.$children.length) {
... ... @@ -68,7 +68,8 @@
}
}, 500);
setInterval(() => {
let reportTimer = setInterval(() => {
if (!this.$children.length) { return clearInterval(reportTimer); }
_.each(_.filter(this.$children, child => child.$options.name === 'ExposureItem'), child => child.report());
}, 3000);
}
... ...