fix: telnet终端输入回车值无法正确发出
This commit is contained in:
@@ -80,16 +80,16 @@ function fnAutoCompleteFilter(input: string, option: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**自动完成按键触发 */
|
/**自动完成按键触发 */
|
||||||
function fnAutoCompleteKeydown(evt: any) {
|
function fnAutoCompleteKeydown(evt: KeyboardEvent) {
|
||||||
if (evt.key === 'Enter') {
|
if (evt.key === 'Enter') {
|
||||||
// 阻止默认的换行行为
|
// 阻止默认的换行行为
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
// 按下 Shift + Enter 键时换行
|
// 按下 Shift + Enter 键时换行
|
||||||
if (evt.shiftKey) {
|
if (evt.shiftKey && evt.target) {
|
||||||
// 插入换行符
|
// 插入换行符
|
||||||
const textarea = evt.target;
|
const textarea = evt.target as HTMLInputElement;
|
||||||
const start = textarea.selectionStart;
|
const start = textarea.selectionStart || 0;
|
||||||
const end = textarea.selectionEnd;
|
const end = textarea.selectionEnd || 0;
|
||||||
const text = textarea.value;
|
const text = textarea.value;
|
||||||
textarea.value = text.substring(0, start) + '\n' + text.substring(end);
|
textarea.value = text.substring(0, start) + '\n' + text.substring(end);
|
||||||
terminalState.text = textarea.value;
|
terminalState.text = textarea.value;
|
||||||
@@ -121,7 +121,7 @@ function fnAutoCompleteKeydown(evt: any) {
|
|||||||
type: 'telnet',
|
type: 'telnet',
|
||||||
data: `${cmdStr}\r\n`,
|
data: `${cmdStr}\r\n`,
|
||||||
});
|
});
|
||||||
terminalState.text = ' ';
|
terminalState.text = '';
|
||||||
|
|
||||||
// 退出登录
|
// 退出登录
|
||||||
if (['q', 'quit', 'exit'].includes(cmdStr)) {
|
if (['q', 'quit', 'exit'].includes(cmdStr)) {
|
||||||
@@ -296,11 +296,12 @@ defineExpose({
|
|||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
:options="terminalState.history"
|
:options="terminalState.history"
|
||||||
:filter-option="fnAutoCompleteFilter"
|
:filter-option="fnAutoCompleteFilter"
|
||||||
@keydown="fnAutoCompleteKeydown"
|
:defaultActiveFirstOption="false"
|
||||||
>
|
>
|
||||||
<a-textarea
|
<a-textarea
|
||||||
:auto-size="{ minRows: 1, maxRows: 6 }"
|
:auto-size="{ minRows: 1, maxRows: 6 }"
|
||||||
placeholder="Execute command. Shift+Enter to line feed, Enter to send"
|
placeholder="Execute command. Shift+Enter to line feed, Enter to send"
|
||||||
|
@keypress="fnAutoCompleteKeydown"
|
||||||
/>
|
/>
|
||||||
</a-auto-complete>
|
</a-auto-complete>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user