article-detail2.vue
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
<Layout class="article-detail">
<RecycleScrollReveal :size="5" ref="scroll" @scroll="onScroll" :offset="800" :on-fetch="onFetch" :manual-init="true">
<template v-slot:eternalTop>
<ArticleDeatilNote :data="article" :scroll-top="scrollTop" :list-title="listTitle"></ArticleDeatilNote>
<!-- <ArticleDeatilLong ref="detailLong" :data="article" :scroll-top="scrollTop" :list-title="listTitle"></ArticleDeatilLong> -->
</template>
<template class="article-item" #item="{ data }">
<ArticleItem2
type="topic"
:index="data.index"
:data="data.data"
:width="colWidthForTwo"
:share="share"
:article-id="data.data.articleId"
:pos-id="posId">
<template v-if="data.data.dataType == 2">
<ArticleResource :data="data.data"></ArticleResource>
</template>
</ArticleItem2>
</template>
</RecycleScrollReveal>
</Layout>
</template>
<script>
import {get} from 'lodash';
import ArticleDeatilLong from './components/detail/article-long';
import ArticleDeatilNote from './components/detail/article-note';
import ArticleItem2 from './components/article/article-item2';
import {createNamespacedHelpers} from 'vuex';
const {mapState, mapActions} = createNamespacedHelpers('article');
export default {
name: 'ArticleDetailPage',
data() {
return {
id: 0,
scrollTop: 0,
scrolling: false,
article: {},
share: false,
listTitle: '推荐阅读',
colWidthForTwo: 370,
posId: 0
};
},
activated() {
if (+this.$route.params.id !== this.id) {
this.id = +this.$route.params.id;
this.init();
}
},
mounted() {
this.colWidthForTwo = Math.floor(this.$el.offsetWidth / 2);
},
computed: {
},
methods: {
...mapActions(['fetchArticleList']),
init() {
this.syncServiceArticleDetail();
},
onScroll({scrollTop}) {
this.scrollTop = scrollTop;
this.scrolling = true;
this._scTimer && clearTimeout(this._scTimer);
this._scTimer = setTimeout(() => {
this.scrolling = false;
}, 400);
},
syncServiceArticleDetail() {
const articleId = parseInt(this.id, 10);
this.fetchArticleList({
articleId,
page: 1,
limit: 1,
columnType: 1002
}).then(res => {
this.article = get(res, 'data.detailList[0]', {});
});
},
onFetch() {
return Promise.resolve([this.article]);
}
},
components: {
ArticleDeatilLong,
ArticleDeatilNote,
ArticleItem2
}
};
</script>
<style lang="scss" scoped>
/deep/ .scroll-reveal-list {
padding: 6px;
background-color: #f0f0f0;
}
</style>