index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <input v-model="from" placeholder="from">
  23. <input v-model="to" placeholder="to">
  24. <button @click="send">Send</button>
  25. <table>
  26. <template v-for="(item, index) in transfers">
  27. <tr>
  28. <td> {{ item.id }}</td>
  29. <td style="width:200px;">
  30. <div id="myProgress">
  31. <div id="myBar" :style="{width: item.progress + '%'}">{{ item.progress }}</div>
  32. </div>
  33. </td>
  34. <td style="width:200px;">
  35. <pre></pre>
  36. </td>
  37. </tr>
  38. <tr>
  39. <td></td>
  40. <td>
  41. <pre>id: {{ item.id}}
  42. from: {{ item.from}}
  43. to: {{ item.to}}
  44. bytesRead: {{ item.bytesRead}}
  45. uploadError: {{ item.uploadError}}
  46. uploadCode: {{ item.uploadCode}}
  47. uploadResponseBody: {{ item.uploadResponseBody}}
  48. uploadDone: {{ item.uploadDone}}
  49. downloadDone: {{ item.downloadDone}}
  50. rate: {{ item.rate}}k/s
  51. </pre>
  52. </td>
  53. <td></td>
  54. </tr>
  55. </template>
  56. </table>
  57. </div>
  58. <script type="application/javascript">
  59. new Vue({
  60. el: '#app',
  61. data: {
  62. input: '',
  63. transfers: [],
  64. from: '',
  65. to: ''
  66. },
  67. created: function () {
  68. setInterval(this.update, 330);
  69. },
  70. watch: {},
  71. methods: {
  72. send: function (ts) {
  73. let data = new URLSearchParams();
  74. data.append('from', this.from);
  75. data.append('to', this.to);
  76. fetch('/xfer', {
  77. method: "POST",
  78. body: data
  79. }).then(response => {
  80. console.log(response);
  81. })
  82. .catch(error => {
  83. this.$data.log = [];
  84. console.log(error)
  85. });
  86. },
  87. ts2txt: function (ts) {
  88. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  89. },
  90. handleErrors: function (response) {
  91. if (!response.ok) throw Error(response.statusText);
  92. return response;
  93. },
  94. update: function (event) {
  95. fetch('/status', {method: "GET"})
  96. .then(this.handleErrors)
  97. .then(response => {
  98. return response.json();
  99. })
  100. .then(myJson => {
  101. this.$data.transfers = myJson;
  102. })
  103. .catch(error => {
  104. this.$data.log = [];
  105. console.log(error)
  106. });
  107. }
  108. }
  109. })
  110. </script>
  111. </body>
  112. </html>