diff --git a/frontend/src/components/terminal/index.vue b/frontend/src/components/terminal/index.vue index 706bab7af..b6edaf519 100644 --- a/frontend/src/components/terminal/index.vue +++ b/frontend/src/components/terminal/index.vue @@ -15,8 +15,9 @@ const termReady = ref(false); const webSocketReady = ref(false); const term = ref(); const terminalSocket = ref(); -const heartbeatTimer = ref(); +const heartbeatTimer = ref(); const latency = ref(0); +const initCmd = ref(''); const readyWatcher = watch( () => webSocketReady.value && termReady.value, @@ -32,12 +33,14 @@ interface WsProps { endpoint: string; args: string; error: string; + initCmd: string; } const acceptParams = (props: WsProps) => { nextTick(() => { if (props.error.length !== 0) { initError(props.error); } else { + initCmd.value = props.initCmd; init(props.endpoint, props.args); } }); @@ -162,6 +165,9 @@ const initWebSocket = (endpoint_: string, args: string = '') => { const runRealTerminal = () => { webSocketReady.value = true; + if (initCmd.value !== '') { + sendMsg(initCmd.value); + } }; const onWSReceive = (message: MessageEvent) => { @@ -169,7 +175,12 @@ const onWSReceive = (message: MessageEvent) => { switch (wsMsg.type) { case 'cmd': { term.value.element && term.value.focus(); - wsMsg.data && term.value.write(Base64.decode(wsMsg.data)); // 这里理论上不用判断,但是Redis和Ctr还没实现Alive处理,所以exit后会一直发数据,todo + let receiveMsg = Base64.decode(wsMsg.data); + if (initCmd.value != '') { + receiveMsg = receiveMsg.replace(initCmd.value.trim(), '').trim(); + initCmd.value = ''; + } + wsMsg.data && term.value.write(receiveMsg); break; } case 'heartbeat': { diff --git a/frontend/src/routers/modules/host.ts b/frontend/src/routers/modules/host.ts index 50f60f9e7..63a05ac28 100644 --- a/frontend/src/routers/modules/host.ts +++ b/frontend/src/routers/modules/host.ts @@ -43,6 +43,7 @@ const hostRouter = { { path: '/hosts/terminal', name: 'Terminal', + props: true, component: () => import('@/views/host/terminal/index.vue'), meta: { title: 'menu.terminal', diff --git a/frontend/src/views/host/file-management/index.vue b/frontend/src/views/host/file-management/index.vue index 81e28ebfe..871f965b4 100644 --- a/frontend/src/views/host/file-management/index.vue +++ b/frontend/src/views/host/file-management/index.vue @@ -85,6 +85,10 @@ + + {{ $t('menu.terminal') }} + + {{ $t('file.paste') }} @@ -758,6 +762,10 @@ const toFavorite = (row: File.Favorite) => { } }; +const toTerminal = () => { + router.push({ path: '/hosts/terminal', query: { path: req.path } }); +}; + const buttons = [ { label: i18n.global.t('file.open'), diff --git a/frontend/src/views/host/terminal/terminal/index.vue b/frontend/src/views/host/terminal/terminal/index.vue index dd78eed45..9c628b9b3 100644 --- a/frontend/src/views/host/terminal/terminal/index.vue +++ b/frontend/src/views/host/terminal/terminal/index.vue @@ -64,10 +64,10 @@