index.html 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <style>
  4. #myProgress {
  5. width: 100%;
  6. background-color: #ddd;
  7. }
  8. #myBar {
  9. width: 1%;
  10. height: 30px;
  11. background-color: #4CAF50;
  12. }
  13. </style>
  14. <head>
  15. <meta charset="utf-8">
  16. <title>Transloadr</title>
  17. <script src="js/vue.js"></script>
  18. <script src="js/moment.js"></script>
  19. </head>
  20. <body>
  21. <div id="app">
  22. <table>
  23. <template v-for="(item, index) in transfers">
  24. <tr>
  25. <td> {{ item.id }}</td>
  26. <td style="width:200px;">
  27. <div id="myProgress">
  28. <div id="myBar" :style="{width: item.progress + '%'}">{{ item.progress }}</div>
  29. </div>
  30. </td>
  31. <td style="width:200px;">
  32. <pre></pre>
  33. </td>
  34. </tr>
  35. <tr>
  36. <td></td>
  37. <td>
  38. <pre>id: {{ item.id}}
  39. from: {{ item.from}}
  40. to: {{ item.to}}
  41. bytesRead: {{ item.bytesRead}}
  42. uploadError: {{ item.uploadError}}
  43. uploadCode: {{ item.uploadCode}}
  44. uploadResponseBody: {{ item.uploadResponseBody}}
  45. uploadDone: {{ item.uploadDone}}
  46. downloadDone: {{ item.downloadDone}}
  47. rate: {{ item.rate}}k/s
  48. </pre>
  49. </td>
  50. <td></td>
  51. </tr>
  52. </template>
  53. </table>
  54. </div>
  55. <script type="application/javascript">
  56. new Vue({
  57. el: '#app',
  58. data: {
  59. input: '',
  60. transfers: [],
  61. },
  62. created: function () {
  63. setInterval(this.update, 330);
  64. },
  65. watch: {},
  66. methods: {
  67. ts2txt: function (ts) {
  68. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  69. },
  70. handleErrors: function (response) {
  71. if (!response.ok) throw Error(response.statusText);
  72. return response;
  73. },
  74. update: function (event) {
  75. fetch('/status', {method: "GET"})
  76. .then(this.handleErrors)
  77. .then(response => {
  78. return response.json();
  79. })
  80. .then(myJson => {
  81. this.$data.transfers = myJson;
  82. })
  83. .catch(error => {
  84. this.$data.log = [];
  85. console.log(error)
  86. });
  87. }
  88. }
  89. })
  90. </script>
  91. </body>
  92. </html>