common_excel_upload.jsp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <%@ page language="java" import="java.util.*"
  2. contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
  3. <%@include file="/context/mytags.jsp" %>
  4. <t:base type="jquery,easyui,tools"></t:base>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <title>Excel导入</title>
  9. <style>
  10. .loading {
  11. width: 95px;
  12. height: 7px;
  13. font-size: 7px;
  14. margin: 5px auto;
  15. background: url(/images/loading.gif) no-repeat
  16. }
  17. </style>
  18. </head>
  19. <body style="overflow: hidden" scroll="no">
  20. <div id="content">
  21. <!-- <div id="wrapper"> -->
  22. <div class="loading upload-icon" style="display:none;position: absolute;left: 150px;top: 50%"></div>
  23. <div id="steps">
  24. <form id="formobj" action="null" name="formobj" method="post">
  25. <input type="hidden" id="btn_sub" class="btn_sub"/>
  26. <%-- <fieldset class="step">--%>
  27. <div class="form" style="width: 97%;">
  28. <link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css"
  29. type="text/css"></link>
  30. <script type="text/javascript"
  31. src="plug-in/uploadify/jquery.uploadify-3.1.js"></script>
  32. <script type="text/javascript" src="plug-in/tools/Map.js"></script>
  33. <script type="text/javascript">
  34. function upload() {
  35. postData();
  36. }
  37. function cancel() {
  38. }
  39. </script>
  40. <span id="file_uploadspan">
  41. <input type="file" id="file" multiple="multiple" onchange="handleFile()">
  42. </span>
  43. </div>
  44. <div class="form" id="filediv">
  45. <p><span>说明:导入文件必须基于系统格式,您可以先点击下载模板:
  46. <c:if test="${empty carType}">
  47. <a href="${controller_name}.do?exportXlsByT" style="width: 81px;margin-top: 10px;" class="l-btn l-btn-plain" plain="true" icon="icon-putout" operationCode="putout" >模板下载</a>
  48. </c:if>
  49. <c:if test="${!empty carType}">
  50. <a href="${controller_name}.do?exportXlsByT&carType=${carType}" style="width: 81px;margin-top: 10px;" class="l-btn l-btn-plain" plain="true" icon="icon-putout" operationCode="putout" >模板下载</a>
  51. </c:if>
  52. </span></p>
  53. </div>
  54. <script type="text/javascript">
  55. $(function () {
  56. $("#filediv").attr("style", "height:200px;overflow:auto;width: 97%;");
  57. $("#filediv").parent("td").attr("style", "width: 650px; height: 400px;");
  58. });
  59. </script>
  60. <%-- </fieldset>--%>
  61. </form>
  62. </div>
  63. <!-- </div> -->
  64. </div>
  65. <script type="text/javascript">
  66. var formData, fs;
  67. function handleFile() {
  68. formData = new FormData(),
  69. fs = $("#file")[0].files;
  70. let max_size = 1024 * 1024 * 30;
  71. for (let i = 0; i < fs.length; i++) {
  72. let d = fs[0]
  73. if (d.size <= max_size) { //文件必须小于30M
  74. if (/.(xls|XLS|xlsx|XLSX)$/.test(d.name)) { //文件必须为文档
  75. formData.append("files", fs[i]); //文件上传处理
  76. } else {
  77. alert('上传文件必须是XLS!')
  78. return false
  79. }
  80. } else {
  81. alert('上传文件过大!')
  82. return false
  83. }
  84. }
  85. // var formData = new FormData();
  86. // formData.append("photo",$("#photo")[0].files[0]);
  87. // formData.append("service",'App.Passion.UploadFile');
  88. // formData.append("token",token);
  89. }
  90. function postData() {
  91. let $icon = $(".upload-icon");
  92. $icon.show();
  93. let ajaxUrl = '${controller_name}.do?importExcel'
  94. if(${!empty carType}){
  95. ajaxUrl += '&carType=' + '${carType}';
  96. }
  97. $.ajax({
  98. url: ajaxUrl, /*接口域名地址*/
  99. type: 'post',
  100. data: formData,
  101. contentType: false,
  102. processData: false,
  103. success: function (res) {
  104. //{"success":true,"msg":"文件导入失败!","obj":null,"attributes":null,"jsonStr":"{\"msg\":\"文件导入失败!\",\"success\":true}"}
  105. W.tip(res.msg);
  106. $icon.hide();
  107. if (res.success) {
  108. W.reloadTable();
  109. windowapi.close();
  110. } else {
  111. console.log(res);
  112. }
  113. }
  114. })
  115. }
  116. function zhaohual(d) {
  117. // console.log(d);
  118. if (d.success == false) {
  119. if (d.msg == "导入模板错误") {
  120. layer.alert(d.msg);
  121. } else if (d.msg == "文件导入失败,请查看日志" || d.msg == "导入模板数据错误") {
  122. layer.alert(d.msg);
  123. // window.location.href="export/template/员工基本档案列表.xls";
  124. var downsrc = d.obj;
  125. location.href = downsrc;
  126. } else {
  127. layer.alert(d.msg);
  128. }
  129. }
  130. }
  131. </script>
  132. </body>
  133. </html>