导入导出

<!-- 导入页面 -->
<div class="modal-dialog" id='ImportMoadl' style='display:none;'>
<div class="modal-content" style='z-index: 9999;'>
<div class="modal-header">
<button type="button" onclick='onExit()' class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">导入终端信息</h4>
</div>
<div class="modal-body">
<form id="terminalUploadForm" >
<div class="row">
<div class="col-sm-6 form-group">
<input id="filePath" name="filePath" class="file-loading"
type="file" multiple accept=".xls,.xlsx" data-min-file-count="1"
data-show-preview="true">
<input class="form-control" id="fileName" name="fileName" type=hidden
data-bv-remote-name="value" disabled="disabled" />
</div>
<div class="col-sm-6 form-group">
<a onclick="onImportModel()" style="cursor: pointer; " >请下载导入的模板</a>
</div>
</div>

</form>
</div>
<div class="modal-footer text-center">
<button type="button" class="btn btn-primary" onclick="uploadInfo();">提交</button>
<button type="button" class="btn btn-default" onclick="onExit();">取消</button>
</div>
</div>
<div class="modal-backdrop fade in"></div>
</div>

js部分

//导入
function onImport(){
$('#ImportMoadl').show();
}
//导入提交
function uploadInfo(){
alert(1)
var filePath = document.getElementById("filePath");
if (filePath.value == null || filePath.value == "" || filePath.value == undefined || filePath.value.length == 0) {
return;
} else {
filePath = filePath.value;
if (checkFiles(filePath) == ".xlsx" || checkFiles(filePath) == ".xls") {
$.ajaxFileUpload({
type : "get",
url : '/sncp/terminal/onImport',
fileElementId : 'filePath',// file标签的id
dataType : 'json',// 返回数据的类型
success : function(data) {
$('#ImportMoadl').hide();
if (data.success == false) {
alertModal("导入成功!");
$("#fileName").val(data.data);
} else {
alertModal("导入失败!");
$('#ImportloserMoadl').show(); //显示失败下载弹框

}
},
error : function(data) {
alertModal("导入失败!");
}
});
} else {
alertModal('格式不正确!');
}
}
}
//检查文件后缀名
function checkFiles(file_name) {
var result = /.[^.]+/.exec(file_name);
return result;
}
//导入取消
function onExit(){
alert(2);
$('#ImportMoadl').hide();
$('#ImportloserMoadl').hide();
}
//导入失败点击下载
function onImportDefeatedModel(){

}

function onExport(){
window.location.href = $ctx +"/t_user/onExport";
}

原文地址:https://www.cnblogs.com/benmumu/p/10437413.html