完善文档上传附件
This commit is contained in:
parent
29fa3a9ca4
commit
c771b9e432
@ -7,32 +7,26 @@
|
|||||||
class="upload"
|
class="upload"
|
||||||
:action="oss.host"
|
:action="oss.host"
|
||||||
:data="upload_data"
|
:data="upload_data"
|
||||||
|
:file-list="fileList"
|
||||||
:show-file-list="false"
|
:show-file-list="false"
|
||||||
:on-success="handleSuccess"
|
:on-success="handleSuccess"
|
||||||
:on-error="handleError"
|
:on-error="handleError"
|
||||||
|
:on-remove="handleRemove"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
:before-upload="beforeUpload"
|
:before-upload="beforeUpload"
|
||||||
:http-request="uploadFile"
|
:http-request="uploadFile"
|
||||||
drag
|
drag
|
||||||
multiple
|
multiple
|
||||||
|
:auto-upload="true"
|
||||||
:limit="5"
|
:limit="5"
|
||||||
:disabled="importDis"
|
|
||||||
>
|
>
|
||||||
<div v-if="!importTrue">
|
<div>
|
||||||
<el-icon class="el-icon--upload"><sc-icon-UploadExcel /></el-icon>
|
<el-icon class="el-icon--upload"><sc-icon-UploadExcel /></el-icon>
|
||||||
<div class="el-upload__text">
|
<div class="el-upload__text">
|
||||||
<span class="laText">请将Excel拖到此处</span>
|
<span class="laText">请将Excel拖到此处</span>
|
||||||
<span class="tipText">,或点击上传</span><em> Excel</em>
|
<span class="tipText">,或点击上传</span><em> Excel</em>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
|
||||||
<div class="el-upload__text">
|
|
||||||
<el-icon class="trueIcon el-icon--upload">
|
|
||||||
<sc-icon-FormXls />
|
|
||||||
<!-- <div class="deleteFile" @click="deleteFile"><el-icon class="icon"><el-icon-Close/></el-icon></div>-->
|
|
||||||
</el-icon>
|
|
||||||
<div class="el-upload__text">文件已选择最大,可以点击立即上传或替换文件。</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<template #tip>
|
<template #tip>
|
||||||
<div class="el-upload__tip">
|
<div class="el-upload__tip">
|
||||||
@ -41,10 +35,19 @@
|
|||||||
<slot name="download"></slot>
|
<slot name="download"></slot>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="importBox" v-if="progressShow">
|
<div class="importBox" v-if="progressShow && fileList.length>0">
|
||||||
<div class="item" v-for="item in listProgress" :key="item">
|
<div v-if="uploadShow">
|
||||||
<div class="name">{{item.type_desc}}</div>
|
<div class="item" v-for="(item,index) in fileList" :key="item">
|
||||||
<el-progress class="exportPopover" :text-inside="true" :stroke-width="12" :percentage="item.rate" />
|
<div class="name">{{item.name}}</div>
|
||||||
|
<el-progress class="exportPopover" :text-inside="true" :stroke-width="12" :percentage="0" />
|
||||||
|
<div class="deleteFile" @click="deleteFileNum(index)"><el-icon class="icon"><el-icon-Close/></el-icon></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<div class="item" v-for="item in listProgress" :key="item">
|
||||||
|
<div class="name">{{item.file_name}}</div>
|
||||||
|
<el-progress class="exportPopover" :text-inside="true" :stroke-width="12" :percentage="item.rate" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -70,20 +73,17 @@ export default {
|
|||||||
data(){
|
data(){
|
||||||
return{
|
return{
|
||||||
visible: false,
|
visible: false,
|
||||||
text:"",
|
fileList:[], // 正在上传的文件
|
||||||
listFile:[],
|
listProgress:[], // 已上传的文件
|
||||||
listProgress:[],
|
|
||||||
|
|
||||||
oss:{
|
oss:{
|
||||||
host:''
|
host:''
|
||||||
},
|
},
|
||||||
upload_data:{},
|
upload_data:{},
|
||||||
fileShow:false,
|
|
||||||
params:{},
|
params:{},
|
||||||
|
|
||||||
importDis:false,
|
|
||||||
importTrue:false,
|
|
||||||
progressShow:false,
|
progressShow:false,
|
||||||
|
uploadShow:false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup(){
|
setup(){
|
||||||
@ -101,20 +101,15 @@ export default {
|
|||||||
methods:{
|
methods:{
|
||||||
getWsResult(res){
|
getWsResult(res){
|
||||||
if(res.data && (res.data.type == 12)){
|
if(res.data && (res.data.type == 12)){
|
||||||
let flag = this.listProgress.some(em=>em.file_unique_id == res.data.file_unique_id);
|
this.listProgress.forEach((em,index)=>{
|
||||||
if(!flag){
|
if(em.uuid == res.data.file_unique_id){
|
||||||
this.listProgress.push(res.data)
|
em.rate = res.data.rate
|
||||||
}else{
|
if(res.data.status == 1){
|
||||||
this.listProgress.forEach((em,index)=>{
|
this.listProgress.splice(index,1);
|
||||||
if(em.file_unique_id == res.data.file_unique_id){
|
this.fileList.splice(index,1);
|
||||||
em.rate = res.data.rate
|
|
||||||
if(res.data.status == 1){
|
|
||||||
this.listProgress.splice(index,1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
this.progressShow = true;
|
|
||||||
if(this.listProgress.length==0 && res.data.status == 1){
|
if(this.listProgress.length==0 && res.data.status == 1){
|
||||||
this.progressShow = false;
|
this.progressShow = false;
|
||||||
}
|
}
|
||||||
@ -130,47 +125,53 @@ export default {
|
|||||||
},
|
},
|
||||||
// 上传前
|
// 上传前
|
||||||
beforeUpload(file){
|
beforeUpload(file){
|
||||||
// const text = file.name.split('.').pop();
|
this.progressShow = true;
|
||||||
// if(!['xls','xlsx'].includes(text)){
|
this.uploadShow = true;
|
||||||
// this.$message.warning(`只能选择的excel文件类型`);
|
this.fileList.push(file);
|
||||||
// return false;
|
return true
|
||||||
// }
|
|
||||||
// this.progressShow = true;
|
|
||||||
this.text = file.name;
|
|
||||||
this.listFile.push(file);
|
|
||||||
return true
|
|
||||||
},
|
},
|
||||||
async uploadFile() {
|
async uploadFile() {
|
||||||
try {
|
try {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
for(let i in this.listFile){
|
for(let i in this.fileList){
|
||||||
formData.append('files[]', this.listFile[i]);
|
formData.append('files[]', this.fileList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const key in this.upload_data) {
|
for (const key in this.upload_data) {
|
||||||
formData.append(key, this.upload_data[key]);
|
formData.append(key, this.upload_data[key]);
|
||||||
}
|
}
|
||||||
this.params = formData;
|
this.params = formData;
|
||||||
this.importTrue = this.listFile.length>4?true:false;
|
|
||||||
this.importDis = this.listFile.length>4?true:false;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteFile(){
|
|
||||||
this.importTrue = false;
|
deleteFileNum(num){
|
||||||
setTimeout(()=>{
|
this.handleRemove(this.fileList[num], this.fileList);
|
||||||
this.importDis = false;
|
|
||||||
},100)
|
|
||||||
},
|
},
|
||||||
async save() {
|
async save() {
|
||||||
const res = await this.$API.docs.manager.upload.post(this.params);
|
const res = await this.$API.docs.manager.upload.post(this.params);
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
this.$message.success('提交成功,正在上传');
|
this.$message.success('提交成功,正在上传');
|
||||||
|
this.uploadShow = false;
|
||||||
|
this.listProgress = res.data.files;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleExceed(){
|
||||||
|
this.$message.warning('文件超出最大限制');
|
||||||
|
},
|
||||||
|
handleRemove(file,fileList){
|
||||||
|
const index = fileList.findIndex(f => f.uid === file.uid);
|
||||||
|
if (index !== -1) {
|
||||||
|
fileList.splice(index, 1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 上传成功
|
// 上传成功
|
||||||
handleSuccess(){
|
handleSuccess(response, file, fileList){
|
||||||
|
const index = fileList.findIndex(f => f.uid === file.uid);
|
||||||
|
if (index !== -1) {
|
||||||
|
fileList.splice(index, 1);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 上传失败
|
// 上传失败
|
||||||
handleError(){
|
handleError(){
|
||||||
@ -214,7 +215,6 @@ export default {
|
|||||||
width: 12px;height: 12px;
|
width: 12px;height: 12px;
|
||||||
color: var(--el-color-white);
|
color: var(--el-color-white);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.upload ::v-deep .el-upload__tip{
|
.upload ::v-deep .el-upload__tip{
|
||||||
@ -233,7 +233,26 @@ export default {
|
|||||||
padding: 10px 5px;
|
padding: 10px 5px;
|
||||||
margin: 15px 0;
|
margin: 15px 0;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
.item{margin-bottom: 10px;}
|
.item{
|
||||||
|
margin-bottom: 10px;position: relative;
|
||||||
|
.deleteFile{
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 1px;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #AAAAAA;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
.icon{
|
||||||
|
width: 12px;height: 12px;
|
||||||
|
color: var(--el-color-white);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
.item:last-child{margin-bottom: 0;}
|
.item:last-child{margin-bottom: 0;}
|
||||||
.name{margin-bottom: 5px;font-size: 13px;}
|
.name{margin-bottom: 5px;font-size: 13px;}
|
||||||
.exportPopover ::v-deep .el-progress-bar__innerText{
|
.exportPopover ::v-deep .el-progress-bar__innerText{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user