D:/workspace/chenjingjing/git/gx_tieta/gx_tieta/.gitignore
2019-01-18 85b6320509504a8407f43e2ff638e46f6a63f7ec
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>上传视频</title>
    <link rel="stylesheet" href="css/basic.css">
    <link rel="stylesheet" href="src/css/layui.css">
</head>
<body>
    <button type="button" class="layui-btn" id="test5"><i class="layui-icon"></i>上传视频</button>
    <button type="button" class="layui-btn" id="upload"><i class="layui-icon"></i>确认上传</button>
    <script src="src/layui.js"></script>
    <script>
        layui.use(['upload', 'jquery'], function() {
            var upload = layui.upload;
            var $ = layui.jquery;
            var StationId = 42000570;
            
            var xhrOnProgress = function (fun) {
                xhrOnProgress.onprogress = fun; //绑定监听
                //使用闭包实现监听绑
                return function () {
                    //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
                    var xhr = $.ajaxSettings.xhr();
                    //判断监听函数是否为函数
                    if (typeof xhrOnProgress.onprogress !== 'function')
                        return xhr;
                    //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
                    if (xhrOnProgress.onprogress && xhr.upload) {
                        xhr.upload.onprogress = xhrOnProgress.onprogress;
                    }
                    return xhr;
                };
            };
            
            // 上传视频
            upload.render({
                elem: '#test5'
                ,url: 'MyFileAction!uploadStationFile'
                ,auto: false
                ,bindAction: '#upload'
                ,multiple: true
                ,number: 1
                ,data: {
                    json:JSON.stringify( {
                        StationId: 123
                    })
                }
                ,accept: 'video' //视频
                ,progress: function(e , percent) {
                    console.log(e);
                    console.log("进度:" + percent + '%');
                    //element.progress('progressBar',percent  + '%');
                }
                ,done: function(res, index, upload) {
                    console.log(res);
                }
            });
        });
    </script>
</body>
</html>