diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 4ebbd64..f106de7 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -262,9 +262,18 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0 .input-actions { display: flex; align-items: center; - justify-content: space-between; + gap: 6px; padding-top: 6px; } +/* 左右侧栏等宽,保证中部的附件按钮位于整行几何中心 */ +.ia-side { + flex: 1 1 0; + min-width: 0; + display: flex; + align-items: center; +} +.ia-left { justify-content: flex-start; } +.ia-right { justify-content: flex-end; } /* 深度思考开关(左侧功能开关) */ .think-toggle { @@ -289,14 +298,10 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0 .plus-btn { flex: none; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; - color: var(--ink); -} -.plus-btn:active { background: #e4e6ec; } -/* 右侧操作组:加号 + 发送,靠右排列 */ -.input-actions-right { - display: flex; align-items: center; - margin-left: auto; + background: var(--surface); color: var(--ink); } +.plus-btn:active { background: #dde0e6; } +.plus-btn.active { background: var(--active-soft); color: var(--active); } /* 文件面板展开时高亮 */ /* 发送按钮:蓝底白向上箭头 */ .send-btn { flex: none; width: 36px; height: 36px; border-radius: 50%; @@ -306,6 +311,49 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0 } .send-btn:active { opacity: 0.85; } +/* ================= 任务文件面板(同步 index 的 files-panel;仅保留上传) ================= */ +.files-panel { + flex: none; display: flex; flex-direction: column; + max-height: 45vh; overflow: hidden; + margin-bottom: 8px; + border: 1px solid var(--border); border-radius: 14px; + background: var(--page); +} +.files-panel-header { + flex: none; display: flex; align-items: center; justify-content: space-between; + padding: 9px 12px 9px 14px; font-size: 14px; font-weight: 600; + border-bottom: 1px solid var(--border); +} +.files-panel-header .file-upload { + width: 30px; height: 30px; border-radius: 50%; + display: flex; align-items: center; justify-content: center; + color: var(--gray); cursor: pointer; +} +.files-panel-header .file-upload:active { background: var(--surface); } +.files-panel-header .file-upload svg { + width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; + stroke-linecap: round; stroke-linejoin: round; +} +.files-panel .files-list { overflow-y: auto; padding: 4px; } +.files-panel .file-row { + display: flex; align-items: center; gap: 10px; + padding: 8px 10px; border-radius: 10px; font-size: 13.5px; +} +.files-panel .file-row:active { background: var(--surface); } +.files-panel .file-name { + flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; +} +.files-panel .file-size { flex: none; color: var(--gray-light); font-size: 12px; } +.files-panel .file-act { + flex: none; color: var(--active); font-size: 13px; padding: 3px 8px; border-radius: 7px; +} +.files-panel .file-act:active { background: var(--active-soft); } +.files-panel .file-act.del { color: #c0392b; } +.files-panel .file-act.del:active { background: #fdecea; } +.files-panel .empty-tip { + padding: 20px 10px; text-align: center; font-size: 13px; color: var(--gray-light); +} + /* ================= 历史记录抽屉 ================= */ #scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); diff --git a/app/server/public/index.html b/app/server/public/index.html index ba22823..40bfd83 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -61,26 +61,38 @@ @@ -691,6 +703,7 @@ async function openSession(id) { closeStream(); removeTyping(); + setFilesPanel(false); // 会话切换,收起文件面板防旧列表残留 state.sessionId = id; state.status = ''; state.streamEl = null; @@ -728,6 +741,7 @@ function newChat() { closeStream(); removeTyping(); + setFilesPanel(false); // 新建会话,文件面板随之收起 state.sessionId = null; state.sessionTitle = ''; state.status = ''; @@ -1131,15 +1145,83 @@ toast(state.deepThink ? '深度思考已开启(暂不影响后端)' : '深度思考已关闭'); }); - // 加号:选择附件(仅入队本地展示,发送时才真正上传) - $('attach-btn').addEventListener('click', () => $('file-input').click()); - $('file-input').addEventListener('change', e => { - for (const f of Array.prototype.slice.call(e.target.files || [])) { - state.attachments.push({ file: f, name: f.name, size: f.size }); - } - e.target.value = ''; - renderAttachChips(); + // ---------- 任务文件面板(点输入行中部的附件按钮展开;同步 index) ---------- + function setFilesPanel(open) { + $('files-panel').classList.toggle('hidden', !open); + $('attach-btn').classList.toggle('active', open); + } + function toggleFilesPanel() { + const panel = $('files-panel'); + const open = panel.classList.contains('hidden'); + if (open && !state.sessionId) { toast('先发送一条消息创建会话,再管理任务文件'); return; } + setFilesPanel(open); + if (open) loadFiles(); + } + $('attach-btn').addEventListener('click', toggleFilesPanel); + + async function loadFiles() { + if (!state.sessionId) return; + try { + const files = await req('GET', '/api/sessions/' + state.sessionId + '/files'); + const el = $('files-list'); + if (!files.length) { + el.innerHTML = '
还没有文件,在对话框上传或让 AI 生成
'; + return; + } + el.innerHTML = files.map(f => + '
' + + '' + esc(String(f.filename).split('/').pop() || f.filename) + '' + + '' + fmtSize(f.size) + '' + + '' + + '' + + '
').join(''); + } catch (e) { toast('读取文件失败:' + e.message); } + } + async function downloadFile(name) { + if (!state.sessionId) return; + try { + const r = await req('GET', '/api/sessions/' + state.sessionId + '/files/download-token?path=' + encodeURIComponent(name)); + window.location.href = r.url; // 原生导航下载:同源自动带登录 cookie,文件名不乱 + } catch (e) { toast('下载失败:' + e.message); } + } + async function deleteFile(name) { + if (!await confirmModal('删除文件', '删除文件 ' + name + ' ?', '删除', true)) return; + try { + await req('DELETE', '/api/sessions/' + state.sessionId + '/files?path=' + encodeURIComponent(name)); + loadFiles(); + } catch (e) { toast('删除失败:' + e.message); } + } + $('files-list').addEventListener('click', e => { + const row = e.target.closest('.file-row'); + if (!row || !state.sessionId) return; + const path = row.dataset.path; + if (!path) return; + if (e.target.closest('.del')) deleteFile(path); + else if (e.target.closest('.file-act')) downloadFile(path); }); + // 面板内上传:直接写入当前会话任务目录 + $('file-input').addEventListener('change', async e => { + const input = e.target; + const files = Array.prototype.slice.call(input.files || []); // 先快照再清空,FileList 是实时的 + input.value = ''; + if (!files.length) return; + if (!state.sessionId) { toast('先发送一条消息创建会话'); return; } + try { + const fd = new FormData(); + for (const f of files) fd.append('files', f, f.name); + await req('POST', '/api/sessions/' + state.sessionId + '/files', fd, true); + toast('已上传 ' + files.length + ' 个文件'); + loadFiles(); + } catch (err) { toast('上传失败:' + err.message); } + }); + // 面板展开时点外部自动收起(与 index 一致) + document.addEventListener('click', e => { + const panel = $('files-panel'); + if (panel.classList.contains('hidden')) return; + if (e.target.closest('#attach-btn')) return; // 附件按钮自身负责开合 + if (!panel.contains(e.target)) setFilesPanel(false); + }); + function renderAttachChips() { const row = $('attach-chips'); row.classList.toggle('hidden', !state.attachments.length);