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

作品上传与pk结果联调

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

+ 2 - 0
api/works.js

@@ -12,6 +12,8 @@ module.exports = {
   getAuthorityList: data => request('/v3/recommend', 'get', data),
   // 发布作品
   publishWorks: data => request('/userRead', 'post', data),
+  // 上传挑战结果
+  uploadPk: data => request('/v3/pk', 'post', data),
   // 获取关注的人的作品
   getFollowWorks: data => request('/fans/interest', 'get', data),
   // 获取作品的挑战记录

+ 1 - 1
app.json

@@ -1,10 +1,10 @@
 {
   "pages": [
+    "pages/pkResult/index",
     "pages/index/index",
     "pages/pkPage/index",
     "pages/rankIntro/index",
     "pages/ranking/index",
-    "pages/pkResult/index",
     "pages/userWorks/index",
     "pages/works/index",
     "pages/collection/index",

+ 3 - 2
components/videoPreview/index.js

@@ -193,14 +193,15 @@ Component({
     },
     toPkPage() {
       let videoInfo = this.data.videoInfoCopy
-      console.log(videoInfo,this.properties.videoType);
+      console.log(videoInfo, this.properties.videoType);
       if (this.properties.videoType == 'pk') {
         this.setPkData({
           nickName: videoInfo.user.nickName || videoInfo.user.eid,
           avatar: videoInfo.user.avatar,
           score: videoInfo.userRead.score,
           audioPath: videoInfo.userRead.audioPath,
-          exampleId: videoInfo.userRead.exampleId
+          exampleId: videoInfo.userRead.exampleId,
+          id: videoInfo.userRead.id
         })
       }
       let readId = videoInfo.userRead.id

+ 2 - 2
mixins/reachBottom.js

@@ -49,7 +49,7 @@ module.exports = Behavior({
       })
 
     },
-    resetData() {
+    resetData(data) {
       console.log("触发resetData");
       if (this.data.loading) return; // 如果接口已经在请求中,则不重置数据,防止用户持续下拉刷新
       this.setData({
@@ -59,7 +59,7 @@ module.exports = Behavior({
         totalSize: 0,
         noMoreData: false,
       })
-      this.loadMore(); // 调用页面中的接口请求方法
+      this.loadMore(data); // 调用页面中的接口请求方法
     },
   },
 })

+ 10 - 6
pages/pkPage/index.js

@@ -1,4 +1,5 @@
 import behavior from '~/mixins/video'
+import reachBottom from '~/mixins/reachBottom'
 import share from '~/mixins/share'
 import {
   getreadInfo
@@ -7,31 +8,34 @@ import {
   getPkRecord
 } from '~/api/works'
 Page({
-  behaviors: [behavior, share],
+  behaviors: [behavior, share, reachBottom],
   data: {
     videoInfo: {}
   },
-
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    console.log(options);
     let videoId = options.videoId
     this.getreadInfo(videoId)
+    this.resetData({
+      userReadId: videoId
+    })
   },
   async getreadInfo(videoId) {
     let videoInfo = await getreadInfo(videoId)
     wx.setNavigationBarTitle({
       title: videoInfo.userRead.title
     })
-    let res = await getPkRecord({
-      userReadId: videoId
-    })
-    console.log(res);
+
     this.setData({
       videoInfo
     })
   },
+  loadMore(data) {
+    this.getData(getPkRecord, data)
+  },
   onHide() {
     this.setData({
       currentId: ''

+ 0 - 1
pages/pkResult/index.json

@@ -1,6 +1,5 @@
 {
   "usingComponents": {
-    "uploadFile": "/components/uploadFile/index"
   },
   "navigationBarTitleText": "挑战结果"
 }

+ 0 - 1
pages/pkResult/index.wxml

@@ -29,6 +29,5 @@
   </view>
   <view class="footer">
     <view class="stBtn" bindtap="result">重新挑战</view>
-    <uploadFile />
   </view>
 </view>

+ 58 - 3
pages/reading/index.js

@@ -2,6 +2,10 @@ import {
   getreadInfo
 } from '~/api/video'
 import {
+  publishWorks,
+  uploadPk
+} from '~/api/works'
+import {
   createStoreBindings
 } from 'mobx-miniprogram-bindings'
 import {
@@ -38,6 +42,8 @@ Page({
     readingReset: false,
     //readingType为public是普通阅读,为pk是pk逻辑
     readingType: 'public',
+    percent: 0,
+    uploadState: false,
     article: [{
       id: 1,
       text: '传说在很久很久以前,',
@@ -94,7 +100,8 @@ Page({
       store,
       fields: {
         userInfo: 'userInfo',
-        readDetail: 'readDetail'
+        readDetail: 'readDetail',
+        pkData: 'pkData'
       },
       actions: {
         setReadDetail: 'setReadDetail'
@@ -310,6 +317,7 @@ Page({
   },
   // 获取测评结果
   getRecordScore(res) {
+    console.log('获取评测结果');
     const result = res.result;
     const integrity = Math.floor(result.integrity); //完成度
     const tone = Math.floor(result.tone); // 语调声调
@@ -327,8 +335,55 @@ Page({
       id: this.data.videoInfo.userRead.exampleId,
     }
     this.setReadDetail(detail)
-    wx.redirectTo({
-      url: this.data.readingType == 'public' ? '/pages/score/index' : '/pages/pkResult/index',
+    console.log(this.data.readingType, 'readingType');
+    if (this.data.readingType == 'public') {
+      wx.redirectTo({
+        url: '/pages/score/index'
+      })
+    } else {
+      this.uploadAudio(detail)
+    }
+  },
+  // 挑战录音上传
+  uploadAudio(detail) {
+    this.setData({
+      uploadState: true
+    })
+    const uploadTask = wx.uploadFile({
+      url: 'https://reader-api.ai160.com//file/upload',
+      filePath: this.data.tempFilePath,
+      name: '朗读录音',
+      header: {
+        uid: wx.getStorageSync('uid')
+      },
+      success: async (res) => {
+        const formateRes = JSON.parse(res.data);
+        let audioPath = formateRes.data;
+        let uploadRes = await publishWorks({
+          exampleId: this.data.pkData.exampleId,
+          audioPath
+        })
+        console.log('uploadRes', uploadRes);
+        /*  let winnerUId = this.data.pkData > detail.myOverall ? this.data.pkData.exampleId : this.data.pkData < detail.myOverall ? detail.id : '' */
+        let data = {
+          challengerUserReadId: uploadRes.id,
+          userReadId: this.data.pkData.id,
+        }
+        await uploadPk(data)
+        wx.redirectTo({
+          url: '/pages/pkResult/index'
+        })
+      },
+      complete: () => {
+        this.setData({
+          uploadState: false
+        })
+      }
+    });
+    uploadTask.onProgressUpdate((res) => {
+      this.setData({
+        percent: res.progress
+      })
     })
   },
   videoPlay() {

+ 40 - 0
pages/reading/index.less

@@ -198,6 +198,45 @@
       }
     }
   }
+
+  
+  .uploadBox {
+    position: fixed;
+    top: 0px;
+    left: 0px;
+    width: 100%;
+    height: 100%;
+    background-color: rgba(255, 255, 255, 0);
+    z-index: 999;
+
+    .upload {
+      position: absolute;
+      left: 0rpx;
+      right: 0rpx;
+      top: 30%;
+      margin: auto;
+      width: 293rpx;
+      height: 293rpx;
+      border-radius: 30rpx;
+      color: white;
+      background-color: rgba(0, 0, 0, 0.8);
+      text-align: center;
+      padding: 0rpx 38rpx;
+      box-sizing: border-box;
+      font-size: 30rpx;
+      z-index: 998;
+
+      .speed {
+        margin-top: 70rpx;
+      }
+
+      .speedProgress {
+        border-radius: 50rpx;
+        overflow: hidden;
+        margin: 18rpx 0rpx 60rpx;
+      }
+    }
+  }
 }
 
 .scoreBoxC {
@@ -331,4 +370,5 @@
       }
     }
   }
+
 }

+ 7 - 0
pages/reading/index.wxml

@@ -95,4 +95,11 @@
       <view class="tips">秒后开始</view>
     </view>
   </view>
+  <view class="uploadBox" wx:if="{{uploadState}}">
+    <view class="upload">
+      <view class="speed">{{percent}}%</view>
+      <progress percent="{{percent}}" class="speedProgress" stroke-width="10" activeColor="#C3F166" />
+      <view>挑战结算中</view>
+    </view>
+  </view>
 </view>

+ 34 - 0
pages/reading/index.wxss

@@ -175,6 +175,40 @@
   font-size: 124rpx;
   margin-bottom: 6rpx;
 }
+.readingBox .uploadBox {
+  position: fixed;
+  top: 0px;
+  left: 0px;
+  width: 100%;
+  height: 100%;
+  background-color: rgba(255, 255, 255, 0);
+  z-index: 999;
+}
+.readingBox .uploadBox .upload {
+  position: absolute;
+  left: 0rpx;
+  right: 0rpx;
+  top: 30%;
+  margin: auto;
+  width: 293rpx;
+  height: 293rpx;
+  border-radius: 30rpx;
+  color: white;
+  background-color: rgba(0, 0, 0, 0.8);
+  text-align: center;
+  padding: 0rpx 38rpx;
+  box-sizing: border-box;
+  font-size: 30rpx;
+  z-index: 998;
+}
+.readingBox .uploadBox .upload .speed {
+  margin-top: 70rpx;
+}
+.readingBox .uploadBox .upload .speedProgress {
+  border-radius: 50rpx;
+  overflow: hidden;
+  margin: 18rpx 0rpx 60rpx;
+}
 .scoreBoxC {
   flex: 1;
   width: 100%;