🔨 回车重连.
This commit is contained in:
@@ -60,7 +60,7 @@
|
||||
{{ dateFormat(new Date(record.startTime)) }}
|
||||
</a-descriptions-item>
|
||||
<!-- 结束时间 -->
|
||||
<a-descriptions-item label="结束时间">
|
||||
<a-descriptions-item v-if="record.endTime" label="结束时间">
|
||||
{{ dateFormat(new Date(record.endTime)) }}
|
||||
</a-descriptions-item>
|
||||
<!-- traceId -->
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</span>
|
||||
</a-space>
|
||||
</template>
|
||||
<!-- 终端面板 -->
|
||||
<!-- 终端面板 FIXME -->
|
||||
<a-tab-pane v-for="tab in panel.items"
|
||||
:key="tab.key">
|
||||
<!-- 标题 -->
|
||||
@@ -54,8 +54,8 @@
|
||||
import SftpView from '../sftp/sftp-view.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
index: number,
|
||||
panel: ITerminalTabManager<TerminalPanelTabItem>,
|
||||
index: number;
|
||||
panel: ITerminalTabManager<TerminalPanelTabItem>;
|
||||
}>();
|
||||
|
||||
const emits = defineEmits(['close', 'openNewConnect']);
|
||||
|
||||
@@ -137,6 +137,7 @@
|
||||
|
||||
// 初始化会话
|
||||
onMounted(async () => {
|
||||
console.log('onMounted', props.tab.key);
|
||||
// 创建终端处理器
|
||||
session.value = await sessionManager.openSsh(props.tab, {
|
||||
el: terminalRef.value,
|
||||
|
||||
@@ -85,6 +85,7 @@ export default class SshSession implements ISshSession {
|
||||
if (e.type !== 'keydown') {
|
||||
return true;
|
||||
}
|
||||
console.log(e);
|
||||
// 检测是否为内置快捷键
|
||||
if (this.handler.checkIsBuiltin(e)) {
|
||||
return true;
|
||||
@@ -93,6 +94,13 @@ export default class SshSession implements ISshSession {
|
||||
if (this.handler.checkPreventDefault(e)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
if (e.key === 'Enter') {
|
||||
console.log("enter start");
|
||||
// TODO 回车 重新连接
|
||||
useTerminalStore().reOpenTerminal(this.hostId, this.sessionId);
|
||||
console.log("enter end");
|
||||
}
|
||||
// 自定义快捷键
|
||||
if (preference.shortcutSetting.enabled && preference.shortcutSetting.keys.length) {
|
||||
// 获取触发的快捷键
|
||||
const shortcutKey = this.handler.getShortcutKey(e);
|
||||
|
||||
@@ -42,6 +42,7 @@ export default class TerminalChannel implements ITerminalChannel {
|
||||
|
||||
// 发送消息
|
||||
send(protocol: Protocol, payload: InputPayload): void {
|
||||
console.log('send', payload);
|
||||
// 检查是否连接
|
||||
if (!this.isConnected()) {
|
||||
return;
|
||||
|
||||
@@ -91,7 +91,7 @@ export default class TerminalOutputProcessor implements ITerminalOutputProcessor
|
||||
}
|
||||
if (session instanceof SshSession) {
|
||||
// ssh 拼接关闭消息
|
||||
session.write(`\r\n[91m${msg || ''}[0m`);
|
||||
session.write(`\r\n\r\n[91m${msg || ''}[0m\r\n\r\n`);
|
||||
// 设置状态
|
||||
session.status = TerminalStatus.CLOSED;
|
||||
session.connected = false;
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
TerminalTabItem,
|
||||
XtermDomRef
|
||||
} from '../types/terminal.type';
|
||||
import type { ISshSession } from '../types/terminal.type';
|
||||
import { sleep } from '@/utils';
|
||||
import { InputProtocol } from '../types/terminal.protocol';
|
||||
import { PanelSessionType } from '../types/terminal.const';
|
||||
@@ -34,8 +35,7 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
|
||||
}
|
||||
|
||||
// 打开 ssh 会话
|
||||
async openSsh(tab: TerminalTabItem,
|
||||
domRef: XtermDomRef) {
|
||||
async openSsh(tab: TerminalTabItem, domRef: XtermDomRef) {
|
||||
const sessionId = tab.key;
|
||||
const hostId = tab.hostId as number;
|
||||
// 初始化客户端
|
||||
@@ -61,6 +61,25 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
|
||||
return session;
|
||||
}
|
||||
|
||||
// 重新打开 ssh 会话
|
||||
async reOpenSsh(sessionId: string, newSessionId: string): Promise<void> {
|
||||
console.log('sessionId', sessionId, 'newSessionId', newSessionId);
|
||||
// 初始化客户端
|
||||
await this.initChannel();
|
||||
// 获取会话并且重新设置 sessionId
|
||||
const session = this.sessions[sessionId] as ISshSession;
|
||||
session.sessionId = newSessionId;
|
||||
this.sessions[sessionId] = undefined as unknown as ISshSession;
|
||||
this.sessions[newSessionId] = session;
|
||||
console.log('ckckck');
|
||||
// 发送会话初始化请求
|
||||
this.channel.send(InputProtocol.CHECK, {
|
||||
sessionId: newSessionId,
|
||||
hostId: session.hostId,
|
||||
connectType: PanelSessionType.SSH.type
|
||||
});
|
||||
}
|
||||
|
||||
// 打开 sftp 会话
|
||||
async openSftp(tab: TerminalTabItem, resolver: ISftpSessionResolver): Promise<ISftpSession> {
|
||||
const sessionId = tab.key;
|
||||
|
||||
@@ -25,6 +25,11 @@ export default class TerminalTabManager<T extends TerminalTabItem = TerminalTabI
|
||||
return this.items.find(s => s.key === this.active);
|
||||
}
|
||||
|
||||
// 获取 tab
|
||||
getTab(key: string): T {
|
||||
return this.items.find(s => s.key === key) as T;
|
||||
}
|
||||
|
||||
// 点击 tab
|
||||
clickTab(key: string): void {
|
||||
this.active = key;
|
||||
|
||||
@@ -112,6 +112,8 @@ export interface ITerminalTabManager<T extends TerminalTabItem = TerminalTabItem
|
||||
|
||||
// 获取当前 tab
|
||||
getCurrentTab: () => T | undefined;
|
||||
// 获取 tab
|
||||
getTab: (key: string) => T;
|
||||
// 点击 tab
|
||||
clickTab: (key: string) => void;
|
||||
// 删除 tab
|
||||
@@ -151,6 +153,8 @@ export interface ITerminalPanelManager<T extends TerminalPanelTabItem = Terminal
|
||||
export interface ITerminalSessionManager {
|
||||
// 打开 ssh 会话
|
||||
openSsh: (tab: TerminalTabItem, domRef: XtermDomRef) => Promise<ISshSession>;
|
||||
// 重新打开 ssh 会话
|
||||
reOpenSsh: (sessionId: string, newSessionId: string) => Promise<void>;
|
||||
// 打开 sftp 会话
|
||||
openSftp: (tab: TerminalTabItem, resolver: ISftpSessionResolver) => Promise<ISftpSession>;
|
||||
// 获取终端会话
|
||||
|
||||
Reference in New Issue
Block a user