article-share.vue 1.65 KB
<template>
  <Article
    ref="article"
    type="article"
    share
    :on-fetch="onFetch">
  </Article>
</template>

<script>
import {get} from 'lodash';
import Article from './components/article/article';
import ArticleItem from './components/article/article-item';
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('article');

export default {
  name: 'ArticleSharePage',
  data() {
    return {
      page: 1,
      id: 0,
    };
  },
  created() {
    this.id = +this.$route.params.id;
  },
  activated() {
    if (+this.$route.params.id !== this.id) {
      this.id = +this.$route.params.id;
      this.init();
    }
  },
  methods: {
    ...mapActions(['fetchArticleList']),
    init() {
      this.page = 1;
      this.$refs.article.init();
    },
    async onFetch() {
      const articleId = parseInt(this.id, 10);

      if (!articleId) {
        return;
      }
      const result = await this.fetchArticleList({
        articleId,
        page: this.page,
        authorUid: this.authorUid,
        authorType: this.authorType,
        type: this.type
      });

      if (result.code === 200) {
        if (get(result, 'data.detailList', []).length) {
          this.page++;
          return Promise.resolve(result.data.detailList);
        }
        return Promise.resolve(false);
      } else {
        this.$createToast && this.$createToast({
          txt: result.message || '服务器开小差了',
          type: 'warn',
          time: 1000
        }).show();
      }
    }
  },
  components: {
    Article,
    ArticleItem
  }
};
</script>

<style lang="scss" scoped>
.article-page {
  background-color: #f0f0f0;
}
</style>