123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <!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/util.js"></script>
- <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()">
- {{ ts2txt(item.ts) }} - {{ item.entry.message }} - <pre>{{ JSON.stringify(item.entry) }}</pre>
- </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 hh:mm ss.SSS ')
- },
- update: function (event) {
- fetch('/log/'+this.lastID, {method: "GET"})
- .then(handleErrors)
- .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;
- let len=this.$data.log.length;
- this.$data.log.splice(0,len-200);
- })
- .catch(error => {
- this.$data.lastID=0;
- this.$data.log=[];
- console.log(error)
- } );
- }
- }
- })
- </script>
- </body>
- </html>
|