更改文件浏览器样式
This commit is contained in:
+108
-29
@@ -367,16 +367,16 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--page);
|
||||
}
|
||||
.files-panel-header .file-upload {
|
||||
width: 30px; height: 30px; border-radius: 50%;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
background: var(--active-soft); color: var(--active); cursor: pointer;
|
||||
.files-panel-header .files-panel-title {
|
||||
flex: 1; min-width: 0;
|
||||
}
|
||||
.files-panel-header .file-upload:active { background: var(--active); color: #fff; }
|
||||
/* 上传总进度条(header 中间,上传中显示):[轨道 | 百分比] 横排,
|
||||
百分比走正常文档流,不再悬浮在 6px 高的轨道里,避免各种裁剪/像素取整导致文字显示不全 */
|
||||
/* 上传总进度条(.files-panel-header 中间,上传中显示):[轨道 | 百分比] 横排,
|
||||
百分比走正常文档流,不再悬浮在 6px 高的轨道里,避免各种裁剪/像素取整导致文字显示不全 */
|
||||
.files-panel-progress {
|
||||
flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; margin: 0 10px;
|
||||
flex: none; min-width: 0; display: flex; align-items: center; gap: 6px; margin: 0 10px;
|
||||
padding: 6px 14px;
|
||||
border-top: 1px solid var(--border);
|
||||
background: var(--page);
|
||||
}
|
||||
.files-panel-progress .fp-track {
|
||||
flex: 1; min-width: 0; height: 6px;
|
||||
@@ -391,41 +391,120 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0
|
||||
.files-panel-progress .pct {
|
||||
flex: none; font-size: 10px; color: var(--gray); line-height: 1; white-space: nowrap;
|
||||
}
|
||||
.files-panel-header .file-upload {
|
||||
width: 32px; height: 32px; border-radius: 50%;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
background: var(--active-soft); color: var(--active); cursor: pointer;
|
||||
}
|
||||
.files-panel-header .file-upload:active { background: var(--active); color: #fff; }
|
||||
.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 6px; }
|
||||
|
||||
/* 文件列表区:占据中部所有可用高度 */
|
||||
.files-panel .files-list {
|
||||
overflow-y: auto; padding: 4px 6px;
|
||||
flex: 1 1 auto; min-height: 0;
|
||||
}
|
||||
/* 底部固定操作栏:固定在面板最下方 */
|
||||
.files-panel-footer {
|
||||
flex: none;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 10px 14px;
|
||||
border-top: 1px solid var(--border);
|
||||
background: var(--page);
|
||||
padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
|
||||
}
|
||||
.files-panel-count {
|
||||
font-size: 13px; color: var(--gray);
|
||||
}
|
||||
.files-panel-actions {
|
||||
display: flex; align-items: center; gap: 12px;
|
||||
}
|
||||
.files-fab {
|
||||
width: 40px; height: 40px; border-radius: 50%;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
border: none; cursor: pointer;
|
||||
background: var(--active-soft); color: var(--active);
|
||||
transition: opacity .15s ease, background .15s ease, color .15s ease;
|
||||
}
|
||||
.files-fab svg {
|
||||
width: 20px; height: 20px; fill: none; stroke: currentColor;
|
||||
stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
|
||||
}
|
||||
.files-fab:active:not([disabled]) { opacity: .75; }
|
||||
.files-fab.del {
|
||||
background: #fdecea; color: #c0392b;
|
||||
}
|
||||
.files-fab[disabled] {
|
||||
background: var(--surface); color: var(--gray-light);
|
||||
cursor: not-allowed; opacity: .6;
|
||||
}
|
||||
|
||||
/* 单个文件行:复选框 | 中间区域(名称 + 副行) */
|
||||
.files-panel .file-row {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 8px; border-radius: 8px; font-size: 13.5px; cursor: default;
|
||||
display: flex; align-items: flex-start; gap: 10px;
|
||||
padding: 10px 8px; border-radius: 10px; font-size: 14px; cursor: default;
|
||||
border-bottom: 1px dashed var(--border);
|
||||
}
|
||||
.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/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;
|
||||
.files-panel .file-row.clickable { cursor: pointer; } /* 默认状态:可点名称预览/下载 */
|
||||
.files-panel .file-row.selected { background: var(--active-soft); }
|
||||
|
||||
/* 复选框:圆形,点击区域够大 */
|
||||
.files-panel .file-check {
|
||||
flex: none;
|
||||
width: 22px; height: 22px; border-radius: 50%;
|
||||
border: 2px solid #c8cee0; background: var(--page);
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
cursor: pointer; box-sizing: border-box;
|
||||
margin-top: 2px;
|
||||
transition: border-color .15s ease, background .15s ease;
|
||||
}
|
||||
/* 长文件名:横向滚动查看全文(隐藏滚动条,靠 touch/Shift+滚轮/方向键滑动) */
|
||||
.files-panel .file-check::after {
|
||||
content: '';
|
||||
display: block;
|
||||
width: 5px; height: 9px;
|
||||
border-right: 2px solid #fff;
|
||||
border-bottom: 2px solid #fff;
|
||||
transform: rotate(45deg) translate(-1px, -2px);
|
||||
opacity: 0;
|
||||
}
|
||||
.files-panel .file-row.selected .file-check {
|
||||
background: var(--active); border-color: var(--active);
|
||||
}
|
||||
.files-panel .file-row.selected .file-check::after { opacity: 1; }
|
||||
|
||||
/* 主区域:名称 + 副信息(图标 + 大小) */
|
||||
.files-panel .file-main {
|
||||
flex: 1; min-width: 0;
|
||||
display: flex; flex-direction: column; gap: 4px;
|
||||
}
|
||||
/* 文件名:最多两行 + 省略号,占据除复选框外所有横向空间 */
|
||||
.files-panel .file-name {
|
||||
flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap;
|
||||
font-weight: 500;
|
||||
scrollbar-width: none; -ms-overflow-style: none;
|
||||
font-weight: 500; color: var(--text, #223);
|
||||
display: -webkit-box; -webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2; line-clamp: 2;
|
||||
overflow: hidden; word-break: break-all;
|
||||
line-height: 1.35;
|
||||
}
|
||||
.files-panel .file-name::-webkit-scrollbar { display: none; }
|
||||
.files-panel .file-meta {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
font-size: 12px; color: var(--gray);
|
||||
}
|
||||
.files-panel .file-ico {
|
||||
width: 14px; height: 14px; flex-shrink: 0;
|
||||
fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
|
||||
}
|
||||
.files-panel .file-ico.eye { stroke: #5b8def; }
|
||||
.files-panel .file-ico.doc { stroke: #f2994a; }
|
||||
.files-panel .file-size {
|
||||
flex: none; background: var(--surface); color: var(--gray);
|
||||
font-size: 11px; padding: 2px 8px; border-radius: 9px;
|
||||
flex: none; color: var(--gray);
|
||||
font-size: 12px;
|
||||
}
|
||||
.files-panel .file-act {
|
||||
flex: none; background: var(--active-soft); color: var(--active);
|
||||
border: none; border-radius: 7px; padding: 4px 9px; font-size: 13px; cursor: pointer;
|
||||
}
|
||||
.files-panel .file-act:active { opacity: .75; }
|
||||
.files-panel .file-act.del { background: #fdecea; color: #c0392b; }
|
||||
.files-panel .file-act.del:active { opacity: .75; }
|
||||
|
||||
.files-panel .empty-tip {
|
||||
padding: 20px 10px; text-align: center; font-size: 13px; color: var(--gray-light);
|
||||
}
|
||||
|
||||
+119
-47
@@ -111,19 +111,30 @@
|
||||
<!-- ================= 任务文件面板(浮层:点输入行右侧发送旁的附件按钮展开;盖住输入区+遮罩) ================= -->
|
||||
<div id="files-mask" aria-hidden="true"></div>
|
||||
<div class="files-panel" id="files-panel" aria-label="任务文件">
|
||||
<div class="files-panel-header">
|
||||
<span>任务文件</span>
|
||||
<div class="files-panel-progress hidden" id="fp-progress" aria-live="polite">
|
||||
<div class="fp-track"><div class="bar" id="fp-progress-bar"></div></div>
|
||||
<span class="pct" id="fp-progress-pct">0%</span>
|
||||
<div class="files-panel-header">
|
||||
<span class="files-panel-title">任务文件</span>
|
||||
<label class="file-upload" title="上传文件" aria-label="上传文件">
|
||||
<input type="file" id="file-input" multiple hidden>
|
||||
<svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg>
|
||||
</label>
|
||||
</div>
|
||||
<div class="files-list" id="files-list"></div>
|
||||
<div class="files-panel-progress hidden" id="fp-progress" aria-live="polite">
|
||||
<div class="fp-track"><div class="bar" id="fp-progress-bar"></div></div>
|
||||
<span class="pct" id="fp-progress-pct">0%</span>
|
||||
</div>
|
||||
<div class="files-panel-footer">
|
||||
<span class="files-panel-count" id="files-count">未选择文件</span>
|
||||
<div class="files-panel-actions">
|
||||
<button class="files-fab" id="files-bulk-download" title="批量下载" aria-label="批量下载" disabled>
|
||||
<svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
|
||||
</button>
|
||||
<button class="files-fab del" id="files-bulk-delete" title="批量删除" aria-label="批量删除" disabled>
|
||||
<svg viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<label class="file-upload" title="上传文件">
|
||||
<input type="file" id="file-input" multiple hidden>
|
||||
<svg viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg>
|
||||
</label>
|
||||
</div>
|
||||
<div class="files-list" id="files-list"></div>
|
||||
</div>
|
||||
|
||||
<!-- ================= 设置区(覆盖层;入口:侧边栏用户区) ================= -->
|
||||
<section id="settings-page" class="hidden" aria-label="设置">
|
||||
@@ -1287,32 +1298,51 @@
|
||||
$('attach-btn').addEventListener('click', toggleFilesPanel);
|
||||
$('files-mask').addEventListener('click', () => setFilesPanel(false)); // 点遮罩收起
|
||||
|
||||
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 = '<div class="empty-tip">还没有文件,在对话框上传或让 AI 生成</div>';
|
||||
return;
|
||||
}
|
||||
el.innerHTML = files.map(f => {
|
||||
// 预览策略:md/txt/html + 图片在 fs-viewer 预览(pdf 不预)
|
||||
const low = f.filename.toLowerCase();
|
||||
const fsPv = /\.(md|txt|html?|png|jpe?g|gif|webp|svg)$/.test(low);
|
||||
const ico = fsPv
|
||||
? '<svg class="file-ico" viewBox="0 0 24 24"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg>'
|
||||
: '<svg class="file-ico" viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline></svg>';
|
||||
return '<div class="file-row' + (fsPv ? ' clickable' : '') + '" data-path="' + esc(f.filename) + '">' +
|
||||
ico +
|
||||
'<span class="file-name">' + esc(String(f.filename).split('/').pop() || f.filename) + '</span>' +
|
||||
'<span class="file-size">' + fmtSize(f.size) + '</span>' +
|
||||
'<button class="file-act" title="下载">下载</button>' +
|
||||
'<button class="file-act del" title="删除">删除</button>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
} catch (e) { toast('读取文件失败:' + e.message); }
|
||||
}
|
||||
// 任务文件面板多选状态:Set 保留当前选中的文件路径
|
||||
const fileSelected = new Set();
|
||||
|
||||
function updateFilesFooter() {
|
||||
const n = fileSelected.size;
|
||||
const countEl = $('files-count');
|
||||
const dlBtn = $('files-bulk-download');
|
||||
const delBtn = $('files-bulk-delete');
|
||||
if (countEl) countEl.textContent = n ? '已选择 ' + n + ' 个文件' : '未选择文件';
|
||||
if (dlBtn) dlBtn.disabled = n === 0;
|
||||
if (delBtn) delBtn.disabled = n === 0;
|
||||
}
|
||||
|
||||
async function loadFiles() {
|
||||
if (!state.sessionId) return;
|
||||
// 重新拉取前清空旧选择,避免脏数据遗留
|
||||
fileSelected.clear();
|
||||
updateFilesFooter();
|
||||
try {
|
||||
const files = await req('GET', '/api/sessions/' + state.sessionId + '/files');
|
||||
const el = $('files-list');
|
||||
if (!files.length) {
|
||||
el.innerHTML = '<div class="empty-tip">还没有文件,在对话框上传或让 AI 生成</div>';
|
||||
return;
|
||||
}
|
||||
el.innerHTML = files.map(f => {
|
||||
// 预览策略:md/txt/html + 图片在 fs-viewer 预览(pdf 不预)
|
||||
const low = f.filename.toLowerCase();
|
||||
const fsPv = /\.(md|txt|html?|png|jpe?g|gif|webp|svg)$/.test(low);
|
||||
const ico = fsPv
|
||||
? '<svg class="file-ico eye" viewBox="0 0 24 24"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg>'
|
||||
: '<svg class="file-ico doc" viewBox="0 0 24 24" aria-label="可下载"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline></svg>';
|
||||
const name = esc(String(f.filename).split('/').pop() || f.filename);
|
||||
return '<div class="file-row' + (fsPv ? ' clickable' : '') + '" data-path="' + esc(f.filename) + '" data-preview="' + (fsPv ? '1' : '0') + '">' +
|
||||
'<span class="file-check" role="checkbox" aria-checked="false" aria-label="选择"></span>' +
|
||||
'<div class="file-main">' +
|
||||
'<div class="file-name">' + name + '</div>' +
|
||||
'<div class="file-meta">' + ico + '<span class="file-size">' + fmtSize(f.size) + '</span></div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
// 重新渲染后刷新底部计数与按钮状态
|
||||
updateFilesFooter();
|
||||
} catch (e) { toast('读取文件失败:' + e.message); }
|
||||
}
|
||||
// 单击可预览文件 → 全屏预览(#fs-viewer):md 按 markdown 渲染、txt 原文排版、html 用沙箱 iframe、图片用 <img>
|
||||
async function previewInFs(name) {
|
||||
try {
|
||||
@@ -1369,15 +1399,57 @@
|
||||
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-row.clickable') && !e.target.closest('.file-act')) previewInFs(path);
|
||||
else if (e.target.closest('.file-act')) downloadFile(path);
|
||||
});
|
||||
// 列表事件委托:
|
||||
// 1) 点击勾选框:仅选中状态,不触发预览/下载;
|
||||
// 2) 一旦处于多选模式(Set 非空),整行点击仅切换选中状态,不再预览/下载;
|
||||
// 3) 未进入多选模式时,点击文件名/图标根据 row.dataset.preview 决定预览或下载。
|
||||
$('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;
|
||||
const isCheck = !!e.target.closest('.file-check');
|
||||
// 多选模式下:任何点击(仅选框/文件名/其他)都只切换选中
|
||||
if (isCheck || fileSelected.size > 0) {
|
||||
if (fileSelected.has(path)) { fileSelected.delete(path); row.classList.remove('selected'); }
|
||||
else { fileSelected.add(path); row.classList.add('selected'); }
|
||||
const ck = row.querySelector('.file-check');
|
||||
if (ck) ck.setAttribute('aria-checked', fileSelected.has(path) ? 'true' : 'false');
|
||||
updateFilesFooter();
|
||||
return;
|
||||
}
|
||||
// 默认模式:依据是否可预览选择预览/下载
|
||||
if (row.dataset.preview === '1') previewInFs(path);
|
||||
else downloadFile(path);
|
||||
});
|
||||
|
||||
// 批量下载:逐个拉取 download-token 后跳转,复用单文件下载路径(多个文件浏览器会连续触发下载)
|
||||
async function bulkDownload() {
|
||||
if (!state.sessionId || fileSelected.size === 0) return;
|
||||
const names = Array.from(fileSelected);
|
||||
for (const name of names) {
|
||||
try {
|
||||
const r = await req('GET', '/api/sessions/' + state.sessionId + '/files/download-token?path=' + encodeURIComponent(name));
|
||||
if (r && r.url) window.location.href = r.url;
|
||||
} catch (e) { toast('下载失败:' + name + ' ' + e.message); }
|
||||
}
|
||||
}
|
||||
async function bulkDelete() {
|
||||
if (!state.sessionId || fileSelected.size === 0) return;
|
||||
const names = Array.from(fileSelected);
|
||||
if (!await confirmModal('批量删除', '确认删除选中的 ' + names.length + ' 个文件?', '删除', true)) return;
|
||||
let ok = 0, fail = 0;
|
||||
for (const name of names) {
|
||||
try {
|
||||
await req('DELETE', '/api/sessions/' + state.sessionId + '/files?path=' + encodeURIComponent(name));
|
||||
ok++;
|
||||
} catch (e) { fail++; toast('删除失败:' + name + ' ' + e.message); }
|
||||
}
|
||||
if (ok) toast('已删除 ' + ok + ' 个文件');
|
||||
loadFiles(); // 重新拉取并重置选中
|
||||
}
|
||||
$('files-bulk-download').addEventListener('click', bulkDownload);
|
||||
$('files-bulk-delete').addEventListener('click', bulkDelete);
|
||||
// ---------- 大图上传前压缩(同步 v1:阈值/参数由 /api/system/status 透出) ----------
|
||||
const DEFAULT_UPLOAD_CFG = { image_compress_threshold_kb: 1536, image_max_dim: 2000, image_quality: 0.85 };
|
||||
let uploadCfgCache = null;
|
||||
|
||||
Reference in New Issue
Block a user