Authored by 李奇

组件特殊情况处理

@@ -29,18 +29,16 @@ @@ -29,18 +29,16 @@
29 visible: false, 29 visible: false,
30 waitingReport: [], 30 waitingReport: [],
31 isVisible: false, 31 isVisible: false,
32 - pagePrefix: yoho.isiOS ? 'i' : (yoho.isAndroid ? 'a' : 'h5') 32 + appPrefix: yoho.isiOS ? 'i' : (yoho.isAndroid ? 'a' : 'h5')
33 }; 33 };
34 }, 34 },
35 methods: { 35 methods: {
36 record(visible) { 36 record(visible) {
37 37
38 -  
39 -  
40 // 元素由不可见变为可见则记录,否则不记录 38 // 元素由不可见变为可见则记录,否则不记录
41 if (!this.isVisiable && visible) { 39 if (!this.isVisiable && visible) {
42 const param = { 40 const param = {
43 - P_NAME: `${this.pagePrefix}${this.pageName}` || '', // 页面名称 41 + P_NAME: `${this.appPrefix}${this.pageName}` || '', // 页面名称
44 P_PARAM: this.pageParam || '', // 页面参数 42 P_PARAM: this.pageParam || '', // 页面参数
45 I_INDEX: this.index, // 内部item的序号 43 I_INDEX: this.index, // 内部item的序号
46 PRD_SKN: this.productSkn // 商品SKN (可选) 44 PRD_SKN: this.productSkn // 商品SKN (可选)
@@ -28,6 +28,15 @@ @@ -28,6 +28,15 @@
28 }, 28 },
29 methods: { 29 methods: {
30 checkReport() { 30 checkReport() {
  31 + // 顶部区域可能切换显示和隐藏所以动态获取
  32 + const topRect = document.querySelector(`.${this.topClassName}`).getBoundingClientRect();
  33 +
  34 + // 可见区域顶部距离视口的上边的距离
  35 + this.viewArea.top = topRect.bottom;
  36 +
  37 + // 可见区域底部距离视口的上边的距离
  38 + this.viewArea.bottom = window.screen.height;
  39 +
31 let children = _.filter(this.$children, child => { 40 let children = _.filter(this.$children, child => {
32 return child.$options.name === 'ExposureItem' 41 return child.$options.name === 'ExposureItem'
33 }); 42 });
@@ -47,19 +56,10 @@ @@ -47,19 +56,10 @@
47 }, 56 },
48 mounted() { 57 mounted() {
49 let timer = setInterval(() => { 58 let timer = setInterval(() => {
50 - const filterRect = document.querySelector(`.${this.topClassName}`).getBoundingClientRect();  
51 -  
52 - // 可见区域顶部距离视口的上边的距离  
53 - this.viewArea.top = filterRect.bottom;  
54 -  
55 - // 可见区域底部距离视口的上边的距离  
56 - this.viewArea.bottom = window.screen.height;  
57 -  
58 this.$scrollEl = window; 59 this.$scrollEl = window;
59 this.scrollEvent = util.throttle(500, this.checkReport); 60 this.scrollEvent = util.throttle(500, this.checkReport);
60 if (this.$scrollEl) { 61 if (this.$scrollEl) {
61 this.$scrollEl.addEventListener('scroll', this.scrollEvent); 62 this.$scrollEl.addEventListener('scroll', this.scrollEvent);
62 -  
63 } 63 }
64 64
65 if (this.$children.length) { 65 if (this.$children.length) {
@@ -68,7 +68,8 @@ @@ -68,7 +68,8 @@
68 } 68 }
69 }, 500); 69 }, 500);
70 70
71 - setInterval(() => { 71 + let reportTimer = setInterval(() => {
  72 + if (!this.$children.length) { return clearInterval(reportTimer); }
72 _.each(_.filter(this.$children, child => child.$options.name === 'ExposureItem'), child => child.report()); 73 _.each(_.filter(this.$children, child => child.$options.name === 'ExposureItem'), child => child.report());
73 }, 3000); 74 }, 3000);
74 } 75 }