martial-arts/pagesB/upload-video/upload-video.vue

155 lines
4.4 KiB
Vue
Raw Normal View History

2022-08-12 10:14:13 +00:00
<template>
<view>
<status-container titlet="上传练习视频" returnc="#FFFFFF">
<view slot="content">
<view class="pad-zy20">
<view class="radius8 bacf pad-sx40 pad-zy40 boxshow2 col26 fon24">
<view class="">视频标题</view>
<input v-model="title" class="width100 radius4 mar-s20 pad-zy20" type="text" style="border: 2rpx solid #ececec;background-color: #f5f5f5;height: 70rpx;box-sizing: border-box;">
2023-03-23 02:51:22 +00:00
<view class="mar-s40">视频上传温馨提示请上传像素720P规格100M以内的视频</view>
2022-08-12 10:14:13 +00:00
<input @tap="uploadVideo" class="width100 radius4 mar-s20 pad-zy20 tcenter" type="text" placeholder="浏览..." disabled
style="border: 2rpx solid #ececec;background-color: #f5f5f5;height: 70rpx;box-sizing: border-box;">
2022-08-17 10:20:07 +00:00
<view class="pad-s20" v-if="videoInfo.full_src">
2022-08-18 06:22:40 +00:00
<video :src="videoInfo.full_src" :controls="true" object-fit="contain" :show-center-play-btn="true" style="height: 388rpx;" class="width100"></video>
2022-08-17 10:20:07 +00:00
</view>
2022-08-18 06:22:40 +00:00
<input @tap="submitEv" class="width100 radius4 mar-s60 tcenter" type="text" placeholder="立即保存" placeholder-style="color:#FFFFFF;" disabled
2022-08-12 10:14:13 +00:00
style="border: 2rpx solid #e42417;background-color: #e42417;height: 70rpx;box-sizing: border-box;">
</view>
</view>
</view>
</status-container>
</view>
</template>
<script>
import {uploadFile} from '@/jsFile/public-api.js';
export default {
data() {
return {
title:'',
videoInfo:{
full_src:'',
src:''
},
2023-03-23 02:51:22 +00:00
flag:true,
qiniuToken:'',
qiniuFilename:'',
hostapi:'',
2022-08-12 10:14:13 +00:00
}
},
2023-03-23 02:51:22 +00:00
onLoad() {
this.hostapi = getApp().globalData.hostapiQi;
this.getQiniu();
},
2022-08-12 10:14:13 +00:00
methods: {
2023-03-23 02:51:22 +00:00
getQiniu() {
this.$requst.post('/api/common/qiniuToken').then(res=>{
if(res.code==0){
console.log(res,'qiniu token')
this.qiniuToken = res.data.token;
this.qiniuFilename = res.data.filename + '.mp4';
}
}).catch(err=>{
})
},
2022-08-12 10:14:13 +00:00
// 上传视频
uploadVideo(){
uni.chooseMedia({
sourceType:['album','camera'],
2023-03-23 02:51:22 +00:00
maxDuration: 60,
2022-08-12 10:14:13 +00:00
success: (res) => {
uni.showToast({
2023-03-23 02:51:22 +00:00
title:'正在上传,请勿关闭页面和退出',
2022-08-12 10:14:13 +00:00
icon:'none',
duration:100000
})
2023-03-23 02:51:22 +00:00
let file = res.tempFiles[0].tempFilePath;
let key = this.qiniuFilename;
let token = this.qiniuToken;
uni.uploadFile({
url: "https://up-z1.qiniup.com",//华北地区上传
filePath: file,
name: 'file',
method: "POST",
formData: {
'key': key,//key值
'token': token //七牛云token值
},
success: uploadFileRes => {
//uploadFileRes 返回了data是一个json字符串
//拿到里面的key拼接上域名再反出去就ok了
let strToObj=JSON.parse(uploadFileRes.data),
backUrl = this.hostapi+ '/' + strToObj.key,
uploadUrl = '/' + strToObj.key;
this.videoInfo.full_src = backUrl;
this.videoInfo.src = uploadUrl;
console.log(this.videoInfo)
setTimeout(()=>{
uni.hideToast();
},500)
},
fail: fail => {
uni.showToast({ title: "网络错误", icon: "none" });
2022-08-12 10:14:13 +00:00
}
})
2023-03-23 02:51:22 +00:00
// uploadFile({path:res.tempFiles[0].tempFilePath}).then(res=>{
// if(res.code==0){
// this.videoInfo = res.data;
// this.$toolAll.tools.showToast('上传视频成功(*^▽^*)');
// }
// setTimeout(()=>{
// uni.hideToast();
// },1500)
// })
2022-08-12 10:14:13 +00:00
}
})
},
// 上传执行事件
submitEv(){
if(!this.title){
this.$toolAll.tools.showToast('请输入视频标题');
} else if(!this.videoInfo.full_src){
this.$toolAll.tools.showToast('请上传视频');
} else {
if(this.flag){
this.flag = false;
let params = {
title:this.title,
2022-08-18 06:22:40 +00:00
video:this.videoInfo.src
2022-08-12 10:14:13 +00:00
}
uni.showToast({
title:'正在上传练习视频',
icon:'none',
duration:100000
})
this.$requst.post('/api/user/practice-video',params).then(res=>{
if(res.code==0){
this.title = '';
this.videoInfo.full_src = '';
2022-08-18 06:22:40 +00:00
this.$toolAll.tools.showToast('保存成功');
2022-08-17 10:20:07 +00:00
setTimeout(()=>{
uni.navigateBack({delta:1})
},1000)
2022-08-12 10:14:13 +00:00
}
setTimeout(()=>{
uni.hideToast();
2023-03-23 02:51:22 +00:00
},500)
2022-08-12 10:14:13 +00:00
}).catch(err=>{
this.flag = true;
})
}
}
}
}
}
</script>
<style>
</style>