index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. {__NOLAYOUT__}
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>A3Mall | Dashboard</title>
  7. <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  8. <link rel="stylesheet" href="{__SYSTEM_PATH__}/js/bootstrap/css/bootstrap.min.css">
  9. <link rel="stylesheet" href="{__SYSTEM_PATH__}/font/font-awesome/css/font-awesome.min.css">
  10. <link rel="stylesheet" href="{__SYSTEM_PATH__}/js/layui/css/layui.css">
  11. <link rel="stylesheet" href="{__SYSTEM_PATH__}/css/base.css">
  12. <script src="{__SYSTEM_PATH__}/js/jquery/jquery.min.js"></script>
  13. <script src="{__SYSTEM_PATH__}/js/bootstrap/js/bootstrap.min.js"></script>
  14. <script src="{__SYSTEM_PATH__}/js/layui/layui.js"></script>
  15. <script src="{__SYSTEM_PATH__}/js/fastclick/fastclick.js"></script>
  16. <script src="{__SYSTEM_PATH__}/js/adminlte/adminlte.min.js"></script>
  17. <script src="{__SYSTEM_PATH__}/js/jquery-slimscroll/jquery.slimscroll.min.js"></script>
  18. </head>
  19. <body>
  20. <div class="material-wrap">
  21. <div class="material-l">
  22. <ul>
  23. <li class="active" data-id="0">全部文件</li>
  24. </ul>
  25. </div>
  26. <div class="material-r">
  27. <div class="material-tools-box">
  28. <div class="left-btn">
  29. <button id="create-category" type="button" class="layui-btn layui-btn-normal layui-btn-sm">
  30. <i class="layui-icon">&#xe654;</i>添加分类
  31. </button>
  32. <button id="delete-image" type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-btn-danger">
  33. <i class="layui-icon">&#xe640;</i>删除选中文件
  34. </button>
  35. </div>
  36. <div class="upload">
  37. <button id="uploadfiy" type="button" class="layui-btn layui-btn-normal layui-btn-sm">
  38. <i class="layui-icon">&#xe67c;</i>上传
  39. </button>
  40. </div>
  41. </div>
  42. <div class="upload-list-box clearfix">
  43. <div id="upload-loading-box"><span class="fa fa-spinner fa-spin fa-2x fa-fw"></span></div>
  44. <div id="upload-empty-list">暂无内容</div>
  45. <div class="layui-row"></div>
  46. </div>
  47. <div class="bottom">
  48. <div class="sel-box">
  49. <button id="sel-btn" type="button" class="layui-btn layui-btn-normal layui-btn-sm">
  50. 选中图片(<i>0</i>)张
  51. </button>
  52. </div>
  53. <div class="page" id="hide"></div>
  54. </div>
  55. </div>
  56. </div>
  57. <script>
  58. var array = [];
  59. layui.use(['upload','layer'], function () {
  60. var upload = layui.upload;
  61. var layer = layui.layer;
  62. $("#sel-btn").on("click",function (){
  63. parent.{$callback}(array);
  64. });
  65. $(".page").show();
  66. var handle = function (res){
  67. $("#upload-loading-box").hide();
  68. $(".upload-list-box .layui-row").html("");
  69. if(res.data.result.length){
  70. $("#upload-empty-list").hide();
  71. for(var obj in res.data.result){
  72. var data = res.data.result[obj];
  73. var str = "<div class='layui-col-md2 layui-col-upload-box'> <div class='upload-ls-box' data-id='"+data.id+"' data-img='"+data.path+"'> <div class='img' align='center'><img src='"+data.path+"'></div><div class='tit'>"+data.name+"</div></div></div>";
  74. $(".upload-list-box .layui-row").append(str);
  75. }
  76. $(".upload-list-box").scrollTop(0);
  77. }else{
  78. if(res.data.count){
  79. if($(".upload-list-box .layui-row .layui-col-upload-box").length){
  80. $("#upload-empty-list").hide();
  81. }else{
  82. $("#upload-empty-list").show();
  83. }
  84. }else{
  85. $("#upload-empty-list").show();
  86. }
  87. }
  88. $(".page").html(res.data.page);
  89. };
  90. var getMenu = function (){
  91. $.get("{:createUrl('common.material/get_cat',['type'=>$type])}",function (res){
  92. if(res.data.length){
  93. var str = "<li data-id='0' class='active'>全部文件</li>";
  94. for(var i=0; i<res.data.length; i++){
  95. str += "<li data-id='"+res.data[i].id+"'>"+res.data[i].name+"<span class='delete'>x</span></li>";
  96. }
  97. $(".material-l ul").html(str);
  98. $("#upload-loading-box").hide();
  99. }
  100. },"json");
  101. };
  102. getMenu();
  103. $(document).on("click",".material-l li",function (e){
  104. e.stopPropagation();
  105. var index = $(".material-l li").index($(this));
  106. $(".material-l li").removeClass("active").eq(index).addClass("active");
  107. $("#upload-loading-box").show();
  108. $.get("{:createUrl('common.material/get_list')}",{
  109. type: '{$type}',"cat_id": $(".material-l li.active").attr("data-id")
  110. },function (res){
  111. handle(res);
  112. },"json");
  113. });
  114. $(document).on("click",".material-l li span",function (e){
  115. e.stopPropagation();
  116. var that = $(this);
  117. var pid = $(this).parent().attr("data-id");
  118. layer.confirm('确定要删除吗,该操作将删除分类下所有资源?', {
  119. btn: ['确定','取消']
  120. }, function(){
  121. $.get("{:createUrl('common.material/delete_category')}",{ id: pid },function (res){
  122. if(res.code){
  123. that.parent().remove();
  124. $(".material-l li").eq(0).trigger("click");
  125. }
  126. layer.msg(res.msg);
  127. },"json");
  128. }, function(){});
  129. });
  130. $("#create-category").on("click",function (){
  131. layer.prompt({title: '请输入分类名称', formType: 0}, function(text, index){
  132. var loadIndex = layer.load(1, {
  133. shade: [0.1,'#fff'],time: 5000 * 1000
  134. });
  135. $.post("{:createUrl('common.material/create_category')}",{ name: text,type: '{$type}' },function(res){
  136. if(res.code){
  137. layer.close(index);
  138. getMenu();
  139. }else{
  140. layer.msg(res.msg);
  141. }
  142. },"json");
  143. layer.close(loadIndex);
  144. });
  145. });
  146. var getList = function (){
  147. $("#upload-loading-box").show();
  148. $.get("{:createUrl('common.material/get_list')}",{
  149. type: '{$type}',cat_id: $(".material-l li.active").attr("data-id")
  150. },function (res){
  151. handle(res);
  152. },"json");
  153. };
  154. getList();
  155. upload.render({
  156. elem: '#uploadfiy'
  157. ,url: '{:createUrl("common.uploadfiy/upload")}'
  158. ,multiple: true
  159. {if input('type','image') == 'image'}
  160. ,exts: 'jpg|png|gif|bmp|jpeg'
  161. {elseif input('type') == 'video'}
  162. ,exts: 'mp4'
  163. {elseif input('type') == 'file'}
  164. ,exts: 'zip|rar|txt'
  165. {/if}
  166. ,data: {
  167. cat_id: function (){
  168. return $(".material-l li.active").attr("data-id");
  169. },
  170. module: function (){
  171. return "{:input('module')}";
  172. },
  173. method: function (){
  174. return "{:input('method')}";
  175. }
  176. }
  177. //,number: 5
  178. ,done: function(res){
  179. if(res.code == 0){
  180. getList();
  181. }else{
  182. layer.msg(res.msg,{ icon : 2 });
  183. }
  184. }
  185. ,error: function(){
  186. layer.msg("调用上传接口失败,请稍后在试。",{ icon : 2 });
  187. }
  188. });
  189. $(document).on("mouseover",".material-l li",function (){
  190. $(this).find("span").show();
  191. });
  192. $(document).on("mouseout",".material-l li",function (){
  193. $(this).find("span").hide();
  194. });
  195. $(document).on("click",".page a",function (){
  196. $.get($(this).attr("href"),function (res){
  197. handle(res);
  198. },"json");
  199. return false;
  200. });
  201. $(document).on("click",".upload-ls-box",function (){
  202. if($(this).is(".active")){
  203. $(this).removeClass("active");
  204. }else{
  205. $(this).addClass("active");
  206. }
  207. if($(".upload-ls-box.active",document).length){
  208. array = [];
  209. $(".upload-ls-box.active",document).each(function (index,item){
  210. array.push($(item).attr("data-img"));
  211. });
  212. $(".sel-box").show();
  213. $(".sel-box i").text($(".upload-ls-box.active",document).length);
  214. }else{
  215. array = [];
  216. $(".sel-box").hide();
  217. $(".sel-box i").text(0);
  218. }
  219. });
  220. $("#delete-image").on("click",function (){
  221. if($(".upload-ls-box.active",document).length <= 0){
  222. layer.msg("请选择要删除的图片");
  223. return false;
  224. }
  225. var array = [];
  226. $(".upload-ls-box.active",document).each(function (){
  227. array.push($(this).attr("data-id"));
  228. });
  229. if(array.length <= 0){
  230. return false;
  231. }
  232. $.get("{:createUrl('common.material/delete')}",{ id: array.join(",") },function(res){
  233. if(res.code){
  234. $.get("{:createUrl('common.material/get_list')}",{
  235. type: '{$type}',"cat_id": $(".material-l li.active").attr("data-id")
  236. },function (res){
  237. handle(res);
  238. },"json");
  239. }
  240. layer.msg(res.msg);
  241. },"json");
  242. });
  243. });
  244. </script>
  245. <style type="text/css">
  246. #hide { display: none; }
  247. .material-wrap { width: 100%; height: 550px; background: #fff; margin: 0px auto 20px auto; }
  248. .material-l { float: left; width: 14%; height: 550px; overflow-y: auto; }
  249. .material-l ul { display: block; overflow-y: auto; }
  250. .material-l ul li { position: relative; color: #333; cursor: pointer; text-align: center; height: 30px; line-height: 30px; }
  251. .material-l ul li.active,.material-l ul li:hover { color: #1E9FFF; }
  252. .material-l ul li:first-child { padding-top: 5px; }
  253. .material-l ul li .delete { display: none; position: absolute; top: 0; right: 10px; }
  254. .material-r { float: right; width: 85%; height: 550px; border-left: 1px solid #e6e6e6; position: relative; }
  255. .material-r #upload-loading-box { background: rgba(255,255,255,.7); z-index: 9999; position: absolute; left: 0; top: 0; width: 100%; height: 550px; }
  256. .material-r #upload-loading-box span { z-index: 19999; color: #666; position: absolute; left: 45%; top: 42%; transform: translate(-45%,-42%); }
  257. .material-r #upload-empty-list { display: none; text-align: center; font-size: 16px; position: absolute; left: 45%; top: 42%; transform: translate(-45%,-42%); }
  258. .material-tools-box { float: left; width: 100%; padding: 10px 1% 0 1%; height: 50px; border-bottom: 1px solid #e6e6e6; }
  259. .material-tools-box .left-btn { float: left; }
  260. .material-tools-box .upload { float: right; }
  261. .upload-list-box { width: 100%; height: 450px; padding-top: 15px; overflow-y: auto; }
  262. .upload-list-box .upload-ls-box { margin: 0 auto; border-radius: 4px; border: 1px solid #fff; background: #f4f4f4; margin-bottom: 10px; width: 123px; height: 171px; overflow: hidden; }
  263. .upload-list-box .upload-ls-box.active { border: 1px solid #f17d7d; }
  264. .upload-list-box .upload-ls-box .img { background: #fff; padding-bottom: 10px; }
  265. .upload-list-box .upload-ls-box .tit { text-align: center; font-size: 14px; padding-top: 5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  266. .upload-list-box .upload-ls-box div img { text-align: center; max-width: 120px; height: 130px; }
  267. .upload-list-box .upload-ls-box div.img { width: 120px; height: 130px; }
  268. .layui-col-upload-box { text-align: center; }
  269. .material-r .bottom { position: absolute; left: 0; bottom: 0px; width: 100%; }
  270. .material-r .bottom .sel-box { float: left; margin-left: 9px; margin-top: 10px; display: none; }
  271. .material-r .bottom .sel-box i { font-style: normal; }
  272. .material-r .page { background-color: #fff; padding-top: 10px; width: 100%; height: 50px; line-height: 50px; display: inline-block; text-align: center; }
  273. .material-r .page .pagination { margin: 0; position: relative; }
  274. .material-r .pagination>li>a,
  275. .material-r .pagination>li>span { position: relative; float: left; height: 30px; margin-left: -1px; line-height: 30px; padding: 0px 12px; color: #337ab7; text-decoration: none; background-color: #fff; border: 1px solid #ddd; }
  276. .material-r .pagination>.active>a,
  277. .material-r .pagination>.active>a:focus,
  278. .material-r .pagination>.active>a:hover,
  279. .material-r .pagination>.active>span,
  280. .material-r .pagination>.active>span:focus,
  281. .material-r .pagination>.active>span:hover { z-index: 3; color: #fff; cursor: default; background-color: #337ab7; border-color: #337ab7; }
  282. </style>
  283. </body>
  284. </html>