Browse Source

小程序:视频评价

panyong 2 years ago
parent
commit
b4d4746766

+ 31 - 0
htmldev/wxMini/pages/mediaDetail/api/index.js

@@ -0,0 +1,31 @@
+const { request } = require('../../../api/request')
+
+/**
+ * 视频点赞
+ * @param videoId 视频ID
+ * @returns {Promise<*>}
+ */
+export const postvideoGood = (videoId) => request({
+  url: '/api/user/video/good',
+  method: 'POST',
+  data: {
+    video_id: videoId
+  },
+  showLoading: true
+})
+
+/**
+ * 视频评论
+ * @param videoId 视频ID
+ * @param videoComment 评论内容
+ * @returns {Promise<*>}
+ */
+export const postVideoComment = (videoId, videoComment) => request({
+  url: '/api/user/video/comment/add',
+  method: 'POST',
+  data: {
+    'video_id': videoId,
+    'video_comment': videoComment
+  },
+  showLoading: true
+})

+ 90 - 1
htmldev/wxMini/pages/mediaDetail/mediaDetail.js

@@ -1,4 +1,5 @@
 const pages = require('../../mixin/pages')
+const { postvideoGood, postVideoComment } = require('./api/index')
 
 Page({
 
@@ -11,7 +12,11 @@ Page({
     searchForm: {
       'video_id': ''
     },
-    videoConfig: {}
+    videoConfig: {},
+    form: {
+      comment: ''
+    },
+    booLock: false
   },
   ...pages.methods,
   /**
@@ -80,5 +85,89 @@ Page({
   },
   bindCallBack() {
     this.refreshOrderList()
+  },
+  onShareAppMessage(options) {
+    const { video_name, video_cover_url } = this.data.videoConfig
+
+    return {
+      title: video_name,
+      path: 'pages/mediaDetail/mediaDetail?videoConfig=' + JSON.stringify(this.data.videoConfig),
+      imageUrl: video_cover_url
+    }
+  },
+  setComment(event) {
+    const { value } = event.detail
+
+    this.setData({
+      'form.comment': value.trim()
+    })
+  },
+  // 点赞
+  async addvideoGood() {
+    const { id } = this.data.videoConfig
+
+    this.setData({
+      booLock: true
+    })
+
+    try {
+      const { status, msg } = await postvideoGood(id)
+      if (status) {
+        wx.showToast({
+          title: '点赞成功',
+          icon: 'none'
+        })
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
+
+    this.setData({
+      booLock: false
+    })
+  },
+  // 评论
+  async addVideoComment() {
+    const { id } = this.data.videoConfig
+    const { comment } = this.data.form
+
+    if (!comment) {
+      wx.showToast({
+        title: '说点什么吧...',
+        icon: 'none'
+      })
+      return
+    }
+
+    this.setData({
+      booLock: true
+    })
+
+    try {
+      const { status, msg } = await postVideoComment(id, comment)
+      if (status) {
+        wx.showToast({
+          title: '评论成功',
+          icon: 'none'
+        })
+
+        this.setData({
+          'form.comment': ''
+        })
+        this.bindCallBack()
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
+
+    this.setData({
+      booLock: false
+    })
   }
 })

+ 12 - 4
htmldev/wxMini/pages/mediaDetail/mediaDetail.wxml

@@ -53,11 +53,19 @@
         src="../../image/common/smile.png"></image>
       <input
         placeholder-class="placeholder"
-        value=""
-        placeholder="说点什么吧..."></input>
-      <button class="btn-send">发送</button>
+        value="{{form.comment}}"
+        placeholder="说点什么吧..."
+        bind:input="setComment"></input>
+      <button
+        class="btn-send"
+        disabled="{{booLock}}"
+        bind:tap="addVideoComment">发送
+      </button>
     </view>
-    <button class="btn-like">
+    <button
+      class="btn-like"
+      disabled="{{booLock}}"
+      bind:tap="addvideoGood">
       <image src="../../image/common/like_1.png"></image>
     </button>
     <button