<!DOCTYPE HTML> <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <meta charset="utf-8"> <head th:include="include :: header"></head> <body class="gray-bg"> <div class="container-div"> <div class="row"> <div class="col-sm-12 select-info"> <form id="material-form"> <div class="select-list"> <ul> <li> 导入表: <select name="table" id="table" th:with="list=${@excelService.getList()}"> <option th:each="ex : ${list}" th:text="${ex['name']}" th:value="${ex['url']}"></option> </select> </li> </ul> </div> </form> </div> <div class="btn-group hidden-xs" id="toolbar" role="group"> <a class="btn btn-outline btn-info btn-rounded" onclick="importTemplate()"> <i class="fa fa-cloud-download"></i> 下载导入模板 </a> </div> <div class="col-sm-12 select-info"> <form enctype="multipart/form-data" class="mt20 mb10"> <div class="col-xs-offset-1 col-sm-3"> <!-- <input type="file" id="file" name="file" class="form-control" />--> <font color="red" class="pull-left mt10"> 提示:仅允许导入“xls”或“xlsx”格式文件! </font> </div> <div class="layui-layer-btn layui-layer-btn- col-sm-3"> <a class="layui-layer-btn0" id="upload"><i class="fa fa-check"></i> 导入</a> <a class="layui-layer-btn1"><i class="fa fa-remove"></i> 取消</a> </div> </form> </div> </div> </div> <div th:include="include :: footer"></div> <script> // 下载模板 function importTemplate() { var table = $("#table option:selected").val(); $.get(ctx+table+"/importTemplate", function(result) { if (result.code == web_status.SUCCESS) { window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true; } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else { $.modal.alertError(result.msg); } }); } // function upload(){ // var table = $("#table option:selected").val(); // var file = $("#file").val(); // if (file == ''){ // $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。"); // return false; // } // $.ajax({ // url: ctx+table+"/importData", // data: "file="+file, // cache: false, // contentType: false, // processData: false, // type: 'POST', // success: function (result) { // if (result.code == web_status.SUCCESS) { // // $.modal.closeAll(); // // $.modal.alertSuccess(result.msg); // // $.table.refresh(); // alert(result.msg()) // } else if (result.code == web_status.WARNING) { // $.modal.enable(); // $.modal.alertWarning(result.msg) // } else { // $.modal.enable(); // $.modal.alertError(result.msg); // } // } // }); // }; layui.use('upload', function(){ var upload = layui.upload; var table = $("#table option:selected").val(); //执行实例 var uploadInst = upload.render({ elem: '#upload' //绑定元素 ,url: ctx+table+"/importData" //上传接口 ,accept: "file" ,exts:'xls|xlsx' ,done: function(res){ alert(res.msg()) //上传完毕回调 } ,error: function(){ //请求异常回调 alert(res.msg()) } }); }); </script> </body> </html>