From 7a34f612e71201bbfd58e73935807e0a8f7d12cc Mon Sep 17 00:00:00 2001 From: kicer Date: Sun, 25 Oct 2026 23:08:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B2=89=E6=B5=B8=E5=BC=8F?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9A=84=E6=98=BE=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/public/css/style.css | 58 +++++++++++++++--------- app/server/public/index.html | 10 +++-- app/server/public/js/viewport.js | 76 ++++++++++++++++++++++++++++++++ app/server/public/login.html | 6 ++- 4 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 app/server/public/js/viewport.js diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index abada14..d385dc3 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -11,12 +11,24 @@ --drawer-bg: rgb(249, 250, 251); /* 侧边栏底色(与页面白底区分;分组表头吸顶同色) */ --border: #ececf1; --radius-lg: 24px; + /* 安全区与软键盘(成因与注入约定见 js/viewport.js 顶部注释): + --sat / --sab 默认取 env()——iOS 独立 PWA 下有效;安卓 WebView 的 env() 只反映 + 屏幕挖孔(display cutout),不含状态栏/导航栏高度,基本恒为 0,需由套壳 App 用 + documentElement.style.setProperty 注入真实高度覆盖。 + --kb 是键盘占用的高度,取两个来源的较大值:--kb-page 由 viewport.js 按 visualViewport + 算(壳不注入时也能工作),--kb-native 由壳按 IME insets 注入(WebView 完全感知不到 + 键盘时只能走这条)。两个变量分开放,避免页面与壳互相覆盖同一个值。 */ + --sat: env(safe-area-inset-top, 0px); + --sab: env(safe-area-inset-bottom, 0px); + --kb-page: 0px; + --kb-native: 0px; + --kb: max(var(--kb-page), var(--kb-native)); } * { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; } /* 整站是视口锁定的 app shell:文档本身永不滚动,滚动只发生在内部容器 (消息流 #chat-view / 抽屉列表 .drawer-list / 设置页 .set-scroll,均已 overflow-y:auto)。 不写 overflow:hidden 时,桌面端只要有一行内容没收缩下(nowrap 胶囊/代码块/宽表格), - 浏览器就给窗口加横向滚动条;横向条又吃掉一屏高度,而 #app 死守 height:100%, + 浏览器就给窗口加横向滚动条;横向条又吃掉一屏高度,而 #app 死守视口高度, 于是竖横向滚动条一起出现、缩窗口页面不动。 */ html, body { height: 100%; overflow: hidden; } body { @@ -37,7 +49,9 @@ input, textarea { font: inherit; color: inherit; border: 0; outline: none; backg /* ================= 应用骨架 ================= */ #app { - height: 100%; + /* 减去 --kb:键盘弹起时整块 shell 收缩,footer 才会落在键盘上沿。 + 壳已正确 resize(adjustResize / resizes-content)时 --kb 恒为 0,不重复收缩。 */ + height: calc(100% - var(--kb)); max-width: 760px; margin: 0 auto; display: flex; @@ -53,7 +67,8 @@ input, textarea { font: inherit; color: inherit; border: 0; outline: none; backg display: flex; align-items: center; gap: 8px; - padding: 10px 12px; + /* 顶栏自己吃下状态栏高度(背景跟着铺上去,不留白条);设置页顶栏同用 .header */ + padding: calc(10px + var(--sat)) 12px 10px; min-height: 56px; background: var(--drawer-bg); } @@ -280,7 +295,7 @@ main { flex: 1; min-height: 0; display: flex; flex-direction: column; } .tool-card .tool-time .act-del:hover { color: #c0392b; } /* ================= 底部输入区 ================= */ -footer { position: relative; flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--page); } +footer { position: relative; flex: none; padding: 8px 12px calc(10px + var(--sab)); background: var(--page); } .attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; } .attach-chip { display: inline-flex; align-items: center; gap: 6px; @@ -436,12 +451,12 @@ body.voice-active .scroll-bottom-btn { display: none; } #voice-overlay { position: absolute; top: -72px; - bottom: calc(-11px - env(safe-area-inset-bottom, 0px)); + bottom: calc(-11px - var(--sab)); left: -13px; right: -13px; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 20px; - padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)); + padding-bottom: calc(70px + var(--sab)); /* 底色必须是**不透明**的 var(--page):早先只铺一层 9% 蓝渐变,遮罩伸进会话流的那一段 会把底下的消息文字透出来,「松手传送」看着就成了半透明。 顶层那 20px 由透明渐变到 --page 只是把上边缘与会话流接上,别把整块都做成渐变。 */ @@ -508,7 +523,7 @@ body.voice-active .scroll-bottom-btn { display: none; } border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(20, 30, 70, 0.16); transform: translateY(105%); transition: transform .25s ease; /* 收起时滑出屏幕 */ - padding-bottom: env(safe-area-inset-bottom, 0px); + padding-bottom: var(--sab); overflow: hidden; } .files-panel.open { transform: translateY(0); } @@ -604,7 +619,7 @@ body.voice-active .scroll-bottom-btn { display: none; } padding: 10px 14px; border-top: 1px solid var(--border); background: var(--page); - padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); + padding-bottom: calc(10px + var(--sab)); } .files-panel-count { font-size: 13px; color: var(--gray); @@ -757,7 +772,9 @@ body.voice-active .scroll-bottom-btn { display: none; } } #scrim.show { opacity: 1; pointer-events: auto; } #drawer { - position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; + /* 抽屉是 fixed 全屏层:顶部让出状态栏,底部随键盘收缩(搜索框输入时列表不被盖住) */ + position: fixed; top: 0; bottom: var(--kb); left: 0; z-index: 50; + padding-top: var(--sat); width: min(78vw, 320px); background: var(--drawer-bg); display: flex; flex-direction: column; @@ -848,7 +865,7 @@ body.voice-active .scroll-bottom-btn { display: none; } /* 底部用户区 */ .drawer-user { flex: none; display: flex; align-items: center; gap: 10px; - padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)); + padding: 12px 14px calc(12px + var(--sab)); border-top: 1px solid var(--border); } .avatar { @@ -933,12 +950,12 @@ body.voice-active .scroll-bottom-btn { display: none; } /* 两层 img 绝对定位居中叠放:滑动切换时旧图滑出、新图同步滑入(见 js/stream.js 的 slideTo) */ #img-viewer img { position: absolute; inset: 0; margin: auto; max-width: 100vw; max-height: 88vh; touch-action: none; cursor: grab; user-select: none; -webkit-user-drag: none; will-change: transform; } /* 组内页码:底部居中悬浮,不参与命中测试(点它等于点背景会关闭) */ -#img-count { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 151; padding: 3px 12px; border-radius: 999px; background: rgba(0,0,0,0.5); color: #fff; font-size: 12px; letter-spacing: .5px; pointer-events: none; } +#img-count { position: fixed; left: 50%; bottom: calc(18px + var(--sab)); transform: translateX(-50%); z-index: 151; padding: 3px 12px; border-radius: 999px; background: rgba(0,0,0,0.5); color: #fff; font-size: 12px; letter-spacing: .5px; pointer-events: none; } #fs-viewer { position: fixed; inset: 0; z-index: 130; background: rgba(8,10,20,0.88); padding: 40px 14px 24px; overflow: auto; /* 缩放后支持横纵滚动 */ } #fs-viewer.hidden { display: none; } .fs-panel { max-width: 860px; margin: 0 auto; background: var(--page); border-radius: 14px; padding: 18px 20px; font-size: 15.5px; } /* 顶部操作区:默认右上角悬浮(消息全屏用);文件预览走 fs-bar 模式时独立成一行 */ -.fs-actions { position: fixed; top: calc(2px + env(safe-area-inset-top, 0px)); right: 14px; z-index: 131; display: flex; align-items: center; gap: 8px; } +.fs-actions { position: fixed; top: calc(2px + var(--sat)); right: 14px; z-index: 131; display: flex; align-items: center; gap: 8px; } .fs-name { display: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; color: var(--ink); } .fs-btn { flex: none; display: flex; align-items: center; justify-content: center; @@ -955,8 +972,8 @@ body.voice-active .scroll-bottom-btn { display: none; } #fs-viewer.fs-bar .fs-actions { position: sticky; top: 0; z-index: 1; flex: none; width: 100%; - height: calc(40px + env(safe-area-inset-top, 0px)); - padding: env(safe-area-inset-top, 0px) 10px 0 14px; + height: calc(40px + var(--sat)); + padding: var(--sat) 10px 0 14px; justify-content: flex-end; gap: 6px; background: var(--page); border-bottom: 1px solid var(--border); } @@ -971,14 +988,14 @@ body.voice-active .scroll-bottom-btn { display: none; } #fs-viewer.fs-bar #fs-body .bubble-ai, #fs-viewer.fs-bar #fs-body .bubble-user { max-width: 100%; margin: 0; border-radius: 0; box-shadow: none; background: var(--page); - padding: 14px 12px calc(28px + env(safe-area-inset-bottom, 0px)); font-size: 15.5px; + padding: 14px 12px calc(28px + var(--sab)); font-size: 15.5px; } #fs-viewer.fs-bar #fs-src-pane { overflow: auto; } -#fs-viewer.fs-bar #fs-src-code { max-height: none; border: 0; border-radius: 0; padding: 12px 14px calc(28px + env(safe-area-inset-bottom, 0px)); } +#fs-viewer.fs-bar #fs-src-code { max-height: none; border: 0; border-radius: 0; padding: 12px 14px calc(28px + var(--sab)); } #fs-viewer.fs-bar .fs-img-frame { max-width: 100%; max-height: 100%; border-radius: 0; margin: 0 auto; } .fs-close { /* 顶到视口最上沿(避开刘海),不再压住预览面板顶部 */ - position: fixed; top: calc(2px + env(safe-area-inset-top, 0px)); right: 14px; z-index: 131; width: 34px; height: 34px; + position: fixed; top: calc(2px + var(--sat)); right: 14px; z-index: 131; width: 34px; height: 34px; border: none; border-radius: 50%; background: rgba(0,0,0,0.42); color: #fff; box-shadow: 0 1px 5px rgba(0,0,0,0.22); font-size: 15px; line-height: 1; cursor: pointer; @@ -1028,7 +1045,7 @@ body.voice-active .scroll-bottom-btn { display: none; } .header-right .icon-btn:active, .header-right label.icon-btn:active { background: var(--surface); } label.icon-btn { cursor: pointer; } #set-body { flex: 1; min-height: 0; background: var(--surface); display: flex; flex-direction: column; } -.set-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 12px 12px calc(16px + env(safe-area-inset-bottom, 0px)); } +.set-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 12px 12px calc(16px + var(--sab)); } .empty-tip { color: var(--gray-light); text-align: center; padding: 18px; font-size: 13px; } /* ---------- 设置主页卡片 ---------- */ @@ -1261,7 +1278,7 @@ label.icon-btn { cursor: pointer; } /* ---------- 编辑器页(config.yml 原文 / 技能文件) ---------- */ .set-editor { flex: 1; min-height: 0; display: flex; flex-direction: column; - padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px)); + padding: 10px 12px calc(12px + var(--sab)); } .set-editor textarea { flex: 1; width: 100%; resize: none; background: #fff; color: var(--ink); @@ -1287,7 +1304,8 @@ label.icon-btn { cursor: pointer; } .btn-row { display: flex; gap: 10px; } .btn-row .primary-btn { flex: 1; } .modal-overlay { - position: fixed; inset: 0; background: rgba(20, 25, 50, 0.45); + /* bottom 让出键盘:弹窗内的输入框(定时任务提示词等)不被软键盘压住 */ + position: fixed; inset: 0; bottom: var(--kb); background: rgba(20, 25, 50, 0.45); display: flex; align-items: center; justify-content: center; z-index: 100; } .modal { diff --git a/app/server/public/index.html b/app/server/public/index.html index 13a1e24..87a26b4 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -2,7 +2,10 @@ - + + Agent 任务台 @@ -525,6 +528,7 @@ + @@ -537,12 +541,12 @@ // 启动自愈:外部工具改前端文件是非原子写入,极端时机下浏览器可能拿到半截或重复拼接的 HTML // (脚本缺半 → 白屏裸首页;重复注入 → 每个文件报 duplicate variable 后 JS 全挂)。 // 这里检测关键脚本数量与入口全局,不对就自动整页重载一次(sessionStorage 防循环)。 - // 注意:js/ 脚本增减时需同步改这里的期望数 7。 + // 注意:js/ 脚本增减时需同步改这里的期望数 9。 (function () { var ok = false; try { var n = document.querySelectorAll('script[src^="/js/"]').length; - ok = n === 7 && typeof state !== 'undefined' && + ok = n === 9 && typeof state !== 'undefined' && typeof openFilePreview === 'function' && typeof restartNow === 'function'; } catch (_) {} if (ok) { try { sessionStorage.removeItem('boot-heal'); } catch (_) {} return; } diff --git a/app/server/public/js/viewport.js b/app/server/public/js/viewport.js new file mode 100644 index 0000000..c5a4a2b --- /dev/null +++ b/app/server/public/js/viewport.js @@ -0,0 +1,76 @@ +// 视口适配:软键盘高度 → CSS 变量 --kb-page(纯页面侧兜底,不依赖套壳 App 改代码) +// ---------------------------------------------------------------------------- +// 症状:套壳 App(Android WebView / ArkWeb)开了 edge-to-edge 后, +// 1) 顶部内容压在状态栏下面 —— 安卓 WebView 的 env(safe-area-inset-top) 只反映屏幕 +// 挖孔(display cutout),不含状态栏高度,基本恒为 0;壳不额外注入就顶不上去。 +// 这一条由壳注入 CSS 变量解决,见下方「注入约定」,本文件不处理。 +// 2) 键盘弹起、输入框被盖住 —— Chromium 默认 interactive-widget=resizes-visual,只缩 +// visual viewport,layout viewport 不动。本页是 height:100% 的固定 shell,footer 全靠 +// layout viewport 变矮才会被顶上来,于是原地不动被键盘压住(看起来像「没给键盘留位置」)。 +// +// 本文件只解决第 2 条:用 visualViewport 与 innerHeight 的差值算出键盘实际占用的高度, +// 写进 --kb-page;#app 按 --kb(= max(--kb-page, --kb-native))收缩,footer 自动落在键盘上沿。 +// 壳若已正确 resize(adjustResize / resizes-content 生效),innerHeight 会同步变矮, +// 差值恒为 0,本逻辑自动失效,不会二次收缩。 +// +// 注入约定(壳侧,loadUrl 之后或 WindowInsets 变化时): +// document.documentElement.style.setProperty('--sat', '36px'); // 状态栏高度 +// document.documentElement.style.setProperty('--sab', '20px'); // 导航栏/手势条高度 +// document.documentElement.style.setProperty('--kb-native', '300px'); // IME 高度(可选) +// --kb-native 用于「WebView 完全感知不到键盘」的情况(窗口不 resize、visualViewport 也不缩), +// 此时本文件量不到任何东西,只能靠壳把 IME insets 报进来;页面与壳各写各的变量,互不覆盖。 +(function () { + 'use strict'; + + const root = document.documentElement; + const vv = window.visualViewport; + // 没有 visualViewport 的老 WebView:只剩 interactive-widget / 壳 resize 两条路 + if (!vv) return; + + // 键盘判定阈值:地址栏/浏览器 UI 收起通常 < 60px,软键盘一般 > 150px, + // 取 80 让两者之间留足余量,避免把浏览器 UI 收起误判成键盘。 + const KB_MIN = 80; + // 贴底判定:与 chat.js 的 SCROLL_BOTTOM_THRESHOLD 同量级即可,不必严格一致 + const STICK_PX = 80; + + let kb = 0; + let raf = 0; + + function nearBottom(box) { + return box.scrollHeight - box.scrollTop - box.clientHeight < STICK_PX; + } + + function measure() { + raf = 0; + // 键盘占掉的高度 = layout viewport 高度 -(visual viewport 顶部偏移 + 可视高度)。 + // 浏览器为露出光标会把 visual viewport 上推(offsetTop > 0),这部分要一并扣掉, + // 否则会按「整段键盘」收缩,footer 反而被顶得比键盘上沿更高。 + let next = Math.round(window.innerHeight - vv.offsetTop - vv.height); + // 双指缩放时 vv.height 被压缩,不代表键盘(user-scalable=no 下基本走不到) + if (vv.scale > 1.01 || next < KB_MIN) next = 0; + // 兜底上限:横屏 + 大字号等极端情况下别把整个 shell 收没 + next = Math.min(next, Math.round(window.innerHeight * 0.7)); + + if (next === kb) return; + + const box = document.getElementById('chat-view'); + // 只在「键盘弹起导致变矮」时继续贴底;收键盘时保持当前阅读位置不动 + const stick = next > kb && !!box && nearBottom(box); + kb = next; + root.style.setProperty('--kb-page', kb + 'px'); + + if (stick) { + // 等一次布局:#app 收缩后 scrollHeight / clientHeight 才是新值 + requestAnimationFrame(() => { box.scrollTop = box.scrollHeight; }); + } + } + + function schedule() { + if (!raf) raf = requestAnimationFrame(measure); + } + + vv.addEventListener('resize', schedule); + vv.addEventListener('scroll', schedule); // 浏览器平移 visual viewport 时 offsetTop 会变 + // 转屏后尺寸与 inset 都变了,等系统栏动画结束再量一次 + window.addEventListener('orientationchange', () => setTimeout(measure, 200)); +})(); diff --git a/app/server/public/login.html b/app/server/public/login.html index a25fa1a..c103bb9 100644 --- a/app/server/public/login.html +++ b/app/server/public/login.html @@ -2,7 +2,7 @@ - + Agent 任务台 · 登录 @@ -13,7 +13,8 @@