From 5a6e2e9cf81ebbb0328a80a9cae5d7c9c0b6c57f Mon Sep 17 00:00:00 2001 From: dalaolala Date: Wed, 4 Mar 2026 14:05:16 +0800 Subject: [PATCH] feat: Add a command library component --- .gitignore | 1 + frontend/src/assets/commands.json | 170 ++++++ frontend/src/components/CommandLibrary.vue | 542 ++++++++++++++++++ frontend/src/components/TerminalStatusBar.vue | 126 ++++ frontend/src/views/QuickConnectTerminal.vue | 299 +++++++--- frontend/src/views/Terminal.vue | 216 +++---- frontend/src/views/TerminalNew.vue | 124 +++- 7 files changed, 1255 insertions(+), 223 deletions(-) create mode 100644 frontend/src/assets/commands.json create mode 100644 frontend/src/components/CommandLibrary.vue create mode 100644 frontend/src/components/TerminalStatusBar.vue diff --git a/.gitignore b/.gitignore index 2d6243f..ac3e6e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules prompt.txt +dist \ No newline at end of file diff --git a/frontend/src/assets/commands.json b/frontend/src/assets/commands.json new file mode 100644 index 0000000..54fa4ef --- /dev/null +++ b/frontend/src/assets/commands.json @@ -0,0 +1,170 @@ +[ + { + "category": "系统信息", + "icon": "Monitor", + "commands": [ + { + "name": "查看系统版本", + "command": "cat /etc/os-release" + }, + { + "name": "查看内核版本", + "command": "uname -a" + }, + { + "name": "查看 CPU 信息", + "command": "lscpu" + }, + { + "name": "查看内存使用", + "command": "free -h" + }, + { + "name": "动态查看资源 (Top)", + "command": "top" + }, + { + "name": "动态查看资源 (htop)", + "command": "htop" + }, + { + "name": "查看系统运行时长", + "command": "uptime" + } + ] + }, + { + "category": "磁盘与文件", + "icon": "Folder", + "commands": [ + { + "name": "查看磁盘空间", + "command": "df -h" + }, + { + "name": "查看当前目录大小", + "command": "du -sh *" + }, + { + "name": "查找大文件 (>100M)", + "command": "find / -type f -size +100M -exec ls -lh {} \\; | awk '{ print $9 \": \" $5 }'" + }, + { + "name": "清空文件内容", + "command": "> filename.log" + }, + { + "name": "查看日志尾部", + "command": "tail -f filename.log" + } + ] + }, + { + "category": "网络查验", + "icon": "Connection", + "commands": [ + { + "name": "查看监听端口", + "command": "netstat -tulnp" + }, + { + "name": "查看端口占用 (ss)", + "command": "ss -tulnp" + }, + { + "name": "查看 IP 地址", + "command": "ip a" + }, + { + "name": "测试网络连通", + "command": "ping -c 4 8.8.8.8" + }, + { + "name": "追踪路由节点", + "command": "traceroute google.com" + }, + { + "name": "发起 HTTP 请求", + "command": "curl -I https://www.google.com" + } + ] + }, + { + "category": "进程管理", + "icon": "Cpu", + "commands": [ + { + "name": "查看所有进程", + "command": "ps aux" + }, + { + "name": "查找 Java 进程", + "command": "ps aux | grep java" + }, + { + "name": "查找 Node 进程", + "command": "ps aux | grep node" + }, + { + "name": "查找 Nginx 进程", + "command": "ps aux | grep nginx" + }, + { + "name": "结束指定的进程", + "command": "kill -9 PID" + } + ] + }, + { + "category": "Docker 常用", + "icon": "Box", + "commands": [ + { + "name": "查看所有容器", + "command": "docker ps -a" + }, + { + "name": "查看正在运行", + "command": "docker ps" + }, + { + "name": "查看容器日志", + "command": "docker logs -f CONTAINER_ID" + }, + { + "name": "查看所有镜像", + "command": "docker images" + }, + { + "name": "查看 Docker 资源统计", + "command": "docker stats" + }, + { + "name": "清理悬空资源", + "command": "docker system prune -f" + } + ] + }, + { + "category": "安全与防火墙", + "icon": "Lock", + "commands": [ + { + "name": "查看防火墙状态 (Firewalld)", + "command": "systemctl status firewalld" + }, + { + "name": "查看防火墙状态 (UFW)", + "command": "ufw status" + }, + { + "name": "查看登录成功的用户", + "command": "last" + }, + { + "name": "查看登录失败的记录", + "command": "lastb" + } + ] + } +] \ No newline at end of file diff --git a/frontend/src/components/CommandLibrary.vue b/frontend/src/components/CommandLibrary.vue new file mode 100644 index 0000000..029f298 --- /dev/null +++ b/frontend/src/components/CommandLibrary.vue @@ -0,0 +1,542 @@ + + + + + diff --git a/frontend/src/components/TerminalStatusBar.vue b/frontend/src/components/TerminalStatusBar.vue new file mode 100644 index 0000000..0aefb6a --- /dev/null +++ b/frontend/src/components/TerminalStatusBar.vue @@ -0,0 +1,126 @@ + + + + + diff --git a/frontend/src/views/QuickConnectTerminal.vue b/frontend/src/views/QuickConnectTerminal.vue index fc10389..fbc0635 100644 --- a/frontend/src/views/QuickConnectTerminal.vue +++ b/frontend/src/views/QuickConnectTerminal.vue @@ -83,14 +83,15 @@ -
- +
+
+
+
+ +
+

正在建立安全连接

+

正在向目标服务器发起 SSH 连接请求...

+
@@ -114,27 +115,17 @@ - -
- - - 已连接 - - - - {{ connectionDisplay }} - - - - 文件管理器 - -
-
+ + + +
@@ -144,11 +135,14 @@ import { useRouter } from 'vue-router' import { Terminal } from 'xterm' import { FitAddon } from 'xterm-addon-fit' import { WebLinksAddon } from 'xterm-addon-web-links' -import { ArrowLeft, Connection, Close, Delete, Monitor, Folder, Document, Edit, DocumentCopy, DocumentAdd, Select } from '@element-plus/icons-vue' +import 'xterm/css/xterm.css' +import { ArrowLeft, Connection, Close, Delete, Monitor, Folder, Document, Edit, DocumentCopy, DocumentAdd, Select, Tickets, Loading } from '@element-plus/icons-vue' import { useAuthStore } from '@/stores/auth' import { useQuickSftp } from '@/composables/useQuickSftp' import { ElMessage } from 'element-plus' import QuickSftpFileManager from '@/components/QuickSftpFileManager.vue' +import CommandLibrary from '@/components/CommandLibrary.vue' +import TerminalStatusBar from '@/components/TerminalStatusBar.vue' import { io } from 'socket.io-client' const props = defineProps({ @@ -171,6 +165,19 @@ const terminalRef = ref(null) const showSftp = ref(false) const sftpPanelWidth = ref(350) +// 常用命令显示控制 +const showCommands = ref(false) + +// 向终端注入并执行命令 +const injectCommand = (cmd) => { + if (socket && isConnected.value) { + socket.emit('ssh-input', cmd + '\n') + focusTerminal() + } else { + ElMessage.warning('终端尚未连接') + } +} + // 右键菜单相关 const contextMenu = ref({ visible: false, @@ -713,7 +720,7 @@ onUnmounted(() => {