Authored by 邱骏

feat(articleDetail.vue) 详情页瀑布流曝光上报 reviewed by 郭帅

1 <template> 1 <template>
2 <LayoutApp class="article-detail-container" :show-back="true" title="社区详情"> 2 <LayoutApp class="article-detail-container" :show-back="true" title="社区详情">
3 - <div class="detail-container"> 3 + <div ref="detailContainer" class="detail-container" @scroll="onScroll">
4 4
5 <div class="author-container"> 5 <div class="author-container">
6 <ArticleAuthor /> 6 <ArticleAuthor />
@@ -30,12 +30,14 @@ @@ -30,12 +30,14 @@
30 <div class="recommend-container"> 30 <div class="recommend-container">
31 <div class="recommend-text">推荐阅读</div> 31 <div class="recommend-text">推荐阅读</div>
32 <ClientOnly> 32 <ClientOnly>
33 - <waterFallList 33 + <waterFallList ref="waterfallComp"
34 :listData="recommendArticleList" 34 :listData="recommendArticleList"
35 :item-w="344" :gutter-w="15" 35 :item-w="344" :gutter-w="15"
36 @update-praise="onUpdatePraise" 36 @update-praise="onUpdatePraise"
37 :yasParams="yasParams" 37 :yasParams="yasParams"
38 :yasOP="yasOP" 38 :yasOP="yasOP"
  39 + :parentHeight="parentHeight"
  40 + :needParent="true"
39 > 41 >
40 </waterFallList> 42 </waterFallList>
41 </ClientOnly> 43 </ClientOnly>
@@ -73,7 +75,8 @@ export default { @@ -73,7 +75,8 @@ export default {
73 data() { 75 data() {
74 return { 76 return {
75 yasParams: {P_NAME: 'XY_UFOArticleDetail', P_PARAM: this.articleId}, 77 yasParams: {P_NAME: 'XY_UFOArticleDetail', P_PARAM: this.articleId},
76 - yasOP: 'XY_STROLL_LIST_ACT_C' 78 + yasOP: 'XY_STROLL_LIST_ACT_C',
  79 + parentHeight: 0
77 }; 80 };
78 }, 81 },
79 computed: { 82 computed: {
@@ -129,6 +132,10 @@ export default { @@ -129,6 +132,10 @@ export default {
129 articleId, 132 articleId,
130 status 133 status
131 }); 134 });
  135 + },
  136 + onScroll() {
  137 + this.parentHeight = this.$refs.detailContainer.clientHeight;
  138 + this.$refs.waterfallComp.scroll();
132 } 139 }
133 } 140 }
134 }; 141 };
@@ -142,6 +149,10 @@ export default { @@ -142,6 +149,10 @@ export default {
142 } 149 }
143 150
144 .detail-container { 151 .detail-container {
  152 + height: 100%;
  153 + overflow-x: hidden;
  154 + overflow-y: scroll;
  155 + -webkit-overflow-scrolling: touch;
145 background: #fff; 156 background: #fff;
146 } 157 }
147 158
@@ -79,6 +79,14 @@ export default { @@ -79,6 +79,14 @@ export default {
79 yasOP: { // 用于监测点击事件的名称 79 yasOP: { // 用于监测点击事件的名称
80 type: String, 80 type: String,
81 default: '' 81 default: ''
  82 + },
  83 + parentHeight: { // 如果有父级元素包含此组件,请传递屏幕高度
  84 + type: Number,
  85 + default: 0
  86 + },
  87 + needParent: {
  88 + type: Boolean,
  89 + default: false
82 } 90 }
83 }, 91 },
84 data() { 92 data() {
@@ -135,6 +143,7 @@ export default { @@ -135,6 +143,7 @@ export default {
135 mounted() { 143 mounted() {
136 console.log('mounted'); 144 console.log('mounted');
137 this.checkLogin(); 145 this.checkLogin();
  146 + // console.log('scrollParent=', this.scrollParent);
138 }, 147 },
139 methods: { 148 methods: {
140 loadMore() { 149 loadMore() {
@@ -145,12 +154,12 @@ export default { @@ -145,12 +154,12 @@ export default {
145 this.scrollTop = this.$refs.waterfall.scrollTop; 154 this.scrollTop = this.$refs.waterfall.scrollTop;
146 this.$refs.waterfallComp.emitLoadMore(); 155 this.$refs.waterfallComp.emitLoadMore();
147 156
148 - let containerHeight = this.$refs.waterfall.offsetHeight; // 容器高度 157 + let containerHeight = this.needParent ? this.parentHeight : this.$refs.waterfall.offsetHeight; // 容器高度
149 let headerHeight = document.querySelector('.header') ? document.querySelector('.header').offsetHeight : 0; // 头部高度 158 let headerHeight = document.querySelector('.header') ? document.querySelector('.header').offsetHeight : 0; // 头部高度
150 159
151 this.scrollHandler({containerHeight: containerHeight, scrollTop: this.scrollTop, headerHeight: headerHeight}); 160 this.scrollHandler({containerHeight: containerHeight, scrollTop: this.scrollTop, headerHeight: headerHeight});
152 }, 161 },
153 - scrollHandler({containerHeight, scrollTop, headerHeight}) { 162 + scrollHandler({containerHeight, scrollTop, headerHeight, containerOffsetTop}) {
154 if (this.timeout) { 163 if (this.timeout) {
155 clearTimeout(this.timeout); 164 clearTimeout(this.timeout);
156 this.timeout = null; 165 this.timeout = null;
@@ -158,7 +167,7 @@ export default { @@ -158,7 +167,7 @@ export default {
158 167
159 let items = document.querySelectorAll('.cell-item:not(.collect)'); 168 let items = document.querySelectorAll('.cell-item:not(.collect)');
160 169
161 - items.forEach((item) => { // 遍历元素,判断在可视区域的元素加上collect并加入上报数组,此方法不可重复曝光 170 + items.forEach((item, index) => { // 遍历元素,判断在可视区域的元素加上collect并加入上报数组,此方法不可重复曝光
162 let isCollected = /collect/.test(item.className); 171 let isCollected = /collect/.test(item.className);
163 let bounding = item.getBoundingClientRect(); 172 let bounding = item.getBoundingClientRect();
164 173
@@ -167,7 +176,7 @@ export default { @@ -167,7 +176,7 @@ export default {
167 item.className += ' collect'; 176 item.className += ' collect';
168 177
169 let yasParam = Object.assign({}, this.yasParams, { 178 let yasParam = Object.assign({}, this.yasParams, {
170 - I_INDEX: item.dataset.index, 179 + I_INDEX: parseInt(item.dataset.index, 10) + 1,
171 ARTICLE_ID: item.dataset.id 180 ARTICLE_ID: item.dataset.id
172 }); 181 });
173 182
@@ -191,7 +200,11 @@ export default { @@ -191,7 +200,11 @@ export default {
191 200
192 }, 201 },
193 isVisible(top, scrollTop, containerHeight, headerHeight) { // 判断元素是否在可视区域 202 isVisible(top, scrollTop, containerHeight, headerHeight) { // 判断元素是否在可视区域
  203 + if (this.needParent && !this.parentHeight) {
  204 + return false;
  205 + }
194 if (top - headerHeight > 0 && (top - headerHeight) < containerHeight - 100) { 206 if (top - headerHeight > 0 && (top - headerHeight) < containerHeight - 100) {
  207 + // console.log(top, scrollTop, containerHeight, headerHeight, (top-headerHeight));
195 return true; 208 return true;
196 } else { 209 } else {
197 return false; 210 return false;