index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>layui</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
  10. <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all"/>
  11. <link rel="stylesheet" href="__CSS__/admin.css" media="all">
  12. <style type="text/css">
  13. /* tooltip */
  14. #tooltip {
  15. position: absolute;
  16. border: 1px solid #ccc;
  17. background: #333;
  18. padding: 2px;
  19. display: none;
  20. color: #fff;
  21. }
  22. </style>
  23. </head>
  24. <body style="padding:10px;">
  25. <div class="tplay-body-div">
  26. <div class="layui-tab">
  27. <ul class="layui-tab-title">
  28. <li class="layui-this">附件管理</li>
  29. <li><a href="javascript:;" permission="{:url('admin/attachment/upload')}" class="a_menu" id="myupload">上传文件</a></li>
  30. </ul>
  31. </div>
  32. <script type="text/html" id="toolbarDemo">
  33. <div class="layui-btn-container">
  34. <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="deletes">批量删除</button>
  35. <!--<button class="layui-btn layui-btn-sm" lay-event="imgPersistence"><i class="layui-icon">&#xe656;</i>文件本地化</button>-->
  36. </div>
  37. </script>
  38. <form class="layui-form serch" action="{:url('index')}" method="post">
  39. <div class="layui-form-item" style="float: left;">
  40. <div class="layui-input-inline">
  41. <input type="text" name="filename" lay-verify="title" autocomplete="off" placeholder="请输入文件名"
  42. class="layui-input layui-btn-sm">
  43. </div>
  44. <div class="layui-input-inline">
  45. <input type="text" name="filepath" lay-verify="title" autocomplete="off" placeholder="请输入文件路径"
  46. class="layui-input layui-btn-sm">
  47. </div>
  48. <div class="layui-input-inline">
  49. <div class="layui-inline">
  50. <select name="status" lay-search="">
  51. <option value="">状态</option>
  52. <option value="0">待审核</option>
  53. <option value="1">已审核</option>
  54. <option value="-1">已拒绝</option>
  55. </select>
  56. </div>
  57. </div>
  58. <div class="layui-input-inline">
  59. <div class="layui-inline">
  60. <select name="type">
  61. <option value="">所有类型</option>
  62. <option value="1">网络文件</option>
  63. <option value="-1">本地文件</option>
  64. </select>
  65. </div>
  66. </div>
  67. <div class="layui-input-inline">
  68. <div class="layui-inline">
  69. <div class="layui-input-inline">
  70. <input type="text" class="layui-input" id="date_time" placeholder="上传时间" name="create_time"
  71. autocomplete="off">
  72. </div>
  73. </div>
  74. </div>
  75. <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
  76. </div>
  77. </form>
  78. <script type="text/html" id="barDemo">
  79. <div class="layui-btn-group">
  80. <button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="down"><i class="fa fa-download"></i></button>
  81. <button class="layui-btn layui-btn-xs delete layui-btn-primary" lay-event="del"><i class="layui-icon"
  82. style="margin-right: 0;"></i></button>
  83. </div>
  84. </script>
  85. <table class="layui-table" id="table" lay-filter="table"></table>
  86. {include file="public/foot"}
  87. <a id="down"></a>
  88. <script type="text/javascript">
  89. layui.use(['table', 'layer', 'form'], function () {
  90. var table = layui.table,
  91. form = layui.form,
  92. layer = layui.layer;
  93. //第一个实例
  94. table.render({
  95. id: 'table'
  96. , elem: '#table'
  97. , size: 'sm' //小尺寸的表格
  98. , toolbar: '#toolbarDemo'
  99. // , defaultToolbar: []
  100. , limit: 15
  101. , limits: [15, 20, 30, 40, 50, 100]
  102. , url: '{:url("index")}' //数据接口
  103. , page: true //开启分页
  104. , cols: [[ //表头
  105. {type: 'checkbox'},
  106. {field: 'id', title: 'ID', width: 60},
  107. {
  108. field: 'thumb_url', title: '缩略图', width: 70, align: 'center', templet: function (row) {
  109. exts = {'jpg': '1', 'gif': '1', 'png': '1', 'jpeg': '1'};
  110. if (exts[row.fileext]) {
  111. return (row.thumb_url == '') ? '' : '<a href="' + row.thumb_url + '" class="tooltip" target="_blank"><img src="' + row.thumb_url + '" width="20" height="20"></a>';
  112. }
  113. return '<i class="fa fa-file"></i>';
  114. }
  115. },
  116. {field: 'filename', title: '名称', width: 180},
  117. {field: 'module', title: '模块',width: 80},
  118. {field: 'use', title: '来源',minWidth:80},
  119. {field: 'filepath', title: '路径',minWidth:200},
  120. {
  121. field: 'filesize', title: '大小', minWidth: 80, templet: function (row) {
  122. var i = 0;
  123. var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
  124. var size = row.filesize;
  125. for (i = 0; size >= 1024 && i < 5; i++) {
  126. size /= 1024;
  127. }
  128. return Math.round(size) + units[i];
  129. }
  130. },
  131. {field: 'fileext', title: '格式'},
  132. {field: 'user_id', title: '上传者id',minWidth:60},
  133. {field: 'uploadip', title: '上传IP',minWidth:60},
  134. {field: 'create_time', title: '上传时间',minWidth:80},
  135. {
  136. field: 'status', title: '审核', width: 80, templet: function (row) {
  137. if (row.status == 1) {
  138. return '<span class="layui-badge status" style="background-color: #8FCDA0" data-id="'+row.id+'">'+row.status_text+'</span>';
  139. } else if (row.status == -1) {
  140. return '<span class="layui-badge status" data-id="'+row.id+'">'+row.status_text+'</span>';
  141. } else {
  142. return '<span class="layui-badge layui-bg-gray status" data-id="'+row.id+'">'+row.status_text+'</span>';
  143. }
  144. }
  145. },
  146. {field: 'admin_id', title: '审核者id',minWidth:80},
  147. {field: 'audit_time', title: '审核时间',minWidth:80},
  148. {field: 'download', title: '已下载',minWidth:80},
  149. {field: 'action', title: '操作', align: 'center', toolbar: '#barDemo', fixed: 'right',minWidth:80}
  150. ]],
  151. done: function () {
  152. showThumb();
  153. $('.status').click(function () {
  154. var id = $(this).attr('data-id');
  155. layer.msg('审核', {
  156. time: 20000,
  157. btn: ['通过', '拒绝','待审', '再想想'],
  158. yes: function (index, layero) {
  159. $.ajax({
  160. url: "{:url('status')}",
  161. type: 'post',
  162. dataType: 'json', data: {id: id, status: '1'},
  163. success: function (res) {
  164. layer.msg(res.msg);
  165. if (res.code == 1) {
  166. table.reload('table');
  167. }
  168. }
  169. })
  170. },
  171. btn2: function (index, layero) {
  172. $.ajax({
  173. url: "{:url('status')}",
  174. type: 'post',
  175. dataType: 'json', data: {id: id, status: '-1'},
  176. success: function (res) {
  177. layer.msg(res.msg);
  178. if (res.code == 1) {
  179. table.reload('table');
  180. }
  181. }
  182. })
  183. }
  184. ,btn3: function(index, layero){
  185. $.ajax({
  186. url: "{:url('status')}",
  187. type: 'post',
  188. dataType: 'json', data: {id: id, status: '0'},
  189. success: function (res) {
  190. layer.msg(res.msg);
  191. if (res.code == 1) {
  192. table.reload('table');
  193. }
  194. }
  195. })
  196. },
  197. })
  198. })
  199. }
  200. });
  201. form.on('submit(serch)', function (data) {
  202. table.reload('table', {
  203. where: data.field
  204. , page: {
  205. curr: 1 //重新从第 1 页开始
  206. }
  207. });
  208. return false;
  209. });
  210. table.on('tool(table)', function (obj) {
  211. if (obj.event == 'del') {
  212. layer.confirm('确定删除文件?', function (index) {
  213. $.ajax({
  214. url: "{:url('delete')}",
  215. dataType: 'json',
  216. data: {id: obj.data.id},
  217. success: function (res) {
  218. layer.msg(res.msg);
  219. if (res.code == 1) {
  220. table.reload('table');
  221. }
  222. }
  223. })
  224. })
  225. }else if(obj.event == 'down'){
  226. var id = obj.data.id;
  227. var download = document.getElementById('down');
  228. $.ajax({
  229. url: "{:url('admin/attachment/download')}",
  230. data: {id: id},
  231. dataType: 'json',
  232. async: false,
  233. success: function (res) {
  234. if (res.code == 1) {
  235. download.setAttribute('href', res.data);
  236. download.setAttribute('download', res.name);
  237. download.click();
  238. table.reload('table');
  239. } else {
  240. layer.msg(res.msg);
  241. }
  242. }
  243. })
  244. }
  245. });
  246. //监听事件
  247. table.on('toolbar(table)', function (obj) {
  248. var checkStatus = table.checkStatus(obj.config.id);//获取选中的数据
  249. var data = checkStatus.data;
  250. if (obj.event == 'deletes') {
  251. if (data.length > 0) {
  252. var ids = [];//数组
  253. data.forEach(function (item, key) {
  254. ids[key] = item.id;
  255. })
  256. layer.confirm('确定删除附件?', function (index, layero) {
  257. $.ajax({
  258. url: "{:url('deletes')}",
  259. dataType: 'json',
  260. data: {"ids": ids},
  261. type: 'post',
  262. success: function (res) {
  263. layer.msg(res.msg);
  264. if (res.code == 1) {
  265. table.reload('table');
  266. }
  267. }
  268. })
  269. layer.close(index)
  270. });
  271. } else {
  272. layer.msg('请先勾选需要操作的记录');
  273. }
  274. }
  275. else if(obj.event == 'imgPersistence'){
  276. layer.confirm('网络文件将转为本地文件,是否继续?', function (index) {
  277. var load = layer.load(1, {
  278. shade: [0.1, '#fff'] //0.1透明度的白色背景
  279. });
  280. $.ajax({
  281. url: "{:url('imgPersistence')}",
  282. dataType: 'json',
  283. success: function (res) {
  284. layer.msg(res.msg);
  285. if (res.code == 1) {
  286. table.reload('table');
  287. }
  288. },
  289. complete: function () {
  290. layer.close(load);
  291. }
  292. })
  293. })
  294. }
  295. });
  296. });
  297. </script>
  298. <script>
  299. layui.use('upload', function () {
  300. var $ = layui.jquery
  301. , upload = layui.upload;
  302. //指定允许上传的文件类型
  303. upload.render({
  304. elem: '#myupload'
  305. , url: "{:url('admin/attachment/upload')}"
  306. , accept: 'file' //普通文件
  307. // , exts: 'zip|rar|7z' //只允许上传压缩文件
  308. , done: function (res) {
  309. layer.msg(res.msg);
  310. if (res.code == 1 && res.url!=null) {
  311. setTimeout(function () {
  312. location.href = res.url;
  313. }, 1500)
  314. }
  315. }
  316. });
  317. });
  318. </script>
  319. </div>
  320. </body>
  321. </html>