2020-07-31 17:40:17 +08:00
|
|
|
<template>
|
|
|
|
<div class="topic-archive-page">
|
2020-08-01 00:39:29 +08:00
|
|
|
<topic-nav :currentTopic="defaultParams.topic_uri"></topic-nav>
|
2021-02-03 16:10:57 +08:00
|
|
|
<article-list :articles="articles" @currentChange="currentChangeArticle"></article-list>
|
2020-07-31 17:40:17 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-02-03 16:10:57 +08:00
|
|
|
import ArticleList from '~/components/archive/list'
|
|
|
|
import {mapState} from 'vuex';
|
2020-07-31 17:40:17 +08:00
|
|
|
|
2021-02-03 16:10:57 +08:00
|
|
|
export default {
|
|
|
|
name: "topicArticleList",
|
|
|
|
components: {
|
|
|
|
ArticleList
|
|
|
|
},
|
|
|
|
validate({params, store}) {
|
|
|
|
if (params.topic_uri === 'news') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return params.topic_uri && store.state.topic.data.some(
|
|
|
|
topic => topic.topicUri === params.topic_uri
|
|
|
|
)
|
|
|
|
},
|
2022-10-29 22:18:17 +08:00
|
|
|
fetch() {
|
|
|
|
let {store, params, query} = this.$nuxt.context
|
2021-02-03 16:10:57 +08:00
|
|
|
params.page = query.page || 1
|
|
|
|
return Promise.all([
|
|
|
|
store.dispatch('article/fetchList', params)
|
|
|
|
])
|
|
|
|
},
|
|
|
|
watch: {
|
2022-10-30 16:56:15 +08:00
|
|
|
'$route'(to, from) {
|
|
|
|
if (from.query.page && to.query.page) {
|
|
|
|
this.$router.go()
|
|
|
|
}
|
2021-02-03 16:10:57 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
articles: state => state.article.list.data
|
|
|
|
}),
|
|
|
|
currentTopic() {
|
|
|
|
if (this.$route.params.topic_uri === 'news') {
|
2020-08-01 00:39:29 +08:00
|
|
|
return true;
|
|
|
|
}
|
2021-02-03 16:10:57 +08:00
|
|
|
return this.$store.state.topic.data.find(
|
|
|
|
topic => topic.topicUri === this.$route.params.topic_uri
|
2020-07-31 17:40:17 +08:00
|
|
|
)
|
|
|
|
},
|
2021-02-03 16:10:57 +08:00
|
|
|
defaultParams() {
|
|
|
|
return {
|
|
|
|
topic_uri: this.$route.params.topic_uri,
|
|
|
|
page: this.$route.query.page || 1
|
2020-07-31 17:40:17 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-03 16:10:57 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
currentChangeArticle(page) {
|
|
|
|
this.$router.push({
|
|
|
|
path: `/topic/${this.defaultParams.topic_uri}?page=${page}`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$store.commit('setActiveMenu', 'topic');
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
if (!this.currentTopic) {
|
|
|
|
this.$router.back()
|
|
|
|
}
|
2020-07-31 17:40:17 +08:00
|
|
|
}
|
2021-02-03 16:10:57 +08:00
|
|
|
}
|
2020-07-31 17:40:17 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|