index.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. </article>
  76. <script>
  77. //通过点击图片来触发文件上传按钮
  78. function uploadFile(params) {
  79. $("#upload_file").click();
  80. }
  81. // 上传处理
  82. function fileChange() {
  83. let uploadFile = $("#upload_file").get(0).files;
  84. // console.log(uploadFile);
  85. if (uploadFile == undefined || uploadFile == null) {
  86. layer.msg("请选择文件", { icon: 5, time: 1000 });
  87. return false;
  88. }
  89. if (uploadFile.length > 20) {
  90. layer.msg("最多20个文件", { icon: 5, time: 1000 });
  91. return false;
  92. }
  93. let formData = new FormData();
  94. for (let i = 0; i < uploadFile.length; i++) {
  95. formData.append('upload_file[]', uploadFile[i]);
  96. }
  97. $.ajax({
  98. url: '{:url("file_manager/uploadFile")}',
  99. type: 'post',
  100. dataType: 'json',
  101. data: formData,
  102. processData: false,
  103. contentType: false,
  104. xhr: function () {
  105. var xhr = new XMLHttpRequest();
  106. //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
  107. xhr.upload.addEventListener('progress', function (e) {
  108. // console.log(e);
  109. //loaded代表上传了多少
  110. //total代表总数为多少
  111. var progressRate = (e.loaded / e.total) * 100 + '%';
  112. //通过设置进度条的宽度达到效果
  113. $('.progress > div').css('width', progressRate);
  114. })
  115. return xhr;
  116. },
  117. success: function (res) {
  118. console.log(res);
  119. if (res.code == 0) {
  120. layer.msg(res.msg, {
  121. icon: 1,
  122. time: 1000
  123. });
  124. window.location.reload();
  125. } else {
  126. layer.msg(res.msg, {
  127. icon: 5,
  128. time: 1000
  129. });
  130. return false;
  131. }
  132. }
  133. });
  134. }
  135. function editTitle(id, title) {
  136. if (id==0) {
  137. layer.msg('id不可为空', {icon: 5,time: 1000});
  138. }
  139. var content = '<div class="cl" style="padding:20px;">';
  140. content += '<label class="form-label col-sm-4">';
  141. content += '<span class="c-red">*</span>文件title:</label>';
  142. content += '<div class="formControls col-sm-6">';
  143. content += '<input type="text" class="input-text" name="filetile" id="filetile">';
  144. content += '</div><div class="col-3"></div></div></div>';
  145. layer.open({
  146. type: 1,
  147. area: ['500px', '200px'],
  148. title: '修改文件title',
  149. content: '\<\div style="padding:20px;">\<\span class="c-red">*\<\/span>文件title:\<\input type="text" class="input-text" name="filetitle" value="'+title+'" id="filetitle">\<\/div>',
  150. btn: ['确定', '取消'],
  151. yes: function(index, layero){
  152. let filetitle = document.querySelector('input[name="filetitle"]').value;
  153. $.ajax({
  154. url: '{:url("file_manager/updateFileTitle")}',
  155. type: 'post',
  156. dataType: 'json',
  157. contentType: 'application/json',
  158. data: JSON.stringify({
  159. id: id,
  160. filetitle: filetitle
  161. }),
  162. success: function (res) {
  163. if (res.code == 0) {
  164. layer.msg(res.msg, {
  165. icon: 1,
  166. time: 1000
  167. });
  168. window.location.reload();
  169. } else {
  170. layer.msg(res.msg, {
  171. icon: 5,
  172. time: 1000
  173. });
  174. }
  175. layer.close(index);
  176. }
  177. });
  178. }
  179. });
  180. // layer.open({
  181. // type: 2,
  182. // area: ['700px', '500px'],
  183. // fix: false, //不固定
  184. // maxmin: true,
  185. // shade: 0.4,
  186. // title: '添加标题图',
  187. // content: 'test'
  188. // });
  189. }
  190. </script>