diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index e160b4c..a42d1d5 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -355,7 +355,7 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0 } .files-panel .file-row:last-child { border-bottom: none; } .files-panel .file-row:active { background: var(--surface); } -.files-panel .file-row.clickable { cursor: pointer; } /* md 文件:整行可点预览 */ +.files-panel .file-row.clickable { cursor: pointer; } /* md/txt 可预览:整行可点 */ .files-panel .file-ico { width: 16px; height: 16px; flex-shrink: 0; stroke: #7f8db0; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; @@ -373,7 +373,6 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0 border: none; border-radius: 7px; padding: 4px 9px; font-size: 13px; cursor: pointer; } .files-panel .file-act:active { opacity: .75; } -.files-panel .file-act.view { background: var(--surface); color: var(--ink); } .files-panel .file-act.del { background: #fdecea; color: #c0392b; } .files-panel .file-act.del:active { opacity: .75; } .files-panel .empty-tip { diff --git a/app/server/public/index.html b/app/server/public/index.html index b00f247..ad98ca1 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -1177,29 +1177,39 @@ return; } el.innerHTML = files.map(f => { - const isMd = /\.md$/i.test(f.filename); - return '
' + - '' + + const pv = /\.(md|txt)$/i.test(f.filename); // md/txt 支持单击预览 + // 可预览文件的行首图标用眼睛,与普通文件图标区分 + const ico = pv + ? '' + : ''; + return '
' + + ico + '' + esc(String(f.filename).split('/').pop() || f.filename) + '' + '' + fmtSize(f.size) + '' + - (isMd ? '' : '') + '' + '' + '
'; }).join(''); } catch (e) { toast('读取文件失败:' + e.message); } } - // 单击 md 文件 → 与双击会话消息同一全屏预览窗(#fs-viewer):拉取文本、markdown 渲染后预览 - async function previewMdFile(name) { + // 单击可预览文件 → 与双击会话消息同一全屏预览窗(#fs-viewer):md 按 markdown 渲染,txt 保持原文排版 + async function previewTextFile(name) { try { const r = await fetch('/api/sessions/' + state.sessionId + '/files/download?path=' + encodeURIComponent(name)); if (r.status === 401) { location.href = '/login'; return; } if (!r.ok) { let msg = 'HTTP ' + r.status; try { msg = (await r.json()).error || msg; } catch (_) {} throw new Error(msg); } const text = await r.text(); - const r2 = mdHtml(text); + let cls = 'bubble-ai', html; + if (/\.md$/i.test(name)) { + const r2 = mdHtml(text); + html = r2.html; + if (r2.fmt) cls += ' md'; + } else { + html = esc(text); + } const wrap = document.createElement('div'); wrap.className = 'msg other'; - wrap.innerHTML = '
' + r2.html + '
'; + wrap.innerHTML = '
' + html + '
'; openFullscreen(wrap.firstChild); // 复用双击气泡的全屏查看器 } catch (e) { toast('预览失败:' + e.message); } } @@ -1223,7 +1233,7 @@ const path = row.dataset.path; if (!path) return; if (e.target.closest('.del')) deleteFile(path); - else if (e.target.closest('.view') || (e.target.closest('.file-row.clickable') && !e.target.closest('.file-act'))) previewMdFile(path); + else if (e.target.closest('.file-row.clickable') && !e.target.closest('.file-act')) previewTextFile(path); else if (e.target.closest('.file-act')) downloadFile(path); }); // 面板内上传:直接写入当前会话任务目录