🔨 命令发送.
This commit is contained in:
@@ -274,6 +274,17 @@ export default defineStore('terminal', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 粘贴命令到会话
|
||||||
|
pasteCommandToSession(session: ISshSession | undefined, command: string, newLine: boolean = false) {
|
||||||
|
const handler = session?.handler;
|
||||||
|
if (handler && handler.enabledStatus('pasteOrigin')) {
|
||||||
|
if (newLine) {
|
||||||
|
command = `${command}\r\n`;
|
||||||
|
}
|
||||||
|
handler.pasteOrigin(command);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,15 +3,26 @@
|
|||||||
<div class="command-header">
|
<div class="command-header">
|
||||||
<!-- 左侧按钮 -->
|
<!-- 左侧按钮 -->
|
||||||
<div class="command-header-left">
|
<div class="command-header-left">
|
||||||
<!-- 粘贴 -->
|
<!-- 发送 -->
|
||||||
<a-button size="mini"
|
<a-button size="mini"
|
||||||
class="mr8"
|
class="mr8"
|
||||||
@click="paste">
|
title="直接发送到终端"
|
||||||
粘贴
|
@click="write(false)">
|
||||||
|
发送
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<icon-send />
|
<icon-send />
|
||||||
</template>
|
</template>
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<!-- 执行 -->
|
||||||
|
<a-button size="mini"
|
||||||
|
class="mr8"
|
||||||
|
title="拼接 \r\n 后发送到终端"
|
||||||
|
@click="write(true)">
|
||||||
|
执行
|
||||||
|
<template #icon>
|
||||||
|
<icon-thunderbolt />
|
||||||
|
</template>
|
||||||
|
</a-button>
|
||||||
<!-- 清空 -->
|
<!-- 清空 -->
|
||||||
<a-button size="mini" @click="clear">
|
<a-button size="mini" @click="clear">
|
||||||
清空
|
清空
|
||||||
@@ -34,8 +45,8 @@
|
|||||||
<!-- 命令框 -->
|
<!-- 命令框 -->
|
||||||
<div class="command-input">
|
<div class="command-input">
|
||||||
<a-textarea v-model="text"
|
<a-textarea v-model="text"
|
||||||
:auto-size="{ minRows: 3, maxRows: 3 }"
|
|
||||||
placeholder="输入命令, F8 发送"
|
placeholder="输入命令, F8 发送"
|
||||||
|
:auto-size="{ minRows: 3, maxRows: 3 }"
|
||||||
@keyup="checkCommandKey" />
|
@keyup="checkCommandKey" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -49,19 +60,37 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { ISshSession } from '@/views/host/terminal/types/define';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useTerminalStore } from '@/store';
|
import { useTerminalStore } from '@/store';
|
||||||
|
import { PanelSessionType } from '@/views/host/terminal/types/const';
|
||||||
|
import { Message } from '@arco-design/web-vue';
|
||||||
|
|
||||||
const { layoutState, appendCommandToCurrentSession } = useTerminalStore();
|
const { layoutState, sessionManager, getCurrentSession, pasteCommandToSession } = useTerminalStore();
|
||||||
|
|
||||||
const text = ref('');
|
const text = ref('');
|
||||||
|
|
||||||
// 粘贴
|
// 写入
|
||||||
const paste = () => {
|
const write = (newLine: boolean) => {
|
||||||
appendCommandToCurrentSession(text.value);
|
if (!text.value) {
|
||||||
|
Message.warning('请选择输入命令');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 写入
|
||||||
|
writeToSession(text.value, newLine);
|
||||||
text.value = '';
|
text.value = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 写入到会话
|
||||||
|
const writeToSession = (command: string, newLine: boolean) => {
|
||||||
|
// 当前会话
|
||||||
|
const session = getCurrentSession(PanelSessionType.SSH.type, false);
|
||||||
|
// 粘贴
|
||||||
|
if (session) {
|
||||||
|
pasteCommandToSession((session as ISshSession), command, newLine);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 清空
|
// 清空
|
||||||
const clear = () => {
|
const clear = () => {
|
||||||
text.value = '';
|
text.value = '';
|
||||||
@@ -70,7 +99,7 @@
|
|||||||
// 检查命令快捷键
|
// 检查命令快捷键
|
||||||
const checkCommandKey = async (e: KeyboardEvent) => {
|
const checkCommandKey = async (e: KeyboardEvent) => {
|
||||||
if (text.value && e.code === 'F8') {
|
if (text.value && e.code === 'F8') {
|
||||||
paste();
|
write(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user