123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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,
- 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');
- const that = this
- const createUpLoad = new VODUpload({
-
- userId: "WaWQOn6gXod13WLEp8cr4ljUdvcbXJ",
-
- retryCount: 3,
-
- retryDuration: 2,
-
- 'onUploadstarted': function (uploadInfo) {
- wx.showLoading({
- title: '上传中...',
- mask: true
- })
-
-
- if (uploadInfo.videoId) {
-
- } else {
-
- }
-
-
- 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: '' };
-
- 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: '上传成功',
- })
- })
-
- },
-
- 'onUploadFailed': function (uploadInfo, code, message) {
-
- wx.showToast({
- title: '上传失败',
- })
- },
-
- 'onUploadProgress': function (uploadInfo, totalSize, loadedPercent) {
-
- },
-
- 'onUploadTokenExpired': function (uploadInfo) {
- wx.showToast({
- title: '上传超时',
- })
- console.log("onUploadTokenExpired");
-
-
- uploader.resumeUploadWithAuth(uploadAuth);
- },
-
- 'onUploadEnd': function (uploadInfo) {
- console.log("onUploadEnd: uploaded all the files");
- }
- });
- uploader = createUpLoad
- },
-
- onReady: function () {
- },
-
- onShow: function () {
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- 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
- });
- },
-
- 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);
-
- that.setData({
- uploadAuth: d.UploadAuth,
- uploadAddress: d.UploadAddress,
- videoId: d.VideoId,
- })
- uploader.addFile(file, null, null, null, userData)
- uploader.startUpload();
-
- }, e => {
- console.log('createUploadVideo error ' + JSON.stringify(e));
- });
- }
- })
- }
- })
|