1.实现功能:文件上传、下载以及删除  不过API中的下载监听方法download一直没有触发,(不确定是我写的有问题还是咋地,反正就是触发不了下载)随用预览的监听方法preview来实现了下载。

组件调用

             <new-upload
ref="upDataMout"
:uploadActionUrl="url.uploadAction"
:urlDownload="url.urlDownload"
:deleteUrl="url.deleteUrl"
@uploadFile="uploadFile"
>
            </new-upload>

自定义上传组件

<template>

  <a-upload
name="file"
:multiple="true"
:disabled="disabled"
:file-list="fileList1"
@change="handleUpload"
@preview="download"
:remove="handleRemove"
:before-upload="beforeUpload"
:showUploadList="{
showDownloadIcon:true,
showRemoveIcon:true
}"
>
<a-button size="small"><a-icon type="upload" style="font-size: 12px;"/>{{ text }}</a-button>
</a-upload> </template> <script>
import axios from 'axios'
import Vue from 'vue'
import {postAction} from '@/api/analysis.js' //接口请求的文件
const FILE_TYPE_ALL = "all" export default {
name: 'JUpload',
data(){
return {
formData:{},//接口传参
fileList1: [],
filedirList:[],
nameList:[],
uploading: false,
}
},
props:{
text:{
type:String,
required:false,
default:"点击上传"
},
fileType:{
type:String,
required:false,
default:FILE_TYPE_ALL
},
value:{
type:[String,Array],
required:false
},
// update-begin- --- author:wangshuai ------ date:20190929 ---- for:Jupload组件增加是否能够点击
disabled:{
type:Boolean,
required:false,
default: false
},
// 用于动态传参修改上传路径
uploadActionUrl:{
type:String,
required:false,
default:"",
},
// 下载地址的动态传参
urlDownload:{
type:String,
required:false,
default:"",
},
deleteUrl:{//删除文件的接口
type:String,
required:false,
default:"",
}
},
methods:{
uidGenerator(){//随机生成
return '-'+parseInt(Math.random()*10000+1,10);
},
add(){//新增原来老数据清空
this.$nextTick(() => {
this.fileList1 = [];
this.filedirList = [];
this.nameList = [];
})
},
edit(recode){//编辑文件回显
console.log("编辑1111",recode);
const data = recode;
const fileName = data.fileName?data.fileName.split(","):[];
const filedir=data.folderId?data.folderId:'';
this.fileList1 = [];
let fileList = [],filedirList=[];
for(var a=0;a<fileName.length;a++){
fileList.push({
uid:this.uidGenerator,
name:fileName[a],
status: 'done',
url: filedir,
response:{
status:"history",
message:filedir
}
});
filedirList.push(filedir);
}
this.$nextTick(() => {
this.fileList1 = fileList;
this.filedirList = filedirList;
this.nameList = fileName;
})
},
handleRemove(file) {//删除文件
this.$confirm("确认删除该文件?",{
type:'error'}).then(()=>{
console.log("确认操作");
const index = this.fileList1.indexOf(file);
const newFileList = this.fileList1.slice();
newFileList.splice(index, 1);//把当前的文件删除
this.fileList1 = newFileList;
const fileName = file.name;
const filedir = this.filedirList[index];//文件地址数组
let newPathList = this.filedirList.slice();
newPathList.splice(index,1);//删除当前文件名
this.filedirList = newPathList; let newNameList = this.nameList.slice();
newNameList.splice(index,1);//删除当前文件名
this.nameList = newNameList;
let url = `${this.deleteUrl}?fileName=${fileName}&filedir=${filedir}`;
let that = this;
postAction(url).then((res) => {
if(res.status==1) {
let paras={
'fileName':newNameList,
'filedir':that.filedirList[0]
}
that.$emit('uploadFile', paras);//文件数据传给父组件
that.$message.success(`删除成功!`);
}
})
}).catch(()=>{
console.log("取消操作");
})
},
beforeUpload(file) {
this.fileList1 = [...this.fileList1, file];
return false;
},
handleUpload(file) {//文件上传监听
console.log("file:",file);
const { fileList1,filedirList,nameList } = this;
const formData = new FormData();
fileList1.forEach(file => {
formData.append('files', file); //文件上传的时候传参
if(file.status!="done" && fileList1.length>1){
formData.append('filedir', filedirList[0]); //文件上传的时候传参
}
});
this.uploading = true;
let that =this;
if(file.file.status=="removed"){//删除状态
return;
}
//文件上传接口请求
axios({
method: "POST",
url: `${this.uploadActionUrl}`,
data: formData,
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(function(res) {
if(res.status==200){
const data = res.data;
let path = filedirList,name = nameList;
path.push(data.filedir);
name.push(file.file.name);
that.nameList = name;
//文件夹id,一个任务一个id即同一个新增上传多个文件都是同一个id
that.filedirList = path; console.log("path:",that.filedirList);
that.fileList1[that.fileList1.length-1].url=data.filedir;//接口返回的上传路径
that.fileList1[that.fileList1.length-1].status="done";//必须该状态下才可以预览和下载 that.$message.success(`${data.fileName} 上传成功!`);
let paras={
'fileName':nameList,
'filedir':that.filedirList[0]
}
that.$emit('uploadFile', paras);//文件数据传给父组件
}
console.log(res);
}).catch(function(error){
console.log(error);
this.$message.warning(error.response);
}); },
download(file){//下载文件
// console.log("fileL:",file);
const index = this.fileList1.indexOf(file);
const filedir=this.filedirList[index];
const that = this;
let url = `${this.urlDownload}?fileName=${file.name}&filedir=${filedir}`;
window.open(url);//下载文件 }, },
model: {
prop: 'value',
event: 'change'
}
}
</script> <style scoped> </style>

  

antdVue--Upload使用的更多相关文章

  1. AntdVue使用

    AntdVue使用 配置与安装 #安装 npm install ant-design-vue --save #按需加载 import { Button, Layout, Row, Col, Menu, ...

  2. 解决ngnix服务器上的Discuz!x2.5 Upload Error:413错误

    1.修改php.ini sudo nano /etc/php5/fpm/php.ini #打开php.ini找到并修改以下的参数,目的是修改上传限制 max_execution_time = 900 ...

  3. 页面无刷新Upload File

    页面无刷新Upload File. 利用jquery.form.js的ajaxForm提交文件. 具体参考以下代码: 前台html <%@ Page Language="C#" ...

  4. 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?

    复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...

  5. 多文档上传(upload multiple documents)功能不能使用怎么办?

    问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰 ...

  6. web 前端常用组件【06】Upload 控件

    因为有万恶的IE存在,所以当Web项目初始化并进入开发阶段时. 如果是项目经理,需要知道客户将会用什么浏览器来访问系统. 明确知道限定浏览器的情况下,你才能从容的让手下的封装必要的前端组件. 本篇文章 ...

  7. AzCopy Upload Files

    We can use many ways upload our Files to Azure, Than I  Introduction to you a good way, AzCopy ! 1. ...

  8. upload&&download

    package am.demo;  import java.io.File;  import java.io.IOException;  import java.util.Iterator;  imp ...

  9. jQuery File Upload 单页面多实例的实现

    jQuery File Upload 的 GitHub 地址:https://github.com/blueimp/jQuery-File-Upload 插件描述:jQuery File Upload ...

  10. jQuery File Upload done函数没有返回

    最近在使用jQuery File Upload 上传图片时发现一个问题,发现done函数没有callback,经过一番折腾,找到问题原因,是由于dataType: ‘json’造成的,改为autoUp ...

随机推荐

  1. 阶梯场景jp@gc - Stepping Thread Group (deprecated)

    1.新建线程,添加配置元件.监听器 由上可见: 需要启动100个线程, 然后间隔30s就持续5s去启动10个线程, 那么就需要这样重复操作10次,才能100个线程全部启动. 最后整体100个线程持续运 ...

  2. Section 2.1: Falsy VSTruthy Value and == VS ===

    Falsy VS Truthy Value and == VS === Falsy values: undefined, null, 0, '', NaN Truthy values: Not fal ...

  3. if语法案例

    if语法案例 1. 判断系统剩余内存 1) 脚本正文 2) 执行结果 2.监控web和数据库的方法 1) 端口监控 2) 进程监控 3) 客户端模拟 4) 数据库判断* 3.mysql数据库检测命令演 ...

  4. 实验:两片ESP8266,分别做客户端和服务器,实现双向收发数据

    手机做热点: 每片都做STATION

  5. 题解 UVA10859 【Placing Lampposts】

    交了N次,重构一次代码终于过了..... 题意:一片森林,1.输出占领所有边需要的最小的路灯个数 2.输出两端点均被占领的边的条数 3.只有一端被占领的边的条数 还是比较简单的 开始的时候思路不够清晰 ...

  6. npm不是内部或外部命令,也不是可运行的程序的解决办法

    通常是nodejs没有安装导致 转载https://segmentfault.com/a/1190000023390756 1.Node.js简介 Node.js 是一个基于 Chrome V8 引擎 ...

  7. uniapp输入空格

    uniapp   密码框输入空格(去除空格)的时候一直回显不及时  经过一番折腾 终于搞定 1.先赋值:     this.pwd = e.detail.value 2. 使用setTimeout(再 ...

  8. 路飞之-后台日志封装-前后端分离的rbac项目演示-全局异常处理封装-封装Response-luffy数据库创建-软件开发模式-User模块用户表-django的配置文件-开启media访问

    目录 路飞之-后台日志封装-前后端分离的rbac项目演示-全局异常处理封装-封装Response-luffy数据库创建-软件开发模式-User模块用户表-django的配置文件-开启media访问 今 ...

  9. 通过一个简单的实例来展示 Java 编程,创建文件 HelloWorld.java

    public class HelloWorld { public static void main(String[] args) { System.out.println("Hello Wo ...

  10. windows安装和重装系统后无法识别U盘

    安装系统的方法: 1. 方案一,用大白菜制写入pe系统,但必须先准备Windows安装包 方案二,把ISO格式的系统安装包直接写入到u盘,写入U盘的方法请百度 2.开机看到电脑的logo后,按f2(不 ...