فهرست منبع

添加评论提交接口

reghao 3 سال پیش
والد
کامیت
e4fe2929ac
3فایلهای تغییر یافته به همراه49 افزوده شده و 6 حذف شده
  1. 6 0
      src/api/comment/comment.js
  2. 42 5
      src/components/card/comment-card.vue
  3. 1 1
      src/components/comment/index.vue

+ 6 - 0
src/api/comment/comment.js

@@ -1,10 +1,16 @@
 import $axios from '../index'
 import $axios from '../index'
 
 
 const commentApi = {
 const commentApi = {
+  commentSubmitApi: '/api/comment/video',
   videoCommentApi: '/api/comment/video',
   videoCommentApi: '/api/comment/video',
   childCommentApi: '/api/comment/child'
   childCommentApi: '/api/comment/child'
 }
 }
 
 
+// 发布评论
+export function submitComment(data) {
+  return $axios.post(commentApi.commentSubmitApi, data)
+}
+
 // 视频评论
 // 视频评论
 export function videoComment(videoId, page) {
 export function videoComment(videoId, page) {
   return $axios.get(commentApi.videoCommentApi + '?videoId=' + videoId + '&page=' + page)
   return $axios.get(commentApi.videoCommentApi + '?videoId=' + videoId + '&page=' + page)

+ 42 - 5
src/components/card/comment-card.vue

@@ -25,12 +25,29 @@
         />
         />
       </div>
       </div>
     </v-row>
     </v-row>
+    <v-snackbar
+      v-model="showMessage"
+      :top="true"
+      :timeout="1000"
+    >
+      {{ message }}
+      <template v-slot:action="{ attrs }">
+        <v-btn
+          color="pink"
+          text
+          v-bind="attrs"
+          @click="showMessage = false"
+        >
+          关闭
+        </v-btn>
+      </template>
+    </v-snackbar>
   </div>
   </div>
 </template>
 </template>
 
 
 <script>
 <script>
 import Comment from '@/components/comment'
 import Comment from '@/components/comment'
-import { videoComment } from '@/api/comment/comment'
+import { submitComment, videoComment } from '@/api/comment/comment'
 
 
 export default {
 export default {
   name: 'CommentCard',
   name: 'CommentCard',
@@ -57,17 +74,20 @@ export default {
         liked: 'liked',
         liked: 'liked',
         reply: 'reply',
         reply: 'reply',
         createAt: 'createAt',
         createAt: 'createAt',
-        user: 'visitor'
+        user: 'user'
       },
       },
       currentUser: null,
       currentUser: null,
       busy: false,
       busy: false,
-      page: 1
+      page: 1,
+      showMessage: false,
+      message: ''
     }
     }
   },
   },
   created() {
   created() {
     const userInfo = this.$store.state.user.userInfo
     const userInfo = this.$store.state.user.userInfo
     if (userInfo !== null) {
     if (userInfo !== null) {
       this.currentUser = {
       this.currentUser = {
+        userId: userInfo.userId,
         name: userInfo.username,
         name: userInfo.username,
         avatar: userInfo.avatarUrl
         avatar: userInfo.avatarUrl
       }
       }
@@ -101,7 +121,6 @@ export default {
           for (const item of res.data.list) {
           for (const item of res.data.list) {
             this.videoComments.push(item)
             this.videoComments.push(item)
           }
           }
-          console.log('已获取的评论数量: ' + this.videoComments.length)
         } else {
         } else {
           console.error(res.msg)
           console.error(res.msg)
         }
         }
@@ -114,11 +133,29 @@ export default {
     async submit(newComment, parent, add) {
     async submit(newComment, parent, add) {
       const res = await new Promise((resolve) => {
       const res = await new Promise((resolve) => {
         setTimeout(() => {
         setTimeout(() => {
+          var parentId = null
+          if (parent !== null) {
+            parentId = parent.id
+          }
+
+          const commentSbtData = {}
+          commentSbtData.videoId = this.video.videoId
+          commentSbtData.userId = newComment.user.userId
+          commentSbtData.parentId = parentId
+          commentSbtData.content = newComment.content
+          commentSbtData.imgSrc = newComment.imgSrc
+          commentSbtData.createAt = newComment.createAt
+          submitComment(commentSbtData).then(res => {
+            if (res.code !== 0) {
+              this.message = '评论发送失败'
+              this.showMessage = true
+            }
+          })
+
           resolve({ newComment, parent })
           resolve({ newComment, parent })
         }, 300)
         }, 300)
       })
       })
       add(Object.assign(res.newComment, { _id: new Date().getTime() }))
       add(Object.assign(res.newComment, { _id: new Date().getTime() }))
-      console.log('addComment: ', res)
     },
     },
     async like(comment) {
     async like(comment) {
       const res = await new Promise((resolve) => {
       const res = await new Promise((resolve) => {

+ 1 - 1
src/components/comment/index.vue

@@ -180,6 +180,7 @@ export default {
     comparePropsAndValues(comment) {
     comparePropsAndValues(comment) {
       // 初始对象
       // 初始对象
       const originObj = {
       const originObj = {
+        videoId: '',
         id: '',
         id: '',
         content: '',
         content: '',
         imgSrc: '',
         imgSrc: '',
@@ -268,7 +269,6 @@ export default {
             delete _comment[key]
             delete _comment[key]
           }
           }
         }
         }
-
         return _comment
         return _comment
       } catch (e) {
       } catch (e) {
         console.error(e)
         console.error(e)