excel_upload.jsp 4.7 KB
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019/3/15
  Time: 16:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="<%=basePath %>resource/css/base.css" rel="stylesheet">
    <link href="<%=basePath %>resource/css/basic_info.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=basePath %>resource/easyui/uimaker/easyui.css">
    <link href="<%=basePath %>resource/css/form.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=basePath %>resource/css/form.css">
    <script type="text/javascript" src="<%=basePath %>resource/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="<%=basePath %>resource/validate/jquery.validate.js"></script>
    <script type="text/javascript" src="<%=basePath %>resource/validate/validate-extends.js"></script>

    <script type="text/javascript" src="<%=basePath %>resource/js/tools.js"></script>
    <!-- validate 验证中英文 -->
    <script type="text/javascript" src="<%=basePath %>resource/validate/jquery.validate-${pageContext.response.locale}.js"></script>
    <script type="text/javascript" src="<%=basePath %>resource/validate/ajaxfileupload.js"></script>
    <script type="text/javascript" src="<%=basePath %>resource/validate/jquery.form.js"></script>
</head>
<body>
<div class="container">
    <div class="content">
        <form class="from-control" id="form">
            <div></div>
            <div>
                <table class="kv-table">
                    <tbody>
                        <div>
                            <tr class="kv-content" >
                                <%--<td style="background-color: #EBEDF4; color: black;" class="kv-label" colspan="6"><spring:message code="manifest.excel"/></td>--%>
                                <td style="background-color: #EBEDF4; color: black;" class="kv-label" colspan="1">
                                    <input type="file" id = "file"  name = "file"  required="required">
                                </td>
                                <td style="background-color: #EBEDF4; color: black;" class="kv-label" colspan="4">
                                    <button type="button"  class="layui-btn layui-btn-sm layui-icon layui-icon-user" id="subbtn" onclick="submitFrom()">
                                        <i class="fa fa-trash hidden" aria-hidden="true"></i>导入
                                    </button>
                                </td>
                            </tr>
                        </div>
                    </tbody>
                </table>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">


    function submitFrom() {
        var excelPath = $("#file").val();
        if(excelPath == null || excelPath == ''){
            alert("请选择要上传的Excel文件");
            return;
        }else{
            var fileExtend = excelPath.substring(excelPath.lastIndexOf('.')).toLowerCase();
            if(fileExtend == '.xls' || fileExtend == '.xlsx'){
                $("#form").ajaxSubmit({
                    url:"<%=basePath %>manifest/excelUpload",
                    cache:false,
                    type:'POST',
                    dataType:'json',
                    success: function(data) {
                        if(data.status == 200){
                            alert("导入成功");
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                            parent.layer.close(index);
                        }else if (data.status == 201){
                            alert(data.msg);
                        }else if(data.status == 202){
                            alert(data.msg);
                        }else if (data.status == 300){
                            alert(data.msg);
                        }else if (data.status == 301){
                            alert(data.msg);
                        }else {
                            alert(data.msg);
                        }
                    }
                });
            } else {
                alert("文件格式需为'.xls'格式");
                return;
            }
        }
    }

</script>
</body>
</html>