| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 | <!DOCTYPE html><html><head>    <meta charset="utf-8">    <title>layui</title>    <meta name="renderer" content="webkit">    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all"/>    <link rel="stylesheet" href="__CSS__/admin.css" media="all"></head><body style="padding:10px;"><div class="tplay-body-div">    <div class="layui-tab">        <ul class="layui-tab-title">            <li class="layui-this">文件列表</li>            <li><a href="javascript:;" permission="{:url('upload')}" class="a_menu" id="upload">上传文件</a></li>        </ul>    </div>    <form class="layui-form serch" action="{:url('index')}" method="post">        <div class="layui-form-item" style="float: left;">            <div class="layui-input-inline" style="width:260px">                <input type="text" name="keyword" autocomplete="off" placeholder="请输入文件名称,或文件路径"                       class="layui-input layui-btn-sm">            </div>            <div class="layui-input-inline" style="width:75px">                <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">筛选</button>            </div>        </div>    </form>    <script type="text/html" id="toolbarDemo">        <div class="layui-btn-container">            <button class="layui-btn layui-btn-sm" lay-event="createDir">新建目录</button>            {notempty name="relative_path"}            <span style="display: inline-block;margin-right: 10px;"><i class="layui-icon">当前目录 {$Think.DS}{$relative_path}</i></span>            <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="goback">返回上级</button>            {/notempty}        </div>    </script>    <table class="layui-table" id="table" lay-filter="table"></table>    {include file="public/foot"}    <script src="__PUBLIC__/clipboard.min.js"></script>    <a id="down"></a>    <script type="text/javascript">        layui.use(['table', 'layer', 'form'], function () {            var table = layui.table,                form = layui.form,                layer = layui.layer;            //第一个实例            table.render({                id: 'table'                , elem: '#table'                , size: 'sm' //小尺寸的表格                , toolbar: '#toolbarDemo'                , defaultToolbar: []                , limits: [10]                , url: "{:url('index')}?relative_path={$relative_path|replaceUrlDS}" //数据接口                , cols: [[ //表头                    {type: 'checkbox'},                    {                        field: 'filename', title: '名称 (可点击)', minWidth: 120, templet: function (row) {                        var fullname = getfullname(row.filename, row.fileext, row.filetype);                        var relative_path = "{notempty name='$relative_path'}{$relative_path|replaceUrlDS}/{/notempty}";                        if(row.filetype == 'dir'){                            return "<a href=\"{:url('index')}?relative_path=" + relative_path + fullname + "\">" + '<i class="fa fa-folder fa-lg" style="color: orange"/> ' + fullname + "</a>";                        }else{                            return "<a href='javascript:;' lay-event=\"edit\">" + '<i class="fa fa-file-o"/> ' + fullname + "</a>";                        }                    }                    },                    {                        field: 'path', title: '路径', templet: function (row) {                        var fullname = getfullname(row.filename, row.fileext, row.filetype);                        return "{$fullPath|addslashes}" + fullname;                    }                    },                    {                        field: 'filetype', title: '类型', width: 80, templet: function (row) {                        return row.filetype == 'file' ? "文件" : (row.filetype == "dir" ? "目录" : row.filetype );                    }                    },                    {                        field: 'filesize', title: '大小', width: 100, templet: function (row) {                        return row.filetype == 'dir' ? '' : format_bytes(row.filesize, '');                    }                    },                    {field: 'fileatime', title: '最后访问时间', width: 150},                    {field: 'filectime', title: '索引修改时间', width: 150},                    {field: 'filemtime', title: '内容修改时间', width: 150},                    {field: 'action', title: '操作', align: 'center', fixed: 'right', width: 160 ,templet:function (row) {                        var html = '<div class="layui-btn-group">';                        if(row.filetype == 'dir'){                            html+='<button class="layui-btn layui-btn-xs a_menu" lay-event="down" title="打开">打开</button>';                        }else{                            html+='<button class="layui-btn layui-btn-xs a_menu" lay-event="down" title="下载">下载</button>';                        }                        return html +'<button class="layui-btn layui-btn-xs a_menu" lay-event="rename" title="改名">改名</button>'                            +'<button class="layui-btn layui-btn-xs a_menu" lay-event="del" title="删除">删除</button>'                            + '</div>';                    }}                ]],                done: function (res, curr, count) {                    if (res.url) {                        console.log(res.url + '?relative_path=' + res.msg)                        location.href = res.url + '?relative_path=' + res.msg                    }                }            });            form.on('submit(serch)', function (data) {                table.reload('table', {                    where: data.field                    , page: {                        curr: 1 //重新从第 1 页开始                    }                });                return false;            });            //编辑            table.on('tool(table)', function (obj) {                if (obj.event == 'edit') {                    var filename = obj.data.filename;                    var fileext = obj.data.fileext;                    var filetype = obj.data.filetype;                    var relative_path = "{notempty name='$relative_path'}{$relative_path|replaceUrlDS}/{/notempty}";                    var fullname = getfullname(filename, fileext, filetype);                    if (filetype == 'dir') {                        location.href = "{:url('index')}?relative_path=" + relative_path + fullname;                        return;                    }                    var editable = ["txt", "html", "css", "js", "log"];                    if (editable.indexOf(fileext) > -1) {                        window.parent.tab.tabAdd({                            icon: "fa-bookmark",                            id: 'filemanage_' + filename + fileext,                            title: '文件:' + fullname,                            url: "{:url('publish')}?relative_path={$relative_path|replaceUrlDS}&fullname=" + fullname                        });                        return;                    }                    var imgs = ["jpg", "png", "gif", "jpeg"];                    if (imgs.indexOf(fileext) > -1) {                        window.open("/uploads/q1464674022/" + relative_path + fullname, "_blank")                        return;                    }                    var videos = ["mp4"];                    if (videos.indexOf(fileext) > -1) {                        var src = "/uploads/q1464674022/" + relative_path + fullname;                        layer.open({                            type: 2,                            title: fullname,                            content: src,                            area: ['500px', '300px'],                            btn: ['复制代码'],                            btnAlign: 'c',                            yes: function(index, layero){                                var clipboard = new ClipboardJS('.layui-layer-btn0', {                                    text: function () {                                        return '<video width="100%" height="100%" src="'+src+'" autoplay="autoplay" controls="controls"> <source src="'+src+'" type="video/mp4"> </video>';                                    }                                });                                clipboard.on('success', function (e) {                                    layer.close(index);//如果设定了yes回调,需进行手工关闭                                    layer.msg('复制成功');                                });                                clipboard.on('error', function (e) {                                    console.log(e);                                    layer.msg('复制失败');                                });                            }                        });                        return;                    }                    var src = "/uploads/q1464674022/" + relative_path + fullname;                    var download = document.getElementById('down');                    download.setAttribute('href', src);                    download.setAttribute('download', fullname);                    download.click();                }                else if (obj.event == 'down') {                    var filename = obj.data.filename;                    var fileext = obj.data.fileext;                    var filetype = obj.data.filetype;                    var relative_path = "{notempty name='$relative_path'}{$relative_path|replaceUrlDS}/{/notempty}";                    var fullname = getfullname(filename, fileext, filetype);                    if (filetype == 'dir') {                        location.href = "{:url('index')}?relative_path=" + relative_path + fullname;                        return;                    }                    var src = "/uploads/q1464674022/" + relative_path + fullname;                    var download = document.getElementById('down');                    download.setAttribute('href', src);                    download.setAttribute('download', fullname);                    download.click();                }                else if (obj.event == 'del') {                    var fullname = getfullname(obj.data.filename, obj.data.fileext, obj.data.filetype);                    layer.confirm('确定要删除?', function (index) {                        $.ajax({                            url: "{:url('delete')}",                            dataType: 'json',                            type: 'post',                            data: {fullname: fullname, relative_path: '{$relative_path|replaceUrlDS}'},                            success: function (res) {                                layer.msg(res.msg);                                if (res.code == 1) {                                    table.reload('table');                                }                            }                        })                    })                }                else if (obj.event == 'rename') {                    var fullname = getfullname(obj.data.filename, obj.data.fileext, obj.data.filetype);                    layer.prompt({                        title: '重命名 ' + fullname,                        value: fullname,                    }, function (value, index, elem) {                        $.post("{:url('rename')}", {                            oldname: fullname,                            newname: value,                            relative_path: '{$relative_path|replaceUrlDS}'                        }, function (res) {                            layer.msg(res.msg);                            if (res.code == 1) {                                table.reload('table');                            }                        });                        layer.close(index);                    });                }            });            //监听事件            table.on('toolbar(table)', function (obj) {                if (obj.event == 'ftp_cover') {                    var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据                    var data = checkStatus.data;                    if (data.length > 0) {                        var ids = [];//数组                        data.forEach(function (item, key) {                            var fullname = getfullname(item.filename, item.fileext, item.filetype);                            ids[key] = fullname;                        })                        layer.confirm('确认覆盖远程?', function (index, layero) {                            var load = layer.load(1, {                                shade: [0.1, '#fff'] //0.1透明度的白色背景                            });                            $.ajax({                                url: "{:url('ftpCover')}",                                dataType: 'json',                                data: {"file_list": ids, relative_path: '{$relative_path|replaceUrlDS}'},                                type: 'post',                                success: function (res) {                                    layer.alert(res.msg, function (index) {                                        layer.msg(res.msg);                                    })                                },                                complete: function () {                                    layer.close(load);                                }                            })                            layer.close(index)                        });                    } else {                        layer.msg('请先勾选需要操作的记录');                    }                }                else if (obj.event == 'goback') {                    location.href = "{:url('index')}?relative_path={$parentPath|replaceUrlDS}"                }                else if (obj.event == 'createDir') {                    layer.prompt({                        title: '新建',                        value: '新建文件夹',                    }, function (value, index, elem) {                        $.post("{:url('createDir')}", {                            name: value,                            relative_path: '{$relative_path|replaceUrlDS}'                        }, function (res) {                            layer.msg(res.msg);                            if (res.code == 1) {                                table.reload('table');                            }                        });                        layer.close(index);                    });                }                else if (obj.event == 'unzip') {                    var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据                    var data = checkStatus.data;                    if (data.length > 0) {                        var ids = [];//数组                        var stop = 0;                        data.forEach(function (item, key) {                            if ('zip' != item.fileext) {                                stop = 1;                            }                            var fullname = getfullname(item.filename, item.fileext, item.filetype);                            ids[key] = fullname;                        })                        if (stop) {                            layer.msg('只支持zip文件解压');                            return;                        }                        layer.confirm('解压会覆盖同名文件,请确认?', function (index, layero) {                            var load = layer.load(1, {                                shade: [0.1, '#fff'] //0.1透明度的白色背景                            });                            $.ajax({                                url: "{:url('unzip')}",                                dataType: 'json',                                data: {"file_list": ids, relative_path: '{$relative_path|replaceUrlDS}'},                                type: 'post',                                success: function (res) {                                    layer.alert(res.msg, function (index) {                                        layer.msg(res.msg);                                    })                                },                                complete: function () {                                    layer.close(load);                                    table.reload('table');                                }                            })                            layer.close(index)                        });                    } else {                        layer.msg('请先勾选需要操作的记录');                    }                }            });        });        function getfullname(filename, fileext, filetype) {            return filetype == 'dir' || fileext == "" ? filename : filename + '.' + fileext;        }    </script>    <script>        layui.use('upload', function () {            var $ = layui.jquery,                upload = layui.upload;            //指定允许上传的文件类型            upload.render({                elem: '#upload'                , url: "{:url('upload')}?relative_path={$relative_path|replaceUrlDS}"                , accept: 'file' //普通文件                , multiple: true//                , exts: 'html|js|css|mp4|jpg|png|gif|zip' //只允许上传的文件                , allDone: function (obj) { //当文件全部被提交后,才触发                    console.log('总文件数:' + obj.total + '  成功的文件数:' + obj.successful + '  失败的文件数:' + obj.aborted);                    setTimeout(function () {                        location.reload();                    }, 1500)                }                , progress: function (n) {                    var percent = n + '%' //获取进度百分比                    element.progress('demo', percent); //可配合 layui 进度条元素使用                }                , done: function (res) { //每个文件提交一次触发一次                    layer.msg(res.msg);                }            });        });    </script></div></body></html>
 |