上传、下载模板
html:
<form id="documeForm" action="" method="post" enctype="multipart/form-data" style="display: inline-block;">
    <span class="zyx_file">
        <input type="file" value="" onchange="addattachment(this)" accept="application/vnd.ms-excel" name="file" id="addDocOfmodMa" >
        <lebal class="greenBtn" style="background: goldenrod;width: 74px;">上传</lebal>
    </span>
</form>
 js:
 var  _baserUrl="http://192.26.45.46:8080/";
$("#documeForm").attr("action", _baserUrl + "application/saveApplication");
//下载模板
$('.downTemplate').click(function () {
    var userType = '';
    window.location.href = _baserUrl + "/addressBook/getExcelTemplate?type=" + userType;
    window.location.download =  _baserUrl + "/addressBook/getExcelTemplate?type=" + userType;
});
//检测上传文件的合法性
// 上传按钮
var maxfilesize = 50;
var noallowfiletype = ["exe", "bat"]
function addattachment(obj) {
console.log(obj)
var size = (obj.files[0].size / 1024 / 1024).toFixed(2);
var name = obj.files[0].name;
var arr = name.split(".")
var arrlen = arr.length
if(!/^.*(\.xls|\.xlsx)$/.test(name)){
alert("只能上传excel");
return false;
}
var IsAllow = noallowfiletype.some(function (item, index) {
return item == arr[arrlen - 1]
});
if (IsAllow) {
alert("该种文件格式不允许上传");
return false
}
if (size > maxfilesize) {
alert("文件大小超过限制");
return false
}
console.log($("#setTreeId").val())
$("#documeForm").ajaxSubmit({
headers : {'Authorization':'Bearer '+token},
url:_baserUrl + 'addressBook/upload',
type:"post",
data:{
departId: $("#setTreeId").val(),
},
success:function(dt) {
console.log(dt);
alert(dt.message)
user(1)
document.getElementById('addDocOfmodMa').value = null;
},
error:function(e){
console.log(e)
}
})
}
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号