From 4fe8715a31845cdb18c12f5adb5c33308e13c804 Mon Sep 17 00:00:00 2001 From: kicer Date: Wed, 2 Sep 2026 14:53:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9D=97=E5=86=85=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E3=80=81=E5=8F=8C=E5=87=BB=E5=85=A8=E5=B1=8F=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E3=80=81=E6=B6=88=E6=81=AF=E6=97=A5=E6=9C=9F=E4=B8=8E?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E3=80=81=E4=B8=8A=E4=BC=A0=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8D=A1=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/public/css/style.css | 19 +++++++++++-- app/server/public/index.html | 16 +++++++---- app/server/public/js/core.js | 23 +++++++++++++-- app/server/public/js/settings.js | 5 ++++ app/server/public/js/tasks.js | 48 ++++++++++++++++++++++++++++++-- 5 files changed, 99 insertions(+), 12 deletions(-) diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index f419a23..af89683 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -135,13 +135,14 @@ body { .msg-bubble { padding: 9px 12px; border-radius: 12px; line-height: 1.55; word-break: break-word; overflow-wrap: break-word; font-size: 14.5px; + max-width: 100%; min-width: 0; background: #fff; box-shadow: 0 1px 3px rgba(30,40,90,0.07); } .msg.me .msg-bubble { background: #e3eaff; border-bottom-right-radius: 4px; white-space: pre-wrap; } .msg.other .msg-bubble { border-bottom-left-radius: 4px; } .msg-bubble pre { background: #f0f2f6; padding: 8px 10px; border-radius: 8px; - overflow-x: auto; font-size: 12.5px; margin: 6px 0; + overflow-x: auto; max-width: 100%; font-size: 12.5px; margin: 6px 0; } .msg-bubble code { background: #f0f2f6; padding: 1px 4px; border-radius: 4px; font-size: 12.5px; } .msg-bubble pre code { background: none; padding: 0; } @@ -161,7 +162,21 @@ body { .pending-timer { margin-left: 8px; font-size: 11px; color: #aab; font-variant-numeric: tabular-nums; } .msg-bubble ul, .msg-bubble ol { padding-left: 1.5em; margin: 6px 0; } .msg-bubble li { margin: 2px 0; } -.msg-time { font-size: 10px; color: #aab; margin-top: 3px; } +.msg-time { font-size: 10px; color: #aab; margin-top: 3px; display: inline-flex; align-items: center; gap: 5px; } +/* 每条消息的复制图标 */ +.copy-btn { display: inline-flex; align-items: center; padding: 1px; border: none; background: none; cursor: pointer; opacity: 0.5; } +.copy-btn svg { width: 11px; height: 11px; stroke: #99a; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; } +.copy-btn:active, .copy-btn:hover { opacity: 1; } +.copy-btn svg.copied { stroke: #2e7d32; } +/* 消息全屏查看器(双击气泡打开) */ +#fs-viewer { position: fixed; inset: 0; z-index: 130; background: rgba(8,10,20,0.88); padding: 40px 14px 24px; overflow-y: auto; } +#fs-viewer.hidden { display: none; } +.fs-panel { max-width: 860px; margin: 0 auto; background: #fff; border-radius: 14px; padding: 18px 20px; font-size: 15.5px; } +.fs-close { + position: fixed; top: 12px; right: 14px; z-index: 131; width: 34px; height: 34px; + border: none; border-radius: 50%; background: rgba(255,255,255,0.18); color: #fff; + font-size: 15px; line-height: 1; cursor: pointer; +} /* 工具卡片 */ .tool-card { diff --git a/app/server/public/index.html b/app/server/public/index.html index dd8568d..9945ee0 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -294,11 +294,17 @@ + + + - - - - - + + + + + diff --git a/app/server/public/js/core.js b/app/server/public/js/core.js index a95f6e7..4d7ce51 100644 --- a/app/server/public/js/core.js +++ b/app/server/public/js/core.js @@ -59,8 +59,27 @@ function fmtTime(ts) { if (!ts) return ''; const d = new Date(ts); const p = n => String(n).padStart(2, '0'); - const today = new Date().toDateString() === d.toDateString(); - return (today ? '' : (d.getMonth() + 1) + '/' + d.getDate() + ' ') + p(d.getHours()) + ':' + p(d.getMinutes()); + const now = new Date(); + const hm = p(d.getHours()) + ':' + p(d.getMinutes()); + if (now.toDateString() === d.toDateString()) return hm; + const md = (d.getMonth() + 1) + '/' + d.getDate(); + // 跨天带日期,跨年再带年份 + return (d.getFullYear() === now.getFullYear() ? md : d.getFullYear() + '/' + md) + ' ' + hm; +} +// 剪贴板:WebView/局域网 http 非安全上下文没有 navigator.clipboard,降级 execCommand +async function copyText(text) { + try { + if (navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(text); return true; } + } catch (_) { /* 落入降级 */ } + try { + const ta = document.createElement('textarea'); + ta.value = text; + ta.style.position = 'fixed'; ta.style.opacity = '0'; + document.body.appendChild(ta); ta.focus(); ta.select(); + const ok = document.execCommand('copy'); + document.body.removeChild(ta); + return ok; + } catch (_) { return false; } } function toast(msg) { const el = $('toast'); diff --git a/app/server/public/js/settings.js b/app/server/public/js/settings.js index ae9b240..92d8a20 100644 --- a/app/server/public/js/settings.js +++ b/app/server/public/js/settings.js @@ -45,6 +45,11 @@ const CFG_FORM = [ { group: '技能', items: [ { path: 'skills.timeout_ms', label: '技能执行超时(ms)', type: 'int' }, ] }, + { group: '图片上传压缩(浏览器端)', items: [ + { path: 'upload.image_compress_threshold_kb', label: '大图阈值(KB)', type: 'int' }, + { path: 'upload.image_max_dim', label: '压缩后长边上限(px)', type: 'int' }, + { path: 'upload.image_quality', label: 'JPEG 质量(0~1)', type: 'float' }, + ] }, { group: '模型租约(会话结束后的保持)', items: [ { path: 'model_hold.idle_release_ms', label: '无人观看释放(ms)', type: 'int' }, { path: 'model_hold.active_max_ms', label: '最长保持(ms)', type: 'int' }, diff --git a/app/server/public/js/tasks.js b/app/server/public/js/tasks.js index 587bf5f..bbd14c8 100644 --- a/app/server/public/js/tasks.js +++ b/app/server/public/js/tasks.js @@ -357,6 +357,18 @@ function fillToolResult(id, content, isError, liveImageUrl) { } } +// 每条消息的复制按钮:原文存 Map(内容可能含引号/换行,不适合嵌进属性),按钮只带自增 id。 +// renderDetail 重建列表时清空,防长会话累积。 +const COPY_SVG = ''; +const copyMap = new Map(); +let copySeq = 0; +function copyBtnHtml(text) { + if (!text) return ''; + const id = ++copySeq; + copyMap.set(id, text); + return ''; +} + function msgNode(m, cardMap) { if (m.role === 'tool') { if (m.tool_call_id && cardMap && cardMap[m.tool_call_id]) { @@ -370,7 +382,7 @@ function msgNode(m, cardMap) { wrap.className = 'msg me'; wrap.innerHTML = '
我
' + '
' + attachBubbleLine(p.files) + esc(p.text) + '
' + - '
' + fmtTime(m.created_at) + '
'; + '
' + fmtTime(m.created_at) + copyBtnHtml(p.text) + '
'; return wrap; } if (m.role === 'assistant') { @@ -379,7 +391,7 @@ function msgNode(m, cardMap) { let inner = '
AI' + (m.model_tag ? ' · ' + esc(m.model_tag) : '') + '
'; if (m.content) inner += '
' + md(m.content) + '
'; - inner += '
' + fmtTime(m.created_at) + '
'; + inner += '
' + fmtTime(m.created_at) + copyBtnHtml(m.content) + '
'; wrap.innerHTML = inner; return wrap; } @@ -406,6 +418,7 @@ async function renderDetail(detail) { state.streamEl = null; state.streamText = ''; state.toolCards = {}; + copyMap.clear(); copySeq = 0; const s = detail.session; state.status = s.status; updatePhaseUI({ model_id: s.model_id, queue_pos: detail.queue_pos }); @@ -489,12 +502,19 @@ function connectStream() { bubble.innerHTML = md(d.content || ''); state.streamEl = null; state.streamText = ''; + if (d.content) { + const timeEl = document.createElement('div'); + timeEl.className = 'msg-time'; + timeEl.innerHTML = fmtTime(Date.now()) + copyBtnHtml(d.content); + bubble.parentElement.appendChild(timeEl); + } } else if (d.content) { const box = $('messages'); const wrap = document.createElement('div'); wrap.className = 'msg other'; wrap.innerHTML = '
AI
' + - '
' + md(d.content) + '
'; + '
' + md(d.content) + '
' + + '
' + fmtTime(Date.now()) + copyBtnHtml(d.content) + '
'; box.appendChild(wrap); } if (d.tool_calls) { @@ -604,6 +624,21 @@ const ui = { $('new-title').focus(); }, closeCreate() { $('create-modal').classList.add('hidden'); }, + openFullscreen(el) { + $('fs-body').innerHTML = el.innerHTML; + $('fs-viewer').classList.remove('hidden'); + }, + closeFullscreen() { $('fs-viewer').classList.add('hidden'); }, + async copyMsg(id, btn) { + const t = copyMap.get(Number(id)); + if (t == null) return; + if (await copyText(t)) { + // 图标短暂变绿作反馈 + const svg = btn && btn.querySelector && btn.querySelector('svg'); + if (svg) { svg.classList.add('copied'); setTimeout(function () { svg.classList.remove('copied'); }, 1200); } + toast('已复制'); + } else toast('复制失败'); + }, async renameSession() { if (!state.sessionId) return; const cur = $('chat-title').textContent; @@ -807,6 +842,13 @@ document.addEventListener('input', e => { if (e.target.id === 'search-input' && !e.target.value.trim()) loadSessions(); }); +// 双击消息气泡全屏查看(长回复/代码更好读) +document.getElementById('messages').addEventListener('dblclick', function (e) { + if (e.target.closest('#fs-viewer')) return; + const b = e.target.closest('.msg-bubble'); + if (b) ui.openFullscreen(b); +}); + // ---------- Tab 注册 ---------- window.tabModules = window.tabModules || {}; tabModules.tasks = {