123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <!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">
- <style type="text/css">
- /* tooltip */
- #tooltip {
- position: absolute;
- border: 1px solid #ccc;
- background: #333;
- padding: 2px;
- display: none;
- color: #fff;
- }
- </style>
- </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('admin/attachment/upload')}" class="a_menu" id="myupload">上传文件</a></li>
- </ul>
- </div>
- <script type="text/html" id="toolbarDemo">
- <div class="layui-btn-container">
- <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deletes">批量删除</button>
- <!--<button class="layui-btn layui-btn-sm" lay-event="imgPersistence"><i class="layui-icon"></i>文件本地化</button>-->
- </div>
- </script>
- <form class="layui-form serch" action="{:url('index')}" method="post">
- <div class="layui-form-item" style="float: left;">
- <div class="layui-input-inline">
- <input type="text" name="filename" lay-verify="title" autocomplete="off" placeholder="请输入文件名"
- class="layui-input layui-btn-sm">
- </div>
- <div class="layui-input-inline">
- <input type="text" name="filepath" lay-verify="title" autocomplete="off" placeholder="请输入文件路径"
- class="layui-input layui-btn-sm">
- </div>
- <div class="layui-input-inline">
- <div class="layui-inline">
- <select name="status" lay-search="">
- <option value="">状态</option>
- <option value="0">待审核</option>
- <option value="1">已审核</option>
- <option value="-1">已拒绝</option>
- </select>
- </div>
- </div>
- <div class="layui-input-inline">
- <div class="layui-inline">
- <select name="type">
- <option value="">所有类型</option>
- <option value="1">网络文件</option>
- <option value="-1">本地文件</option>
- </select>
- </div>
- </div>
- <div class="layui-input-inline">
- <div class="layui-inline">
- <div class="layui-input-inline">
- <input type="text" class="layui-input" id="date_time" placeholder="上传时间" name="create_time"
- autocomplete="off">
- </div>
- </div>
- </div>
- <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
- </div>
- </form>
- <script type="text/html" id="barDemo">
- <div class="layui-btn-group">
- <button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="down"><i class="fa fa-download"></i></button>
- <button class="layui-btn layui-btn-xs delete layui-btn-primary" lay-event="del"><i class="layui-icon"
- style="margin-right: 0;"></i></button>
- </div>
- </script>
- <table class="layui-table" id="table" lay-filter="table"></table>
- {include file="public/foot"}
- <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: []
- , limit: 15
- , limits: [15, 20, 30, 40, 50, 100]
- , url: '{:url("index")}' //数据接口
- , page: true //开启分页
- , cols: [[ //表头
- {type: 'checkbox'},
- {field: 'id', title: 'ID', width: 60},
- {
- field: 'thumb_url', title: '缩略图', width: 70, align: 'center', templet: function (row) {
- exts = {'jpg': '1', 'gif': '1', 'png': '1', 'jpeg': '1'};
- if (exts[row.fileext]) {
- return (row.thumb_url == '') ? '' : '<a href="' + row.thumb_url + '" class="tooltip" target="_blank"><img src="' + row.thumb_url + '" width="20" height="20"></a>';
- }
- return '<i class="fa fa-file"></i>';
- }
- },
- {field: 'filename', title: '名称', width: 180},
- {field: 'module', title: '模块',width: 80},
- {field: 'use', title: '来源',minWidth:80},
- {field: 'filepath', title: '路径',minWidth:200},
- {
- field: 'filesize', title: '大小', minWidth: 80, templet: function (row) {
- var i = 0;
- var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
- var size = row.filesize;
- for (i = 0; size >= 1024 && i < 5; i++) {
- size /= 1024;
- }
- return Math.round(size) + units[i];
- }
- },
- {field: 'fileext', title: '格式'},
- {field: 'user_id', title: '上传者id',minWidth:60},
- {field: 'uploadip', title: '上传IP',minWidth:60},
- {field: 'create_time', title: '上传时间',minWidth:80},
- {
- field: 'status', title: '审核', width: 80, templet: function (row) {
- if (row.status == 1) {
- return '<span class="layui-badge status" style="background-color: #8FCDA0" data-id="'+row.id+'">'+row.status_text+'</span>';
- } else if (row.status == -1) {
- return '<span class="layui-badge status" data-id="'+row.id+'">'+row.status_text+'</span>';
- } else {
- return '<span class="layui-badge layui-bg-gray status" data-id="'+row.id+'">'+row.status_text+'</span>';
- }
- }
- },
- {field: 'admin_id', title: '审核者id',minWidth:80},
- {field: 'audit_time', title: '审核时间',minWidth:80},
- {field: 'download', title: '已下载',minWidth:80},
- {field: 'action', title: '操作', align: 'center', toolbar: '#barDemo', fixed: 'right',minWidth:80}
- ]],
- done: function () {
- showThumb();
- $('.status').click(function () {
- var id = $(this).attr('data-id');
- layer.msg('审核', {
- time: 20000,
- btn: ['通过', '拒绝','待审', '再想想'],
- yes: function (index, layero) {
- $.ajax({
- url: "{:url('status')}",
- type: 'post',
- dataType: 'json', data: {id: id, status: '1'},
- success: function (res) {
- layer.msg(res.msg);
- if (res.code == 1) {
- table.reload('table');
- }
- }
- })
- },
- btn2: function (index, layero) {
- $.ajax({
- url: "{:url('status')}",
- type: 'post',
- dataType: 'json', data: {id: id, status: '-1'},
- success: function (res) {
- layer.msg(res.msg);
- if (res.code == 1) {
- table.reload('table');
- }
- }
- })
- }
- ,btn3: function(index, layero){
- $.ajax({
- url: "{:url('status')}",
- type: 'post',
- dataType: 'json', data: {id: id, status: '0'},
- success: function (res) {
- layer.msg(res.msg);
- if (res.code == 1) {
- table.reload('table');
- }
- }
- })
- },
- })
- })
- }
- });
- 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 == 'del') {
- layer.confirm('确定删除文件?', function (index) {
- $.ajax({
- url: "{:url('delete')}",
- dataType: 'json',
- data: {id: obj.data.id},
- success: function (res) {
- layer.msg(res.msg);
- if (res.code == 1) {
- table.reload('table');
- }
- }
- })
- })
- }else if(obj.event == 'down'){
- var id = obj.data.id;
- var download = document.getElementById('down');
- $.ajax({
- url: "{:url('admin/attachment/download')}",
- data: {id: id},
- dataType: 'json',
- async: false,
- success: function (res) {
- if (res.code == 1) {
- download.setAttribute('href', res.data);
- download.setAttribute('download', res.name);
- download.click();
- table.reload('table');
- } else {
- layer.msg(res.msg);
- }
- }
- })
- }
- });
- //监听事件
- table.on('toolbar(table)', function (obj) {
- var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
- var data = checkStatus.data;
- if (obj.event == 'deletes') {
- if (data.length > 0) {
- var ids = [];//数组
- data.forEach(function (item, key) {
- ids[key] = item.id;
- })
- layer.confirm('确定删除附件?', function (index, layero) {
- $.ajax({
- url: "{:url('deletes')}",
- dataType: 'json',
- data: {"ids": ids},
- type: 'post',
- success: function (res) {
- layer.msg(res.msg);
- if (res.code == 1) {
- table.reload('table');
- }
- }
- })
- layer.close(index)
- });
- } else {
- layer.msg('请先勾选需要操作的记录');
- }
- }
- else if(obj.event == 'imgPersistence'){
- layer.confirm('网络文件将转为本地文件,是否继续?', function (index) {
- var load = layer.load(1, {
- shade: [0.1, '#fff'] //0.1透明度的白色背景
- });
- $.ajax({
- url: "{:url('imgPersistence')}",
- dataType: 'json',
- success: function (res) {
- layer.msg(res.msg);
- if (res.code == 1) {
- table.reload('table');
- }
- },
- complete: function () {
- layer.close(load);
- }
- })
- })
- }
- });
- });
- </script>
- <script>
- layui.use('upload', function () {
- var $ = layui.jquery
- , upload = layui.upload;
- //指定允许上传的文件类型
- upload.render({
- elem: '#myupload'
- , url: "{:url('admin/attachment/upload')}"
- , accept: 'file' //普通文件
- // , exts: 'zip|rar|7z' //只允许上传压缩文件
- , done: function (res) {
- layer.msg(res.msg);
- if (res.code == 1 && res.url!=null) {
- setTimeout(function () {
- location.href = res.url;
- }, 1500)
- }
- }
- });
- });
- </script>
- </div>
- </body>
- </html>
|