mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 文件增加打开终端功能 (#2660)
Refs https://github.com/1Panel-dev/1Panel/issues/958
This commit is contained in:
parent
d7f25da581
commit
3c3fd5fd78
@ -15,8 +15,9 @@ const termReady = ref(false);
|
|||||||
const webSocketReady = ref(false);
|
const webSocketReady = ref(false);
|
||||||
const term = ref();
|
const term = ref();
|
||||||
const terminalSocket = ref<WebSocket>();
|
const terminalSocket = ref<WebSocket>();
|
||||||
const heartbeatTimer = ref<number>();
|
const heartbeatTimer = ref<NodeJS.Timer>();
|
||||||
const latency = ref(0);
|
const latency = ref(0);
|
||||||
|
const initCmd = ref('');
|
||||||
|
|
||||||
const readyWatcher = watch(
|
const readyWatcher = watch(
|
||||||
() => webSocketReady.value && termReady.value,
|
() => webSocketReady.value && termReady.value,
|
||||||
@ -32,12 +33,14 @@ interface WsProps {
|
|||||||
endpoint: string;
|
endpoint: string;
|
||||||
args: string;
|
args: string;
|
||||||
error: string;
|
error: string;
|
||||||
|
initCmd: string;
|
||||||
}
|
}
|
||||||
const acceptParams = (props: WsProps) => {
|
const acceptParams = (props: WsProps) => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (props.error.length !== 0) {
|
if (props.error.length !== 0) {
|
||||||
initError(props.error);
|
initError(props.error);
|
||||||
} else {
|
} else {
|
||||||
|
initCmd.value = props.initCmd;
|
||||||
init(props.endpoint, props.args);
|
init(props.endpoint, props.args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -162,6 +165,9 @@ const initWebSocket = (endpoint_: string, args: string = '') => {
|
|||||||
|
|
||||||
const runRealTerminal = () => {
|
const runRealTerminal = () => {
|
||||||
webSocketReady.value = true;
|
webSocketReady.value = true;
|
||||||
|
if (initCmd.value !== '') {
|
||||||
|
sendMsg(initCmd.value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onWSReceive = (message: MessageEvent) => {
|
const onWSReceive = (message: MessageEvent) => {
|
||||||
@ -169,7 +175,12 @@ const onWSReceive = (message: MessageEvent) => {
|
|||||||
switch (wsMsg.type) {
|
switch (wsMsg.type) {
|
||||||
case 'cmd': {
|
case 'cmd': {
|
||||||
term.value.element && term.value.focus();
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case 'heartbeat': {
|
case 'heartbeat': {
|
||||||
|
@ -43,6 +43,7 @@ const hostRouter = {
|
|||||||
{
|
{
|
||||||
path: '/hosts/terminal',
|
path: '/hosts/terminal',
|
||||||
name: 'Terminal',
|
name: 'Terminal',
|
||||||
|
props: true,
|
||||||
component: () => import('@/views/host/terminal/index.vue'),
|
component: () => import('@/views/host/terminal/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'menu.terminal',
|
title: 'menu.terminal',
|
||||||
|
@ -85,6 +85,10 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
</el-button-group>
|
</el-button-group>
|
||||||
|
|
||||||
|
<el-button class="btn" @click="toTerminal">
|
||||||
|
{{ $t('menu.terminal') }}
|
||||||
|
</el-button>
|
||||||
|
|
||||||
<el-button-group class="copy-button" v-if="moveOpen">
|
<el-button-group class="copy-button" v-if="moveOpen">
|
||||||
<el-tooltip class="box-item" effect="dark" :content="$t('file.paste')" placement="bottom">
|
<el-tooltip class="box-item" effect="dark" :content="$t('file.paste')" placement="bottom">
|
||||||
<el-button plain @click="openPaste">{{ $t('file.paste') }}</el-button>
|
<el-button plain @click="openPaste">{{ $t('file.paste') }}</el-button>
|
||||||
@ -758,6 +762,10 @@ const toFavorite = (row: File.Favorite) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toTerminal = () => {
|
||||||
|
router.push({ path: '/hosts/terminal', query: { path: req.path } });
|
||||||
|
};
|
||||||
|
|
||||||
const buttons = [
|
const buttons = [
|
||||||
{
|
{
|
||||||
label: i18n.global.t('file.open'),
|
label: i18n.global.t('file.open'),
|
||||||
|
@ -64,10 +64,10 @@
|
|||||||
<template #label>
|
<template #label>
|
||||||
<el-button v-popover="popoverRef" class="tagButton" icon="Plus"></el-button>
|
<el-button v-popover="popoverRef" class="tagButton" icon="Plus"></el-button>
|
||||||
<el-popover ref="popoverRef" width="250px" trigger="hover" virtual-triggering persistent>
|
<el-popover ref="popoverRef" width="250px" trigger="hover" virtual-triggering persistent>
|
||||||
<div style="margin-left: 10px">
|
<div class="ml-2.5">
|
||||||
<el-button link type="primary" @click="onNewSsh">{{ $t('terminal.createConn') }}</el-button>
|
<el-button link type="primary" @click="onNewSsh">{{ $t('terminal.createConn') }}</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-left: 10px">
|
<div class="ml-2.5">
|
||||||
<el-button link type="primary" @click="onNewLocal">
|
<el-button link type="primary" @click="onNewLocal">
|
||||||
{{ $t('terminal.localhost') }}
|
{{ $t('terminal.localhost') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
@ -128,7 +128,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, getCurrentInstance, watch, nextTick, computed } from 'vue';
|
import { ref, getCurrentInstance, watch, nextTick, computed, onMounted } from 'vue';
|
||||||
import Terminal from '@/components/terminal/index.vue';
|
import Terminal from '@/components/terminal/index.vue';
|
||||||
import HostDialog from '@/views/host/terminal/terminal/host-create.vue';
|
import HostDialog from '@/views/host/terminal/terminal/host-create.vue';
|
||||||
import type Node from 'element-plus/es/components/tree/src/model/node';
|
import type Node from 'element-plus/es/components/tree/src/model/node';
|
||||||
@ -139,6 +139,7 @@ import { Host } from '@/api/interface/host';
|
|||||||
import { getHostTree, testByID } from '@/api/modules/host';
|
import { getHostTree, testByID } from '@/api/modules/host';
|
||||||
import { getCommandList } from '@/api/modules/host';
|
import { getCommandList } from '@/api/modules/host';
|
||||||
import { GlobalStore } from '@/store';
|
import { GlobalStore } from '@/store';
|
||||||
|
import router from '@/routers';
|
||||||
|
|
||||||
const dialogRef = ref();
|
const dialogRef = ref();
|
||||||
const ctx = getCurrentInstance() as any;
|
const ctx = getCurrentInstance() as any;
|
||||||
@ -183,6 +184,7 @@ interface Tree {
|
|||||||
label: string;
|
label: string;
|
||||||
children?: Tree[];
|
children?: Tree[];
|
||||||
}
|
}
|
||||||
|
const initCmd = ref('');
|
||||||
|
|
||||||
const acceptParams = async () => {
|
const acceptParams = async () => {
|
||||||
globalStore.isFullScreen = false;
|
globalStore.isFullScreen = false;
|
||||||
@ -358,8 +360,10 @@ const onConnTerminal = async (title: string, wsID: number, isLocal?: boolean) =>
|
|||||||
ctx.refs[`t-${terminalValue.value}`][0].acceptParams({
|
ctx.refs[`t-${terminalValue.value}`][0].acceptParams({
|
||||||
endpoint: '/api/v1/terminals',
|
endpoint: '/api/v1/terminals',
|
||||||
args: `id=${wsID}`,
|
args: `id=${wsID}`,
|
||||||
|
initCmd: initCmd.value,
|
||||||
error: res.data ? '' : 'Authentication failed. Please check the host information !',
|
error: res.data ? '' : 'Authentication failed. Please check the host information !',
|
||||||
});
|
});
|
||||||
|
initCmd.value = '';
|
||||||
});
|
});
|
||||||
tabIndex++;
|
tabIndex++;
|
||||||
};
|
};
|
||||||
@ -377,6 +381,13 @@ defineExpose({
|
|||||||
acceptParams,
|
acceptParams,
|
||||||
cleanTimer,
|
cleanTimer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (router.currentRoute.value.query.path) {
|
||||||
|
const path = String(router.currentRoute.value.query.path);
|
||||||
|
initCmd.value = `cd ${path} \n`;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user