Jelajahi Sumber

feat: 收藏交流

icenaked 3 tahun lalu
induk
melakukan
b792e68ca7

+ 1 - 4
src/api/communication.js

@@ -4,18 +4,15 @@ const prefix = "/communication";
 
 function getAllCommunications(payload) {
     const {page, size, sort} = payload;
-    // return axios.get("https://www.fastmock.site/mock/7626b3aeb545b939cbf526e8fcfda744/api/communications", {params: {userId, page, size, sort}});
      return axios.get(`${prefix}`, {params: {page, size, sort}});
 
 }
 
 function getCommunicationStarers(communicationId) {
-    // return axios.get(`https://www.fastmock.site/mock/7626b3aeb545b939cbf526e8fcfda744/api/communications/${communicationId}/stars/users`);
     return axios.get(`${prefix}/${communicationId}/stars/users`);
 }
 
 function getCommunicationDetail(communicationId) {
-    // return axios.get(`https://www.fastmock.site/mock/7626b3aeb545b939cbf526e8fcfda744/api/communications/${communicationId}`);
     return axios.get(`${prefix}/${communicationId}`);
 
 }
@@ -25,7 +22,7 @@ function getUserPublishCommunication(userId,page,size){
 }
 
 function starCommunication(userId,communicationId){
-    return axios.post(`${prefix}/${communicationId}/stars`,{params:{userId}});
+    return axios.post(`${prefix}/${communicationId}/stars?userId=${userId}`);
 }
 
 function cancelStarCommunication(userId,communicationId){

+ 5 - 3
src/views/CommunicationPage/CommunicationDetail.vue

@@ -21,8 +21,8 @@
                   <p style="max-width:500px;">{{starersListString}}收藏了本交流</p>
                 </template>
                 <div>
-                  <el-icon v-if="communicationInfo.starred===true" style="font-size: 20px" @click="star()"><Star /></el-icon>
-                  <el-icon v-if="communicationInfo.starred===false" style="font-size: 20px;color: orange" @click="cancelStar()">
+                  <el-icon v-if="communicationInfo.starred===false" style="font-size: 20px" @click="star()"><Star /></el-icon>
+                  <el-icon v-if="communicationInfo.starred===true" style="font-size: 20px;color: orange" @click="cancelStar()">
                     <StarFilled />
                   </el-icon>
                 </div>
@@ -101,7 +101,7 @@ export default {
             this.starersList = starRes.data.data;
             this.starersListString = "";
             this.starersList.forEach(starer=>{
-              this.starersListString = this.starersListString + starer.userName + ",";
+              this.starersListString = this.starersListString + starer.username + ",";
             });
             if (this.starersListString === ""){
               this.starersListString = "暂无用户";
@@ -111,10 +111,12 @@ export default {
     },
     star(){
       this.communicationInfo.starred = !this.communicationInfo.starred;
+      this.$apis.starCommunication(this.$store.state.user.id, this.communicationInfo.id);
       ElMessage.success("收藏成功");
     },
     cancelStar(){
       this.communicationInfo.starred = !this.communicationInfo.starred;
+      this.$apis.cancelStarCommunication(this.$store.state.user.id, this.communicationInfo.id);
       ElMessage.success("取消收藏成功");
     },
     downloadAttachment(){

+ 3 - 2
src/views/CommunicationPage/components/ExploreItem.vue

@@ -87,10 +87,12 @@ export default {
   methods: {
     star(){
       this.$emit("starChange",this.communicationVO);
+      this.$apis.starCommunication(this.$store.state.user.id, this.communicationVO.id);
       ElMessage.success("收藏成功");
     },
     cancelStar(){
       this.$emit("starChange",this.communicationVO);
+      this.$apis.cancelStarCommunication(this.$store.state.user.id, this.communicationVO.id);
       ElMessage.success("取消收藏成功");
     },
     fetchData(){
@@ -99,7 +101,7 @@ export default {
           this.starersList = res.data.data;
           this.starersListString = "";
           this.starersList.forEach(starer=>{
-            this.starersListString = this.starersListString + starer.userName + ",";
+            this.starersListString = this.starersListString + starer.username + ",";
           });
           if (this.starersListString === ""){
             this.starersListString = "暂无用户";
@@ -110,7 +112,6 @@ export default {
   },
   mounted() {
     this.fetchData();
-    console.log(this.communicationVO.starred);
   }
 };
 </script>