|
|
@@ -48,17 +48,22 @@
|
|
|
</view>
|
|
|
<compress ref="compress"></compress>
|
|
|
<toast ref="toast"></toast>
|
|
|
+ <uploadAlert ref="uploadAlert" :updateProgress="updateProgress" @cancelUpload="cancelUpload"></uploadAlert>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import compress from "@/components/compress.vue"
|
|
|
import uploadImg from "@/components/uploadImg/uploadImg.vue"
|
|
|
+ import uploadAlert from "@/components/alert/uploadAlert.vue"
|
|
|
+ import config from "@/assets/http/config.js"
|
|
|
+ let uploadTask
|
|
|
export default {
|
|
|
name: '',
|
|
|
components: {
|
|
|
compress,
|
|
|
- uploadImg
|
|
|
+ uploadImg,
|
|
|
+ uploadAlert
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -82,6 +87,7 @@
|
|
|
|
|
|
applyInfo: {},
|
|
|
activeType: '', //活动类型: VIDEO_TEXT视频图文 IMAGE_TEXT图片文本
|
|
|
+ updateProgress: '', //上传进度
|
|
|
};
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
@@ -161,19 +167,26 @@
|
|
|
* 上传视频作品
|
|
|
*/
|
|
|
async uploadVideoWork() {
|
|
|
- this.$dialog.showLoading('正在上传中..')
|
|
|
let resp = await this.chooseVideo()
|
|
|
+ // this.$dialog.showLoading('正在上传中..')
|
|
|
+ this.$refs.uploadAlert.show = true;
|
|
|
//上传视频链接
|
|
|
- let videoRes = await this.$api.uploadFile(resp.tempFilePath)
|
|
|
- this.applyInfo.videoUrl = videoRes.data.data.link
|
|
|
+ let videoRes = await this.uploadVideo(resp.tempFilePath)
|
|
|
+ this.applyInfo.videoUrl = videoRes.data.link;
|
|
|
//上传视频封面链接
|
|
|
- let coverRes = await this.$api.uploadFile(resp.thumbTempFilePath)
|
|
|
+ // let coverRes = await this.$api.uploadFile(resp.thumbTempFilePath)
|
|
|
// this.applyInfo.imgUrl = coverRes.data.data.link
|
|
|
// this.$refs.uploadImg.imgList = [this.applyInfo.imgUrl]
|
|
|
//显示的是视频链接
|
|
|
this.showUrl = this.applyInfo.videoUrl
|
|
|
uni.hideLoading()
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 取消视频作品
|
|
|
+ */
|
|
|
+ cancelUpload(){
|
|
|
+ uploadTask.abort();
|
|
|
+ },
|
|
|
/**
|
|
|
* 选择视频
|
|
|
*/
|
|
|
@@ -184,7 +197,12 @@
|
|
|
count: 1,
|
|
|
sourceType: ['album'],
|
|
|
success: function(res) {
|
|
|
- console.log("视频大小", res)
|
|
|
+ let fileSize = (res.size/1024/1024).toFixed(2)
|
|
|
+ console.log("视频大小", fileSize)
|
|
|
+ if(fileSize > 50){
|
|
|
+ that.$refs.toast.error('上传视频不能大于50M')
|
|
|
+ return
|
|
|
+ }
|
|
|
resolve(res)
|
|
|
},
|
|
|
fail() {
|
|
|
@@ -193,6 +211,41 @@
|
|
|
});
|
|
|
})
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 上传视频
|
|
|
+ */
|
|
|
+ uploadVideo(tempFilePath) {
|
|
|
+ let that = this;
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uploadTask = uni.uploadFile({
|
|
|
+ url: `${config.baseURL}/blade-resource/oss/endpoint/put-file`,
|
|
|
+ filePath: tempFilePath,
|
|
|
+ name: 'file',
|
|
|
+ formData: { user: 'test' },
|
|
|
+ header: { "Blade-Auth": uni.getStorageSync('token') },
|
|
|
+ success(res) {
|
|
|
+ resolve(JSON.parse(res.data))
|
|
|
+ that.$refs.uploadAlert.show = false;
|
|
|
+ that.updateProgress = '';
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ //用户取消上传
|
|
|
+ if(err.errMsg === 'uploadFile:fail abort'){
|
|
|
+ that.$refs.uploadAlert.show = false;
|
|
|
+ that.updateProgress = '';
|
|
|
+ that.$refs.toast.warn('取消上传')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ uploadTask.onProgressUpdate(function(res) {
|
|
|
+ that.updateProgress = res;
|
|
|
+ console.log('上传进度' + res.progress);
|
|
|
+ console.log('已经上传的数据长度' + res.totalBytesSent);
|
|
|
+ console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
/**
|
|
|
* 压缩视频
|
|
|
*/
|