//父页面部分
<attachment @newFileList="newFileList" :operationType="operationType" btnName="上传PO/PI凭证" fileListType="1" :fileList="fileList" uploadBtnWidth="91"></attachment>
//父页面组件引入
import attachment from 'base/publicComponents/attachment'
components:{
  attachment
},
//父页面接收回传的附件列表
newFileList(reList,fileListType){
  let vm = this;
  if(fileListType=='1'){
    vm.fileList1 = reList;
  }else if(fileListType=='2'){
    vm.fileList2 = reList;
  }
},
//子组件部分
<template>
<div class="item attachment attachmentNew">
<span class="btnSpan" v-show="operationType<2" :title="btnName">
<a id="btnName">{{btnName}}</a>
<input type ="file" name="file" @change="uploadFileOnlyOne($event)" class="hiddenClass" :style="{width:uploadBtnWidth + 'px'}"/>
</span>
<ul class="fileContent">
<li v-show="fileList.length>0">
<div class="fileName">文件名</div>
<div class="fileSize">文件大小</div>
<div class="UploadingPerson">上传人</div>
<div class="fileTime">上传时间</div>
<div class="fileRemove" v-show="operationType<2">操作</div>
</li>
<li v-for="(item,index) in fileList">
<div class="fileName"><a :href="prefixUrl+'/file/'+item.url" target="_blank" style="color:#78BC27" :title="item.fileName">{{item.fileName}}</a></div>
<div class="fileSize">{{item.fileSize}}</div>
<div class="UploadingPerson">{{item.userName}}</div>
<div class="fileTime">{{item.createTime|dateDay}}</div>
<div class="fileRemove" v-show="operationType<2" @click="delFile(item.id)"><span class="fa fa-trash-o"></span></div>
</li>
</ul>
</div>
</template>
<script>
import { modal } from '../../common/js/modal.js'
export default {
props:{
//判断是否有删除操作功能,只有编辑和创建的时候才有此功能
operationType:{
default:0
},
//按钮名称与隐藏的input上传附件按钮的宽度要保持一致
uploadBtnWidth:{
default:82
},
//上传附件按钮的名称
btnName:{
type: String,
default:''
},
//同一页面存在多个附件上传按钮,用来区分当前操作的按钮是哪一个;
fileListType:{
type: String,
default:''
},
//当前附件列表
fileList:{
type: Array,
default:[]
},
},
data(){
return{
prefixUrl:$.getCookie('prefixUrl'),
}
},
methods:{
delFile(thisId){
let vm = this;
var params = {
id: thisId
};
var url = '/file/delete';
$.ajaxSend(url, params).done(function (data) {
if (data.code === '00000000') {
vm.fileList.forEach((el,index) =>{
if(thisId===el.id){
vm.fileList.splice(index,1);
}
});
vm.$emit("newFileList",vm.fileList,vm.fileListType);
}
})
},
uploadFileOnlyOne(el){
let vm = this;
var getFiles = el.target.files[0];
var fileName = getFiles.name;
var fFN = fileName.substring(0,fileName.lastIndexOf('.'));
if(/[@#\$%\^&\*]+/g.test(fFN)){
modal.error('文件名不能包含特殊符号!');
return false;
}
var fLN = fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);
if(fLN=='doc'||fLN=='docx'||fLN=='xls'||fLN=='xlsx'||fLN=='pdf'||fLN=='PDF'||fLN=='jpg'||fLN=='JPG'||fLN=='png'||fLN=='xlsx'||fLN=='xls'||fLN=='eml'){ }else{
modal.error('只允许上传word/excel/pdf/图片jpg,png/eml文件格式。');
return false;
}
var commonUrl = $.getCookie('prefixUrl');
let sessionId=$.getCookie('sessionId');
let areaCode=$.getCookie('areaCode');
let formData = new FormData();
formData.append('sessionId', sessionId);
// formData.append('areaCode', areaCode);
formData.append('file',getFiles);
$.ajax({
url: commonUrl+'/file/upload',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (data) {
if(data.payload.results.file.fileName){
vm.fileList.push(data.payload.results.file);
vm.$emit("newFileList",vm.fileList,vm.fileListType);
}
},
error: function (data) {
console.log('server error!');
}
});
},
},
filters: {
dateDay(input) {
if(input){
var oDate = new Date(input);
return oDate.getFullYear() + '-' + (oDate.getMonth() + 1 > 9 ? oDate.getMonth() + 1 : '0' + (oDate.getMonth() + 1)) + '-' + (oDate.getDate() > 9 ? oDate.getDate() : '0' + oDate.getDate());
}
},
},
mounted(){
//console.log(document.getElementById('btnName').offsetWidth);//获取按钮名称的宽度
}
}
</script>
<style scoped lang='stylus'>
.attachmentNew
.fileContent
padding-left 16px
li
div
display: inline-block
.fileName
width: 200px
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap; //文本不换行,这样超出一行的部分被截取,显示...
a:hover
text-decoration underline
.fileSize
width: 80px
.UploadingPerson
width: 100px
.fileTime
width: 120px
.fileRemove
width: 40px
span
color #78BC27
&:hover
cursor pointer
.btnSpan
margin 4px
a
padding 2px 4px
border 1px solid #78BC27
border-radius 4px
background #78BC27
color white
font-size 12px
.hiddenClass
opacity: 0;
position:relative;
top:-20px;
height:20px; </style>

附件上传vue组件封装(一)的更多相关文章

  1. React实战之Ant Design—Upload上传_附件上传

    React实战之Ant Design—Upload上传_附件上传 Upload组件大家都在官方文档中看过了,但写的时候还是会遇到许多问题,一些新手看了文档后感觉无从下手,本文过多的简绍就不说了,直接看 ...

  2. 循序渐进VUE+Element 前端应用开发(23)--- 基于ABP实现前后端的附件上传,图片或者附件展示管理

    在我们一般系统中,往往都会涉及到附件的处理,有时候附件是图片文件,有时候是Excel.Word等文件,一般也就是可以分为图片附件和其他附件了,图片附件可以进行裁剪管理.多个图片上传管理,及图片预览操作 ...

  3. 基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用

    大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随笔<Web开发中的文件上传组件uploadify的使用>中可以看到,Asp.NET中 ...

  4. 基于MVC4+EasyUI的Web开发框架形成之旅(4)--附件上传组件uploadify的使用

    大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随笔<Web开发中的文件上传组件uploadify的使用>中可以看到,Asp.NET中 ...

  5. (转)基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用

    http://www.cnblogs.com/wuhuacong/p/3343967.html 大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随 ...

  6. java 附件上传、下载前后端代码

    前言:业务需要:附件上传,需要同时满足浏览器上传,和APP上传附件,并且浏览器端不可使用form表单提交,因为表单提交无法直接获取返回值,除非刷新页面才可显示上传的附件.所以此处使用ajaxfileu ...

  7. 使用plupload做一个类似qq邮箱附件上传的效果

    公司项目中使用的框架是springmvc+hibernate+spring,目前需要做一个类似qq邮箱附件上传的功能,暂时只是上传小类型的附件 处理过程和解决方案都需要添加附件,处理过程和解决方案都可 ...

  8. SNF开发平台WinForm之六-上传下载组件使用-SNF快速开发平台3.3-Spring.Net.Framework

    6.1运行效果: 6.2开发实现: 1.先在要使用的项目进行引用,SNF.WinForm.Attachments.dll文件. 2.在工具箱内新建选项卡->选择项,浏览找到文件SNF.WinFo ...

  9. fsLayuiPlugin附件上传使用说明

    fsLayuiPlugin 是一个基于layui的快速开发插件,支持数据表格增删改查操作,提供通用的组件,通过配置html实现数据请求,减少前端js重复开发的工作. GitHub下载 码云下载 测试环 ...

随机推荐

  1. Turbine Netflix

    Turbine是聚合服务器发送事件流数据的一个工具,用来监控集群下hystrix的metrics情况. 本实例是在consul做为服务发现时的配置. Turbine聚合器: 可以参照:https:// ...

  2. Python中使用第三方库xlrd来写入Excel文件示例

    Python中使用第三方库xlrd来写入Excel文件示例 这一篇文章就来介绍下,如何来写Excel,写Excel我们需要使用第三方库xlwt,和xlrd一样,xlrd表示read xls,xlwt表 ...

  3. IntelliJ IDEA入门之常用配置以及问题解决(持续更新中)

    软件版本: IntelliJ IDEA 2019.1.1(Ultimate Edition) 运行环境: JDK1.8, Tomcat8.0, Maven3.6 我们在学习新的无论是jar包, 框架, ...

  4. 【POJ - 1970】The Game(dfs)

    -->The Game 直接中文 Descriptions: 判断五子棋棋局是否有胜者,有的话输出胜者的棋子类型,并且输出五个棋子中最左上的棋子坐标:没有胜者输出0.棋盘是这样的,如图 Samp ...

  5. 2019年最新Web安全攻防班课程

    咨询请加QQ:1373721311 或 2644148223 课程核心大纲总览 Web安全攻防班以业界权威的OWASP TOP 10的漏洞为主干课程.更加详细教学思维导图可访问如下链接:https:/ ...

  6. 酷Q插件_SDK———入门与使用

    1.这里使用的是易语言的SDK,所以请看不惯的人自行离开.{wymbf.} 1.2 这里不会直接给你工程,请用动手打代码,动脑思考. 1.3 不知道.不了解酷Q是干嘛的,请访问:https://cqp ...

  7. SQL --------JDBC 用用户名查询用户的信息

    package demo; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; ...

  8. freeRTOS学习8-22

    互斥量的优先级继承机制可以减少优先级翻转问题,通过将持有锁的任务的优先级提升到当前任务中优先级任务最高的任务. #define KEY1_EVENT (0x01 << 0) #define ...

  9. gdb移植(交叉版本)

    Gdb下载地址: http://ftp.gnu.org/gnu/gdb/ termcap下载地址:http://ftp.gnu.org/gnu/termcap/tar -zxvf termcap-1. ...

  10. 使用 WijmoJS 轻松实现撤消重做(Undo /Redo)

    使用 WijmoJS 轻松实现撤消重做(Undo /Redo) 在V2019.0 Update2 的全新版本中,WijmoJS能够轻松实现撤消和重做操作,使Web应用程序的使用更加友好.更加高效. 不 ...