index.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Vue.js markdown editor example</title>
  6. <link rel="stylesheet" href="css/style.css">
  7. <script src="js/util.js"></script>
  8. <script src="js/moment.js"></script>
  9. <script src="js/vue.js"></script>
  10. </head>
  11. <body>
  12. <div id="app">
  13. <textarea v-model="input" cols="80" rows="20"></textarea>
  14. <button v-on:click="send">send</button>
  15. <ul id="loglist">
  16. <li v-for="(item, index) in log.slice().reverse()">
  17. {{ ts2txt(item.ts) }} - {{ item.entry.message }} - <pre>{{ JSON.stringify(item.entry) }}</pre>
  18. </li>
  19. </ul>
  20. </div>
  21. <script type="application/javascript">
  22. new Vue({
  23. el: '#app',
  24. data: {
  25. input: '// rde.writeCmd("set_digital_out(2,True)");\n' +
  26. '// rde.writeCmd("movej([-1.95,-1.58,-1.16,-1.15,-1.55,1.25], a=1.0, v=0.1)");\n' +
  27. '//rde.writeCmd("freedrive_mode()");\n'+
  28. 'def asdf():\n' +
  29. ' set_digital_out(3, True) \n' +
  30. ' set_digital_out(4, True) \n' +
  31. 'end',
  32. log: [],
  33. lastID: -1
  34. },
  35. created: function() {
  36. setInterval(this.update, 200);
  37. },
  38. methods: {
  39. send: function (event) {
  40. fetch('/cmd', {method: "POST", body: this.input})
  41. .then(function(response) {
  42. return response;
  43. });
  44. },
  45. ts2txt: function (ts) {
  46. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  47. },
  48. update: function (event) {
  49. fetch('/log/'+this.lastID, {method: "GET"})
  50. .then(handleErrors)
  51. .then((response) => {
  52. return response.json();
  53. })
  54. .then((myJson) => {
  55. console.log(JSON.stringify(myJson));
  56. this.$data.log=this.$data.log.concat(myJson.entries);
  57. this.$data.lastID=myJson.lastID;
  58. let len=this.$data.log.length;
  59. this.$data.log.splice(0,len-200);
  60. })
  61. .catch(error => {
  62. this.$data.lastID=0;
  63. this.$data.log=[];
  64. console.log(error)
  65. } );
  66. }
  67. }
  68. })
  69. </script>
  70. </body>
  71. </html>