index.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. {extend name="common/base"/}
  2. {block name="style"}
  3. <style>
  4. body { display: flex; overflow: hidden; height: 100vh; }
  5. ::-webkit-scrollbar { display: none; width: 6px; height: 6px; }
  6. ::-webkit-scrollbar-thumb { border-radius: 10px; background-color: #e1e1e1; }
  7. .layui-tab{margin:0;}
  8. .container { display: flex; flex: 1; flex-direction: column; overflow: hidden; padding:12px;}
  9. .file-container { display: flex; flex: 1; flex-direction: column; overflow: hidden; border-radius: 2px; background: #ffffff; box-shadow: rgba(0, 0, 0, 0.05) 0 1px 2px 0; }
  10. .file-item {display: flex; flex: 1; justify-content: space-between; overflow: hidden; }
  11. .file-header {padding-top: 4px; }
  12. /** 分组 **/
  13. .file-item .group { position: relative; display: flex; flex-direction: column; padding-top: 8px; width: 200px; border-right: 1px solid #f6f6f6; }
  14. .file-item .group ul::-webkit-scrollbar { display: block; }
  15. .file-item .group ul { flex: 1; overflow: hidden; overflow-y: auto; }
  16. .file-item .group ul li {display: flex; align-items: center; justify-content: space-between; cursor:pointer; padding: 0 12px; height: 38px; font-size: 13px; color: #666666; }
  17. .file-item .group ul li i.iconfont{ margin-right:8px; font-size:24px; color:#E1AF1A; font-weight:800;}
  18. .file-item .group ul li > span { display: flex; flex: 1; overflow: hidden; margin-right: 0.5rem; text-overflow: ellipsis; white-space: nowrap; }
  19. .file-item .group ul li.active { background: #edefff; }
  20. .file-item .group ul li:hover { background: #f5f7fa; }
  21. .file-item .group ul li .dropdown:hover dl { display: block; }
  22. .file-item .group ul li .dropdown dl { position: absolute; top: 36px; right: -15px; z-index: 10000; display: none; padding: 5px 0; width: 88px; border-radius: 2px; text-align: center; background-color: #ffffff; box-shadow: #cccccc 0 0 10px; }
  23. .file-item .group ul li .dropdown dl dd { height: 32px; line-height: 32px; }
  24. .file-item .group ul li .dropdown dl dd:hover { color: #4a5dff; background-color: #edefff; }
  25. .file-item .group ul li .dropdown dl::before { position: absolute; top: -16px; left: 44px; z-index: 12; display: block; padding: 0; width: 0; height: 0; border-top: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid #ffffff; border-left: 8px solid transparent; content: ""; box-sizing: content-box; }
  26. .file-item .group .footer { display: flex; align-items: center; justify-content: center; width: 100%; height: 50px; border-top: 1px solid #f2f2f2; border-right: 1px solid #f2f2f2; }
  27. /** 菜单 **/
  28. .file-item .attach #move:hover { position: relative; opacity: 1; }
  29. .file-item .attach #move:hover .dropdown { display: block; background-color: #ffffff; }
  30. .file-item .attach .dropdown { position: absolute; top: 38px; z-index: 100000; display: none; padding: 5px 0; width: 150px; border: 1px solid #dddddd; text-align: left; background-color: #ffffff; line-height: 1.6; }
  31. .file-item .attach .dropdown em { font-size: 13px; font-weight: 400; color: #333333; font-style: normal; }
  32. .file-item .attach .dropdown em { display: block; clear: both; padding: 6px 20px; white-space: nowrap; }
  33. .file-item .attach .dropdown em:hover { background: #eeeeee; }
  34. .file-item .attach .dropdown em:first-child { font-size: 12px; color: #999999; }
  35. .file-item .attach .dropdown::before { position: absolute; top: -16px; left: 21px; z-index: 12; display: block; padding: 0; width: 0; height: 0; border-top: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid #ffffff; border-left: 8px solid transparent; content: ""; box-sizing: content-box; }
  36. .file-item .attach .dropdown::after { position: absolute; top: -18px; left: 20px; z-index: 10; display: block; padding: 0; width: 0; height: 0; border-top: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 9px solid #cccccc; border-left: 9px solid transparent; content: ""; box-sizing: content-box; }
  37. /** 文件 **/
  38. .file-item .attach { position: relative; display: flex; flex: 1; flex-direction: column; }
  39. .file-item .attach .header { display: flex; align-items: center; justify-content: space-between; padding:12px 15px; margin:0;}
  40. .file-item .attach .header .search{ display: flex; }
  41. .file-item .attach .header .search input { height: 30px; border-color: #eeeeee; border-top-right-radius: 0; border-bottom-right-radius: 0; }
  42. .file-item .attach .header .search button { border-color: #eeeeee; background: #f5f7fa; border-top-left-radius: 0; border-bottom-left-radius: 0; }
  43. .file-item .attach .header .search button:hover { background-color: #eeeeef; }
  44. .file-item .attach .subject { flex: 1; overflow: hidden; overflow-y: auto; margin: 10px; box-sizing: border-box; }
  45. .file-item .attach .subject:hover::-webkit-scrollbar { display: block; }
  46. .file-item .attach .subject ul { display: flex; flex-wrap: wrap; }
  47. .file-item .attach .subject ul li { position: relative; height: 120px; margin: 5px; padding: 9px; border: 1px solid rgba(0, 0, 0, 0.05); border-radius: 3px; transition: all 0.2s ease-in-out; }
  48. .file-item .attach .subject ul li:hover {border: 1px solid #cccccc; }
  49. .file-item .attach .subject ul li.on {border: 1px solid #ff5722; }
  50. .file-item .attach .subject ul li img { width: 100px; height: 100px; border-radius: 2px; }
  51. .file-item .attach .subject ul li video { width: 100px; height: 100px; border-radius: 3px; }
  52. .file-item .attach .subject ul li p { overflow: hidden; margin: 5px 0 0; width: 98px; font-size: 13px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
  53. .file-item .attach .subject ul li::after {position: absolute; width:22px; height:22px; right: -1px; bottom: -1px; display: none; font-size: 14px; font-family: layui-icon, serif; border-radius:3px 0 3px 0; text-align: center; color: #ffffff; background: #ff5722; content: "\e605"; line-height: 24px; }
  54. .file-item .attach .subject ul li.on::after { display: block; }
  55. .file-item .attach .subject ul li .layui-btn-group{position:absolute; top:3px; right:3px; display:none;}
  56. .file-item .attach .subject ul li:hover .layui-btn-group{display:block}
  57. .file-item .attach .footer { display: flex; align-items: center; justify-content: end; padding: 5px 15px 0; height: 45px; border-top: 1px solid #f2f2f2; text-align: center; background: #ffffff; }
  58. /** 无数据 **/
  59. .file-item .empty { display: flex; flex: 1; align-items: center; flex-direction: column; justify-content: center; overflow: hidden; text-align: center; color: #cccccc; }
  60. .file-item .empty i { font-size: 180px; }
  61. .file-item .empty p { width: 180px; text-align: center; }
  62. </style>
  63. {/block}
  64. <!-- 主体 -->
  65. {block name="body"}
  66. <div class="container">
  67. <div class="file-container">
  68. <div class="file-header">
  69. <div class="layui-tab layui-tab-brief" lay-filter="tab">
  70. <ul class="layui-tab-title">
  71. <li class="layui-this" data-tab="0">全部</li>
  72. <li data-tab="1">图片</li>
  73. <li data-tab="2">视频</li>
  74. <li data-tab="3">文档</li>
  75. <li data-tab="4">压缩包</li>
  76. </ul>
  77. </div>
  78. </div>
  79. <div class="file-item">
  80. <!-- 分组 -->
  81. <div class="group">
  82. <ul id="group" class="groups">
  83. <li data-id="" class="active"><i class="iconfont icon-sucaiziyuan"></i><span>全部</span></li>
  84. <li data-id="0"><i class="iconfont icon-sucaiziyuan"></i><span>未分组</span></li>
  85. </ul>
  86. <div class="footer">
  87. <span class="layui-btn layui-btn-primary layui-btn-sm add-new">添加分组</span>
  88. </div>
  89. </div>
  90. <!-- 文件 -->
  91. <div class="attach">
  92. <!-- 工具 -->
  93. <form class="layui-form" lay-filter="barsearchform" style="display:block; margin:0;padding:0;">
  94. <div class="header">
  95. <div class="layui-btn-group">
  96. <span class="layui-btn layui-btn-sm layui-btn-normal" id="fileUpload">上传文件</span>
  97. <span class="layui-btn layui-btn-sm layui-btn-danger" id="fileDelete">批量删除</span>
  98. <span class="layui-btn layui-btn-sm layui-btn-warm" id="fileMove">移动至 <i class="layui-icon layui-icon-triangle-d"></i></span>
  99. <span style="margin-left:36px;"><input type="checkbox" name="select_all" lay-filter="all" title="全选"></span>
  100. </div>
  101. <div class="search">
  102. <input type="hidden" name="limit" value="44" />
  103. <input type="hidden" name="page" value="1" />
  104. <input type="hidden" name="tab" value="0" />
  105. <input type="hidden" name="group_id" value="" />
  106. <label><input type="text" name="keywords" placeholder="请输入名称" autocomplete="off" class="layui-input"></label>
  107. <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search"></i></button>
  108. </div>
  109. </div>
  110. </form>
  111. <!-- 主体 -->
  112. <div class="subject">
  113. <ul id="filesBox"></ul>
  114. </div>
  115. <!-- 页脚 -->
  116. <div class="footer">
  117. <div id="laypage"></div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <script type="text/html" id="toolbarDemo">
  124. <h3 class="h3-title" style="height:28px;">审批列表</h3>
  125. </script>
  126. {/block}
  127. <!-- /主体 -->
  128. <!-- 脚本 -->
  129. {block name="script"}
  130. <script>
  131. const moduleInit = ['tool'];
  132. function gouguInit() {
  133. var table = layui.table, tool = layui.tool ,form = layui.form,laypage = layui.laypage,upload = layui.upload, element=layui.element, dropdown=layui.dropdown ;
  134. element.on('tab(tab)', function(data){
  135. $('[name="tab"]').val(data.index);
  136. $('[lay-filter="webform"]').click();
  137. return false;
  138. });
  139. //监听多选框点击事件 通过 lay-filter="menu"来监听
  140. form.on('checkbox(all)', function (data) {
  141.   let val = data.value;
  142. if(data.elem.checked){
  143. //判断当前多选框是选中还是取消选中
  144. $('#filesBox li').addClass('on');
  145. }
  146. else{
  147. $('#filesBox li').removeClass('on');
  148. }
  149. });
  150. var uploadInst = upload.render({
  151. elem: '#fileUpload'
  152. ,url: "/admin/api/upload"
  153. , accept: 'file' //普通文件
  154. , exts: 'jpeg|jpg|png|gif|doc|docx|ppt|pptx|xls|xlsx|pdf|zip|rar|7z|txt|mp4|psd|svg' //只允许上传文件
  155. , before: function (obj) {
  156. layer.msg('上传中...', { time: 3600000 });
  157. }
  158. ,done: function (res) {
  159. layer.msg(res.msg);
  160. $('[lay-filter="webform"]').click();
  161. }, error: function (index, upload) {
  162. layer.msg('上传失败');
  163. }
  164. });
  165. $('body').on('click','.add-new',function(){
  166. add_group(0,'');
  167. });
  168. $('#group').on('click','li',function(){
  169. let id=$(this).data('id');
  170. $(this).siblings().removeClass('active');
  171. $(this).addClass('active');
  172. $('[name="group_id"]').val(id);
  173. $('[lay-filter="webform"]').click();
  174. });
  175. $('#fileDelete').on('click',function(){
  176. let select_array = [];
  177. $('#filesBox').find('li.on').each(function(index,item){
  178. select_array.push($(item).data('id'));
  179. })
  180. if(select_array.length<1){
  181. layer.msg('请先选择文件');
  182. }
  183. else{
  184. layer.confirm('确定要删除这些文件吗?请慎重', { icon: 3, title: '提示' }, function (index) {
  185. let callback = function (e) {
  186. layer.closeAll();
  187. layer.msg(e.msg);
  188. $('[lay-filter="webform"]').click();
  189. }
  190. tool.delete("/admin/files/delete", {ids:select_array.join(',')}, callback);
  191. });
  192. }
  193. });
  194. function add_group(id,val){
  195. var title = '新增分组';
  196. if(id>0){
  197. title = '编辑分组';
  198. }
  199. layer.prompt({
  200. title: title,
  201. value: val,
  202. yes: function(index, layero) {
  203. // 获取文本框输入的值
  204. var value = layero.find(".layui-layer-input").val();
  205. if (value!='') {
  206. let callback = function (e) {
  207. layer.msg(e.msg);
  208. if(e.code==0){
  209. location.reload();
  210. }
  211. }
  212. tool.post("/admin/files/add_group", {id: id,title: value}, callback);
  213. layer.close(index);
  214. } else {
  215. layer.msg('请填写分组名称');
  216. }
  217. }
  218. })
  219. }
  220. var data = form.val('barsearchform');
  221. get_files(data);
  222. get_group();
  223. function get_group(param){
  224. $.ajax({
  225. url:"/admin/files/get_group",
  226. success:function(res){
  227. if(res.code==0){
  228. var group=res.data,item='';
  229. if(group.length>0){
  230. for(var a=0;a<group.length;a++){
  231. item+='<li data-id="'+group[a].id+'" data-title="'+group[a].title+'"><i class="iconfont icon-sucaiziyuan"></i><span>'+group[a].title+'</span><i class="layui-icon layui-icon-more-vertical dropdown-on"></i></li>';
  232. }
  233. $('#group').append(item);
  234. // 自定义事件
  235. dropdown.render({
  236. elem: '.dropdown-on',
  237. trigger: 'hover',
  238. align: 'right',
  239. data: [{
  240. title: '重命名分组',
  241. id: 100
  242. },{
  243. title: '删除该分组',
  244. id: 101
  245. }],
  246. click: function(data, othis){
  247. let id = $(this.elem).parent().data('id');
  248. let title = $(this.elem).parent().data('title');
  249. if(data.id==100){
  250. add_group(id,title);
  251. }else{
  252. del_group(id);
  253. }
  254. }
  255. });
  256. group.push({id:0,title:'未分组'});
  257. dropdown.render({
  258. elem: '#fileMove',
  259. data: group,
  260. click: function(obj){
  261. let select_array = [];
  262. $('#filesBox').find('li.on').each(function(index,item){
  263. select_array.push($(item).data('id'));
  264. })
  265. if(select_array.length<1){
  266. layer.msg('请先选择文件');
  267. }
  268. else{
  269. layer.confirm('确定要把选中的文件移动到『'+obj.title+'』分组吗?', { icon: 3, title: '提示' }, function (index) {
  270. let callback = function (e) {
  271. layer.closeAll();
  272. layer.msg(e.msg);
  273. $('[lay-filter="webform"]').click();
  274. }
  275. tool.delete("/admin/files/move", {group_id:obj.id,ids:select_array.join(',')}, callback);
  276. });
  277. }
  278. }
  279. });
  280. }
  281. }
  282. }
  283. });
  284. }
  285. function del_group(id) {
  286. layer.confirm('确定要删除该分组吗?请慎重', { icon: 3, title: '提示' }, function (index) {
  287. let callback = function (e) {
  288. layer.closeAll();
  289. layer.msg(e.msg);
  290. //$('#group').find('[data-id="'+id+'"]').remove();
  291. if(e.code==0){
  292. location.reload();
  293. }
  294. }
  295. tool.delete("/admin/files/del_group", {ids:id}, callback);
  296. });
  297. }
  298. function get_files(param){
  299. var loadIndex = layer.load(0);
  300. $.ajax({
  301. url:"/admin/files/index",
  302. data:param,
  303. complete:function(){
  304. setTimeout(function(){
  305. layer.close(loadIndex)
  306. }, 200);
  307. },
  308. success:function(res){
  309. $('[name="select_all"]').prop('checked', false);
  310. form.render('checkbox');
  311. if(res.code==0){
  312. laypage.render({
  313. elem: 'laypage',
  314. limit:param['limit'],
  315. curr:param['page'],
  316. count: res.count, // 数据总数
  317. jump: function(obj, first){
  318. console.log(obj.curr); // 得到当前页,以便向服务端请求对应页的数据。
  319. console.log(obj.limit); // 得到每页显示的条数
  320. // 首次不执行
  321. if(!first){
  322. var data = form.val('barsearchform');
  323. data['page'] = obj.curr;
  324. get_files(data);
  325. }
  326. }
  327. });
  328. var item=res.data,li='';
  329. if(item.length>0){
  330. for(var a=0;a<item.length;a++){
  331. let image = ['jpg','jpeg','png','gif'];
  332. let doc = ['doc','docx','xls','xlsx','ppt','pptx','txt','pdf','zip','rar','7z'];
  333. let down = '<a href="'+item[a].filepath+'" target="_blank" class="layui-btn layui-btn-xs layui-btn-normal" download="'+item[a].name+'">下载</a>';
  334. // 判断元素是否在数组中
  335. let path='/static/home/images/icon/file.png';
  336. if (image.includes(item[a].fileext)) {
  337. path=item[a].filepath;
  338. down = '<span data-href="'+item[a].filepath+'" class="layui-btn layui-btn-xs layui-btn-normal file-view-img">预览</span>';
  339. } else if (doc.includes(item[a].fileext)){
  340. path='/static/home/images/icon/'+item[a].fileext+'.png';
  341. }
  342. if(item[a].fileext == 'pdf'){
  343. down = '<span data-href="'+item[a].filepath+'" class="layui-btn layui-btn-xs layui-btn-normal file-view-pdf">预览</span>';
  344. }
  345. li+='<li data-id="'+item[a].id+'" data-title="'+item[a].name+'" data-ext="'+item[a].fileext+'"><img src="'+path+'" alt="'+item[a].filename+'" style="object-fit: contain;" class="file-item"><p title="'+item[a].name+'">'+item[a].name+'</p><div class="layui-btn-group"><span class="layui-btn layui-btn-xs file-edit">重命名</span>'+down+'<span class="layui-btn layui-btn-xs layui-btn-danger file-del">删除</span></div></li>';
  346. }
  347. $('#filesBox').html(li);
  348. $('#laypage').show();
  349. }
  350. else{
  351. $('#filesBox').html('<div class="empty"><i class="layui-icon layui-icon-upload"></i><p>无文件文件,赶紧去上传吧!</p></div>');
  352. $('#laypage').hide();
  353. }
  354. }
  355. }
  356. });
  357. }
  358. $('#filesBox').on('click','.file-item',function(){
  359. $(this).parent().toggleClass("on");
  360. })
  361. $('#filesBox').on('click','.file-del',function(){
  362. let id = $(this).parent().parent().data('id');
  363. layer.confirm('确定要删除该文件吗?请慎重', { icon: 3, title: '提示' }, function (index) {
  364. let callback = function (e) {
  365. layer.closeAll();
  366. layer.msg(e.msg);
  367. $('[lay-filter="webform"]').click();
  368. }
  369. tool.delete("/admin/files/delete", {ids:id}, callback);
  370. });
  371. })
  372. $('#filesBox').on('click','.file-edit',function(){
  373. let id = $(this).parent().parent().data('id');
  374. let title = $(this).parent().parent().data('title');
  375. let ext = $(this).parent().parent().data('ext');
  376. layer.prompt({
  377. title: '重命名',
  378. value: title,
  379. yes: function(index, layero) {
  380. // 获取文本框输入的值
  381. var value = layero.find(".layui-layer-input").val();
  382. if (value!='') {
  383. let callback = function (e) {
  384. layer.msg(e.msg);
  385. $('[lay-filter="webform"]').click();
  386. }
  387. tool.post("/admin/files/edit", {id: id,title: value+'.'+ext}, callback);
  388. layer.close(index);
  389. } else {
  390. layer.msg('请填写分组名称');
  391. }
  392. }
  393. })
  394. })
  395. //监听搜索提交
  396. form.on('submit(webform)', function(data) {
  397. get_files(data.field);
  398. return false;
  399. });
  400. }
  401. </script>
  402. {/block}
  403. <!-- /脚本 -->