chore: sync local changes (2026-03-12)

This commit is contained in:
2026-03-12 18:56:35 +08:00
parent f27996dde0
commit ec28b7bceb
5 changed files with 410 additions and 192 deletions

View File

@@ -1,5 +1,5 @@
<template>
<div class="app">
<div class="app" ref="appRef">
<header v-if="!focusMode" class="app-header">
<div class="brand">
<button class="sidebar-toggle" type="button" @click="toggleSidebar">
@@ -85,20 +85,21 @@
</div>
<!-- 终端下方快捷按键条移动端友好尽量占用较少高度 -->
<div v-if="sessions.length && !focusMode" class="quick-keys">
<button class="quick-key" @click="sendQuickKey('esc')">ESC</button>
<button class="quick-key" @click="sendQuickKey('slash')">/</button>
<button class="quick-key" @click="sendQuickKey('minus')">-</button>
<button class="quick-key" @click="sendQuickKey('home')">HOME</button>
<button class="quick-key" @click="sendQuickKey('up')"></button>
<button class="quick-key" @click="sendQuickKey('end')">END</button>
<button class="quick-key" @click="sendQuickKey('pgup')">PGUP</button>
<button class="quick-key primary" @click="sendQuickKey('enter')"></button>
<button class="quick-key" @click="sendQuickKey('left')"></button>
<button class="quick-key" @click="sendQuickKey('down')"></button>
<button class="quick-key" @click="sendQuickKey('right')"></button>
<button class="quick-key" @click="sendQuickKey('pgdn')">PGDN</button>
<div v-if="sessions.length && !focusMode" class="quick-keys" @contextmenu.prevent>
<button class="quick-key" @click="sendQuickKey('esc')" @touchend.prevent="sendQuickKey('esc')">ESC</button>
<button class="quick-key" :class="{ active: shiftPending }" @click="sendQuickKey('shift')" @touchend.prevent="sendQuickKey('shift')">SHIFT</button>
<button class="quick-key" :class="{ active: ctrlPending }" @click="sendQuickKey('ctrl')" @touchend.prevent="sendQuickKey('ctrl')">CTRL</button>
<button class="quick-key" @click="sendQuickKey('tab')" @touchend.prevent="sendQuickKey('tab')">TAB</button>
<button class="quick-key" @click="sendQuickKey('up')" @touchend.prevent="sendQuickKey('up')"></button>
<button class="quick-key" @click="sendQuickKey('down')" @touchend.prevent="sendQuickKey('down')"></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')" @touchend.prevent="sendQuickKey('enter')"></button>
<button class="quick-key" @click="sendQuickKey('slash')" @touchend.prevent="sendQuickKey('slash')">/</button>
<button class="quick-key" @click="sendQuickKey('minus')" @touchend.prevent="sendQuickKey('minus')">-</button>
<button class="quick-key" @click="sendQuickKey('dot')" @touchend.prevent="sendQuickKey('dot')">.</button>
<button class="quick-key" @click="sendQuickKey('hash')" @touchend.prevent="sendQuickKey('hash')">#</button>
<button class="quick-key" @click="sendQuickKey('amp')" @touchend.prevent="sendQuickKey('amp')">&amp;</button>
</div>
</section>
@@ -158,7 +159,7 @@
</label>
</div>
<div class="form-actions">
<button class="primary" @click="createSession">打开终端</button>
<button class="primary" @click="createSession">连接</button>
<button class="secondary" @click="resetForm">清空</button>
</div>
<p v-if="formError" class="error">{{ formError }}</p>
@@ -291,7 +292,7 @@
</div>
<div class="command-actions">
<button class="secondary tiny" @click="applyCommandToTerminal(item)">
到当前终端
</button>
<button class="secondary tiny" @click="editCommand(item, index)">
编辑
@@ -359,7 +360,7 @@
<div class="script-editor">
<div class="form-grid">
<label>
脚本名称
名称
<input
v-model.trim="scriptForm.name"
placeholder="例如 docker-info.sh"
@@ -382,7 +383,7 @@
@click="saveScript"
:disabled="scriptSaving"
>
{{ scriptSaving ? "保存中..." : scriptSelected ? "更新脚本" : "新建脚本" }}
{{ scriptSaving ? "保存中..." : scriptSelected ? "更新" : "新建" }}
</button>
<button
v-if="scriptSelected"
@@ -390,7 +391,7 @@
type="button"
@click="deleteScript"
>
删除当前脚本
删除
</button>
<button class="secondary small" type="button" @click="resetScriptForm">
重置
@@ -401,7 +402,7 @@
@click="applyScriptToTerminal"
:disabled="!scriptForm.content"
>
到当前终端
</button>
</div>
</div>
@@ -446,6 +447,8 @@ const terminalRefs = new Map();
const activePanel = ref("");
const showSidebar = ref(false);
const focusMode = ref(false);
const shiftPending = ref(false);
const ctrlPending = ref(false);
const wsUrl = computed(() => {
const envUrl = import.meta.env.VITE_WS_URL;
@@ -544,7 +547,6 @@ function fillFromSSH(item) {
function connectWithSSH(item) {
fillFromSSH(item);
activePanel.value = "";
createSession();
}
@@ -704,6 +706,7 @@ async function deleteCommand(index) {
function applyCommandToTerminal(item) {
const session = sessions.value.find((s) => s.id === activeId.value);
if (!session || !session.ws || session.ws.readyState !== WebSocket.OPEN) {
commandError.value = "当前没有可用终端连接";
return;
}
const cmd = item.command || "";
@@ -714,6 +717,7 @@ function applyCommandToTerminal(item) {
data: `${cmd}\n`,
})
);
closeOverlay();
}
// ─── 脚本管理 (/api/scripts) ──────────────────────
@@ -808,6 +812,7 @@ async function deleteScript() {
function applyScriptToTerminal() {
const session = sessions.value.find((s) => s.id === activeId.value);
if (!session || !session.ws || session.ws.readyState !== WebSocket.OPEN) {
scriptError.value = "当前没有可用终端连接";
return;
}
if (!scriptForm.content) return;
@@ -817,6 +822,7 @@ function applyScriptToTerminal() {
data: `${scriptForm.content}\n`,
})
);
closeOverlay();
}
function sendQuickKey(type) {
@@ -825,22 +831,38 @@ function sendQuickKey(type) {
return;
}
// SHIFT / CTRL 单独发送通常无效果,做成“下一次快捷键生效”的修饰键
if (type === "shift") {
shiftPending.value = !shiftPending.value;
return;
}
if (type === "ctrl") {
ctrlPending.value = !ctrlPending.value;
return;
}
let data = "";
switch (type) {
case "esc":
data = "\x1b";
break;
case "tab":
data = "\t";
break;
case "slash":
data = "/";
break;
case "minus":
data = "-";
break;
case "home":
data = "\x1b[H";
case "dot":
data = ".";
break;
case "end":
data = "\x1b[F";
case "hash":
data = "#";
break;
case "amp":
data = "&";
break;
case "up":
data = "\x1b[A";
@@ -854,12 +876,6 @@ function sendQuickKey(type) {
case "left":
data = "\x1b[D";
break;
case "pgup":
data = "\x1b[5~";
break;
case "pgdn":
data = "\x1b[6~";
break;
case "enter":
data = "\r";
break;
@@ -867,12 +883,58 @@ function sendQuickKey(type) {
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(
JSON.stringify({
type: "input",
data,
})
);
shiftPending.value = false;
ctrlPending.value = false;
}
function resetForm() {
@@ -926,6 +988,7 @@ function createSession() {
};
nextTick(() => initSession(session, payload));
closeOverlay();
}
function initSession(session, payload) {
@@ -938,6 +1001,10 @@ function initSession(session, payload) {
fontSize: 14,
lineHeight: 1.4,
cursorBlink: true,
scrollback: 8000,
smoothScrollDuration: 140,
scrollSensitivity: 1.15,
fastScrollSensitivity: 4,
theme: {
background: "#0b0f17",
foreground: "#e6edf3",
@@ -1009,12 +1076,12 @@ function initSession(session, payload) {
} else if (msg.type === "status") {
session.status = msg.status || session.status;
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") {
session.status = "error";
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();
});
}
@@ -1107,8 +1175,46 @@ function toggleFocus() {
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(() => {
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();
loadCommands();
@@ -1117,6 +1223,16 @@ onMounted(() => {
onBeforeUnmount(() => {
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) => {
session.ws?.close();
session.term?.dispose();
@@ -1126,9 +1242,13 @@ onBeforeUnmount(() => {
<style scoped>
.app {
min-height: 100vh;
/* 初始高度用 100svh支持动态视口JS 会在键盘弹出时动态覆盖为 visualViewport.height */
height: 100svh;
height: 100vh; /* 降级 */
display: flex;
flex-direction: column;
overflow: hidden;
overscroll-behavior: none;
background: radial-gradient(circle at top, #1f2937 0, #020617 55%, #000 100%);
color: #e5e7eb;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
@@ -1238,12 +1358,22 @@ onBeforeUnmount(() => {
.app-nav {
display: flex;
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 {
position: relative;
border-radius: 12px;
white-space: nowrap;
flex-shrink: 0;
border: 1px solid rgba(148, 163, 184, 0.5);
background: radial-gradient(circle at top, #0f172a, #020617);
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);
}
.app-nav {
/* 移动端横滑时更顺手,避免被按钮点击完全吞掉 */
-webkit-overflow-scrolling: touch;
touch-action: pan-x;
}
.nav-btn::before {
content: "";
width: 6px;
@@ -1291,6 +1427,7 @@ onBeforeUnmount(() => {
position: relative;
padding: 12px 12px 16px;
gap: 8px;
min-height: 0;
}
.focus-main {
@@ -1384,6 +1521,9 @@ onBeforeUnmount(() => {
0 30px 80px rgba(15, 23, 42, 0.95),
0 0 40px rgba(56, 189, 248, 0.12);
overflow: hidden;
/* 虚拟键盘覆盖时,给底部留白避免遮挡终端最后几行 */
padding-bottom: var(--keyboard-inset, 0px);
min-height: 0;
}
.tabs {
@@ -1470,6 +1610,7 @@ onBeforeUnmount(() => {
background: #020617;
/* 交给 xterm 内部滚动,外层不再出现滚动条 */
overflow: hidden;
min-height: 0;
}
.empty-terminal {
@@ -1508,6 +1649,7 @@ onBeforeUnmount(() => {
inset: 0;
display: flex;
flex-direction: column;
min-height: 0;
}
.terminal-header {
@@ -1528,21 +1670,33 @@ onBeforeUnmount(() => {
.terminal-body {
flex: 1;
padding: 8px;
min-height: 0;
overflow: hidden;
overscroll-behavior: contain;
}
.quick-keys {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
touch-action: pan-x;
gap: 4px;
padding: 4px 8px 6px;
background: #020617;
border-top: 1px solid rgba(31, 41, 55, 0.9);
scrollbar-width: none;
}
.quick-keys::-webkit-scrollbar {
display: none;
}
.quick-key {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
min-width: 44px;
height: 26px;
border-radius: 8px;
border: 1px solid rgba(55, 65, 81, 0.9);
@@ -1550,8 +1704,12 @@ onBeforeUnmount(() => {
color: #e5e7eb;
font-size: 11px;
letter-spacing: 0.06em;
white-space: nowrap;
text-align: center;
cursor: pointer;
touch-action: manipulation;
user-select: none;
-webkit-user-select: none;
}
.quick-key.primary {
@@ -1559,6 +1717,12 @@ onBeforeUnmount(() => {
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 {
transform: translateY(1px);
background: #030712;
@@ -1856,8 +2020,12 @@ textarea {
.app-nav {
width: 100%;
justify-content: space-between;
flex-wrap: wrap;
justify-content: flex-start;
flex-wrap: nowrap !important;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
touch-action: pan-x;
white-space: nowrap;
}
.brand {
@@ -1876,11 +2044,24 @@ textarea {
</style>
<style>
html,
body,
#app {
width: 100%;
height: 100%;
overflow: hidden;
overscroll-behavior: none;
}
html,
body {
/* 保留整页滚动,但隐藏浏览器默认滚动条 */
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE/Edge */
margin: 0;
padding: 0;
/* 禁止页面级滚动,由 .app 内部负责布局 */
height: 100%;
overflow: hidden;
scrollbar-width: none;
-ms-overflow-style: none;
}
html::-webkit-scrollbar,
@@ -1889,14 +2070,42 @@ body::-webkit-scrollbar {
height: 0;
}
/* 隐藏 xterm 内部滚动条,但保留滚动行为 */
/* xterm 终端滚动:移动端更顺滑 + 细窄主题滚动条 */
.xterm-viewport {
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE/Edge */
overflow-y: auto !important;
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 {
width: 0;
height: 0;
width: 6px;
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>

View File

@@ -1,33 +1,33 @@
export function getApiBase() {
const envBase = import.meta.env.VITE_API_BASE;
if (envBase) {
return String(envBase).replace(/\/+$/, "");
}
// 默认走同源 /api更适合反向代理 + HTTPS
if (typeof window === "undefined") return "http://localhost:8080/api";
return `${window.location.origin}/api`;
}
export async function apiRequest(path, options = {}) {
const base = getApiBase();
const res = await fetch(`${base}${path}`, {
headers: {
"Content-Type": "application/json",
...(options.headers || {}),
},
...options,
});
let body = null;
try {
body = await res.json();
} catch {
body = null;
}
if (!res.ok) {
const message =
(body && body.error) || `请求失败 (${res.status} ${res.statusText})`;
throw new Error(message);
}
return body;
}
export function getApiBase() {
const envBase = import.meta.env.VITE_API_BASE;
if (envBase) {
return String(envBase).replace(/\/+$/, "");
}
// 默认走同源 /api更适合反向代理 + HTTPS
if (typeof window === "undefined") return "http://localhost:8080/api";
return `${window.location.origin}/api`;
}
export async function apiRequest(path, options = {}) {
const base = getApiBase();
const res = await fetch(`${base}${path}`, {
headers: {
"Content-Type": "application/json",
...(options.headers || {}),
},
...options,
});
let body = null;
try {
body = await res.json();
} catch {
body = null;
}
if (!res.ok) {
const message =
(body && body.error) || `请求失败 (${res.status} ${res.statusText})`;
throw new Error(message);
}
return body;
}