提交 b8fe4bc4 authored 作者: 翟畅's avatar 翟畅

Merge branch 'dev' of http://test16.zhongdianyun.com/zhaichang/rs-admin into dev

......@@ -57,4 +57,14 @@ export function deleteFileAPI(data) {
method: 'post',
data
})
}
//文件上传
export function uploadFileAPI(data,config={}) {
return request({
url: `${requestPath.file}/upload/info`,
method: 'post',
data,
...config,
})
}
\ No newline at end of file
......@@ -7,7 +7,12 @@ import { isPhone } from "@/libs/wechat";
const qs = require('qs');
const service = axios.create({
baseURL: SettingMer.httpUrl,
timeout: 60000 // 过期时间
timeout: 60000, // 过期时间
// onUploadProgress: event => {
// // event.loaded:已上传文件大小
// // event.total:被上传文件的总大小
// console.log(Number((event.loaded / event.total * 100) | 0));
// }
})
// request interceptor
......
......@@ -42,7 +42,7 @@
<el-input v-model="dataForm.source" style="width:85%;"></el-input>
</el-form-item> -->
<el-form-item label="附件:" prop="annexName">
<el-upload :action="`${fileUrl}upload/info`" :show-file-list="false" accept=".rar,.zip"
<el-upload :action="`${fileUrl}upload/info`" :show-file-list="false"
:on-success="handleSuccess" :on-error="handleError" :before-upload="beforeUpload" style="float:left;">
<el-button size="small" type="primary" :loading='loading' :disabled="loading">上传文件</el-button>
</el-upload>
......@@ -459,12 +459,12 @@ export default {
this.loading = false
this.$message.error('文件上传失败');
},
beforeUpload(file) { //annex限制
let type = file.name.slice(file.name.lastIndexOf('.')+1).toLowerCase()
if (!(type == 'zip'||type == 'rar')) {
this.$message.warning('上传文件仅支持rar或zip格式!');
return false;
}
beforeUpload(file) { //附件限制
// let type = file.name.slice(file.name.lastIndexOf('.')+1).toLowerCase()
// if (!(type == 'zip'||type == 'rar')) {
// this.$message.warning('上传文件仅支持rar或zip格式!');
// return false;
// }
this.loading = true
},
......
......@@ -59,14 +59,15 @@
</div>
</el-form-item>
<el-form-item label="视频文件:" prop="video">
<el-upload :action="`${fileUrl}upload/info`" :show-file-list="false" style="display:inline-block;"
:on-success="handleVideoSuccess" :before-upload="beforeVideoUpload" accept=".mp4,.avi,.mov,.wmv,.3gp,.webm,.flv,.rmvb" :disabled="loading">
<!-- 使用:http-request自定义上传指令,:on-success, :on-error指令是不会触发的 -->
<el-upload action="string" :show-file-list="false" style="display:inline-block;"
:before-upload="beforeVideoUpload" :http-request="handleRequest" accept=".mp4,.avi,.mov,.wmv,.3gp,.webm,.flv,.rmvb" :disabled="loading">
<!-- <div class="upload_btn" style="background:#1F71FF">上传文件</div> -->
<el-button size="small" type="primary" :loading='loading' :disabled="loading">上传文件</el-button>
</el-upload>
<span class="video_names">{{dataForm.videoName?dataForm.videoName:'未上传文件'}}</span>
<i v-if="dataForm.video" class="el-icon-delete" style="color:#f56c6c;font-size:16px;cursor:pointer" @click="deleteSource"></i>
<div v-if="showProgress" class="progress"><el-progress :percentage="progress"></el-progress></div>
<div class="progress" v-if="showProgress"><el-progress :percentage="progressPercent"></el-progress></div>
<div v-if="dataForm.video">
<video :src="`${fileUrl}?fileName=${dataForm.video}&isOnLine=true`" controls class="video_style"></video>
</div>
......@@ -101,7 +102,7 @@
<script>
import { videoSaveAPI, videoDetailsAPI } from '@/api/resource/video'
import { sortListAPI,labelListAPI,authorLibraryAPI,deleteFileAPI } from '@/api/common'
import { sortListAPI,labelListAPI,authorLibraryAPI,deleteFileAPI, uploadFileAPI, } from '@/api/common'
import { fileUrl } from '@/utils/global'
import { formatSort } from '@/utils/format'
import { valValidate } from '@/utils/validate'
......@@ -167,6 +168,7 @@ export default {
translatorList:[],
sortList: [],
options: [],
progressPercent: 0,
}
},
created() {
......@@ -329,6 +331,43 @@ export default {
}
return isFile && isLimit;
},
handleRequest(data) {
let formdata = new FormData();
formdata.append('file', data.file);
const config = {
onUploadProgress: event => {
this.showProgress = true
// event.loaded:已上传文件大小
// event.total:被上传文件的总大小
this.progressPercent = Number((event.loaded / event.total * 100) | 0);
// console.log(event,7777777)
}
};
uploadFileAPI(formdata,config).then(res=>{
// console.log(res,666666)
if (res.data) {
this.progressPercent = 100;
this.loading = false
this.showProgress = false
this.$message.success("文件上传成功");
this.dataForm.video = res.data.fileName
this.dataForm.videoName = res.data.originalFileName
this.dataForm.size = res.data.size
this.dataForm.timeLength = res.data.time
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate('video');
})
} else {
this.progressPercent = 0;
this.loading = false
this.showProgress = false
this.$message.warning("文件上传失败");
}
}).catch(err=>{
console.log(err)
})
// console.log('uploadRes',uploadRes);
},
handleVideoSuccess(response, file, fileList){//视频上传成功
this.loading = false
this.dataForm.video = response.fileName
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论