mirror of https://github.com/1Panel-dev/1Panel
fix: 容器终端断开连接时,保持抽屉打开 (#1926)
parent
5bbda8f842
commit
18e8af6234
|
@ -13,20 +13,7 @@ const terminalElement = ref<HTMLDivElement | null>(null);
|
|||
const fitAddon = new FitAddon();
|
||||
const termReady = ref(false);
|
||||
const webSocketReady = ref(false);
|
||||
const term = ref(
|
||||
new Terminal({
|
||||
lineHeight: 1.2,
|
||||
fontSize: 12,
|
||||
fontFamily: "Monaco, Menlo, Consolas, 'Courier New', monospace",
|
||||
theme: {
|
||||
background: '#000000',
|
||||
},
|
||||
cursorBlink: true,
|
||||
cursorStyle: 'underline',
|
||||
scrollback: 100,
|
||||
tabStopWidth: 4,
|
||||
}),
|
||||
);
|
||||
const term = ref();
|
||||
const terminalSocket = ref<WebSocket>();
|
||||
const heartbeatTimer = ref<number>();
|
||||
const latency = ref(0);
|
||||
|
@ -56,6 +43,21 @@ const acceptParams = (props: WsProps) => {
|
|||
});
|
||||
};
|
||||
|
||||
const newTerm = () => {
|
||||
term.value = new Terminal({
|
||||
lineHeight: 1.2,
|
||||
fontSize: 12,
|
||||
fontFamily: "Monaco, Menlo, Consolas, 'Courier New', monospace",
|
||||
theme: {
|
||||
background: '#000000',
|
||||
},
|
||||
cursorBlink: true,
|
||||
cursorStyle: 'underline',
|
||||
scrollback: 100,
|
||||
tabStopWidth: 4,
|
||||
});
|
||||
};
|
||||
|
||||
const init = (endpoint: string, args: string) => {
|
||||
if (initTerminal(true)) {
|
||||
initWebSocket(endpoint, args);
|
||||
|
@ -78,11 +80,13 @@ function onClose(isKeepShow: boolean = false) {
|
|||
term.value.dispose();
|
||||
} catch {}
|
||||
}
|
||||
terminalElement.value.innerHTML = '';
|
||||
}
|
||||
|
||||
// terminal 相关代码 start
|
||||
|
||||
const initTerminal = (online: boolean = false): boolean => {
|
||||
newTerm();
|
||||
if (terminalElement.value) {
|
||||
term.value.open(terminalElement.value);
|
||||
term.value.loadAddon(fitAddon);
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<el-button v-if="!terminalOpen" @click="initTerm(formRef)">
|
||||
{{ $t('commons.button.conn') }}
|
||||
</el-button>
|
||||
<el-button v-else @click="handleClose()">{{ $t('commons.button.disconn') }}</el-button>
|
||||
<el-button v-else @click="onClose()">{{ $t('commons.button.disconn') }}</el-button>
|
||||
<Terminal style="height: calc(100vh - 302px)" ref="terminalRef"></Terminal>
|
||||
</el-form>
|
||||
</el-drawer>
|
||||
|
@ -99,10 +99,14 @@ const initTerm = (formEl: FormInstance | undefined) => {
|
|||
});
|
||||
};
|
||||
|
||||
function handleClose() {
|
||||
const onClose = () => {
|
||||
terminalRef.value?.onClose();
|
||||
terminalVisiable.value = false;
|
||||
terminalOpen.value = false;
|
||||
};
|
||||
|
||||
function handleClose() {
|
||||
onClose();
|
||||
terminalVisiable.value = false;
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
|
|
Loading…
Reference in New Issue