|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <v-text-field |
| 4 | + :value="newValue" |
| 5 | + @input="emitChange" |
| 6 | + :items="history" |
| 7 | + class="ma-4" |
| 8 | + clearable |
| 9 | + solo |
| 10 | + dense |
| 11 | + hide-details |
| 12 | + placeholder="Send gcode" |
| 13 | + append-outer-icon="mdi-send" |
| 14 | + @click:append-outer="emitSend(newValue)" |
| 15 | + @keyup.enter="emitSend(newValue)" |
| 16 | + @keyup.up="historyUp()" |
| 17 | + @keyup.down="historyDown()"> |
| 18 | + </v-text-field> |
| 19 | + <!-- {{ originalHistory}}<br /> |
| 20 | + {{ history }} --> |
| 21 | + </div> |
| 22 | +</template> |
| 23 | + |
| 24 | +<script lang="ts"> |
| 25 | +import { Vue, Component, Prop } from 'vue-property-decorator' |
| 26 | +
|
| 27 | +@Component({}) |
| 28 | +export default class InputConsoleCommand extends Vue { |
| 29 | + @Prop({ type: String, required: true }) |
| 30 | + public value!: string |
| 31 | +
|
| 32 | + newValue = '' |
| 33 | + history: string[] = [] |
| 34 | + originalHistory: string[] = [] |
| 35 | + isFirst = true |
| 36 | +
|
| 37 | + mounted () { |
| 38 | + this.newValue = this.value |
| 39 | + } |
| 40 | +
|
| 41 | + emitChange (val: string) { |
| 42 | + this.newValue = val |
| 43 | + this.$emit('input', val) |
| 44 | + } |
| 45 | +
|
| 46 | + emitSend (val: string) { |
| 47 | + if (val && val.length > 0) { |
| 48 | + this.newValue = '' |
| 49 | + if (this.history.length >= 5) { |
| 50 | + this.originalHistory.shift() |
| 51 | + } |
| 52 | + this.originalHistory.unshift(val) |
| 53 | + this.history = Object.assign([], this.originalHistory) |
| 54 | + this.isFirst = true |
| 55 | + this.$emit('send', val) |
| 56 | + } |
| 57 | + } |
| 58 | +
|
| 59 | + historyUp () { |
| 60 | + if (this.history.length >= 1) { |
| 61 | + if (!this.isFirst) { |
| 62 | + const f = this.history.shift() as string |
| 63 | + this.history.push(f) |
| 64 | + } |
| 65 | + this.newValue = this.history[0] |
| 66 | + this.isFirst = false |
| 67 | + } |
| 68 | + } |
| 69 | +
|
| 70 | + historyDown () { |
| 71 | + if (this.history.length >= 1) { |
| 72 | + if (!this.isFirst) { |
| 73 | + const f = this.history.pop() as string |
| 74 | + this.history.unshift(f) |
| 75 | + } |
| 76 | + this.newValue = this.history[0] |
| 77 | + this.isFirst = false |
| 78 | + } |
| 79 | + } |
| 80 | +} |
| 81 | +</script> |
0 commit comments