Browse Source

添加来源过滤器

asd123a20 2 years ago
parent
commit
66f57037f9
3 changed files with 25 additions and 10 deletions
  1. 12 2
      src/store/index.js
  2. 3 5
      src/views/Home.vue
  3. 10 3
      src/views/details.vue

+ 12 - 2
src/store/index.js

@@ -10,7 +10,8 @@ const api = {
   linkTypeQuery: '/api/cms/imgtype/query',
   contentsFetch: '/api/cms/contents/fetch',
   pagesFetch: '/api/cms/pages/fetch',
-  imgNewsFetch: '/api/cms/imgnews/fetch'
+  imgNewsFetch: '/api/cms/imgnews/fetch',
+  sourceQuery: '/api/code/dictionary/query'
 };
 
 const state = () => ({
@@ -24,10 +25,16 @@ const state = () => ({
   listTotal: 0,
   contentsItem: null,
   pagesItem: null,
-  upwindow: []
+  upwindow: [],
+  dict: {}
 });
 
 const actions = {
+  async sourceQuery ({ commit }) {
+    const res = await $axios.get(api.sourceQuery, { parentCode: 'source' });
+    commit('sourceQuery', res);
+    return res;
+  },
   async menusQueryNoShow ({ commit }) {
     const res = await $axios.get(api.menusQuery);
     return res.data;
@@ -98,6 +105,9 @@ const actions = {
 };
 
 const mutations = {
+  sourceQuery(state, payload) {
+    state.dict.source = payload.data;
+  },
   menusQueryAll(state, payload) {
     state.menusall = payload.data;
   },

+ 3 - 5
src/views/Home.vue

@@ -98,10 +98,8 @@ export default {
     };
   },
   async mounted() {
-    // 社会组织建设
-    // await this.btnClick({ name: '031', type: 'corporation' });
-    // 社科普及
-    // await this.btnClick({ name: '041', type: 'prize', parentCode: true });
+    // 字典
+    await this.sourceQuery();
     // 科学评奖
     await this.btnClick({ name: '061', type: 'universal', limit: 6 });
     // 智库基金
@@ -118,7 +116,7 @@ export default {
     await this.menusQueryAll();
   },
   methods: {
-    ...mapActions(['contentsQuery', 'menusQueryAll']),
+    ...mapActions(['contentsQuery', 'menusQueryAll', 'sourceQuery']),
     async btnClick(e) {
       const filter = { bind: e?.name };
       if (e?.parentCode) filter.parentCode = e?.name;

+ 10 - 3
src/views/details.vue

@@ -6,7 +6,7 @@
       <h2 class="title">{{ contentsItem.title }}</h2>
       <h4 class="title" v-if="contentsItem && contentsItem.curtTitle">{{ contentsItem.curtTitle }}</h4>
       <!-- <span class="describe">{{ contentsItem.describe }}</span> -->
-      <span class="date">发表时间: {{ contentsItem.date | dates }}<span class="visit" v-if="contentsItem.source">来源: {{ contentsItem.source }}</span><span class="visit">访问量: {{ contentsItem.visit }}</span></span>
+      <span class="date">发表时间: {{ contentsItem.date | dates }}<span class="visit" v-if="contentsItem.source">来源: {{ contentsItem.source | source }}</span><span class="visit">访问量: {{ contentsItem.visit }}</span></span>
       <div class="content" v-html="contentsItem.content"></div>
       <div v-if="contentsItem && contentsItem.annex">
         <a v-for="(item, index) in contentsItem.annex" :key="index" :href="item.url" :download="item.url" target="view_window">下载附件:{{ item.name }}<br/></a>
@@ -20,13 +20,14 @@
 import moment from 'moment';
 import breadcrumb from '../components/breadcrumb/index.vue';
 import { mapState, mapActions } from 'vuex';
+let _this;
 export default {
   name: 'detailsHome',
   components: {
     breadcrumb
   },
   computed: {
-    ...mapState(['contentsItem']),
+    ...mapState(['contentsItem', 'dict']),
     isshow() {
       if (this.contentsItem.bind.includes('012')) return true;
       return false;
@@ -38,6 +39,7 @@ export default {
     };
   },
   async mounted() {
+    _this = this;
     this.id = this.$route.params.id;
     const type = this.$route.query.type;
     if (type) {
@@ -46,13 +48,18 @@ export default {
     }
     await this.contentsFetch({ id: this.id });
     this.$refs.detailsHome.scrollIntoView(true);
+    await this.sourceQuery();
   },
   methods: {
-    ...mapActions(['contentsFetch', 'imgNewsFetch'])
+    ...mapActions(['contentsFetch', 'imgNewsFetch', 'sourceQuery'])
   },
   filters: {
     dates(e) {
       return moment(e).format('YYYY-MM-DD');
+    },
+    source(code) {
+      const name = _this.dict.source.find(e => e.code == code).name;
+      return name;
     }
   }
 };