Browse Source

关注用户功能及worksList组件

bayi 2 years ago
parent
commit
ed661f5f4e

+ 2 - 2
api/user.js

@@ -5,8 +5,6 @@ import {
 module.exports = {
     // 用户登录
     userLogin: data => request('/user/openId', 'get', data),
-    // 获取用户session_key和open_id
-    getUserSO: data => request('/user/openId', 'get', data),
     //获取用户信息
     getUserInfo: data => request('/v3/user/my', 'get', data),
     // 设置用户信息
@@ -19,6 +17,8 @@ module.exports = {
     getUserRead: data => request('/userRead', 'get', data),
     // 获取用户关注列表
     getFansList: data => request('/fans', 'get', data),
+    // 加关注
+    setFans: data => request('/fans', 'post', data),
     // 获取收藏列表
     getFavoritesList: data => request('/favorites', 'get', data),
 }

+ 0 - 1
components/navigationBar/index.less

@@ -7,7 +7,6 @@
     background: #00C657;
 
     .view {
-        padding: 0px 31rpx;
         width: 100%;
         color: #fff;
         position: absolute;

+ 0 - 1
components/navigationBar/index.wxss

@@ -7,7 +7,6 @@
   background: #00C657;
 }
 .nav-bar .view {
-  padding: 0px 31rpx;
   width: 100%;
   color: #fff;
   position: absolute;

+ 30 - 4
components/videoPreview/index.js

@@ -1,8 +1,11 @@
 import {
     setVideoStatus,
     likeVideo,
-    collectVideo
+    collectVideo,
 } from '~/api/video'
+import {
+    setFans
+} from '~/api/user'
 Component({
     /**
      * 组件的属性列表
@@ -10,7 +13,17 @@ Component({
     properties: {
         videoInfo: {
             type: Object,
-            value: {}
+            value: {},
+            observer(newVal) {
+                this.setData({
+                    videoInfoCopy: newVal
+                })
+            }
+        },
+        videoType: {
+            type: String,
+            // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开
+            value: 'public'
         },
         index: {
             type: Number,
@@ -20,7 +33,8 @@ Component({
         }
     },
     data: {
-
+        selfUid: wx.getStorageSync('uid'),
+        videoInfoCopy: {}
     },
     methods: {
         // 播放视频
@@ -133,7 +147,7 @@ Component({
                 content: '作品将被永久删除,无法找回。',
                 confirmText: '确认',
                 cancelText: '取消',
-                success: async(res) => {
+                success: async (res) => {
                     if (res.confirm) {
                         let data = {
                             id,
@@ -170,5 +184,17 @@ Component({
             }
             this.triggerEvent('changStatus', options)
         },
+        // 关注
+        async setFans() {
+            if (this.properties.videoInfo.isFans) {
+                return
+            }
+            await setFans({
+                uid: this.properties.videoInfo.user.uid
+            })
+            this.setData({
+                ['videoInfoCopy.isFans']: true
+            })
+        }
     }
 })

+ 26 - 1
components/videoPreview/index.less

@@ -1,6 +1,8 @@
 .work {
-    margin-bottom: 20rpx;
+    margin-bottom: 24rpx;
     background-color: white;
+    border-radius: 32rpx;
+    box-shadow: rgba(99, 99, 99, 0.1) 0px 2px 8px 0px;
 
     .workHead {
         display: flex;
@@ -56,6 +58,29 @@
                     color: rgba(0, 0, 0, 0.74);
                 }
             }
+
+            .follow {
+                display: flex;
+                align-items: center;
+                justify-content: center;
+                width: 140rpx;
+                font-size: 24rpx;
+                padding: 6rpx 0rpx;
+                border-radius: 50rpx;
+                border: 1rpx solid #1BC665;
+                color: #1BC665;
+
+                .character {
+                    width: 22rpx;
+                    height: 22rpx;
+                    margin-right: 6rpx;
+                }
+            }
+
+            .isFans {
+                border: 1rpx solid #969696;
+                color: #969696;
+            }
         }
     }
 

+ 28 - 21
components/videoPreview/index.wxml

@@ -2,13 +2,13 @@
 <view class="work">
     <view class="workHead">
         <view class="wH-left">
-            <image src="{{videoInfo.user.avatar}}" class="avatar" mode="" />
+            <image src="{{videoInfoCopy.user.avatar}}" class="avatar" mode="" />
             <view class="wH-left-user">
-                <view class="nickname textOver">{{videoInfo.user.nickName}}</view>
-                <view class="time">发布时间:{{videoInfo.userRead.day}}</view>
+                <view class="nickname textOver">{{videoInfoCopy.user.nickName}}</view>
+                <view class="time">{{videoInfoCopy.userRead.day}}</view>
             </view>
         </view>
-        <view class="wH-right" wx:if="{{videoInfo.userRead.status!='CHECK'}}">
+        <view class="wH-right" wx:if="{{videoType=='my'}}">
             <view class="wH-right-btn" bindtap="download">
                 <image class="img" src="/static/down.png" mode="" />
                 <view class="text">下载</view>
@@ -19,53 +19,60 @@
             </view>
             <view class="wH-right-btn" bindtap="setVideoPublic">
                 <image class="img" style="width:30rpx"
-                    src="{{videoInfo.userRead.status==='NORMAL'? '/static/unlock.png': '/static/lock.png'}}" />
+                    src="{{videoInfoCopy.userRead.status==='NORMAL'? '/static/unlock.png': '/static/lock.png'}}" />
                 <view class="text">
-                    {{videoInfo.userRead.status==='NORMAL'? '公开': '私密'}}
+                    {{videoInfoCopy.userRead.status==='NORMAL'? '公开': '私密'}}
                 </view>
             </view>
         </view>
+        <view class="wH-right" wx:elif="{{videoType=='public'&&selfUid!=videoInfoCopy.user.uid}}">
+            <view class="follow {{videoInfoCopy.isFans?'isFans':''}}" bindtap="setFans">
+                <image src="{{videoInfoCopy.isFans?'/static/follow_2.png':'/static/follow_1.png'}}" class="character"
+                    mode="" />
+                <text class="text">{{videoInfoCopy.isFans?'已关注':'关注'}}</text>
+            </view>
+        </view>
     </view>
     <view class="workContent">
         <!-- 审核中遮罩 -->
-        <view class="videoBox" wx:if="{{videoInfo.userRead.status=='CHECK'&&videoInfo.userRead.id!=currentId}}">
+        <view class="videoBox" wx:if="{{videoInfoCopy.userRead.status=='CHECK'&&videoInfoCopy.userRead.id!=currentId}}">
             <view class="maskBg"></view>
             <image class="maskImg" src="/static/checking.png" />
-            <image class="cover" src="{{videoInfo.userRead.coverImg}}" />
+            <image class="cover" src="{{videoInfoCopy.userRead.coverImg}}" />
         </view>
         <!--未播放-->
-        <view class="videoBox" wx:if="{{videoInfo.userRead.status!='CHECK'&&videoInfo.userRead.id!=currentId}}"
+        <view class="videoBox" wx:if="{{videoInfoCopy.userRead.status!='CHECK'&&videoInfoCopy.userRead.id!=currentId}}"
             bindtap="playVideo">
             <image class="play" src="/static/play-btn.png" />
-            <image class="cover" src="{{videoInfo.userRead.coverImg}}" />
+            <image class="cover" src="{{videoInfoCopy.userRead.coverImg}}" />
         </view>
         <!-- 播放时渲染的video -->
-        <video class="video" id="myVideo" wx:if="{{videoInfo.userRead.id==currentId}}"
-            src="{{videoInfo.userRead.videoPath}}" autoplay="true" object-fit="contain">
+        <video class="video" id="myVideo" wx:if="{{videoInfoCopy.userRead.id==currentId}}"
+            src="{{videoInfoCopy.userRead.videoPath}}" autoplay="true" object-fit="contain">
         </video>
     </view>
     <view class="workFooter">
-        <view class="mange" wx:if="{{videoInfo.userRead.status!='CHECK'}}">
+        <view class="mange" wx:if="{{videoInfoCopy.userRead.status!='CHECK'}}">
             <view class="mangeL" bindtap="collect">
-                <view class="mangeL-box">
-                    <image src="{{videoInfo.isFavorites ? '/static/star_colored.png' : '/static/star.png'}}" mode=""
-                        class="icon" />
-                    <view class="icon-name">{{item.isFavorites}}</view>
-                </view>
                 <button class="resetBtn mangeL-box" open-type="share" data-info='{{videoInfo}}'>
                     <image src="/static/share.png" mode="" class="icon" />
                     <view class="icon-name">分享</view>
                 </button>
+                <view class="mangeL-box">
+                    <image src="{{videoInfoCopy.isFavorites ? '/static/star_colored.png' : '/static/star.png'}}" mode=""
+                        class="icon" />
+                    <view class="icon-name">{{item.isFavorites}}</view>
+                </view>
             </view>
             <view class="mangeL">
                 <view class="mangeL-box" bindtap="likeVideo">
-                    <image src="{{videoInfo.isLike ? '/static/heart_colored.png' : '/static/heart.png'}}" mode=""
+                    <image src="{{videoInfoCopy.isLike ? '/static/heart_colored.png' : '/static/heart.png'}}" mode=""
                         class="icon" />
-                    <view class="icon-name">{{filters.numFilter(videoInfo.userRead.likeAmount)}}</view>
+                    <view class="icon-name">{{filters.numFilter(videoInfoCopy.userRead.likeAmount)}}</view>
                 </view>
                 <view class="mangeL-box" bindtap="openComment">
                     <image src="/static/comment.png" mode="" class="icon" />
-                    <view class="icon-name">{{filters.numFilter(videoInfo.userRead.commentAmount)}}</view>
+                    <view class="icon-name">{{filters.numFilter(videoInfoCopy.userRead.commentAmount)}}</view>
                 </view>
             </view>
         </view>

+ 23 - 1
components/videoPreview/index.wxss

@@ -1,6 +1,8 @@
 .work {
-  margin-bottom: 20rpx;
+  margin-bottom: 24rpx;
   background-color: white;
+  border-radius: 32rpx;
+  box-shadow: rgba(99, 99, 99, 0.1) 0px 2px 8px 0px;
 }
 .work .workHead {
   display: flex;
@@ -49,6 +51,26 @@
   font-size: 26rpx;
   color: rgba(0, 0, 0, 0.74);
 }
+.work .workHead .wH-right .follow {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  width: 140rpx;
+  font-size: 24rpx;
+  padding: 6rpx 0rpx;
+  border-radius: 50rpx;
+  border: 1rpx solid #1BC665;
+  color: #1BC665;
+}
+.work .workHead .wH-right .follow .character {
+  width: 22rpx;
+  height: 22rpx;
+  margin-right: 6rpx;
+}
+.work .workHead .wH-right .isFans {
+  border: 1rpx solid #969696;
+  color: #969696;
+}
 .work .workContent {
   font-size: 0px;
 }

+ 1 - 1
components/worksList/index.js

@@ -11,7 +11,7 @@ Component({
      
     },
     methods: {
-
+   
     },
 
 })

+ 2 - 1
components/worksList/index.json

@@ -1,6 +1,7 @@
 {
     "component": true,
     "usingComponents": {
-        "videoPreview": "/components/videoPreview/index"
+        "videoPreview": "/components/videoPreview/index",
+        "Comment": "/components/comment/index"
     }
 }

+ 1 - 1
components/worksList/index.wxml

@@ -2,6 +2,6 @@
     <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>
-    <!-- <Comment id="comment" /> -->
+    <Comment id="comment" />
     <canvas id='share' type="2d"> </canvas>
 </view>

+ 1 - 0
custom-tab-bar/index.less

@@ -17,6 +17,7 @@
         justify-content: center;
         align-items: center;
         flex-direction: column;
+        padding-bottom: 10rpx;
 
         image {
             width: 48rpx;

+ 1 - 0
custom-tab-bar/index.wxss

@@ -17,6 +17,7 @@
   justify-content: center;
   align-items: center;
   flex-direction: column;
+  padding-bottom: 10rpx;
 }
 .tab-bar .tab-bar-item image {
   width: 48rpx;

+ 1 - 1
mixins/video.js

@@ -18,7 +18,7 @@ module.exports = Behavior({
         openComment({
             target
         }) {
-            this.selectComponent("#comment").open(target.dataset.id)
+            this.selectComponent('#comment').open(target.dataset.id)
         },
     }
 })

+ 2 - 2
pages/index/index.less

@@ -37,11 +37,11 @@
         .firstBox {
             text-align: center;
             display: inline-block;
-            width: 100rpx;
+            width: 98rpx;
             padding: 0rpx 20rpx;
 
             .icon {
-                width: 58rpx;
+                width: 60rpx;
                 height: 58rpx;
             }
 

+ 2 - 2
pages/index/index.wxss

@@ -31,11 +31,11 @@
 .recommend .firstClassify .firstBox {
   text-align: center;
   display: inline-block;
-  width: 100rpx;
+  width: 98rpx;
   padding: 0rpx 20rpx;
 }
 .recommend .firstClassify .firstBox .icon {
-  width: 58rpx;
+  width: 60rpx;
   height: 58rpx;
 }
 .recommend .firstClassify .firstBox .name {

+ 150 - 150
pages/userWorks/index.js

@@ -1,162 +1,162 @@
 import {
-  getSelfRead
+    getSelfRead
 } from '~/api/user'
 let videoContext = null
 Page({
 
-  /**
-   * 页面的初始数据
-   */
-  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()
-    this.setData({
-      list
-    })
-  },
-  creatShare(video) {
-    return new Promise((resolve, reject) => {
-      let context = wx.createSelectorQuery();
-      context
-        .select('#share')
-        .fields({
-          node: true,
-          size: true
-        }).exec((res) => {
-          const canvas = res[0].node;
-          const ctx = canvas.getContext('2d');
-          const dpr = wx.getSystemInfoSync().pixelRatio;
-          canvas.width = res[0].width * dpr;
-          canvas.height = res[0].height * dpr;
-          ctx.scale(dpr, dpr);
-          ctx.font = '14px PingFang';
-          let pic = canvas.createImage();
-          pic.src = video.userRead.coverImg; //可以是本地,也可以是网络图片
-          pic.onload = () => {
-            ctx.drawImage(pic, 0, 0, 375, 211);
-          }
-          let peiyin = canvas.createImage();
-          peiyin.src = '/static/peiyin.jpg';
-          peiyin.onload = () => {
-            ctx.drawImage(peiyin, 0, 211, 375, 89);
-            // 收藏,一个一个渲染
-            let sc = canvas.createImage();
-            sc.src = '/static/star.png'
-            sc.onload = () => {
-              ctx.drawImage(sc, 12, 220, 20, 20)
-              ctx.fillText('收藏', 36, 238)
-              //分享
-              let fx = canvas.createImage();
-              fx.src = '/static/share.png'
-              fx.onload = () => {
-                ctx.drawImage(fx, 78, 220, 22, 22)
-                ctx.fillText('分享', 104, 238)
-                //点赞
-                let dz = canvas.createImage();
-                dz.src = video.isLike ? '/static/heart_colored.png' : '/static/heart.png'
-                dz.onload = () => {
-                  ctx.drawImage(dz, 258, 222, 22, 22)
-                  ctx.fillText(video.userRead.likeAmount, 284, 238)
-                  //评论
-                  let pl = canvas.createImage();
-                  pl.src = '/static/comment.png'
-                  pl.onload = () => {
-                    ctx.drawImage(pl, 318, 222, 22, 22)
-                    ctx.fillText(video.userRead.commentAmount, 340, 238)
-                    setTimeout(() => {
-                      wx.canvasToTempFilePath({
-                        canvas: canvas,
-                        success(res) {
-                          resolve({
-                            title: '请欣赏我的课文朗读作品,点赞+评论。',
-                            path: `/pages/index/index?readId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}`,
-                            imageUrl: res.tempFilePath
-                          })
-                        },
-                        fail(res) {
-                          reject()
+    /**
+     * 页面的初始数据
+     */
+    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()
+        this.setData({
+            list
+        })
+    },
+    creatShare(video) {
+        return new Promise((resolve, reject) => {
+            let context = wx.createSelectorQuery();
+            context
+                .select('#share')
+                .fields({
+                    node: true,
+                    size: true
+                }).exec((res) => {
+                    const canvas = res[0].node;
+                    const ctx = canvas.getContext('2d');
+                    const dpr = wx.getSystemInfoSync().pixelRatio;
+                    canvas.width = res[0].width * dpr;
+                    canvas.height = res[0].height * dpr;
+                    ctx.scale(dpr, dpr);
+                    ctx.font = '14px PingFang';
+                    let pic = canvas.createImage();
+                    pic.src = video.userRead.coverImg; //可以是本地,也可以是网络图片
+                    pic.onload = () => {
+                        ctx.drawImage(pic, 0, 0, 375, 211);
+                    }
+                    let peiyin = canvas.createImage();
+                    peiyin.src = '/static/peiyin.jpg';
+                    peiyin.onload = () => {
+                        ctx.drawImage(peiyin, 0, 211, 375, 89);
+                        // 收藏,一个一个渲染
+                        let sc = canvas.createImage();
+                        sc.src = '/static/star.png'
+                        sc.onload = () => {
+                            ctx.drawImage(sc, 12, 220, 20, 20)
+                            ctx.fillText('收藏', 36, 238)
+                            //分享
+                            let fx = canvas.createImage();
+                            fx.src = '/static/share.png'
+                            fx.onload = () => {
+                                ctx.drawImage(fx, 78, 220, 22, 22)
+                                ctx.fillText('分享', 104, 238)
+                                //点赞
+                                let dz = canvas.createImage();
+                                dz.src = video.isLike ? '/static/heart_colored.png' : '/static/heart.png'
+                                dz.onload = () => {
+                                    ctx.drawImage(dz, 258, 222, 22, 22)
+                                    ctx.fillText(video.userRead.likeAmount, 284, 238)
+                                    //评论
+                                    let pl = canvas.createImage();
+                                    pl.src = '/static/comment.png'
+                                    pl.onload = () => {
+                                        ctx.drawImage(pl, 318, 222, 22, 22)
+                                        ctx.fillText(video.userRead.commentAmount, 340, 238)
+                                        setTimeout(() => {
+                                            wx.canvasToTempFilePath({
+                                                canvas: canvas,
+                                                success(res) {
+                                                    resolve({
+                                                        title: '请欣赏我的课文朗读作品,点赞+评论。',
+                                                        path: `/pages/index/index?readId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}`,
+                                                        imageUrl: res.tempFilePath
+                                                    })
+                                                },
+                                                fail(res) {
+                                                    reject()
+                                                }
+                                            }, this)
+                                        }, 500)
+                                    }
+                                }
+                            }
                         }
-                      }, this)
-                    }, 500)
-                  }
-                }
-              }
-            }
-          }
+                    }
 
+                })
         })
-    })
-
-  },
-  // 改变视频状态
-  changStatus({
-    detail
-  }) {
-    this.setData(detail)
-  },
-  // 开始播放
-  playVideo({
-    currentTarget
-  }) {
-    this.setData({
-      videoState: true,
-      currentId: currentTarget.dataset.id
-    })
-  },
-  /* 改变视频播放状态 ,暂时先不用*/
-  changeVideoState() {
-    this.videoContext = wx.createVideoContext('myVideo')
-    let videoState = this.data.videoState
-    if (videoState) {
-      this.videoContext.pause()
-    } else {
-      this.videoContext.play()
-    }
-    this.setData({
-      videoState: !videoState
-    })
-  },
 
-  onShareAppMessage({
-    from,
-    target
-  }) {
-    if (from == 'button') {
-      let video = target.dataset.info
-      const promise = new Promise(resolve => {
-        this.creatShare(video).then(res => {
-          resolve(res)
+    },
+    // 改变视频状态
+    changStatus({
+        detail
+    }) {
+        this.setData(detail)
+    },
+    // 开始播放
+    playVideo({
+        currentTarget
+    }) {
+        this.setData({
+            videoState: true,
+            currentId: currentTarget.dataset.id
         })
-      })
-      console.log(video);
-      return {
-        title: '请欣赏我的课文朗读作品,点赞+评论。',
-        path: `/pages/index/index?readId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}`,
-        imageUrl: video.userRead.coverImg,
-        promise
-      }
-    } else {
-      return {
-        title: '课文朗读,从未如此有趣。',
-        path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
-        imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
-      }
+    },
+    /* 改变视频播放状态 ,暂时先不用*/
+    changeVideoState() {
+        this.videoContext = wx.createVideoContext('myVideo')
+        let videoState = this.data.videoState
+        if (videoState) {
+            this.videoContext.pause()
+        } else {
+            this.videoContext.play()
+        }
+        this.setData({
+            videoState: !videoState
+        })
+    },
+
+    onShareAppMessage({
+        from,
+        target
+    }) {
+        if (from == 'button') {
+            let video = target.dataset.info
+            const promise = new Promise(resolve => {
+                this.creatShare(video).then(res => {
+                    resolve(res)
+                })
+            })
+            console.log(video);
+            return {
+                title: '请欣赏我的课文朗读作品,点赞+评论。',
+                path: `/pages/index/index?readId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}`,
+                imageUrl: video.userRead.coverImg,
+                promise
+            }
+        } else {
+            return {
+                title: '课文朗读,从未如此有趣。',
+                path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
+                imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
+            }
+        }
     }
-  }
 })

BIN
static/follow_1.png


BIN
static/follow_2.png


BIN
static/lz.png