Browse Source

优化视频组件

bayi 2 years ago
parent
commit
1fe68773d5

+ 1 - 1
app.json

@@ -1,7 +1,7 @@
 {
     "pages": [
-        "pages/userWorks/index",
         "pages/index/index",
+        "pages/userWorks/index",
         "pages/my/index",
         "pages/editUser/index",
         "pages/notice/index",

+ 11 - 33
components/videoPreview/index.js

@@ -25,9 +25,6 @@ Component({
             // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开
             value: 'public'
         },
-        index: {
-            type: Number,
-        },
         currentId: {
             type: Number,
         }
@@ -41,11 +38,6 @@ Component({
         playVideo() {
             this.triggerEvent('playVideo', this.properties.videoInfo.userRead.id)
         },
-        // 分享视频
-        shareVideo() {
-            let videoInfo = this.properties.videoInfo
-            console.log(videoInfo);
-        },
         // 设置视频公开还是隐私
         async setVideoPublic() {
             let info = this.properties.videoInfo.userRead
@@ -61,13 +53,9 @@ Component({
                     duration: 2000
                 })
             }
-            let index = this.properties.index
-            let status = `list[${index}].userRead.status`;
-            let val = info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
-            let options = {
-                [status]: val
-            }
-            this.triggerEvent('changStatus', options)
+            this.setData({
+                ['videoInfoCopy.userRead.status']:info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
+            })
         },
         // 点赞
         async likeVideo() {
@@ -78,14 +66,10 @@ Component({
                 return
             }
             await likeVideo(id)
-            let index = this.properties.index
-            let likeStr = `list[${index}].isLike`;
-            let likeNumStr = `list[${index}].userRead.likeAmount`;
-            let options = {
-                [likeStr]: true,
-                [likeNumStr]: this.properties.videoInfo.userRead.likeAmount + 1
-            }
-            this.triggerEvent('changStatus', options)
+            this.setData({
+                ['videoInfoCopy.isLike']: true,
+                ['videoInfoCopy.userRead.likeAmount']: this.data.videoInfoCopy.userRead.likeAmount + 1
+            })
         },
         // 下载视频
         download() {
@@ -136,7 +120,6 @@ Component({
         openComment() {
             this.triggerEvent('openComment', this.properties.videoInfo.userRead.id)
         },
-
         // 删除
         delete() {
             let {
@@ -177,12 +160,9 @@ Component({
                 targetCode: id,
                 favoritesType: type
             })
-            let index = this.properties.index
-            let isFavorites = `list[${index}].isFavorites`;
-            let options = {
-                [isFavorites]: !this.properties.videoInfo.isFavorites
-            }
-            this.triggerEvent('changStatus', options)
+            this.setData({
+                ['videoInfoCopy.isFavorites']: !this.data.videoInfoCopy.isFavorites
+            })
         },
         // 关注
         async setFans() {
@@ -192,9 +172,7 @@ Component({
             await setFans({
                 uid: this.properties.videoInfo.user.uid
             })
-            this.setData({
-                ['videoInfoCopy.isFans']: true
-            })
+            this.triggerEvent('setListFans', this.properties.videoInfo.user.uid)
         }
     }
 })

+ 20 - 3
components/worksList/index.js

@@ -4,14 +4,31 @@ Component({
     properties: {
         worksList: {
             type: Array,
-            value: []
+            value: [],
+            observer(newVal) {
+                this.setData({
+                    worksListCopy: newVal
+                })
+            }
         }
     },
     data: {
-     
+        worksListCopy: {}
     },
     methods: {
-   
+        setListFans({
+            detail
+        }) {
+            let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
+            worksListCopy.forEach(item => {
+                if (item.user.uid == detail) {
+                    item.isFans = true
+                }
+            })
+            this.setData({
+                worksListCopy
+            })
+        }
     },
 
 })

+ 4 - 2
components/worksList/index.wxml

@@ -1,6 +1,8 @@
 <view class="worksList">
-    <videoPreview wx:for="{{worksList}}" wx:key="index" videoInfo="{{item}}" index='{{index}}' currentId="{{currentId}}"
-        data-id="{{item.userRead.id}}" bind:playVideo="playVideo" bind:openComment="openComment">
+    <videoPreview wx:for="{{worksListCopy}}" wx:key="index" videoInfo="{{item}}" index='{{index}}' currentId="{{currentId}}"
+        data-id="{{item.userRead.id}}" bind:playVideo="playVideo" 
+        bind:openComment="openComment"
+        bind:setListFans="setListFans">
     </videoPreview>
     <Comment id="comment" />
     <canvas id='share' type="2d"> </canvas>

+ 0 - 6
mixins/video.js

@@ -20,11 +20,5 @@ module.exports = Behavior({
         }) {
             this.selectComponent('#comment').open(target.dataset.id)
         },
-        // 改变视频状态
-        changStatus({
-            detail
-        }) {
-            this.setData(detail)
-        },
     }
 })

+ 0 - 1
pages/userWorks/index.js

@@ -107,7 +107,6 @@ Page({
             videoState: !videoState
         })
     },
-
     onShareAppMessage({
         from,
         target

+ 3 - 3
pages/userWorks/index.wxml

@@ -2,9 +2,9 @@
     <!-- 作品列表 -->
     <canvas id='share' type="2d"> </canvas>
     <block wx:if="{{list.length>0}}">
-        <videoPreview wx:for="{{list}}" videoType='my' wx:key="index" videoInfo="{{item}}" index='{{index}}'
-            currentId="{{currentId}}" data-id="{{item.userRead.id}}" bind:playVideo="playVideo"
-            bind:changStatus="changStatus" bind:getList="getSelfRead" bind:openComment="openComment">
+        <videoPreview wx:for="{{list}}" videoType='my' wx:key="index" videoInfo="{{item}}" currentId="{{currentId}}"
+            data-id="{{item.userRead.id}}" bind:playVideo="playVideo" bind:getList="getSelfRead"
+            bind:openComment="openComment">
         </videoPreview>
     </block>
     <emptyBg wx:if="{{list.length==0}}" message='您还没有作品哦,赶快去发表吧!'></emptyBg>