david-PC\david
2018-06-12 f240ac3ccd37c541cab2c21cfc433d3510999a3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html>
 <head>
     <title>文件上载</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Pragma" content="no-cache"> 
    <meta http-equiv="Cache-Control" content="no-cache"> 
    <meta http-equiv="Expires" content="0">
    <link href="../../../css/home.css" rel="stylesheet"/>
    <link href="../../../css/common.css" rel="stylesheet" type="text/css">
    <link href="../../../css/control.css" rel="stylesheet" />
    
    <script src="../../../js/jquery-1.7.2.min.js"></script>
    <script src="../../../js/foundation-2.0.js"></script>
    <script src="../../../js/jquery.form.js"></script>
    <script src="../../../js/control.js"></script>
           
    <script type="text/javascript" >
        var multifile, progress, btn_upload, btn_close, lbl_progress, fileForm, browsertype, fromPage;
        var toDB = "", idx = 0;
        var template = [
            '<div class="list_line">',
                '<div id="inform_no" class="inform_no" ></div>',
                '<div id="content" class="inform_content" ></div>',
            '</div>'
        ];
        
        function upload() {
            var file = multifile.val(); 
            if (!file || file.length == 0) {
                Dialog.alert("请选择上传附件~~");
                return;
            }
            
            if (browsertype.type == "IE" && browsertype.version < 10) {
                var returnParams = {};
                fileForm.attr("action", "root/fine/uplodeFile?toDB=" + toDB);
                fileForm.ajaxForm(function(result){    
                var resultJson = JSON.parse(result);
                 resultJson = $.fm.decode(resultJson);
                 returnParams.path = resultJson.path;
                 returnParams.path = resultJson.path;
                Win.close(resultJson.path);
                });  
                
                fileForm.submit();
                return;
            }
            
            var files = multifile[0].files;
             
            doUpload(files);
        }
        
        function doUpload(datas){
            var no = datas.length;
            Dialog.confirm("信息提示", "确定上载[" + no + "]个附件?", function(result) {
                if(result){
                    var formData = new FormData();
                    for (var i = 0; i < datas.length; i++) {
                        formData.append("file", datas[i]);
                    }
                    $.ajax({
                         url : "root/fine/uplodeFile?toDB=" + toDB,  
                         type : "POST",  
                         data : formData, 
                         processData : false, 
                         contentType : false, 
                         success : function(result) {
                             var resultJson = JSON.parse(result);
                             resultJson = $.fm.decode(resultJson);
                            Win.close(resultJson.path);
                         },  
                         error : function(result) {  
                            alert(JSON.stringify(result));  
                         }  
                    });  
                }
            });
        }
        
        function refresh(data) {
            fromPage =data.from;
            if (data.toDB) {
                toDB = data.toDB;
            }
        }
        
        function _close() {
            Win.close();
        }
        
        function showFilesName() {
            var filesname = [];
            idx = 0;
            if (browsertype.type == "IE" && browsertype.version < 10) {
                filesname[0] = multifile.val();
            }
            else {
                var files = multifile[0].files;
                for (var i = 0; i < files.length; i++) {
                    var fileName = files[i].name.toLowerCase();
                    filesname[i] = fileName;
                }
            }
            
            list_inform.setData(filesname);
        }
        
        function renderLine(record, item, sender) {
            idx++;
            $("#inform_no", item).html(idx + "、");
            $("#content", item).html(record);
        }
        
        $(document).ready(function() {
            multifile = $("#multifile");
            btn_upload = $("#btn_upload");
            btn_close = $("#btn_close");
            fileForm = $("#fileForm");
            browsertype = BrowserType();
            
            list_inform = new List({
                template: template,
                element: "filename",
                onRender: renderLine
            });
            
            $("#fileHover").hover(function(){  
                $("#fileBackground").css("background-color", "#32ad7f");  
            },function(){  
                $("#fileBackground").css("background-color", "#368467");  
            });
            
            Win.onShow(refresh);
        });    
            
    </script>
</head>
 
<body style="overflow: hidden; font: 25px 微软雅黑;">
    <div style='height: 50px; background-color: #009AD1; color: white; font: 18px 微软雅黑; text-align: left; line-height: 50px; padding-left: 40px'>文件上传</div>
    <div id="filename" style="border: 1px #CCC dashed; overflow: auto; position: absolute; width: 90%; top: 50px; left: 20px; bottom: 100px;">
    </div>
    
    <div style="position: absolute; width:100%; height: 50px; bottom:50px; font-size: 20px; line-height: 50px;">
        <div style="position: relative; width:100%; height: 100%">
            <div id="fileHover" class="btn btn-green" style="position: absolute; z-index:100; top: 0px; right: 100px; cursor: pointer; opacity: 0; filter:alpha(opacity=0)">
                <form id="fileForm" method="post" enctype="multipart/form-data">
                    <input type="file" name="file" id="multifile" multiple="multiple" onchange="showFilesName()" class="btn btn-green"/>
                </form>
            </div>
            <div id="fileBackground" class="btn btn-green" style="position: absolute; z-index:10; top: 0px; right: 100px">选择文件</div>
            <div style='font-size: 12px; position: absolute; bottom: 0px; right: 150px; height: 20px; line-height: 20px'><label>可多附件上传(IE9+)</label></div>
        </div>
    </div>
    
    <div style='position: absolute; bottom: 10px; left: 40px; right: 40px;'>
        <div class="btn btn-green" style="float: left;" onclick="upload();">上载</div>
        <div class="btn btn-green" style="float: right;" onclick="_close();">关闭</div>
    </div>
</body>
</html>