|
| 1 | +<template> |
| 2 | + <div class="fit row wrap justify-start items-start content-start"> |
| 3 | + <div class="col-grow"> |
| 4 | + <div>Terminal</div> |
| 5 | + <div> |
| 6 | + <q-input |
| 7 | + ref="commandInput" |
| 8 | + outlined |
| 9 | + v-model="command" |
| 10 | + type="textarea" |
| 11 | + :disable="executing" |
| 12 | + :loading="executing" |
| 13 | + :error="errorIndicator" |
| 14 | + > |
| 15 | + <q-inner-loading :showing="executing"> |
| 16 | + <q-spinner-gears size="50px" color="primary" /> |
| 17 | + </q-inner-loading> |
| 18 | + </q-input> |
| 19 | + </div> |
| 20 | + <div style="margin-top: 4px"> |
| 21 | + <q-btn |
| 22 | + label="Execute as PowerShell" |
| 23 | + color="black" |
| 24 | + unelevated |
| 25 | + :disable="executing" |
| 26 | + @click=" |
| 27 | + () => { |
| 28 | + executeCommand(true); |
| 29 | + } |
| 30 | + " |
| 31 | + style="margin-right: 4px" |
| 32 | + /> |
| 33 | + <q-btn |
| 34 | + color="primary" |
| 35 | + label="Execute as Command Line" |
| 36 | + unelevated |
| 37 | + :disable="executing" |
| 38 | + @click=" |
| 39 | + () => { |
| 40 | + executeCommand(false); |
| 41 | + } |
| 42 | + " |
| 43 | + /> |
| 44 | + </div> |
| 45 | + <div> |
| 46 | + <div class="term"> |
| 47 | + {{ terminalResult }} |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | +</template> |
| 53 | + |
| 54 | +<style lang="scss" scoped> |
| 55 | +.term { |
| 56 | + background-color: #000; |
| 57 | + color: #fff; |
| 58 | + height: 460px; |
| 59 | + overflow: auto; |
| 60 | + padding: 10px; |
| 61 | + font-family: monospace; |
| 62 | + font-size: 12px; |
| 63 | + white-space: pre-wrap; |
| 64 | + word-wrap: break-word; |
| 65 | + border-radius: 5px; |
| 66 | + box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); |
| 67 | + margin-top: 20px; |
| 68 | + margin-bottom: 10px; |
| 69 | +} |
| 70 | +</style> |
| 71 | + |
| 72 | +<script lang="ts"> |
| 73 | +import { PropType, computed, defineComponent, ref } from 'vue'; |
| 74 | +import * as serviceApi from '../service-api'; |
| 75 | +import { ShellResponse, WinRMPayload } from '../models'; |
| 76 | +import { QInput } from 'quasar'; |
| 77 | +
|
| 78 | +export default defineComponent({ |
| 79 | + name: 'TerminalComponent', |
| 80 | +
|
| 81 | + props: { |
| 82 | + host: { |
| 83 | + type: Object as PropType<WinRMPayload>, |
| 84 | + required: true, |
| 85 | + }, |
| 86 | + }, |
| 87 | +
|
| 88 | + methods: { |
| 89 | + async executeCommand(isPowerShell: boolean) { |
| 90 | + this.executing = true; |
| 91 | + this.response = await serviceApi.execCommand( |
| 92 | + this.host, |
| 93 | + this.command, |
| 94 | + isPowerShell, |
| 95 | + ); |
| 96 | +
|
| 97 | + this.errorIndicator = this.response.exitCode !== 0; |
| 98 | + window.setTimeout(() => { |
| 99 | + this.errorIndicator = false; |
| 100 | + }, 5000); |
| 101 | + if (this.response.exitCode === 0) { |
| 102 | + this.command = ''; |
| 103 | + } |
| 104 | + this.executing = false; |
| 105 | + window.setTimeout(() => { |
| 106 | + (this.commandInput! as QInput).focus(); |
| 107 | + }, 100); |
| 108 | + }, |
| 109 | + }, |
| 110 | +
|
| 111 | + setup() { |
| 112 | + const command = ref(''); |
| 113 | + const response = ref<ShellResponse>({} as ShellResponse); |
| 114 | + const executing = ref(false); |
| 115 | + const errorIndicator = ref(false); |
| 116 | + const commandInput = ref(null); |
| 117 | + const terminalResult = computed(() => { |
| 118 | + if (response.value.exitCode === 0) { |
| 119 | + return response.value.stdout; |
| 120 | + } else { |
| 121 | + return response.value.stderr; |
| 122 | + } |
| 123 | + }); |
| 124 | + return { |
| 125 | + command, |
| 126 | + commandInput, |
| 127 | + response, |
| 128 | + executing, |
| 129 | + errorIndicator, |
| 130 | + terminalResult, |
| 131 | + }; |
| 132 | + }, |
| 133 | +}); |
| 134 | +</script> |
0 commit comments