This commit is contained in:
雷欧(林平凡)
2025-08-28 10:17:48 +08:00
parent 6d257dc840
commit ef1a0430d4

View File

@@ -21,10 +21,23 @@
<el-col :span="12"> <el-col :span="12">
<el-form label-position="top"> <el-form label-position="top">
<el-form-item label="响应"> <el-form-item label="响应">
<template v-if="resultList.length > 0">
<div v-for="(msg, idx) in resultList" :key="idx" style="margin-bottom: 12px;">
<el-input :value="msg" type="textarea" :rows="8" readonly />
<div style="margin-top: 6px;">
<el-button size="mini" type="success" @click="copyOne(msg)">复制第{{ idx + 1 }}</el-button>
</div>
</div>
<div>
<el-button size="mini" type="primary" @click="copyAll">复制全部</el-button>
</div>
</template>
<template v-else>
<el-input :value="result" type="textarea" :rows="18" readonly /> <el-input :value="result" type="textarea" :rows="18" readonly />
<div style="margin-top: 8px;"> <div style="margin-top: 8px;">
<el-button size="mini" type="success" @click="copyResult" :disabled="!result">复制响应</el-button> <el-button size="mini" type="success" @click="copyResult" :disabled="!result">复制响应</el-button>
</div> </div>
</template>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-col> </el-col>
@@ -42,13 +55,26 @@ export default {
return { return {
form: { command: '' }, form: { command: '' },
loading: false, loading: false,
result: '' result: '',
resultList: []
} }
}, },
methods: { methods: {
copyOne(text) {
if (!text) return
this.doCopy(text)
},
copyAll() {
if (!this.resultList || this.resultList.length === 0) return
const text = this.resultList.join('\n\n')
this.doCopy(text)
},
copyResult() { copyResult() {
if (!this.result) return if (!this.result) return
const text = this.result const text = this.result
this.doCopy(text)
},
doCopy(text) {
if (navigator.clipboard) { if (navigator.clipboard) {
navigator.clipboard.writeText(text).then(() => { navigator.clipboard.writeText(text).then(() => {
this.$modal.msgSuccess('复制成功') this.$modal.msgSuccess('复制成功')
@@ -74,7 +100,14 @@ export default {
executeInstruction({ command: cmd }).then(res => { executeInstruction({ command: cmd }).then(res => {
this.loading = false this.loading = false
if (res && (res.code === 200 || res.msg === '操作成功')) { if (res && (res.code === 200 || res.msg === '操作成功')) {
this.result = res.data || res.msg || '' const data = res.data
if (Array.isArray(data)) {
this.resultList = data
this.result = ''
} else {
this.result = data || res.msg || ''
this.resultList = []
}
} else { } else {
this.$modal.msgError(res && res.msg ? res.msg : '执行失败') this.$modal.msgError(res && res.msg ? res.msg : '执行失败')
} }
@@ -89,6 +122,7 @@ export default {
clearAll() { clearAll() {
this.form.command = '' this.form.command = ''
this.result = '' this.result = ''
this.resultList = []
} }
} }
} }