guhongwei 4 years ago
parent
commit
662903538d
3 changed files with 34 additions and 4 deletions
  1. 5 3
      src/store/topic.js
  2. 28 1
      src/views/community/detail.vue
  3. 1 0
      src/views/community/parts/list.vue

+ 5 - 3
src/store/topic.js

@@ -17,12 +17,14 @@ const actions = {
     const res = await this.$axios.$post(`${api.topic}`, payload);
     return res;
   },
-  async fetch({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.topic}/${payload}`);
+  async fetch({ commit, rootState }, payload) {
+    const res = await this.$axios.$get(`${api.topic}/${payload}`, {
+      openid: rootState.user.openid,
+    });
     return res;
   },
   async update({ commit }, { id, ...info } = {}) {
-    const res = await this.$axios.$post(`${api.topic}/update/${id}`, {
+    const res = await this.$axios.$post(`${api.refute}/update/${id}`, {
       ...info,
     });
     return res;

+ 28 - 1
src/views/community/detail.vue

@@ -20,7 +20,7 @@
         <el-col :span="24" class="foot">
           <el-col :span="8" class="button"><i class="el-icon-position"></i>分享</el-col>
           <el-col :span="8" class="button"><i class="el-icon-chat-line-round"></i>评论</el-col>
-          <el-col :span="8" class="button"><i class="el-icon-thumb"></i>点赞</el-col>
+          <el-col :span="8" class="button zan" @click.native="zanBtn"><img :src="detailInfo.thumbs ? zan2 : zan" /><span>点赞</span></el-col>
         </el-col>
       </el-col>
     </el-row>
@@ -33,6 +33,7 @@ import comment from './parts/comment.vue';
 import top from '@/layout/common/top.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions: mapTopic } = createNamespacedHelpers('topic');
+const { mapActions: mapThumbs } = createNamespacedHelpers('thumbs');
 export default {
   name: 'detail',
   props: {},
@@ -69,6 +70,9 @@ export default {
           renew_time: '2021-02-01 10:00:00',
         },
       ],
+      // 点赞
+      zan: require('@a/zan.png'),
+      zan2: require('@a/zan2.png'),
     };
   },
   async created() {
@@ -80,6 +84,7 @@ export default {
   },
   methods: {
     ...mapTopic(['fetch']),
+    ...mapThumbs(['create']),
     async search() {
       if (this.id) {
         let res = await this.fetch(this.id);
@@ -92,6 +97,19 @@ export default {
     upBack() {
       this.$router.push({ path: '/community/index' });
     },
+    // 点赞
+    async zanBtn() {
+      let data = {
+        openid: this.user.openid,
+        type: '1',
+        article_id: this.detailInfo.id,
+      };
+      let res = await this.create(data);
+      if (this.$checkRes(res)) {
+        this.$toast({ type: 'success', message: this.detailInfo.thumbs ? '取消点赞' : '点赞成功' });
+        this.search();
+      }
+    },
   },
   computed: {
     ...mapState(['user']),
@@ -146,6 +164,15 @@ export default {
     .button:last-child {
       border-right: none;
     }
+    // 点赞
+    .zan {
+      img {
+        width: 15px;
+        height: 15px;
+        position: relative;
+        top: 2px;
+      }
+    }
   }
 }
 </style>

+ 1 - 0
src/views/community/parts/list.vue

@@ -87,6 +87,7 @@ export default {
   .content {
     font-size: 15px;
     margin: 0 0 5px 0;
+    word-wrap: break-word;
   }
   .other {
     color: #666;