Преглед изворни кода

pk结果上传与播放次数统计

bayi пре 2 година
родитељ
комит
1ac12d8153

+ 25 - 24
api/global.js

@@ -1,28 +1,29 @@
 import {
-    request
+  request
 } from "../utils/request";
 module.exports = {
-    //获取充值配置信息
-    getProducts: data => request('/v3/product', 'get', data),
-    // 获取任务配置
-    getTasks: data => request('/v3/task', 'get', data),
-    // 提交任务
-    submitTask: data => request('/v3/task', 'post', data),
-    // 获取轮播图列表
-    getBannerList: data => request(`/v3/banner/${data}`, 'get', data),
-    // 获取官方活动
-    getActivities: data => request('/v3/activity', 'get', data),
-    // 获取排行榜详情
-    getRankingData: data => request(`/v3/activity/${data}`, 'get', data),
-    // 获取朗读赛范文
-    getModelTexts: data => request('/activityRead', 'get', data),
-    // 获取朗读赛排行榜
-    getReadRanking: data => request('/activityJoinUser/hotAmountTop', 'get', data),
-    // 获取朗读赛排行榜参赛作品
-    getSelfReadRanking: data => request('/activityJoinUser/activityRead', 'get', data),
-    // 获取消息通知列表
-    getMessageList: data => request('/message', 'get', data),
-    // 用户行为统计
-    // RECOMMEND(name: "推荐”) ,MY(name: ”我的 "),RESOURCES(name: "资源"), SUBSCRIBE(name: "关注"),REC_ READ(name: ”推荐 - 我要配音 "),READING(name: ”开始朗读 ") ,EXAMPLE(name: "示范"), RERECORDING(name: "重录"), UPLOAD(name: "上传作品"), MY_ INFO(name: “个人信息 ") ,INTEGRAL(name: "小红花"), MY_ SUBSCRIBE(name: "我的关注"), MY_ FAVORITES(name: ”我的收藏”),MESSAGE(name: ”消息通知”), SERVICE(name: "客服"),
-    userEvent: data => request('/userEvent/v2', 'post', data),
+  //获取充值配置信息
+  getProducts: data => request('/v3/product', 'get', data),
+  // 获取任务配置
+  getTasks: data => request('/v3/task', 'get', data),
+  // 提交任务
+  submitTask: data => request('/v3/task', 'post', data),
+  // 获取轮播图列表
+  getBannerList: data => request(`/v3/banner/${data}`, 'get', data),
+  // 获取官方活动
+  getActivities: data => request('/v3/activity', 'get', data),
+  // 获取排行榜详情
+  getRankingData: data => request(`/v3/activity/${data}`, 'get', data),
+  // 获取朗读赛范文
+  getModelTexts: data => request('/activityRead', 'get', data),
+  // 获取朗读赛排行榜
+  getReadRanking: data => request('/activityJoinUser/hotAmountTop', 'get', data),
+  // 获取朗读赛排行榜参赛作品
+  getSelfReadRanking: data => request('/activityJoinUser/activityRead', 'get', data),
+  // 获取消息通知列表
+  getMessageList: data => request('/message', 'get', data),
+  // 用户行为统计
+  // RECOMMEND(name: "推荐”) ,MY(name: ”我的 "),RESOURCES(name: "资源"), SUBSCRIBE(name: "关注"),REC_ READ(name: ”推荐 - 我要配音 "),READING(name: ”开始朗读 ") ,EXAMPLE(name: "示范"), RERECORDING(name: "重录"), UPLOAD(name: "上传作品"), MY_ INFO(name: “个人信息 ") ,INTEGRAL(name: "小红花"), MY_ SUBSCRIBE(name: "我的关注"), MY_ FAVORITES(name: ”我的收藏”),MESSAGE(name: ”消息通知”), SERVICE(name: "客服"),
+  userEvent: data => request('/userEvent/v2', 'post', data),
+
 }

+ 19 - 17
api/video.js

@@ -1,22 +1,24 @@
 import {
-    request
+  request
 } from "../utils/request";
 
 module.exports = {
-    // 获取阅读的详情
-    getreadInfo: data => request(`/userRead/readInfo/${data}`, 'get', data),
-    //设置视频状态。比如删除。禁用
-    setVideoStatus: data => request('/userRead', 'put', data),
-    // 作品点赞
-    likeVideo: data => request(`/userRead/like/${data}`, 'get'),
-    // 收藏
-    collectVideo: data => request('/favorites', 'post', data),
-    // 获取评论
-    getComment: data => request('/posts/reply', 'get', data),
-    // 发布评论
-    postReply: data => request('/posts', 'post', data),
-    // 回复评论
-    ReplyComment: data => request('/reply', 'post', data),
-    // 评论点赞
-    likeReply: data => request(`/posts/like/${data}`, 'get'),
+  // 获取阅读的详情
+  getreadInfo: data => request(`/userRead/readInfo/${data}`, 'get', data),
+  //设置视频状态。比如删除。禁用
+  setVideoStatus: data => request('/userRead', 'put', data),
+  // 作品点赞
+  likeVideo: data => request(`/userRead/like/${data}`, 'get'),
+  // 收藏
+  collectVideo: data => request('/favorites', 'post', data),
+  // 获取评论
+  getComment: data => request('/posts/reply', 'get', data),
+  // 发布评论
+  postReply: data => request('/posts', 'post', data),
+  // 回复评论
+  ReplyComment: data => request('/reply', 'post', data),
+  // 评论点赞
+  likeReply: data => request(`/posts/like/${data}`, 'get'),
+  // 作品播放统计
+  submitPlayLog: data => request('/base/playLog', 'post', data),
 }

+ 13 - 2
components/videoPreview/index.js

@@ -8,6 +8,7 @@ import {
   setVideoStatus,
   likeVideo,
   collectVideo,
+  submitPlayLog
 } from '~/api/video'
 import {
   setFans
@@ -57,7 +58,9 @@ Component({
     // 播放视频
     playVideo() {
       this.triggerEvent('playVideo', this.properties.videoInfo.userRead.id)
+      this.submitPlayLog(this.properties.videoInfo.userRead.id)
     },
+
     // 设置视频公开还是隐私
     async setVideoPublic() {
       let info = this.properties.videoInfo.userRead
@@ -208,6 +211,7 @@ Component({
         }
         this.setPkData({
           nickName: videoInfo.user.nickName || videoInfo.user.eid,
+          uid: videoInfo.user.uid,
           avatar: videoInfo.user.avatar,
           score: videoInfo.userRead.score,
           audioPath: videoInfo.userRead.audioPath,
@@ -216,7 +220,6 @@ Component({
         })
       }
       let readId = videoInfo.userRead.id
-      console.log(this.properties.videoType);
       let url = this.properties.videoType == 'excellent' ? `/pages/pkPage/index?videoId=${readId}` : `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&readingType=${this.properties.videoType}`
       wx.navigateTo({
         url
@@ -230,6 +233,14 @@ Component({
     // 控制音频播放
     audioPlay() {
       this.triggerEvent('playAudio')
-    }
+      this.submitPlayLog(this.properties.videoInfo.userRead.id)
+    },
+    // 统计作品播放次数
+    async submitPlayLog(userReadId) {
+      await submitPlayLog({
+        userReadId,
+        playStopTime: 1000
+      })
+    },
   }
 })

+ 1 - 1
components/videoPreview/index.less

@@ -9,7 +9,7 @@
     display: flex;
     justify-content: space-between;
     align-items: center;
-    padding: 20rpx 20rpx 8rpx;
+    padding: 20rpx 20rpx 10rpx;
 
     .wH-left {
       display: flex;

+ 1 - 1
components/videoPreview/index.wxss

@@ -9,7 +9,7 @@
   display: flex;
   justify-content: space-between;
   align-items: center;
-  padding: 20rpx 20rpx 8rpx;
+  padding: 20rpx 20rpx 10rpx;
 }
 .work .workHead .wH-left {
   display: flex;

+ 87 - 80
components/worksList/index.js

@@ -1,92 +1,99 @@
 import behavior from '~/mixins/video'
+import {
+  submitPlayLog
+} from '~/api/video'
 let _observer
 Component({
-    behaviors: [behavior],
-    properties: {
-        worksList: {
-            type: Array,
-            value: [],
-            observer(newVal) {
-                this.setData({
-                    worksListCopy: newVal
+  behaviors: [behavior],
+  properties: {
+    worksList: {
+      type: Array,
+      value: [],
+      observer(newVal) {
+        this.setData({
+          worksListCopy: newVal
+        })
+        if (this.properties.autoPlay) {
+          // 自动播放
+          this._observer = this.createIntersectionObserver({
+            observeAll: true
+          })
+          this._observer.relativeTo('.playLine')
+            .observe('.videoPreview', (res) => {
+              let intersectionRatio = res.intersectionRatio
+              if (intersectionRatio > 0) {
+                submitPlayLog({
+                  userReadId: res.dataset.id,
+                  playStopTime: 1000
                 })
-                if (this.properties.autoPlay) {
-                    // 自动播放
-                    this._observer = this.createIntersectionObserver({
-                        observeAll: true
-                    })
-                    this._observer.relativeTo('.playLine')
-                        .observe('.videoPreview', (res) => {
-                            let intersectionRatio = res.intersectionRatio
-                            if (intersectionRatio > 0) {
-                                if (res.dataset.type == 0) {
-                                    this.resetAudio();
-                                    this.setData({
-                                        currentId: res.dataset.id
-                                    })
-                                } else {
-                                    this.playAudio({
-                                        currentTarget: {
-                                            dataset: res.dataset
-                                        }
-                                    })
-                                }
-                            }
-                        })
+                if (res.dataset.type == 0) {
+                  this.resetAudio();
+                  this.setData({
+                    currentId: res.dataset.id
+                  })
+                } else {
+                  this.playAudio({
+                    currentTarget: {
+                      dataset: res.dataset
+                    }
+                  })
                 }
-            }
-        },
-        // 是否自动播放
-        autoPlay: {
-            type: Boolean,
-            value: true
-        },
-        videoType: {
-            type: String,
-            // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,collection为收藏时的样式,excellent优秀作品展播
-            value: 'public'
-        },
-        // 是否在tabbar页面使用
-        tabBarPadding: {
-            type: Boolean,
-            value: false
+              }
+            })
         }
+      }
     },
-    data: {
-        worksListCopy: {}
+    // 是否自动播放
+    autoPlay: {
+      type: Boolean,
+      value: true
     },
-    lifetimes: {
-        detached: function () {
-            // 在组件实例被从页面节点树移除时执行
-            this.resetAudio()
-        },
+    videoType: {
+      type: String,
+      // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,collection为收藏时的样式,excellent优秀作品展播
+      value: 'public'
     },
-    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
-            })
-        },
-        addCommentNum({
-            detail
-        }) {
-            let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
-            worksListCopy.forEach(item => {
-                if (item.userRead.id == detail) {
-                    item.userRead.commentAmount = ++item.userRead.commentAmount
-                }
-            })
-            this.setData({
-                worksListCopy
-            })
+    // 是否在tabbar页面使用
+    tabBarPadding: {
+      type: Boolean,
+      value: false
+    }
+  },
+  data: {
+    worksListCopy: {}
+  },
+  lifetimes: {
+    detached: function () {
+      // 在组件实例被从页面节点树移除时执行
+      this.resetAudio()
+    },
+  },
+  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
+      })
     },
+    addCommentNum({
+      detail
+    }) {
+      let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
+      worksListCopy.forEach(item => {
+        if (item.userRead.id == detail) {
+          item.userRead.commentAmount = ++item.userRead.commentAmount
+        }
+      })
+      this.setData({
+        worksListCopy
+      })
+    }
+  },
 })

+ 125 - 125
mixins/video.js

@@ -1,131 +1,131 @@
 module.exports = Behavior({
-    data: {
-        currentId: '',
+  data: {
+    currentId: '',
+  },
+  properties: {},
+  pageLifetimes: {
+    hide() {
+      this.resetAudio()
     },
-    properties: {},
-    pageLifetimes: {
-        hide() {
-            this.resetAudio()
-        },
+  },
+  methods: {
+    // 开始播放
+    playVideo({
+      currentTarget
+    }) {
+      this.setData({
+        currentId: currentTarget.dataset.id
+      })
     },
-    methods: {
-        // 开始播放
-        playVideo({
-            currentTarget
-        }) {
-            this.setData({
-                currentId: currentTarget.dataset.id
-            })
-        },
-        // 播放音频
-        playAudio({
-            currentTarget
-        }) {
-            if (this.data.currentId == currentTarget.dataset.id) {
-                return this.resetAudio()
-            }
-            if (this.innerAudioContext) {
-                this.resetAudio()
-            } else {
-                this.innerAudioContext = wx.createInnerAudioContext()
-                this.innerAudioContext.onEnded(res => {
-                    this.resetAudio()
-                })
+    // 播放音频
+    playAudio({
+      currentTarget
+    }) {
+      if (this.data.currentId == currentTarget.dataset.id) {
+        return this.resetAudio()
+      }
+      if (this.innerAudioContext) {
+        this.resetAudio()
+      } else {
+        this.innerAudioContext = wx.createInnerAudioContext()
+        this.innerAudioContext.onEnded(res => {
+          this.resetAudio()
+        })
+      }
+      this.innerAudioContext.src = currentTarget.dataset.audio
+      this.innerAudioContext.play();
+      this.setData({
+        currentId: currentTarget.dataset.id
+      })
+    },
+    // 重置音频
+    resetAudio() {
+      if (this.innerAudioContext) {
+        this.innerAudioContext.stop();
+      }
+      this.setData({
+        currentId: ''
+      })
+    },
+    // 打开评论
+    openComment({
+      target
+    }) {
+      this.selectComponent('#comment').open(target.dataset.id)
+    },
+    // 分享
+    creatShare(video) {
+      console.log(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);
             }
-            this.innerAudioContext.src = currentTarget.dataset.audio
-            this.innerAudioContext.play();
-            this.setData({
-                currentId: currentTarget.dataset.id
-            })
-        },
-        // 重置音频
-        resetAudio() {
-            if (this.innerAudioContext) {
-                this.innerAudioContext.stop();
+            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/no_collect.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.likes, 284, 238)
+                    //评论
+                    let pl = canvas.createImage();
+                    pl.src = '/static/comment.png'
+                    pl.onload = () => {
+                      ctx.drawImage(pl, 318, 222, 22, 22)
+                      ctx.fillText(video.commentAmount, 340, 238)
+                      setTimeout(() => {
+                        wx.canvasToTempFilePath({
+                          canvas: canvas,
+                          success(res) {
+                            resolve({
+                              title: '请欣赏我的课文朗读作品,点赞+评论。',
+                              path: `/pages/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
+                              imageUrl: res.tempFilePath
+                            })
+                          },
+                          fail(res) {
+                            reject()
+                          }
+                        }, this)
+                      }, 500)
+                    }
+                  }
+                }
+              }
             }
-            this.setData({
-                currentId: ''
-            })
-        },
-        // 打开评论
-        openComment({
-            target
-        }) {
-            this.selectComponent('#comment').open(target.dataset.id)
-        },
-        // 分享
-        creatShare(video) {
-            console.log(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/no_collect.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.likes, 284, 238)
-                                        //评论
-                                        let pl = canvas.createImage();
-                                        pl.src = '/static/comment.png'
-                                        pl.onload = () => {
-                                            ctx.drawImage(pl, 318, 222, 22, 22)
-                                            ctx.fillText(video.commentAmount, 340, 238)
-                                            setTimeout(() => {
-                                                wx.canvasToTempFilePath({
-                                                    canvas: canvas,
-                                                    success(res) {
-                                                        resolve({
-                                                            title: '请欣赏我的课文朗读作品,点赞+评论。',
-                                                            path: `/pages/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
-                                                            imageUrl: res.tempFilePath
-                                                        })
-                                                    },
-                                                    fail(res) {
-                                                        reject()
-                                                    }
-                                                }, this)
-                                            }, 500)
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    })
-            })
-        },
-    }
+          })
+      })
+    },
+  }
 })

+ 5 - 6
pages/childClassify/index.less

@@ -17,13 +17,13 @@
       display: inline-block;
       padding: 0rpx 20rpx;
       margin-right: 40rpx;
-      color: #666666;
+      color: #777;
       font-weight: bold;
       font-size: 28rpx;
     }
 
     .currentClass {
-      font-size: 32rpx;
+      font-size: 34rpx;
       color: #333;
     }
   }
@@ -125,9 +125,9 @@
 
           .title {
             width: 270rpx;
-            font-size: 32rpx;
+            font-size: 34rpx;
             font-weight: bold;
-            margin-bottom: 10rpx;
+            margin-bottom: 12rpx;
           }
 
           .statistics {
@@ -135,10 +135,9 @@
             align-items: center;
 
             .statistic {
+              width: 110rpx;
               display: flex;
               align-items: center;
-              justify-content: space-between;
-              margin-right: 14rpx;
 
               .playImg {
                 width: 30rpx;

+ 5 - 6
pages/childClassify/index.wxss

@@ -17,12 +17,12 @@
   display: inline-block;
   padding: 0rpx 20rpx;
   margin-right: 40rpx;
-  color: #666666;
+  color: #777;
   font-weight: bold;
   font-size: 28rpx;
 }
 .classBox .classify .currentClass {
-  font-size: 32rpx;
+  font-size: 34rpx;
   color: #333;
 }
 .classBox .searchBox {
@@ -114,19 +114,18 @@
 }
 .classBox .worksList .worksBox .left .work .title {
   width: 270rpx;
-  font-size: 32rpx;
+  font-size: 34rpx;
   font-weight: bold;
-  margin-bottom: 10rpx;
+  margin-bottom: 12rpx;
 }
 .classBox .worksList .worksBox .left .work .statistics {
   display: flex;
   align-items: center;
 }
 .classBox .worksList .worksBox .left .work .statistics .statistic {
+  width: 110rpx;
   display: flex;
   align-items: center;
-  justify-content: space-between;
-  margin-right: 14rpx;
 }
 .classBox .worksList .worksBox .left .work .statistics .statistic .playImg {
   width: 30rpx;

+ 1 - 1
pages/reading/index.js

@@ -342,9 +342,9 @@ Page({
         let data = {
           challengerUserReadId: uploadRes.id,
           userReadId: this.data.pkData.id,
+          winnerUId: this.data.pkData.score > _data.myOverall ? this.data.pkData.uid : this.data.pkData.score == _data.myOverall ? '' : wx.getStorageSync('uid')
         }
         let result = await uploadPk(data)
-        console.log(result, 'pk结果');
         wx.redirectTo({
           url: `/pages/pkResult/index?id=${result.id}`
         })