From c43de6d23e8014926aa8aeca555ffec6ceaba8d1 Mon Sep 17 00:00:00 2001
From: Copilot <198982749+Copilot@users.noreply.github.com>
Date: Fri, 16 Jan 2026 22:32:22 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E6=95=B0=E6=8D=AE=E5=BA=93?=
=?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E7=BB=88=E7=AB=AF=E6=8C=89=E9=92=AE=20(#1249)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Initial plan
* feat: 为数据库服务器列表添加终端按钮功能
- 在操作列添加终端按钮
- 支持MySQL和PostgreSQL数据库终端
- PostgreSQL无密码时自动切换到postgres用户
Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>
---
web/src/views/database/ServerList.vue | 51 +++++++++++++++++++++++++--
1 file changed, 49 insertions(+), 2 deletions(-)
diff --git a/web/src/views/database/ServerList.vue b/web/src/views/database/ServerList.vue
index 78180cdd..2c0ad021 100644
--- a/web/src/views/database/ServerList.vue
+++ b/web/src/views/database/ServerList.vue
@@ -4,6 +4,7 @@ import { NButton, NInput, NInputGroup, NPopconfirm, NTag } from 'naive-ui'
import { useGettext } from 'vue3-gettext'
import database from '@/api/panel/database'
+import PtyTerminalModal from '@/components/common/PtyTerminalModal.vue'
import { formatDateTime } from '@/utils'
import UpdateServerModal from '@/views/database/UpdateServerModal.vue'
@@ -11,6 +12,34 @@ const { $gettext } = useGettext()
const updateModal = ref(false)
const updateID = ref(0)
+// 终端弹窗
+const terminalModal = ref(false)
+const terminalTitle = ref('')
+const terminalCommand = ref('')
+
+// 打开数据库终端
+const openTerminal = (row: any) => {
+ if (row.type === 'mysql') {
+ // MySQL 使用 mysql 命令行
+ terminalTitle.value = `MySQL - ${row.name}`
+ terminalCommand.value = `mysql -u'${row.username}' -p'${row.password}' -h'${row.host}' -P'${row.port}'`
+ } else if (row.type === 'postgresql') {
+ // PostgreSQL 判断是否有密码
+ terminalTitle.value = `PostgreSQL - ${row.name}`
+ if (row.password) {
+ // 有密码时使用 PGPASSWORD 环境变量
+ terminalCommand.value = `PGPASSWORD='${row.password}' psql -U '${row.username}' -h '${row.host}' -p '${row.port}'`
+ } else {
+ // 无密码时切换到 postgres 用户
+ terminalCommand.value = `su - postgres -c 'psql'`
+ }
+ } else {
+ window.$message.error($gettext('Unsupported database type'))
+ return
+ }
+ terminalModal.value = true
+}
+
const columns: any = [
{
title: $gettext('Type'),
@@ -133,10 +162,21 @@ const columns: any = [
{
title: $gettext('Actions'),
key: 'actions',
- width: 300,
+ width: 350,
hideInExcel: true,
render(row: any) {
return [
+ h(
+ NButton,
+ {
+ size: 'small',
+ type: 'info',
+ onClick: () => openTerminal(row)
+ },
+ {
+ default: () => $gettext('Terminal')
+ }
+ ),
h(
NPopconfirm,
{
@@ -158,7 +198,8 @@ const columns: any = [
NButton,
{
size: 'small',
- type: 'success'
+ type: 'success',
+ style: 'margin-left: 15px;'
},
{
default: () => $gettext('Sync')
@@ -278,6 +319,12 @@ onUnmounted(() => {
}"
/>
+
+