diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index f0e07de..c917f3d 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -461,6 +461,34 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0 .files-panel .file-row.clickable { cursor: pointer; } /* 默认状态:可点名称预览/下载 */ .files-panel .file-row.selected { background: var(--active-soft); } +/* 目录行:箭头 + 文件夹图标 + 名称 + 文件数;点整行切换折叠(状态由 .collapsed 控制) */ +.files-panel .file-dir-head { + display: flex; align-items: center; gap: 8px; + padding: 9px 8px; border-radius: 10px; font-size: 14px; cursor: pointer; + border-bottom: 1px dashed var(--border); +} +.files-panel .file-dir-head:active { background: var(--surface); } +.files-panel .file-dir-arrow { + width: 14px; height: 14px; flex: none; + fill: none; stroke: var(--gray); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; + transform: rotate(90deg); /* 展开时箭头朝下,收起时朝右 */ + transition: transform .15s ease; +} +.files-panel .file-dir.collapsed > .file-dir-head .file-dir-arrow { transform: rotate(0deg); } +.files-panel .file-dir-ico { + width: 16px; height: 16px; flex: none; + fill: none; stroke: #f2b544; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; +} +.files-panel .file-dir-name { + flex: 1; min-width: 0; font-weight: 600; color: var(--text, #223); + overflow: hidden; text-overflow: ellipsis; white-space: nowrap; +} +.files-panel .file-dir-count { flex: none; font-size: 12px; color: var(--gray); } +.files-panel .file-dir.collapsed > .file-dir-body { display: none; } +/* 列表末尾收起的目录不再需要分隔线(常见两级,更深嵌套容忍多一条虚线) */ +.files-panel .files-list > .file-dir:last-child.collapsed > .file-dir-head, +.files-panel .file-dir-body > .file-dir:last-child.collapsed > .file-dir-head { border-bottom: none; } + /* 复选框:圆形,点击区域够大 */ .files-panel .file-check { flex: none; diff --git a/app/server/public/index.html b/app/server/public/index.html index cc90d0c..40bc790 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -1698,6 +1698,95 @@ updateFilesFooter(); } + // ---------- 目录分组:后端返回扁平列表(路径可含子目录),前端组树渲染 ---------- + // 规则:每一级都是目录在上、文件在下;同级目录按名称排序,同级文件按时间倒序(新的在前)。 + // filesCollapsedDirs 记住手动折叠过的目录(相对路径),上传/删除后重新渲染仍保持折叠。 + const filesCollapsedDirs = new Set(); + + function fileTimeOf(f) { return f.ctime || f.mtime || 0; } + function sortFilesByTime(arr) { + arr.sort(function (a, b) { + const d = fileTimeOf(b) - fileTimeOf(a); // 时间缺失的排最后,与原逻辑一致 + if (d) return d; + return a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; + }); + return arr; + } + function sortDirsByName(arr) { + arr.sort(function (a, b) { return a.name < b.name ? -1 : a.name > b.name ? 1 : 0; }); + return arr; + } + + // 扁平文件列表 → 树节点 { name, path, dirs: Map, files: [] } + function buildFilesTree(files) { + const root = { name: '', path: '', dirs: new Map(), files: [] }; + for (const f of files) { + const segs = String(f.filename).split('/'); + let node = root, rel = ''; + for (let i = 0; i < segs.length - 1; i++) { + const seg = segs[i]; + rel = rel ? rel + '/' + seg : seg; + if (!node.dirs.has(seg)) node.dirs.set(seg, { name: seg, path: rel, dirs: new Map(), files: [] }); + node = node.dirs.get(seg); + } + node.files.push(f); + } + return root; + } + + // 目录(含子目录)内文件总数,用于目录头计数 + function countDirFiles(node) { + let n = node.files.length; + for (const d of node.dirs.values()) n += countDirFiles(d); + return n; + } + + // 缩进:每层加深一点,封顶避免深层目录把文件名挤出屏幕 + function filesIndent(depth) { return 8 + Math.min(depth, 3) * 14; } + + function fileRowHtml(f, depth) { + // 预览策略: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 + ? '' + : ''; + const name = esc(String(f.filename).split('/').pop() || f.filename); + const ftime = fmtTime(f.ctime || f.mtime); + return '