123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Vue.js markdown editor example</title>
- <link rel="stylesheet" href="css/style.css">
- <script src="js/moment.js"></script>
- <script src="js/vue.js"></script>
- </head>
- <body>
- <div id="app">
- <textarea v-model="input" cols="80" rows="20"></textarea>
- <button v-on:click="send">send</button>
- <ul id="loglist">
- <li v-for="(item, index) in log.slice().reverse()">
- {{ index }} - {{ item.entry.message }} - {{ ts2txt(item.ts) }}
- </li>
- </ul>
- </div>
- <script type="application/javascript">
- new Vue({
- el: '#app',
- data: {
- input: '// rde.writeCmd("set_digital_out(2,True)");\n' +
- '// rde.writeCmd("movej([-1.95,-1.58,-1.16,-1.15,-1.55,1.25], a=1.0, v=0.1)");\n' +
- '//rde.writeCmd("freedrive_mode()");\n'+
- 'def asdf():\n' +
- ' set_digital_out(3, True) \n' +
- ' set_digital_out(4, True) \n' +
- 'end',
- log: [],
- lastID: -1
- },
- created: function() {
- setInterval(this.update, 200);
- },
- methods: {
- send: function (event) {
- fetch('/cmd', {method: "POST", body: this.input})
- .then(function(response) {
- return response;
- });
- },
- ts2txt: function (ts) {
- return moment(ts).format('YYYY-MM-DD [at] hh:mm')
- },
- update: function (event) {
- fetch('/log/'+this.lastID, {method: "GET"})
- .then((response) => {
- return response.json();
- })
- .then((myJson) => {
- console.log(JSON.stringify(myJson));
- this.$data.log=this.$data.log.concat(myJson.entries);
- this.$data.lastID=myJson.lastID;
- });
- }
- }
- })
- </script>
- </body>
- </html>
|