index.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. }
  10. /* 初始状态设置进度条宽度为0px */
  11. .progress>div {
  12. width: 0px;
  13. height: 100%;
  14. background-color: yellowgreen;
  15. transition: all .3s ease;
  16. }
  17. </style>
  18. <article class="cl pd-10">
  19. <div class="cl pd-5 bg-1 bk-gray mt-20">
  20. <span class="l">
  21. <a class="btn radius btn-secondary"><i class="Hui-iconfont Hui-iconfont-jifen"></i>数据库模式</a>
  22. <a class="btn radius btn-default" href="{:url('explorer')}"><i class="Hui-iconfont Hui-iconfont-pages"></i> 目录模式 </a>
  23. <a class="btn btn-primary radius" onclick="uploadFile();"><i class="Hui-iconfont Hui-iconfont-add"></i>上传附件</a>
  24. <input type="file" id="upload_file" hidden multiple onchange ="fileChange()">
  25. <div class="progress">
  26. <div></div>
  27. </div>
  28. </span>
  29. <span class="r">共有数据:<strong id="total">{$list->total()}</strong>条</span>
  30. </div>
  31. <div class="cl mt-20">
  32. <table class="table table-border table-bordered table-bg">
  33. <thead>
  34. <tr class="text-c">
  35. <th width="25px;">
  36. <input type="checkbox" name="allcheck" value="">
  37. </th>
  38. <th width="60px;">ID</th>
  39. <th width="120px;">文件title</th>
  40. <th style="min-width: 260px;">文件名</th>
  41. <th>文件类型</th>
  42. <th>文件大小</th>
  43. <th>增加者</th>
  44. <th>增加时间</th>
  45. <th width="100px;">操作</th>
  46. </tr>
  47. </thead>
  48. <tbody>
  49. {foreach $list as $val}
  50. <tr class="text-c">
  51. <td>
  52. <input type="checkbox" value="{$val.fileid}" name="checkbox[]">
  53. </td>
  54. <td>{$val.fileid}</td>
  55. <td class="text-l">{$val.title}</td>
  56. <td class="text-l">
  57. <a href="{$val.filepath}" title="{$val.filepath}" target="_blank">{$val.filename}</a>
  58. </td>
  59. <td>{$val.fileextension}</td>
  60. <td>{$val.filesize|format_bytes}</td>
  61. <td>{$val.username}</td>
  62. <td>{$val.filetime|date="Y-m-d"}</td>
  63. <td><a class="btn btn-danger radius" title="删除" onClick="del(this,'{$val.fileid}')"><i class="Hui-iconfont Hui-iconfont-del2"></i></a></td>
  64. </tr>
  65. {/foreach}
  66. </tbody>
  67. </table>
  68. </div>
  69. </article>
  70. <script>
  71. //通过点击图片来触发文件上传按钮
  72. function uploadFile(params) {
  73. $("#upload_file").click();
  74. }
  75. // 上传处理
  76. function fileChange() {
  77. let data = $("#upload_file").get(0).files;
  78. console.log(data);
  79. if (data == undefined || data == null) {
  80. layer.msg("请选择视频文件", { icon: 5, time: 1000 });
  81. return false;
  82. }
  83. let formData = new FormData();
  84. formData.append("upload_file", data);
  85. $.ajax({
  86. url: '{:url("file_manager/uploadFile")}',
  87. type: 'post',
  88. dataType: 'json',
  89. data: formData,
  90. processData: false,
  91. contentType: false,
  92. xhr: function () {
  93. var xhr = new XMLHttpRequest();
  94. //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
  95. xhr.upload.addEventListener('progress', function (e) {
  96. console.log(e);
  97. //loaded代表上传了多少
  98. //total代表总数为多少
  99. var progressRate = (e.loaded / e.total) * 100 + '%';
  100. //通过设置进度条的宽度达到效果
  101. $('.progress > div').css('width', progressRate);
  102. })
  103. return xhr;
  104. },
  105. success: function (res) {
  106. console.log(res);
  107. if (res.code == 1) {
  108. layer.msg(data.msg, {
  109. icon: 5,
  110. time: 1000
  111. });
  112. window.location.reload();
  113. } else {
  114. layer.msg(res.msg, {
  115. icon: 5,
  116. time: 1000
  117. });
  118. return false;
  119. }
  120. }
  121. });
  122. }
  123. </script>