Browse Source

视频秀上传

zhangshuling 3 years ago
parent
commit
42fab70a4f

+ 6 - 2
pages/index/index.js

@@ -140,7 +140,7 @@ Page({
     }
     let today = util.curTime().substring(0, 10).replace(/\//g, '-')
     wx.navigateTo({
-      url: e.currentTarget.dataset.url + '?beginDate=' + today + '&endDate=' + today,
+      url: e.currentTarget.dataset.url + '?beginDate=' + (today.substring(0, 5) + '01-01') + '&endDate=' + today,
     })
   },
 
@@ -322,8 +322,12 @@ Page({
         'q.attenceDate': today
       }).then(r => {
         // console.log('今日课程 : ' + JSON.stringify(r));
+        let courseCount = 0
+        if (r && r.length > 0) {
+          courseCount = r[0].total;
+        }
         this.setData({
-          'classList[0].num': (r ? r.length : 0)
+          'classList[0].num': courseCount
         })
       })
 

+ 1 - 1
pages/schedule/schedule.js

@@ -23,7 +23,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    let date = options.beginDate;
+    let date = options.endDate;
     if (date) {
       this.setData({ bd: date })
     }

+ 2 - 1
pages/showVideoList/showVideoList.js

@@ -31,7 +31,7 @@ Page({
     this.setData({ personType: personType })
   },
 
-  uploadTap:function(){
+  uploadTap: function () {
     wx.navigateTo({
       url: '/pages/uploadShow/uploadShow',
     })
@@ -48,6 +48,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
+    this.setData({ pageNum: 0, list: [] })
     this.queryList();
   },
 

+ 1 - 1
pages/showVideoList/showVideoList.wxml

@@ -10,7 +10,7 @@
   </view>
   <!-- end -->
 
-  <view class="uploadTap" bindtap="uploadTap">发布</view>
+  <view class="uploadTap" bindtap="uploadTap" wx:if="{{personType=='0'}}">发布</view>
 
   <view class="loading">{{loading}}</view>
 

+ 222 - 2
pages/uploadShow/uploadShow.js

@@ -1,19 +1,113 @@
 // pages/uploadShow/uploadShow.js
+import VODUpload from '../../utils/aliyun-upload-sdk-1.0.1.min'
+const app = getApp()
+const util = require("../../utils/util")
+const urlDef = require("../../utils/urls")
+
+var uploader = null //阿里云视频上传对象
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    array:['钢琴','芭蕾舞'],
-    arrIndex: 0
+    array: [],
+    arrIndex: 0,
+    videoItems: [],
+    videoFlag: 0,
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    let stu = wx.getStorageSync('student');
+    const urls = urlDef.urls;
+    util.apiPost(urls.person_video_course + '&q.studentId=' + stu.studentId).then(rs => {
+      this.setData({ array: rs })
+    });
+
+
 
+    this.videoContext = wx.createVideoContext('play-video'); // 	创建 video 上下文 VideoContext 对象。
+    const that = this
+    const createUpLoad = new VODUpload({
+      //阿里账号ID,必须有值
+      userId: "WaWQOn6gXod13WLEp8cr4ljUdvcbXJ",
+      //网络原因失败时,重新上传次数,默认为3
+      retryCount: 3,
+      //网络原因失败时,重新上传间隔时间,默认为2秒
+      retryDuration: 2,
+      //开始上传
+      'onUploadstarted': function (uploadInfo) {
+        wx.showLoading({
+          title: '上传中...',
+          mask: true
+        })
+        // console.log("onUploadStarted:" + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object)
+        //上传方式1,需要根据uploadInfo.videoId是否有值,调用点播的不同接口获取uploadauth和uploadAddress,如果videoId有值,调用刷新视频上传凭证接口,否则调用创建视频上传凭证接口
+        if (uploadInfo.videoId) {
+          //如果uploadInfo.videoId存在,调用刷新视频上传凭证接口
+        } else {
+          //如果uploadInfo.videoId不存在,调用获取视频上传地址和凭证接口
+        }
+        //从点播服务获取的uploadAuth、uploadAddress和videoId,设置SDK
+        // console.log(that.data)
+        uploader.setUploadAuthAndAddress(uploadInfo, that.data.uploadAuth, that.data.uploadAddress, that.data.videoId);
+      },
+      //文件上传成功
+      'onUploadSucceed': function (uploadInfo) {
+        console.log("上传成功:" + JSON.stringify(uploadInfo))
+
+        let vid = uploadInfo.videoId
+        let stu = wx.getStorageSync('student')
+        var video = { name: vid, videoId: vid, orgId: stu.orgId, size: uploadInfo.fileSize, title: '', content: '' };
+        // 保存一个 video
+        let urls = urlDef.urls
+        util.apiPost(urls.video_save, video, 'application/json').then((rs) => {
+          var json = {
+            url: uploadInfo.videoId,
+            playUrl: uploadInfo.url,
+            imgUrl: uploadInfo.coverUrl
+          }
+          console.log('视频上传成功' + JSON.stringify(json))
+          var list = [json]
+          that.setData({
+            videoItems: that.data.videoItems.concat(list)
+          })
+          wx.showToast({
+            title: '上传成功',
+          })
+        })
+        // console.log("onUploadSucceed: " + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
+      },
+      //文件上传失败
+      'onUploadFailed': function (uploadInfo, code, message) {
+        // console.log("onUploadFailed: file:" + uploadInfo.file.name + ",code:" + code + ", message:" + message);
+        wx.showToast({
+          title: '上传失败',
+        })
+      },
+      //文件上传进度,单位:字节
+      'onUploadProgress': function (uploadInfo, totalSize, loadedPercent) {
+        // console.log("onUploadProgress:file:" + uploadInfo.file.name + ", fileSize:" + totalSize + ", percent:" + Math.ceil(loadedPercent * 100) + "%");
+      },
+      //上传凭证超时
+      'onUploadTokenExpired': function (uploadInfo) {
+        wx.showToast({
+          title: '上传超时',
+        })
+        console.log("onUploadTokenExpired");
+        //实现时,根据uploadInfo.videoId调用刷新视频上传凭证接口重新获取UploadAuth
+        //从点播服务刷新的uploadAuth,设置到SDK里
+        uploader.resumeUploadWithAuth(uploadAuth);
+      },
+      //全部文件上传结束
+      'onUploadEnd': function (uploadInfo) {
+        console.log("onUploadEnd: uploaded all the files");
+      }
+    });
+    uploader = createUpLoad
   },
 
   /**
@@ -63,5 +157,131 @@ Page({
    */
   onShareAppMessage: function () {
 
+  },
+  bindPickerChange: function (e) {
+    this.setData({
+      arrIndex: e.detail.value
+    })
+  },
+
+  len: function (s) {
+    return (s == null ? 0 : s.length);
+  },
+  formSubmit: function (e) {
+    if (this.data.videoItems.length == 0) {
+      wx.showToast({ title: '请先上传视频', icon: 'none' });
+      return;
+    }
+
+    let entity = e.detail.value
+    let stu = wx.getStorageSync('student')
+    entity.personId = stu.studentId
+    entity.orgId = stu.orgId
+    entity.personType = 0; // 学生
+    if (this.len(entity.title) === 0) {
+      wx.showToast({ title: '请先上输入视频标题', icon: 'none' });
+      return;
+    }
+
+    wx.showLoading({
+      title: '保存中...',
+      mask: true
+    })
+    const urls = urlDef.urls;
+    entity.videoId = this.data.videoItems[0].url;
+    util.apiPost(urls.person_video_save, entity, 'application/json').then(rs => {
+      entity = rs;
+      wx.showToast({ title: '保存成功,等待校方审核' });
+      setTimeout(() => {
+        wx.navigateBack({
+          delta: 1, // 返回上一级页面。
+          success: function () {
+            console.log('成功!')
+          }
+        })
+      }, 1000)
+    })
+  },
+  addVideo: function () {
+    if (this.data.videoItems.length > 0) {
+      wx.showToast({ title: '请先删除视频', icon: 'none' });
+      return;
+    }
+    this.getVideoList(); // 选择视频
+  },
+
+  showVideo: function (e) {
+    const index = e.currentTarget.dataset.index
+    const curVideo = this.data.videoItems[index].playUrl
+    this.setData({
+      curVideo
+    })
+
+    this.videoContext.requestFullScreen({ // 设置全屏时视频的方向,不指定则根据宽高比自动判断。
+      direction: 90 // 屏幕逆时针90度
+    });
+  },
+
+  // 监听视频是否为全屏,否则直接关闭
+  bindfullscreenchange: function () {
+    if (this.data.videoFlag == 0) {
+      this.setData({
+        videoFlag: 1
+      })
+    } else {
+      this.setData({
+        videoFlag: 0,
+        curVideo: ""
+      })
+    }
+  },
+  delVideo: function (e) {
+    const index = e.currentTarget.dataset.index
+    let videos = this.data.videoItems;
+    let video = videos[index]
+    let delFiles = [];
+    delFiles.push(video.url)
+    const params = { 'ids[]': delFiles }
+    const urls = urlDef.urls;
+    util.apiPost(urls.video_delete, params).then((rs) => {
+      this.data.videoItems.splice(index, 1);
+      this.setData({
+        videoItems: this.data.videoItems
+      })
+    });
+
+
+
+  },
+  getVideoList: function () {
+    let that = this
+    wx.chooseVideo({
+      camera: ['album'],
+      success(res) {
+        var file = {
+          url: res.tempFilePath,
+          coverUrl: res.thumbTempFilePath
+        };
+        var userData = '{"Vod":{}}';
+        const urls = urlDef.urls;
+        let createUrl = urls.video_create_upload + '?title=' + res.tempFilePath + '&fileName=' + res.tempFilePath;
+        console.log('createUploadVideo ... ');
+        util.apiPost(createUrl).then((rs) => {
+
+          let d = JSON.parse(rs.data);
+          // console.log('createUploadVideo ' + JSON.stringify(d));
+          that.setData({
+            uploadAuth: d.UploadAuth,
+            uploadAddress: d.UploadAddress,
+            videoId: d.VideoId,
+          })
+          uploader.addFile(file, null, null, null, userData)
+          uploader.startUpload();
+          // uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId);
+        }, e => {
+          console.log('createUploadVideo error ' + JSON.stringify(e));
+        });
+      }
+    })
   }
 })

+ 10 - 6
pages/uploadShow/uploadShow.wxml

@@ -1,10 +1,11 @@
 <view class="container">
+  <form catchsubmit="formSubmit">
   <view class="show-box">
     <view class="title">选择关联课程</view>
     <view class="select-view">
-      <picker bindchange="bindPickerChange" value="{{arrIndex}}" range="{{array}}">
+      <picker bindchange="bindPickerChange" value="{{arrIndex}}" range="{{array}}" range-key="name">
           <view class="picker">
-            {{array[arrIndex]}}
+            {{array[arrIndex].name}}
           </view>
         </picker>
     </view>
@@ -14,19 +15,19 @@
     </view>
     <view class="title textarea-title">视频说明</view>
     <view class="textarea-view">
-      <textarea name="desc" placeholder="与大家具体描述这次精彩的表现内容把" maxlength="200"></textarea>
+      <textarea name="content" placeholder="与大家具体描述这次精彩的表现内容把" maxlength="200"></textarea>
     </view>
   </view>
   <view class="video-box">
     <view class="title">上传视频</view>
     <view class="uploadImg-task-view">
-      <view class="my-img-view" wx:for="{{1}}" wx:key="index" data-index="{{index}}" catchtap="showVideo">
+      <view class="my-img-view" wx:for="{{videoItems}}" wx:key="index" data-index="{{index}}" catchtap="showVideo">
         <view class="new-task-img">
           <image src="{{item.imgUrl}}"></image>
         </view>
         <view class="del-btn" data-index="{{index}}" catchtap="delVideo">X</view>
       </view>
-      <view class="upload-btn" bindtap="upLoadVideo">
+      <view class="upload-btn" bindtap="addVideo">
         <view style="margin-top:30rpx">
           <image src="/images/addFile.png"></image>
           <view>添加视频</view>
@@ -34,5 +35,8 @@
       </view>
       </view>
   </view>
-  <view class="submit-btn">发布</view>
+    <view class="btn-view">
+      <button class="submint-btn" formType="submit">发布</button>
+    </view>
+  </form>
 </view>

+ 15 - 12
pages/uploadShow/uploadShow.wxss

@@ -107,17 +107,20 @@ textarea {
   border: 1rpx dashed #ccc;
 }
 
-.submit-btn{
-  font-size: 32rpx;
+.new-task-img image{
+  width: 100%;
+  height: 100%;
+}
+
+.btn-view{
+  position: fixed;
+    bottom: 60rpx;
+    width: 750rpx;
+}
+.submint-btn{
   background: #005033;
-  color: #FFF;
-  width: 400rpx;
-  height: 80rpx;
-  line-height: 80rpx;
-  position: relative;
-  left: 50%;
-  margin-left: -200rpx;
-  margin-top: 50rpx;
-  text-align: center;
-  border-radius: 50rpx;
+    border-radius: 50rpx;
+    color: #FFF;
+    font-weight: 400;
+    width: 400rpx;
 }