html
<div class="attachNameDiv">
<form id="uploadimgform" target="uploadiframe" action="/upload" method="post" >
<input type="file" multiple="multiple" name="file" id="uploadinputimg" class="w-icon5" style="position:absolute;opacity:0;width:70px;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)">
<a href="#" id="uploadimg"><img style="margin-right:5px;" src="../img/icon_uplod.png"/><fmt:message code="global.th.fileup" />
</form>
//js
// 附件上传
$('#uploadinputimg').fileupload({
dataType:'json',
done:function (e, data) {
if(data.result.obj !=''){
var data = data.result.obj;
var str ='';
var str1 ='';
for (var i =0; i < data.length; i++) {
var gs = data[i].attachName.split('.')[1];
if(gs =='jsp'||gs =='css'||gs =='js'||gs =='html'||gs =='java'||gs =='php' ){
str +='';
layer.alert('<fmt:message code="dem.th.uploading" />!',{},function(){
layer.closeAll();
});
}else{
var fileExtension=data[i].attachName.substring(data[i].attachName.lastIndexOf(".")+1,data[i].attachName.length);//截取附件文件后缀
var attName =encodeURI(data[i].attachName).replace(/\+/g, "%2b").replace(/\@/g,"%40").replace(/\#/g,"%23").replace(/\&/g,"%26").replace(/\//g,"%2F").replace(/\?/g,"%3F").replace(/\¥/g,"%ef%bf%a5").replace(/\$/g,"%24").replace(/\!/g,"%ef%bc%81").replace(/\(/g,"%ef%bc%88").replace(/\)/g,"%ef%bc%89").replace(/\…/g,"%e2%80%a6%e2%80%a6");
var fileExtensionName=attName.substring(0,attName.lastIndexOf("."));
var deUrl = data[i].attUrl.split('&ATTACHMENT_NAME=')[0]+"&ATTACHMENT_NAME="+fileExtensionName+"."+fileExtension+"&FILESIZE="+data[i].size;
str +='<div class="dech" deUrl="' + deUrl+'">' +
'<a NAME="' + data[i].attachName +'*" style="text-decoration:none;margin-left:5px;">' +
'<img src="/img/attachment_icon.png"/>' + data[i].attachName +'</a>' +
'<img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/>' +
'<a fileExtension="'+fileExtension+'" onclick="pdurls($(this))" href="javascript:;" style="padding-left: 5px">' +
'<img src="/img/attachmentIcon/icon_skim.png" style="padding: 0 5px;">查阅</a>' +
'<a class="download" style="padding-left: 5px;display: none" href="/download?'+encodeURI(deUrl)+'" >' +
'<img src="/img/attachmentIcon/icon_down.png" style="padding: 0 5px;">下载</a>' +
'<a fileExtension="'+fileExtension+'" href="javascript:;" style="padding-left: 5px" class="printing " deUrl="' + deUrl+'" onclick="daPrinting($(this),0)">' +
'<img src="/img/attachmentIcon/icon_down.png" id="print" style="padding: 0 5px;">打印</a>' +
'<input type="hidden" class="inHidden" value="' + data[i].aid +'@' + data[i].ym +'_' + data[i].attachId +',">' +
''
}
}
$('.attachNameDiv').append(str);
}else{
//alert('添加附件大小不能为空!');
layer.alert('<fmt:message code="dem.th.AddEmpty" />!',{},function(){
layer.closeAll();
});
}
}
});
// 附件删除
$(document).on('click', '.deImgs', function () {
var _this =this;
var attUrl =$(this).parents('.dech').attr('deUrl');
layer.confirm('确定删除该附件吗?', function (index) {
$.ajax({
type:'get',
url:'/delete?' + attUrl,
dataType:'json',
success:function (res) {
if (res.flag ==true) {
layer.msg('删除成功', {icon:6, time:1000});
$(_this).parent().remove();
}else {
layer.msg('删除失败', {icon:2, time:1000});
}
}
})
});
});
//附件打印,目前只能打印图片和pdf文件。word不行
function daPrinting(_this,num){//根据后缀判断选择调取那种打开方式
console.log(_this)
var atturl=_this.attr('deUrl')
// var atturl=_this.parents('.dech').attr('deUrl')
if(atturl != undefined&&atturl.indexOf('&ATTACHMENT_NAME=') > -1){
var atturl1 = atturl.split('&ATTACHMENT_NAME=')[0] +'&ATTACHMENT_NAME=';
var atturl2 ='';
if(atturl.split('&ATTACHMENT_NAME=')[1] != undefined&&atturl.split('&ATTACHMENT_NAME=')[1].indexOf('&') > -1){
for(var i=1;i
atturl2 +='&' + atturl.split('&ATTACHMENT_NAME=')[1].split('&')[i];
}
atturl = atturl1 + atturl2;
}else{
atturl = atturl1;
}
}
var gs=_this.attr('fileExtension')
if(gs =='png'||gs =='jpg'||gs =='bmp' || gs =='emf' || gs =='gif'|| gs =='pcx'|| gs =='pcd'|| gs =='ai'|| gs =='webp'|| gs =='WMF'|| gs =='dxf' ||gs =='PNG'||gs =='JPG'||gs =='BMP' || gs =='EMF' || gs =='GIF'|| gs =='PCX'|| gs =='PCD'|| gs =='AI'|| gs =='WEBP'|| gs =='wmf'|| gs =='DXF'|| gs =='txt'|| gs =='TXT'){
// $.popWindow("/xs?"+atturl,PreviewPage,'0','0','1200px','600px');
var url1 ="/xs?"+atturl
$('#printIframe').attr('src',url1)
setTimeout(function(){
if(num ==0){
$("#printIframe")[0].contentWindow.print();
}else {
return url1
}
}, 1000)
}else if(gs =='mp4'||gs =='rmvb'||gs =='avi'||gs =='ifo'||gs =='wmv'||gs =='MP4'||gs =='RMVB'||gs =='AVI'||gs =='IFO'||gs =='WMV'){
// layer.open({type: 2, title: false, area: ['630px', '360px'], shade: 0.8, closeBtn: 0, shadeClose: true, content: "/common/video?videoatturlsplit="+atturl});
var url2 ="/common/video?videoatturlsplit="+atturl
$('#printIframe').attr('src',url2)
setTimeout(function(){
if(num ==0){
$("#printIframe")[0].contentWindow.print();
}else {
return url2
}
}, 1000)
layer.msg('点击任意处关闭');
}else if(gs =='pdf'||gs =='PDF'){
// $.popWindow("/pdfPreview?"+atturl,PreviewPage,'0','0','1200px','600px');
var url3 ="/pdfPreview?"+atturl
$('#printIframe').attr('src',url3)
setTimeout(function() {
if (num ==0) {
$("#printIframe")[0].contentWindow.print();
}else {
return url3
}
},1000)
}else{
var url =" "
$.ajax({
url:'',
type:'post',
datatype:'json',
async:false,
success:function (res) {
if(res.flag){
if(res.object[0].paraValue ==0){
//默认加载NTKO插件 进行跳转
url =" "
}
}
}
})
// $.popWindow(url,PreviewPage,'0','0','1200px','600px');
$('#printIframe').attr('src',url)
setTimeout(function() {
if(num ==0){
$("#printIframe")[0].contentWindow.print();
}else {
return url
}
},1000)
}
}