index.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <style>
  2. .progress {
  3. width: 600px;
  4. height: 10px;
  5. border: 1px solid #ccc;
  6. border-radius: 10px;
  7. margin: 10px 0px;
  8. overflow: hidden;
  9. display: -webkit-inline-box;
  10. }
  11. /* 初始状态设置进度条宽度为0px */
  12. .progress>div {
  13. width: 0px;
  14. height: 100%;
  15. background-color: yellowgreen;
  16. transition: all .3s ease;
  17. }
  18. </style>
  19. <article class="cl pd-10">
  20. <div class="cl pd-5 bg-1 bk-gray mt-20">
  21. <span class="l">
  22. <a class="btn radius btn-secondary"><i class="Hui-iconfont Hui-iconfont-jifen"></i>数据库模式</a>
  23. <a class="btn radius btn-default" href="{:url('explorer')}"><i class="Hui-iconfont Hui-iconfont-pages"></i> 目录模式 </a>
  24. <a class="btn btn-danger radius" onclick="del_all();"><i class="Hui-iconfont Hui-iconfont-del2"></i>批量删除</a>
  25. <a class="btn btn-primary radius" onclick="uploadFile();"><i class="Hui-iconfont Hui-iconfont-add"></i>上传附件</a>
  26. <input type="file" id="upload_file" hidden multiple onchange="fileChange()">
  27. <div class="progress">
  28. <div></div>
  29. </div>
  30. </span>
  31. <span class="r">共有数据:<strong id="total">{$list->total()}</strong>条</span>
  32. </div>
  33. <div class="cl mt-20">
  34. <table class="table table-border table-bordered table-bg">
  35. <thead>
  36. <tr class="text-c">
  37. <th width="25px;">
  38. <input type="checkbox" name="allcheck" value="">
  39. </th>
  40. <th width="60px;">ID</th>
  41. <th>文件title</th>
  42. <th style="min-width: 260px;">文件路径</th>
  43. <th>文件类型</th>
  44. <th>文件大小</th>
  45. <th>增加者</th>
  46. <th>增加时间</th>
  47. <th width="100px;">操作</th>
  48. </tr>
  49. </thead>
  50. <tbody>
  51. {foreach $list as $val}
  52. <tr class="text-c">
  53. <td>
  54. <input type="checkbox" value="{$val.fileid}" name="checkbox[]">
  55. </td>
  56. <td>{$val.fileid}</td>
  57. <td class="text-l">{$val.title}</td>
  58. <td class="text-l">
  59. <a href="{$val.filepath}" title="{$val.filepath}" target="_blank">{$val.filepath}</a>
  60. </td>
  61. <td>{$val.fileextension}</td>
  62. <td>{$val.filesize|format_bytes}</td>
  63. <td>{$val.username}</td>
  64. <td>{$val.filetime|date="Y-m-d H:i:s"}</td>
  65. <td class="td-manager">
  66. <a class="btn btn-secondary radius" title="编辑title" onClick="editTitle('{$val.fileid}','{$val.title}')"><i
  67. class="Hui-iconfont Hui-iconfont-edit"></i></a>
  68. <a class="btn btn-danger radius" title="删除" onClick="del(this,'{$val.fileid}')"><i
  69. class="Hui-iconfont Hui-iconfont-del2"></i></a></td>
  70. </tr>
  71. {/foreach}
  72. </tbody>
  73. </table>
  74. </div>
  75. <div class="cl pd-5 bg-1 bk-gray mt-20 ">
  76. <span class="r">{$list->render()|raw}</span>
  77. </div>
  78. </article>
  79. <script>
  80. //通过点击图片来触发文件上传按钮
  81. function uploadFile(params) {
  82. $("#upload_file").click();
  83. }
  84. // 上传处理
  85. function fileChange() {
  86. let uploadFile = $("#upload_file").get(0).files;
  87. // console.log(uploadFile);
  88. if (uploadFile == undefined || uploadFile == null) {
  89. layer.msg("请选择文件", { icon: 5, time: 1000 });
  90. return false;
  91. }
  92. if (uploadFile.length > 20) {
  93. layer.msg("最多20个文件", { icon: 5, time: 1000 });
  94. return false;
  95. }
  96. let formData = new FormData();
  97. for (let i = 0; i < uploadFile.length; i++) {
  98. formData.append('upload_file[]', uploadFile[i]);
  99. }
  100. $.ajax({
  101. url: '{:url("file_manager/uploadFile")}',
  102. type: 'post',
  103. dataType: 'json',
  104. data: formData,
  105. processData: false,
  106. contentType: false,
  107. xhr: function () {
  108. var xhr = new XMLHttpRequest();
  109. //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
  110. xhr.upload.addEventListener('progress', function (e) {
  111. // console.log(e);
  112. //loaded代表上传了多少
  113. //total代表总数为多少
  114. var progressRate = (e.loaded / e.total) * 100 + '%';
  115. //通过设置进度条的宽度达到效果
  116. $('.progress > div').css('width', progressRate);
  117. })
  118. return xhr;
  119. },
  120. success: function (res) {
  121. console.log(res);
  122. if (res.code == 0) {
  123. layer.msg(res.msg, {
  124. icon: 1,
  125. time: 1000
  126. });
  127. window.location.reload();
  128. } else {
  129. layer.msg(res.msg, {
  130. icon: 5,
  131. time: 1000
  132. });
  133. return false;
  134. }
  135. }
  136. });
  137. }
  138. function editTitle(id, title) {
  139. if (id==0) {
  140. layer.msg('id不可为空', {icon: 5,time: 1000});
  141. }
  142. var content = '<div class="cl" style="padding:20px;">';
  143. content += '<label class="form-label col-sm-4">';
  144. content += '<span class="c-red">*</span>文件title:</label>';
  145. content += '<div class="formControls col-sm-6">';
  146. content += '<input type="text" class="input-text" name="filetile" id="filetile">';
  147. content += '</div><div class="col-3"></div></div></div>';
  148. layer.open({
  149. type: 1,
  150. area: ['500px', '200px'],
  151. title: '修改文件title',
  152. content: '\<\div style="padding:20px;">\<\span class="c-red">*\<\/span>文件title:\<\input type="text" class="input-text" name="filetitle" value="'+title+'" id="filetitle">\<\/div>',
  153. btn: ['确定', '取消'],
  154. yes: function(index, layero){
  155. let filetitle = document.querySelector('input[name="filetitle"]').value;
  156. $.ajax({
  157. url: '{:url("file_manager/updateFileTitle")}',
  158. type: 'post',
  159. dataType: 'json',
  160. contentType: 'application/json',
  161. data: JSON.stringify({
  162. id: id,
  163. filetitle: filetitle
  164. }),
  165. success: function (res) {
  166. if (res.code == 0) {
  167. layer.msg(res.msg, {
  168. icon: 1,
  169. time: 1000
  170. });
  171. window.location.reload();
  172. } else {
  173. layer.msg(res.msg, {
  174. icon: 5,
  175. time: 1000
  176. });
  177. }
  178. layer.close(index);
  179. }
  180. });
  181. }
  182. });
  183. // layer.open({
  184. // type: 2,
  185. // area: ['700px', '500px'],
  186. // fix: false, //不固定
  187. // maxmin: true,
  188. // shade: 0.4,
  189. // title: '添加标题图',
  190. // content: 'test'
  191. // });
  192. }
  193. </script>