| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <%--
- Created by IntelliJ IDEA.
- User: EDZ
- Date: 2021/6/28
- Time: 11:08
- To change this template use File | Settings | File Templates.
- --%>
- <%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
- <%@include file="/context/mytags.jsp" %>
- <!DOCTYPE html>
- <html>
- <head>
- <title>模板导入</title>
- <t:base type="jquery,easyui,tools,DatePicker"></t:base>
- <style>
- .loading{width:95px;height:7px;font-size:7px;margin:5px auto;background:url(http://static.tieba.baidu.com/tb/editor/images/loading.gif) no-repeat}
- </style>
- <script type="text/javascript">
- //编写自定义JS代码
- </script>
- </head>
- <body>
- <t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" beforeSubmit="postData">
- <div class="loading upload-icon" style="display:none;position: absolute;left: 150px;top: 50%"></div>
- <table style="width: 200px;" cellpadding="0" cellspacing="1" class="formtable">
- <tr>
- <td align="right">
- <label class="Validform_label">
- 选择文件:
- </label>
- </td>
- <td class="value">
- <input type="file" id="file" multiple="multiple" onchange="handleFile()">
- <span class="Validform_checktip"></span>
- <label class="Validform_label" style="display: none;">名称</label>
- </td>
- </tr>
- </table>
- </t:formvalid>
- </body>
- <script>
- /**
- * $icon: 文件上传中loading图标
- * fs: 上传的文件($("#file")[0].files)
- * max_size: 文件大小的最大值(1024 * 1024 * 100为100M)
- */
- var formData,fs;
- function handleFile() {
- formData = new FormData(),
- fs = $("#file")[0].files;
- let max_size = 1024 * 1024 * 30;
- for (let i = 0; i < fs.length; i++) {
- let d = fs[0]
- if(d.size <= max_size){ //文件必须小于30M
- if(/.(xls|XLS|xlsx|XLSX)$/.test(d.name)){ //文件必须为文档
- formData.append("files", fs[i]); //文件上传处理
- }else{
- alert('上传文件必须是XLS!')
- return false
- }
- }else{
- alert('上传文件过大!')
- return false
- }
- }
- }
-
- function postData() {
- let $icon = $(".upload-icon");
- $icon.show();
- $.ajax({
- url:'./carController.do?importExcel', /*接口域名地址*/
- type:'post',
- data: formData,
- contentType: false,
- processData: false,
- success:function(res){
- //{"success":true,"msg":"文件导入失败!","obj":null,"attributes":null,"jsonStr":"{\"msg\":\"文件导入失败!\",\"success\":true}"}
- W.tip(res.msg);
- $icon.hide();
- if(res.success){
- W.reloadTable();
- windowapi.close();
- }else{
- console.log(res);
- }
- }
- })
- }
- </script>
- </html>
|