topic-list.vue
2.21 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
<template>
<Layout class="topic-list-page">
<LayoutHeader :hide="noHeader" slot='header' theme="white" class="topic-list-header" title="全部话题"></LayoutHeader>
<Scroll
class="main-container"
ref="scroll"
:scroll-events="['scroll-end','scroll']"
@scroll="onScroll"
@scroll-end="fetchList">
<div class="topic-list">
<TopicItem v-for="(item, index) in topicList" :key="index" :data="item"></TopicItem>
</div>
</Scroll>
<ReplaceToHome :scrolling="scrolling" ></ReplaceToHome>
</Layout>
</template>
<script>
import {get} from 'lodash';
import {Scroll, Loading} from 'cube-ui';
import TopicItem from './components/topic/list-item';
import {createNamespacedHelpers, mapState} from 'vuex';
import ReplaceToHome from 'components/replace-to-home/replace-to-home';
const {mapState: articleMapState, mapActions: articleMapActions} = createNamespacedHelpers('article');
export default {
name: 'TopicListPage',
data() {
return {
data: {},
noMore: false,
scrolling: false
};
},
created() {
},
activated() {
this.fetchList();
},
async serverPrefetch() {
return this.fetchTopicList({});
},
computed: {
...articleMapState(['topicList', 'fetchTopicPage']),
...mapState(['yoho']),
noHeader() {
return this.yoho.context.env.isChat;
},
},
methods: {
...articleMapActions(['fetchTopicList']),
onScroll() {
this.scrolling = true;
this._scTimer && clearTimeout(this._scTimer);
this._scTimer = setTimeout(() => {
this.scrolling = false;
}, 400);
},
fetchList() {
if (this.noMore) {
return;
}
this.fetchTopicList({}).then(res => {
if (+this.fetchTopicPage > +get(res, 'data.totalPage')) {
this.noMore = true;
}
this.$nextTick(() => {
this.$refs.scroll.forceUpdate(true);
});
});
}
},
components: {
ReplaceToHome,
Scroll,
Loading,
TopicItem
}
};
</script>
<style lang="scss" scoped>
.topic-list {
padding: 10px 0;
}
.loading {
padding-bottom: 20px;
text-align: center;
line-height: 1.2;
}
.load-icon {
display: flex;
justify-content: center;
}
</style>