附件上传

<div class="content" slot="content">
<div class="item attachment attachmentNew">
<span class="name">附件</span>
<span class="triggerUpLoad btnSpan" onclick="triggerUpLoadList(this)"><a>{{attachmentName}}</a></span>
<form class="uploadForm" style="padding-left: 150px">
<input type ="file" name="file" class="fileContent hiddenClass" onchange="doUploadList(this)"/>
<input type ="text" name="sessionId" class="hiddenClass"/>
</form>
<div class="picC">
<ul class="fileContent" id="fileBack">
<li>
<div class="fileName">文件名</div>
<div class="fileSize">文件大小</div>
<div class="UploadingPerson">上传人</div>
<div class="fileTime">上传时间</div>
<div class="fileRemove">操作</div>
</li>
</ul>
</div>
</div>
</div>
function doUpload(thisObj) {
var uploadFormAll=$(thisObj).parent('.uploadForm');
var areaCode=$.getCookie('areaCode');
var sessionId=$.getCookie('sessionId');
uploadFormAll.children('input:eq(1)').val(sessionId);
uploadFormAll.children('input:eq(2)').val(areaCode);
var commonUrl = $.getCookie('prefixUrl');
var fileName=$(thisObj)[0].files[0];
if(!fileName){
return false;
}
var thisP=$(thisObj).parent('form.uploadForm');
var formData = new FormData(thisP[0]);
//console.log(file[0].size);
//console.log(file[0].size/1024 + 'kb');
$.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){
var file=data.payload.results.file;
var imgUrl=commonUrl+'/file/'+file.url;
var fileName=file.fileName;
var fileLastName = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length);
//console.log(file[0].size/1024 + 'kb');
if(fileLastName=='jpg'||fileLastName=='png'||fileLastName=='wbm'||fileLastName=='gif'||fileLastName=='icon'){
var imgShow='<li picIds="'+file.id+'"><div class="enlargePic" onclick="closePic(this)"><img src="'+imgUrl+'" style="width:400px;height: 400px;border: 1px solid #78BC27" onclick="enlarge(this)"/></div><div style="height: 100px;padding: 0px;overflow: hidden" class="imgContent"><img src="'+imgUrl+'" style="width:100px;height: 100px" onclick="enlarge(this)"/><span onclick="removeImg(this,\''+file.id+'\')" class="removeImg removeImgFile">&times;</span></div></li>';
thisP.siblings('.picC').children('.picContent').append(imgShow);
}else{
if(fileLastName=='pptx'||fileLastName=='ppt'||fileLastName=='pps'||fileLastName=='docx'||fileLastName=='doc'||fileLastName=='xlsx'||fileLastName=='xls'){
imgUrl='http://view.officeapps.live.com/op/view.aspx?src='+imgUrl;
}
var imgShow='<li picIds="'+file.id+'"><div style="height: 24px;padding: 0px;overflow: hidden" ><a href="'+imgUrl+'" target="_blank" style="color:#78BC27"><span class="fileNameClass">'+fileName+'</span></a><span onclick="removeImg(this,\''+file.id+'\')" class="removeFile removeImgFile">&times;</span></div></li>';
thisP.siblings('.picC').children('.fileContent').append(imgShow);
}
}
},
error: function (data) {
console.log('server error!');
}
});
}
function removeImg(obj,thisId) {
$(obj).parent('div').parent('li').remove();
var params = {
id: thisId
};
var url = '/file/delete';
$.ajaxSend(url, params).done(function (data) {
if (data.code === '00000000') {
}
})
}
function enlarge(obj) {
var Left = (document.documentElement.clientWidth-400)/2;
var top = (document.documentElement.clientHeight-400)/2;
$(obj).parent('div').siblings('div').show().css('left',Left+'px').css('top',top+'px');
}
function enlargeNotice(obj) {
var thisTOP=document.getElementsByClassName('router');
var Left = (document.documentElement.clientWidth-400-220)/2;
var top = (document.documentElement.clientHeight-400)/2+thisTOP[0].scrollTop;
$(obj).parent('div').siblings('div').show().css('left',Left+'px').css('top',top+'px');
}
function closePic(obj) {
$(obj).hide();
}
function triggerUpLoad(obj) {
$(obj).siblings('form.uploadForm').children('.fileContent').trigger('click');
}
 
//列表展示的上传方式
function doUploadList(thisObj) {
var uploadFormAll=$(thisObj).parent('.uploadForm');
var areaCode=$.getCookie('areaCode');
var sessionId=$.getCookie('sessionId');
uploadFormAll.children('input:eq(1)').val(sessionId);
uploadFormAll.children('input:eq(2)').val(areaCode);
var commonUrl = $.getCookie('prefixUrl');
var fileName=$(thisObj)[0].files[0];
if(!fileName){
return false;
}
var fFN = fileName.name.substring(0,fileName.name.lastIndexOf('.'));
// console.log(/[@#\$%\^&\*]+/g.test(fFN));
if(/[@#\$%\^&\*]+/g.test(fFN)){
alert('文件名不能包含特殊符号!');
return false;
}
var fLN = fileName.name.substring(fileName.name.lastIndexOf('.')+1,fileName.name.length);
// console.log(fileName);
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{
// console.log(fLN);
alert('只允许上传word,excel,pdf,图片jpg/png,以及后缀名为.eml的邮件格式文件。');
return false;
}
var thisP=$(thisObj).parent('form.uploadForm');
// console.log(thisP[0]);
var formData = new FormData(thisP[0]);
//console.log(file[0].size);
//console.log(file[0].size/1024 + 'kb');
$.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){
var file=data.payload.results.file;
var imgUrl=commonUrl+'/file/'+file.url;
var fileName=file.fileName;
var fileLastName = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length);
var oDate = new Date(file.createTime);
createTime=oDate.getFullYear() + '-' + (oDate.getMonth() + 1 > 9 ? oDate.getMonth() + 1 : '0' + (oDate.getMonth() + 1)) + '-' + (oDate.getDate() > 9 ? oDate.getDate() : '0' + oDate.getDate());
//var imgUrlScan='http://view.officeapps.live.com/op/view.aspx?src='+imgUrl;
var imgShow='<li picIds="'+file.id+'">'
+'<div class="fileName"><a href="'+imgUrl+'" target="_blank" style="color:#78BC27" title="'+fileName+'">'+fileName+'</a></div>'
+'<div class="fileSize" style="margin-left:4px">'+file.fileSize+'</div>'
+'<div class="UploadingPerson" style="margin-left:4px">'+file.userName+'</div>'
+'<div class="fileTime" style="margin-left:4px">'+createTime+'</div>'
+'<div class="fileRemove" style="margin-left:4px;color:#78BC27;cursor:pointer" onclick="removeImgList(this,\''+file.id+'\')"><span class="fa fa-trash-o"></span></div>'
+'</li>';
thisP.siblings('.picC').children('.fileContent').append(imgShow);
}
},
error: function (data) {
console.log('server error!');
}
});
}
function removeImgList(obj,thisId) {
$(obj).parent('li').remove();
var params = {
id: thisId
};
var url = '/file/delete';
$.ajaxSend(url, params).done(function (data) {
if (data.code === '00000000') {
}
})
}
function enlargeList(obj) {
var Left = (document.documentElement.clientWidth-400)/2;
var top = (document.documentElement.clientHeight-400)/2;
$(obj).parent('div').siblings('div').show().css('left',Left+'px').css('top',top+'px');
}
function enlargeNoticeList(obj) {
var thisTOP=document.getElementsByClassName('router');
var Left = (document.documentElement.clientWidth-400-220)/2;
var top = (document.documentElement.clientHeight-400)/2+thisTOP[0].scrollTop;
$(obj).parent('div').siblings('div').show().css('left',Left+'px').css('top',top+'px');
}
function closePicList(obj) {
$(obj).hide();
}
function triggerUpLoadList(obj) {
$(obj).siblings('form.uploadForm').children('.fileContent').trigger('click');
}

猜你喜欢

转载自www.cnblogs.com/cx709452428/p/9447638.html