代码块内滚动、双击全屏查看、消息日期与复制、上传压缩设置卡片

This commit is contained in:
2026-09-02 14:53:20 +08:00
parent 41adb96a81
commit 4fe8715a31
5 changed files with 99 additions and 12 deletions
+17 -2
View File
@@ -135,13 +135,14 @@ body {
.msg-bubble { .msg-bubble {
padding: 9px 12px; border-radius: 12px; line-height: 1.55; padding: 9px 12px; border-radius: 12px; line-height: 1.55;
word-break: break-word; overflow-wrap: break-word; font-size: 14.5px; 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); 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.me .msg-bubble { background: #e3eaff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.other .msg-bubble { border-bottom-left-radius: 4px; } .msg.other .msg-bubble { border-bottom-left-radius: 4px; }
.msg-bubble pre { .msg-bubble pre {
background: #f0f2f6; padding: 8px 10px; border-radius: 8px; 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 code { background: #f0f2f6; padding: 1px 4px; border-radius: 4px; font-size: 12.5px; }
.msg-bubble pre code { background: none; padding: 0; } .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; } .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 ul, .msg-bubble ol { padding-left: 1.5em; margin: 6px 0; }
.msg-bubble li { margin: 2px 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 { .tool-card {
+11 -5
View File
@@ -294,11 +294,17 @@
<div class="toast hidden" id="toast"></div> <div class="toast hidden" id="toast"></div>
<!-- 消息全屏查看器(双击气泡打开) -->
<div id="fs-viewer" class="hidden" onclick="if(event.target===this)ui.closeFullscreen()">
<button class="fs-close" onclick="ui.closeFullscreen()">✕</button>
<div class="msg-bubble fs-panel" id="fs-body"></div>
</div>
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS --> <!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
<script src="/js/core.js?v=20260902e"></script> <script src="/js/core.js?v=20260902f"></script>
<script src="/js/tasks.js?v=20260902e"></script> <script src="/js/tasks.js?v=20260902f"></script>
<script src="/js/skills.js?v=20260902e"></script> <script src="/js/skills.js?v=20260902f"></script>
<script src="/js/models.js?v=20260902e"></script> <script src="/js/models.js?v=20260902f"></script>
<script src="/js/settings.js?v=20260902e"></script> <script src="/js/settings.js?v=20260902f"></script>
</body> </body>
</html> </html>
+21 -2
View File
@@ -59,8 +59,27 @@ function fmtTime(ts) {
if (!ts) return ''; if (!ts) return '';
const d = new Date(ts); const d = new Date(ts);
const p = n => String(n).padStart(2, '0'); const p = n => String(n).padStart(2, '0');
const today = new Date().toDateString() === d.toDateString(); const now = new Date();
return (today ? '' : (d.getMonth() + 1) + '/' + d.getDate() + ' ') + p(d.getHours()) + ':' + p(d.getMinutes()); 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) { function toast(msg) {
const el = $('toast'); const el = $('toast');
+5
View File
@@ -45,6 +45,11 @@ const CFG_FORM = [
{ group: '技能', items: [ { group: '技能', items: [
{ path: 'skills.timeout_ms', label: '技能执行超时(ms)', type: 'int' }, { 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: [ { group: '模型租约(会话结束后的保持)', items: [
{ path: 'model_hold.idle_release_ms', label: '无人观看释放(ms)', type: 'int' }, { path: 'model_hold.idle_release_ms', label: '无人观看释放(ms)', type: 'int' },
{ path: 'model_hold.active_max_ms', label: '最长保持(ms)', type: 'int' }, { path: 'model_hold.active_max_ms', label: '最长保持(ms)', type: 'int' },
+45 -3
View File
@@ -357,6 +357,18 @@ function fillToolResult(id, content, isError, liveImageUrl) {
} }
} }
// 每条消息的复制按钮:原文存 Map(内容可能含引号/换行,不适合嵌进属性),按钮只带自增 id。
// renderDetail 重建列表时清空,防长会话累积。
const COPY_SVG = '<svg viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>';
const copyMap = new Map();
let copySeq = 0;
function copyBtnHtml(text) {
if (!text) return '';
const id = ++copySeq;
copyMap.set(id, text);
return '<button class="copy-btn" title="复制本条" onclick="ui.copyMsg(' + id + ',this)">' + COPY_SVG + '</button>';
}
function msgNode(m, cardMap) { function msgNode(m, cardMap) {
if (m.role === 'tool') { if (m.role === 'tool') {
if (m.tool_call_id && cardMap && cardMap[m.tool_call_id]) { if (m.tool_call_id && cardMap && cardMap[m.tool_call_id]) {
@@ -370,7 +382,7 @@ function msgNode(m, cardMap) {
wrap.className = 'msg me'; wrap.className = 'msg me';
wrap.innerHTML = '<div class="msg-user">我</div>' + wrap.innerHTML = '<div class="msg-user">我</div>' +
'<div class="msg-bubble">' + attachBubbleLine(p.files) + esc(p.text) + '</div>' + '<div class="msg-bubble">' + attachBubbleLine(p.files) + esc(p.text) + '</div>' +
'<div class="msg-time">' + fmtTime(m.created_at) + '</div>'; '<div class="msg-time">' + fmtTime(m.created_at) + copyBtnHtml(p.text) + '</div>';
return wrap; return wrap;
} }
if (m.role === 'assistant') { if (m.role === 'assistant') {
@@ -379,7 +391,7 @@ function msgNode(m, cardMap) {
let inner = '<div class="msg-user"><span class="ai-avatar' + gray + '"></span>AI' + let inner = '<div class="msg-user"><span class="ai-avatar' + gray + '"></span>AI' +
(m.model_tag ? ' · ' + esc(m.model_tag) : '') + '</div>'; (m.model_tag ? ' · ' + esc(m.model_tag) : '') + '</div>';
if (m.content) inner += '<div class="msg-bubble">' + md(m.content) + '</div>'; if (m.content) inner += '<div class="msg-bubble">' + md(m.content) + '</div>';
inner += '<div class="msg-time">' + fmtTime(m.created_at) + '</div>'; inner += '<div class="msg-time">' + fmtTime(m.created_at) + copyBtnHtml(m.content) + '</div>';
wrap.innerHTML = inner; wrap.innerHTML = inner;
return wrap; return wrap;
} }
@@ -406,6 +418,7 @@ async function renderDetail(detail) {
state.streamEl = null; state.streamEl = null;
state.streamText = ''; state.streamText = '';
state.toolCards = {}; state.toolCards = {};
copyMap.clear(); copySeq = 0;
const s = detail.session; const s = detail.session;
state.status = s.status; state.status = s.status;
updatePhaseUI({ model_id: s.model_id, queue_pos: detail.queue_pos }); updatePhaseUI({ model_id: s.model_id, queue_pos: detail.queue_pos });
@@ -489,12 +502,19 @@ function connectStream() {
bubble.innerHTML = md(d.content || ''); bubble.innerHTML = md(d.content || '');
state.streamEl = null; state.streamEl = null;
state.streamText = ''; 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) { } else if (d.content) {
const box = $('messages'); const box = $('messages');
const wrap = document.createElement('div'); const wrap = document.createElement('div');
wrap.className = 'msg other'; wrap.className = 'msg other';
wrap.innerHTML = '<div class="msg-user"><span class="ai-avatar"></span>AI</div>' + wrap.innerHTML = '<div class="msg-user"><span class="ai-avatar"></span>AI</div>' +
'<div class="msg-bubble">' + md(d.content) + '</div>'; '<div class="msg-bubble">' + md(d.content) + '</div>' +
'<div class="msg-time">' + fmtTime(Date.now()) + copyBtnHtml(d.content) + '</div>';
box.appendChild(wrap); box.appendChild(wrap);
} }
if (d.tool_calls) { if (d.tool_calls) {
@@ -604,6 +624,21 @@ const ui = {
$('new-title').focus(); $('new-title').focus();
}, },
closeCreate() { $('create-modal').classList.add('hidden'); }, 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() { async renameSession() {
if (!state.sessionId) return; if (!state.sessionId) return;
const cur = $('chat-title').textContent; const cur = $('chat-title').textContent;
@@ -807,6 +842,13 @@ document.addEventListener('input', e => {
if (e.target.id === 'search-input' && !e.target.value.trim()) loadSessions(); 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 注册 ---------- // ---------- Tab 注册 ----------
window.tabModules = window.tabModules || {}; window.tabModules = window.tabModules || {};
tabModules.tasks = { tabModules.tasks = {