Browse Source

优化视频组件

bayi 2 years ago
parent
commit
92efeb2e27
4 changed files with 19 additions and 38 deletions
  1. 1 1
      app.json
  2. 6 0
      mixins/video.js
  3. 2 27
      pages/userWorks/index.js
  4. 10 10
      pages/userWorks/index.wxml

+ 1 - 1
app.json

@@ -1,12 +1,12 @@
 {
     "pages": [
+        "pages/userWorks/index",
         "pages/index/index",
         "pages/my/index",
         "pages/editUser/index",
         "pages/notice/index",
         "pages/collection/index",
         "pages/follow/index",
-        "pages/userWorks/index",
         "pages/logs/logs"
     ],
     "tabBar": {

+ 6 - 0
mixins/video.js

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

+ 2 - 27
pages/userWorks/index.js

@@ -1,28 +1,18 @@
 import {
     getSelfRead
 } from '~/api/user'
+import behavior from '~/mixins/video'
 let videoContext = null
 Page({
-
-    /**
-     * 页面的初始数据
-     */
+    behaviors: [behavior],
     data: {
         list: null,
-        currentId: '',
-        videoState: true,
         canvasHidden: false, //设置画板的显示与隐藏
         shareImgPath: '' //用于储存canvas生成的图片
     },
     onLoad(options) {
         this.getSelfRead()
     },
-    // 打开评论
-    openComment({
-        target
-    }) {
-        this.selectComponent("#comment").open(target.dataset.id)
-    },
     //获取自己作品列表
     async getSelfRead() {
         let list = await getSelfRead()
@@ -104,21 +94,6 @@ Page({
         })
 
     },
-    // 改变视频状态
-    changStatus({
-        detail
-    }) {
-        this.setData(detail)
-    },
-    // 开始播放
-    playVideo({
-        currentTarget
-    }) {
-        this.setData({
-            videoState: true,
-            currentId: currentTarget.dataset.id
-        })
-    },
     /* 改变视频播放状态 ,暂时先不用*/
     changeVideoState() {
         this.videoContext = wx.createVideoContext('myVideo')

+ 10 - 10
pages/userWorks/index.wxml

@@ -1,12 +1,12 @@
 <view class="worksBox">
-  <!-- 作品列表 -->
-  <canvas id='share' type="2d"> </canvas>
-  <block wx:if="{{list.length>0}}">
-    <videoPreview wx:for="{{list}}" 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>
-  </block>
-  <emptyBg wx:if="{{list.length==0}}" message='您还没有作品哦,赶快去发表吧!'></emptyBg>
-  <Comment id="comment" />
+    <!-- 作品列表 -->
+    <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>
+    </block>
+    <emptyBg wx:if="{{list.length==0}}" message='您还没有作品哦,赶快去发表吧!'></emptyBg>
+    <Comment id="comment" />
 </view>