chore: sync local changes (2026-03-12)
This commit is contained in:
@@ -1,33 +1,33 @@
|
|||||||
FROM golang:1.21-alpine AS builder
|
FROM golang:1.21-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o mengyaconnect-backend .
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o mengyaconnect-backend .
|
||||||
|
|
||||||
FROM alpine:3.19
|
FROM alpine:3.19
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates && \
|
RUN apk add --no-cache ca-certificates && \
|
||||||
adduser -D -H appuser
|
adduser -D -H appuser
|
||||||
|
|
||||||
COPY --from=builder /app/mengyaconnect-backend /app/mengyaconnect-backend
|
COPY --from=builder /app/mengyaconnect-backend /app/mengyaconnect-backend
|
||||||
|
|
||||||
ENV DATA_DIR=/app/data
|
ENV DATA_DIR=/app/data
|
||||||
ENV PORT=8080
|
ENV PORT=8080
|
||||||
|
|
||||||
RUN mkdir -p "$DATA_DIR" && chown -R appuser:appuser /app
|
RUN mkdir -p "$DATA_DIR" && chown -R appuser:appuser /app
|
||||||
|
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
CMD ["/app/mengyaconnect-backend"]
|
CMD ["/app/mengyaconnect-backend"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,78 +1,78 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 数据目录辅助
|
// 数据目录辅助
|
||||||
func dataBasePath() string { return getEnv("DATA_DIR", "data") }
|
func dataBasePath() string { return getEnv("DATA_DIR", "data") }
|
||||||
func sshDir() string { return filepath.Join(dataBasePath(), "ssh") }
|
func sshDir() string { return filepath.Join(dataBasePath(), "ssh") }
|
||||||
func cmdFilePath() string { return filepath.Join(dataBasePath(), "command", "command.json") }
|
func cmdFilePath() string { return filepath.Join(dataBasePath(), "command", "command.json") }
|
||||||
func scriptDir() string { return filepath.Join(dataBasePath(), "script") }
|
func scriptDir() string { return filepath.Join(dataBasePath(), "script") }
|
||||||
|
|
||||||
// sanitizeName 防止路径穿越攻击
|
// sanitizeName 防止路径穿越攻击
|
||||||
func sanitizeName(name string) (string, error) {
|
func sanitizeName(name string) (string, error) {
|
||||||
base := filepath.Base(name)
|
base := filepath.Base(name)
|
||||||
if base == "" || base == "." || base == ".." {
|
if base == "" || base == "." || base == ".." {
|
||||||
return "", errors.New("invalid name")
|
return "", errors.New("invalid name")
|
||||||
}
|
}
|
||||||
return base, nil
|
return base, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func corsMiddleware() gin.HandlerFunc {
|
func corsMiddleware() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
if c.Request.Method == http.MethodOptions {
|
if c.Request.Method == http.MethodOptions {
|
||||||
c.AbortWithStatus(http.StatusNoContent)
|
c.AbortWithStatus(http.StatusNoContent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isOriginAllowed(origin string, allowed []string) bool {
|
func isOriginAllowed(origin string, allowed []string) bool {
|
||||||
if origin == "" {
|
if origin == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if len(allowed) == 0 {
|
if len(allowed) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for _, item := range allowed {
|
for _, item := range allowed {
|
||||||
if item == "*" || strings.EqualFold(strings.TrimSpace(item), origin) {
|
if item == "*" || strings.EqualFold(strings.TrimSpace(item), origin) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseListEnv(name string) []string {
|
func parseListEnv(name string) []string {
|
||||||
raw := strings.TrimSpace(os.Getenv(name))
|
raw := strings.TrimSpace(os.Getenv(name))
|
||||||
if raw == "" {
|
if raw == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
parts := strings.Split(raw, ",")
|
parts := strings.Split(raw, ",")
|
||||||
out := make([]string, 0, len(parts))
|
out := make([]string, 0, len(parts))
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
part = strings.TrimSpace(part)
|
part = strings.TrimSpace(part)
|
||||||
if part != "" {
|
if part != "" {
|
||||||
out = append(out, part)
|
out = append(out, part)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEnv(key, fallback string) string {
|
func getEnv(key, fallback string) string {
|
||||||
if val := strings.TrimSpace(os.Getenv(key)); val != "" {
|
if val := strings.TrimSpace(os.Getenv(key)); val != "" {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app">
|
<div class="app" ref="appRef">
|
||||||
<header v-if="!focusMode" class="app-header">
|
<header v-if="!focusMode" class="app-header">
|
||||||
<div class="brand">
|
<div class="brand">
|
||||||
<button class="sidebar-toggle" type="button" @click="toggleSidebar">
|
<button class="sidebar-toggle" type="button" @click="toggleSidebar">
|
||||||
@@ -85,20 +85,21 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 终端下方快捷按键条(移动端友好,尽量占用较少高度) -->
|
<!-- 终端下方快捷按键条(移动端友好,尽量占用较少高度) -->
|
||||||
<div v-if="sessions.length && !focusMode" class="quick-keys">
|
<div v-if="sessions.length && !focusMode" class="quick-keys" @contextmenu.prevent>
|
||||||
<button class="quick-key" @click="sendQuickKey('esc')">ESC</button>
|
<button class="quick-key" @click="sendQuickKey('esc')" @touchend.prevent="sendQuickKey('esc')">ESC</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('slash')">/</button>
|
<button class="quick-key" :class="{ active: shiftPending }" @click="sendQuickKey('shift')" @touchend.prevent="sendQuickKey('shift')">SHIFT</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('minus')">-</button>
|
<button class="quick-key" :class="{ active: ctrlPending }" @click="sendQuickKey('ctrl')" @touchend.prevent="sendQuickKey('ctrl')">CTRL</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('home')">HOME</button>
|
<button class="quick-key" @click="sendQuickKey('tab')" @touchend.prevent="sendQuickKey('tab')">TAB</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('up')">↑</button>
|
<button class="quick-key" @click="sendQuickKey('up')" @touchend.prevent="sendQuickKey('up')">↑</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('end')">END</button>
|
<button class="quick-key" @click="sendQuickKey('down')" @touchend.prevent="sendQuickKey('down')">↓</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('pgup')">PGUP</button>
|
<button class="quick-key" @click="sendQuickKey('left')" @touchend.prevent="sendQuickKey('left')">←</button>
|
||||||
|
<button class="quick-key" @click="sendQuickKey('right')" @touchend.prevent="sendQuickKey('right')">→</button>
|
||||||
<button class="quick-key primary" @click="sendQuickKey('enter')">↵</button>
|
<button class="quick-key primary" @click="sendQuickKey('enter')" @touchend.prevent="sendQuickKey('enter')">↵</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('left')">←</button>
|
<button class="quick-key" @click="sendQuickKey('slash')" @touchend.prevent="sendQuickKey('slash')">/</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('down')">↓</button>
|
<button class="quick-key" @click="sendQuickKey('minus')" @touchend.prevent="sendQuickKey('minus')">-</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('right')">→</button>
|
<button class="quick-key" @click="sendQuickKey('dot')" @touchend.prevent="sendQuickKey('dot')">.</button>
|
||||||
<button class="quick-key" @click="sendQuickKey('pgdn')">PGDN</button>
|
<button class="quick-key" @click="sendQuickKey('hash')" @touchend.prevent="sendQuickKey('hash')">#</button>
|
||||||
|
<button class="quick-key" @click="sendQuickKey('amp')" @touchend.prevent="sendQuickKey('amp')">&</button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -158,7 +159,7 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button class="primary" @click="createSession">打开终端</button>
|
<button class="primary" @click="createSession">连接</button>
|
||||||
<button class="secondary" @click="resetForm">清空</button>
|
<button class="secondary" @click="resetForm">清空</button>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="formError" class="error">{{ formError }}</p>
|
<p v-if="formError" class="error">{{ formError }}</p>
|
||||||
@@ -291,7 +292,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="command-actions">
|
<div class="command-actions">
|
||||||
<button class="secondary tiny" @click="applyCommandToTerminal(item)">
|
<button class="secondary tiny" @click="applyCommandToTerminal(item)">
|
||||||
发到当前终端
|
发送
|
||||||
</button>
|
</button>
|
||||||
<button class="secondary tiny" @click="editCommand(item, index)">
|
<button class="secondary tiny" @click="editCommand(item, index)">
|
||||||
编辑
|
编辑
|
||||||
@@ -359,7 +360,7 @@
|
|||||||
<div class="script-editor">
|
<div class="script-editor">
|
||||||
<div class="form-grid">
|
<div class="form-grid">
|
||||||
<label>
|
<label>
|
||||||
脚本名称
|
名称
|
||||||
<input
|
<input
|
||||||
v-model.trim="scriptForm.name"
|
v-model.trim="scriptForm.name"
|
||||||
placeholder="例如 docker-info.sh"
|
placeholder="例如 docker-info.sh"
|
||||||
@@ -382,7 +383,7 @@
|
|||||||
@click="saveScript"
|
@click="saveScript"
|
||||||
:disabled="scriptSaving"
|
:disabled="scriptSaving"
|
||||||
>
|
>
|
||||||
{{ scriptSaving ? "保存中..." : scriptSelected ? "更新脚本" : "新建脚本" }}
|
{{ scriptSaving ? "保存中..." : scriptSelected ? "更新" : "新建" }}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="scriptSelected"
|
v-if="scriptSelected"
|
||||||
@@ -390,7 +391,7 @@
|
|||||||
type="button"
|
type="button"
|
||||||
@click="deleteScript"
|
@click="deleteScript"
|
||||||
>
|
>
|
||||||
删除当前脚本
|
删除
|
||||||
</button>
|
</button>
|
||||||
<button class="secondary small" type="button" @click="resetScriptForm">
|
<button class="secondary small" type="button" @click="resetScriptForm">
|
||||||
重置
|
重置
|
||||||
@@ -401,7 +402,7 @@
|
|||||||
@click="applyScriptToTerminal"
|
@click="applyScriptToTerminal"
|
||||||
:disabled="!scriptForm.content"
|
:disabled="!scriptForm.content"
|
||||||
>
|
>
|
||||||
发到当前终端
|
发送
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -446,6 +447,8 @@ const terminalRefs = new Map();
|
|||||||
const activePanel = ref("");
|
const activePanel = ref("");
|
||||||
const showSidebar = ref(false);
|
const showSidebar = ref(false);
|
||||||
const focusMode = ref(false);
|
const focusMode = ref(false);
|
||||||
|
const shiftPending = ref(false);
|
||||||
|
const ctrlPending = ref(false);
|
||||||
|
|
||||||
const wsUrl = computed(() => {
|
const wsUrl = computed(() => {
|
||||||
const envUrl = import.meta.env.VITE_WS_URL;
|
const envUrl = import.meta.env.VITE_WS_URL;
|
||||||
@@ -544,7 +547,6 @@ function fillFromSSH(item) {
|
|||||||
|
|
||||||
function connectWithSSH(item) {
|
function connectWithSSH(item) {
|
||||||
fillFromSSH(item);
|
fillFromSSH(item);
|
||||||
activePanel.value = "";
|
|
||||||
createSession();
|
createSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,6 +706,7 @@ async function deleteCommand(index) {
|
|||||||
function applyCommandToTerminal(item) {
|
function applyCommandToTerminal(item) {
|
||||||
const session = sessions.value.find((s) => s.id === activeId.value);
|
const session = sessions.value.find((s) => s.id === activeId.value);
|
||||||
if (!session || !session.ws || session.ws.readyState !== WebSocket.OPEN) {
|
if (!session || !session.ws || session.ws.readyState !== WebSocket.OPEN) {
|
||||||
|
commandError.value = "当前没有可用终端连接";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const cmd = item.command || "";
|
const cmd = item.command || "";
|
||||||
@@ -714,6 +717,7 @@ function applyCommandToTerminal(item) {
|
|||||||
data: `${cmd}\n`,
|
data: `${cmd}\n`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
closeOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── 脚本管理 (/api/scripts) ──────────────────────
|
// ─── 脚本管理 (/api/scripts) ──────────────────────
|
||||||
@@ -808,6 +812,7 @@ async function deleteScript() {
|
|||||||
function applyScriptToTerminal() {
|
function applyScriptToTerminal() {
|
||||||
const session = sessions.value.find((s) => s.id === activeId.value);
|
const session = sessions.value.find((s) => s.id === activeId.value);
|
||||||
if (!session || !session.ws || session.ws.readyState !== WebSocket.OPEN) {
|
if (!session || !session.ws || session.ws.readyState !== WebSocket.OPEN) {
|
||||||
|
scriptError.value = "当前没有可用终端连接";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!scriptForm.content) return;
|
if (!scriptForm.content) return;
|
||||||
@@ -817,6 +822,7 @@ function applyScriptToTerminal() {
|
|||||||
data: `${scriptForm.content}\n`,
|
data: `${scriptForm.content}\n`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
closeOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendQuickKey(type) {
|
function sendQuickKey(type) {
|
||||||
@@ -825,22 +831,38 @@ function sendQuickKey(type) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SHIFT / CTRL 单独发送通常无效果,做成“下一次快捷键生效”的修饰键
|
||||||
|
if (type === "shift") {
|
||||||
|
shiftPending.value = !shiftPending.value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type === "ctrl") {
|
||||||
|
ctrlPending.value = !ctrlPending.value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let data = "";
|
let data = "";
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "esc":
|
case "esc":
|
||||||
data = "\x1b";
|
data = "\x1b";
|
||||||
break;
|
break;
|
||||||
|
case "tab":
|
||||||
|
data = "\t";
|
||||||
|
break;
|
||||||
case "slash":
|
case "slash":
|
||||||
data = "/";
|
data = "/";
|
||||||
break;
|
break;
|
||||||
case "minus":
|
case "minus":
|
||||||
data = "-";
|
data = "-";
|
||||||
break;
|
break;
|
||||||
case "home":
|
case "dot":
|
||||||
data = "\x1b[H";
|
data = ".";
|
||||||
break;
|
break;
|
||||||
case "end":
|
case "hash":
|
||||||
data = "\x1b[F";
|
data = "#";
|
||||||
|
break;
|
||||||
|
case "amp":
|
||||||
|
data = "&";
|
||||||
break;
|
break;
|
||||||
case "up":
|
case "up":
|
||||||
data = "\x1b[A";
|
data = "\x1b[A";
|
||||||
@@ -854,12 +876,6 @@ function sendQuickKey(type) {
|
|||||||
case "left":
|
case "left":
|
||||||
data = "\x1b[D";
|
data = "\x1b[D";
|
||||||
break;
|
break;
|
||||||
case "pgup":
|
|
||||||
data = "\x1b[5~";
|
|
||||||
break;
|
|
||||||
case "pgdn":
|
|
||||||
data = "\x1b[6~";
|
|
||||||
break;
|
|
||||||
case "enter":
|
case "enter":
|
||||||
data = "\r";
|
data = "\r";
|
||||||
break;
|
break;
|
||||||
@@ -867,12 +883,58 @@ function sendQuickKey(type) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SHIFT 一次性修饰
|
||||||
|
if (shiftPending.value) {
|
||||||
|
if (data === "\t") {
|
||||||
|
data = "\x1b[Z"; // Shift+Tab
|
||||||
|
} else if (data === "/") {
|
||||||
|
data = "?";
|
||||||
|
} else if (data === "-") {
|
||||||
|
data = "_";
|
||||||
|
} else if (data === ".") {
|
||||||
|
data = ">";
|
||||||
|
} else if (data === "\x1b[A") {
|
||||||
|
data = "\x1b[1;2A";
|
||||||
|
} else if (data === "\x1b[B") {
|
||||||
|
data = "\x1b[1;2B";
|
||||||
|
} else if (data === "\x1b[C") {
|
||||||
|
data = "\x1b[1;2C";
|
||||||
|
} else if (data === "\x1b[D") {
|
||||||
|
data = "\x1b[1;2D";
|
||||||
|
} else if (data.length === 1) {
|
||||||
|
data = data.toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CTRL 一次性修饰
|
||||||
|
if (ctrlPending.value) {
|
||||||
|
if (data === "\x1b[A") {
|
||||||
|
data = "\x1b[1;5A";
|
||||||
|
} else if (data === "\x1b[B") {
|
||||||
|
data = "\x1b[1;5B";
|
||||||
|
} else if (data === "\x1b[C") {
|
||||||
|
data = "\x1b[1;5C";
|
||||||
|
} else if (data === "\x1b[D") {
|
||||||
|
data = "\x1b[1;5D";
|
||||||
|
} else if (data.length === 1) {
|
||||||
|
const ch = data.toLowerCase();
|
||||||
|
if (ch >= "a" && ch <= "z") {
|
||||||
|
data = String.fromCharCode(ch.charCodeAt(0) - 96);
|
||||||
|
} else if (ch === "/") {
|
||||||
|
data = "\x1f"; // Ctrl+/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
session.ws.send(
|
session.ws.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: "input",
|
type: "input",
|
||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
shiftPending.value = false;
|
||||||
|
ctrlPending.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetForm() {
|
function resetForm() {
|
||||||
@@ -926,6 +988,7 @@ function createSession() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
nextTick(() => initSession(session, payload));
|
nextTick(() => initSession(session, payload));
|
||||||
|
closeOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSession(session, payload) {
|
function initSession(session, payload) {
|
||||||
@@ -938,6 +1001,10 @@ function initSession(session, payload) {
|
|||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
lineHeight: 1.4,
|
lineHeight: 1.4,
|
||||||
cursorBlink: true,
|
cursorBlink: true,
|
||||||
|
scrollback: 8000,
|
||||||
|
smoothScrollDuration: 140,
|
||||||
|
scrollSensitivity: 1.15,
|
||||||
|
fastScrollSensitivity: 4,
|
||||||
theme: {
|
theme: {
|
||||||
background: "#0b0f17",
|
background: "#0b0f17",
|
||||||
foreground: "#e6edf3",
|
foreground: "#e6edf3",
|
||||||
@@ -1009,12 +1076,12 @@ function initSession(session, payload) {
|
|||||||
} else if (msg.type === "status") {
|
} else if (msg.type === "status") {
|
||||||
session.status = msg.status || session.status;
|
session.status = msg.status || session.status;
|
||||||
if (msg.message) {
|
if (msg.message) {
|
||||||
term.writeln(`\r\n\x1b[90m[${msg.message}]\x1b[0m`);
|
term.writeln(`\r\x1b[90m[${msg.message}]\x1b[0m`);
|
||||||
}
|
}
|
||||||
} else if (msg.type === "error") {
|
} else if (msg.type === "error") {
|
||||||
session.status = "error";
|
session.status = "error";
|
||||||
if (msg.message) {
|
if (msg.message) {
|
||||||
term.writeln(`\r\n\x1b[31m[${msg.message}]\x1b[0m`);
|
term.writeln(`\r\x1b[31m[${msg.message}]\x1b[0m`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1055,6 +1122,7 @@ function focusSession(session) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
session.term.scrollToBottom();
|
||||||
session.term.focus();
|
session.term.focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1107,8 +1175,46 @@ function toggleFocus() {
|
|||||||
focusMode.value = !focusMode.value;
|
focusMode.value = !focusMode.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根元素引用,用于动态调整高度以适配移动端虚拟键盘
|
||||||
|
const appRef = ref(null);
|
||||||
|
let viewportFitTimer = null;
|
||||||
|
|
||||||
|
function updateAppHeight() {
|
||||||
|
const vv = window.visualViewport;
|
||||||
|
const h = vv ? vv.height : window.innerHeight;
|
||||||
|
// 部分移动端浏览器键盘弹出时高度不缩,但会覆盖页面;用 padding-bottom 兜底
|
||||||
|
const keyboard =
|
||||||
|
vv && typeof vv.height === "number"
|
||||||
|
? Math.max(0, window.innerHeight - vv.height - (vv.offsetTop || 0))
|
||||||
|
: 0;
|
||||||
|
if (appRef.value) {
|
||||||
|
appRef.value.style.height = h + "px";
|
||||||
|
appRef.value.style.setProperty("--keyboard-inset", keyboard + "px");
|
||||||
|
}
|
||||||
|
// 触发布局变化后,让终端重新适配可视区域
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const session = sessions.value.find((item) => item.id === activeId.value);
|
||||||
|
if (session) focusSession(session);
|
||||||
|
});
|
||||||
|
if (viewportFitTimer) {
|
||||||
|
clearTimeout(viewportFitTimer);
|
||||||
|
}
|
||||||
|
viewportFitTimer = setTimeout(() => {
|
||||||
|
const session = sessions.value.find((item) => item.id === activeId.value);
|
||||||
|
if (session) focusSession(session);
|
||||||
|
}, 140);
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
window.addEventListener("resize", handleWindowResize);
|
window.addEventListener("resize", handleWindowResize);
|
||||||
|
// 移动端虚拟键盘弹出时,visualViewport 会缩减,用它动态撑高度
|
||||||
|
if (window.visualViewport) {
|
||||||
|
window.visualViewport.addEventListener("resize", updateAppHeight);
|
||||||
|
window.visualViewport.addEventListener("scroll", updateAppHeight);
|
||||||
|
} else {
|
||||||
|
window.addEventListener("resize", updateAppHeight);
|
||||||
|
}
|
||||||
|
updateAppHeight();
|
||||||
// 尝试加载后端配置,如后端未启动仅在面板中提示错误
|
// 尝试加载后端配置,如后端未启动仅在面板中提示错误
|
||||||
loadSSH();
|
loadSSH();
|
||||||
loadCommands();
|
loadCommands();
|
||||||
@@ -1117,6 +1223,16 @@ onMounted(() => {
|
|||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener("resize", handleWindowResize);
|
window.removeEventListener("resize", handleWindowResize);
|
||||||
|
if (viewportFitTimer) {
|
||||||
|
clearTimeout(viewportFitTimer);
|
||||||
|
viewportFitTimer = null;
|
||||||
|
}
|
||||||
|
if (window.visualViewport) {
|
||||||
|
window.visualViewport.removeEventListener("resize", updateAppHeight);
|
||||||
|
window.visualViewport.removeEventListener("scroll", updateAppHeight);
|
||||||
|
} else {
|
||||||
|
window.removeEventListener("resize", updateAppHeight);
|
||||||
|
}
|
||||||
sessions.value.forEach((session) => {
|
sessions.value.forEach((session) => {
|
||||||
session.ws?.close();
|
session.ws?.close();
|
||||||
session.term?.dispose();
|
session.term?.dispose();
|
||||||
@@ -1126,9 +1242,13 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.app {
|
.app {
|
||||||
min-height: 100vh;
|
/* 初始高度用 100svh(支持动态视口),JS 会在键盘弹出时动态覆盖为 visualViewport.height */
|
||||||
|
height: 100svh;
|
||||||
|
height: 100vh; /* 降级 */
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
overscroll-behavior: none;
|
||||||
background: radial-gradient(circle at top, #1f2937 0, #020617 55%, #000 100%);
|
background: radial-gradient(circle at top, #1f2937 0, #020617 55%, #000 100%);
|
||||||
color: #e5e7eb;
|
color: #e5e7eb;
|
||||||
font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
|
font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
|
||||||
@@ -1238,12 +1358,22 @@ onBeforeUnmount(() => {
|
|||||||
.app-nav {
|
.app-nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
flex-wrap: wrap;
|
flex-wrap: nowrap;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
-ms-overflow-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-nav::-webkit-scrollbar {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-btn {
|
.nav-btn {
|
||||||
position: relative;
|
position: relative;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
|
white-space: nowrap;
|
||||||
|
flex-shrink: 0;
|
||||||
border: 1px solid rgba(148, 163, 184, 0.5);
|
border: 1px solid rgba(148, 163, 184, 0.5);
|
||||||
background: radial-gradient(circle at top, #0f172a, #020617);
|
background: radial-gradient(circle at top, #0f172a, #020617);
|
||||||
color: #e5e7eb;
|
color: #e5e7eb;
|
||||||
@@ -1262,6 +1392,12 @@ onBeforeUnmount(() => {
|
|||||||
box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.9), 0 10px 30px rgba(15, 23, 42, 0.6);
|
box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.9), 0 10px 30px rgba(15, 23, 42, 0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.app-nav {
|
||||||
|
/* 移动端横滑时更顺手,避免被按钮点击完全吞掉 */
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
touch-action: pan-x;
|
||||||
|
}
|
||||||
|
|
||||||
.nav-btn::before {
|
.nav-btn::before {
|
||||||
content: "";
|
content: "";
|
||||||
width: 6px;
|
width: 6px;
|
||||||
@@ -1291,6 +1427,7 @@ onBeforeUnmount(() => {
|
|||||||
position: relative;
|
position: relative;
|
||||||
padding: 12px 12px 16px;
|
padding: 12px 12px 16px;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.focus-main {
|
.focus-main {
|
||||||
@@ -1384,6 +1521,9 @@ onBeforeUnmount(() => {
|
|||||||
0 30px 80px rgba(15, 23, 42, 0.95),
|
0 30px 80px rgba(15, 23, 42, 0.95),
|
||||||
0 0 40px rgba(56, 189, 248, 0.12);
|
0 0 40px rgba(56, 189, 248, 0.12);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
/* 虚拟键盘覆盖时,给底部留白避免遮挡终端最后几行 */
|
||||||
|
padding-bottom: var(--keyboard-inset, 0px);
|
||||||
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabs {
|
.tabs {
|
||||||
@@ -1470,6 +1610,7 @@ onBeforeUnmount(() => {
|
|||||||
background: #020617;
|
background: #020617;
|
||||||
/* 交给 xterm 内部滚动,外层不再出现滚动条 */
|
/* 交给 xterm 内部滚动,外层不再出现滚动条 */
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.empty-terminal {
|
.empty-terminal {
|
||||||
@@ -1508,6 +1649,7 @@ onBeforeUnmount(() => {
|
|||||||
inset: 0;
|
inset: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.terminal-header {
|
.terminal-header {
|
||||||
@@ -1528,21 +1670,33 @@ onBeforeUnmount(() => {
|
|||||||
.terminal-body {
|
.terminal-body {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
overscroll-behavior: contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quick-keys {
|
.quick-keys {
|
||||||
display: grid;
|
display: flex;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
|
flex-wrap: nowrap;
|
||||||
|
overflow-x: auto;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
touch-action: pan-x;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
padding: 4px 8px 6px;
|
padding: 4px 8px 6px;
|
||||||
background: #020617;
|
background: #020617;
|
||||||
border-top: 1px solid rgba(31, 41, 55, 0.9);
|
border-top: 1px solid rgba(31, 41, 55, 0.9);
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
.quick-keys::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quick-key {
|
.quick-key {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
min-width: 44px;
|
||||||
height: 26px;
|
height: 26px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
border: 1px solid rgba(55, 65, 81, 0.9);
|
border: 1px solid rgba(55, 65, 81, 0.9);
|
||||||
@@ -1550,8 +1704,12 @@ onBeforeUnmount(() => {
|
|||||||
color: #e5e7eb;
|
color: #e5e7eb;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
letter-spacing: 0.06em;
|
letter-spacing: 0.06em;
|
||||||
|
white-space: nowrap;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
touch-action: manipulation;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quick-key.primary {
|
.quick-key.primary {
|
||||||
@@ -1559,6 +1717,12 @@ onBeforeUnmount(() => {
|
|||||||
background: radial-gradient(circle at top, #1d4ed8, #1e293b);
|
background: radial-gradient(circle at top, #1d4ed8, #1e293b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.quick-key.active {
|
||||||
|
border-color: rgba(59, 130, 246, 0.9);
|
||||||
|
box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35) inset;
|
||||||
|
background: radial-gradient(circle at top, #1d4ed8, #111827);
|
||||||
|
}
|
||||||
|
|
||||||
.quick-key:active {
|
.quick-key:active {
|
||||||
transform: translateY(1px);
|
transform: translateY(1px);
|
||||||
background: #030712;
|
background: #030712;
|
||||||
@@ -1856,8 +2020,12 @@ textarea {
|
|||||||
|
|
||||||
.app-nav {
|
.app-nav {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
justify-content: space-between;
|
justify-content: flex-start;
|
||||||
flex-wrap: wrap;
|
flex-wrap: nowrap !important;
|
||||||
|
overflow-x: auto;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
touch-action: pan-x;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.brand {
|
.brand {
|
||||||
@@ -1876,11 +2044,24 @@ textarea {
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#app {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
overscroll-behavior: none;
|
||||||
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
/* 保留整页滚动,但隐藏浏览器默认滚动条 */
|
margin: 0;
|
||||||
scrollbar-width: none; /* Firefox */
|
padding: 0;
|
||||||
-ms-overflow-style: none; /* IE/Edge */
|
/* 禁止页面级滚动,由 .app 内部负责布局 */
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
scrollbar-width: none;
|
||||||
|
-ms-overflow-style: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
html::-webkit-scrollbar,
|
html::-webkit-scrollbar,
|
||||||
@@ -1889,14 +2070,42 @@ body::-webkit-scrollbar {
|
|||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 隐藏 xterm 内部滚动条,但保留滚动行为 */
|
/* xterm 终端滚动:移动端更顺滑 + 细窄主题滚动条 */
|
||||||
.xterm-viewport {
|
.xterm-viewport {
|
||||||
scrollbar-width: none; /* Firefox */
|
overflow-y: auto !important;
|
||||||
-ms-overflow-style: none; /* IE/Edge */
|
overflow-x: hidden !important;
|
||||||
|
scrollbar-width: thin; /* Firefox */
|
||||||
|
scrollbar-color: rgba(56, 189, 248, 0.55) rgba(2, 6, 23, 0.65);
|
||||||
|
-ms-overflow-style: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
touch-action: pan-y;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
}
|
}
|
||||||
|
|
||||||
.xterm-viewport::-webkit-scrollbar {
|
.xterm-viewport::-webkit-scrollbar {
|
||||||
width: 0;
|
width: 6px;
|
||||||
height: 0;
|
height: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.xterm-viewport::-webkit-scrollbar-track {
|
||||||
|
background: rgba(2, 6, 23, 0.55);
|
||||||
|
border-left: 1px solid rgba(15, 23, 42, 0.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
.xterm-viewport::-webkit-scrollbar-thumb {
|
||||||
|
border-radius: 999px;
|
||||||
|
background: linear-gradient(
|
||||||
|
to bottom,
|
||||||
|
rgba(56, 189, 248, 0.6),
|
||||||
|
rgba(59, 130, 246, 0.5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.xterm-viewport::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: linear-gradient(
|
||||||
|
to bottom,
|
||||||
|
rgba(103, 232, 249, 0.75),
|
||||||
|
rgba(96, 165, 250, 0.65)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
export function getApiBase() {
|
export function getApiBase() {
|
||||||
const envBase = import.meta.env.VITE_API_BASE;
|
const envBase = import.meta.env.VITE_API_BASE;
|
||||||
if (envBase) {
|
if (envBase) {
|
||||||
return String(envBase).replace(/\/+$/, "");
|
return String(envBase).replace(/\/+$/, "");
|
||||||
}
|
}
|
||||||
// 默认走同源 /api(更适合反向代理 + HTTPS)
|
// 默认走同源 /api(更适合反向代理 + HTTPS)
|
||||||
if (typeof window === "undefined") return "http://localhost:8080/api";
|
if (typeof window === "undefined") return "http://localhost:8080/api";
|
||||||
return `${window.location.origin}/api`;
|
return `${window.location.origin}/api`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apiRequest(path, options = {}) {
|
export async function apiRequest(path, options = {}) {
|
||||||
const base = getApiBase();
|
const base = getApiBase();
|
||||||
const res = await fetch(`${base}${path}`, {
|
const res = await fetch(`${base}${path}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...(options.headers || {}),
|
...(options.headers || {}),
|
||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
let body = null;
|
let body = null;
|
||||||
try {
|
try {
|
||||||
body = await res.json();
|
body = await res.json();
|
||||||
} catch {
|
} catch {
|
||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const message =
|
const message =
|
||||||
(body && body.error) || `请求失败 (${res.status} ${res.statusText})`;
|
(body && body.error) || `请求失败 (${res.status} ${res.statusText})`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,5 +6,14 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: true,
|
host: true,
|
||||||
port: 5173,
|
port: 5173,
|
||||||
|
proxy: {
|
||||||
|
// HTTP API:/api/... → http://localhost:8080/api/...
|
||||||
|
"/api": {
|
||||||
|
target: "http://localhost:8080",
|
||||||
|
changeOrigin: true,
|
||||||
|
// WebSocket 升级(ws:// / wss://)
|
||||||
|
ws: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user