Blame view

src/main/resources/templates/tool/import/import.html 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
<!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>
                            导入表:
mahuandong authored
14
15
                            <select name="table" id="table" th:with="list=${@excelService.getList()}">
                                <option th:each="ex : ${list}" th:text="${ex['name']}" th:value="${ex['url']}"></option>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
                        </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){
103
                alert(res.msg())
104
105
106
107
                //上传完毕回调
            }
            ,error: function(){
                //请求异常回调
108
                alert(res.msg())
109
110
111
112
113
114
            }
        });
    });
</script>
</body>
</html>