任务文件窗口按时间倒序排列

This commit is contained in:
2026-09-04 15:04:08 +08:00
parent 66bb97fcdf
commit ee2fc36ffd
2 changed files with 22 additions and 5 deletions
+8 -1
View File
@@ -1367,6 +1367,11 @@
el.innerHTML = '<div class="empty-tip">还没有文件,在对话框上传或让 AI 生成</div>';
return;
}
// 后端已按创建时间倒序,这里再排一次防旧排序缓存;时间缺失排最后
files.sort(function (a, b) {
const ca = a.ctime || a.mtime || 0, cb = b.ctime || b.mtime || 0;
return cb - ca;
});
filesAllPaths = files.map(f => f.filename);
el.innerHTML = files.map(f => {
// 预览策略:md/txt/html + 图片在 fs-viewer 预览(pdf 不预)
@@ -1376,11 +1381,13 @@
? '<svg class="file-ico eye" viewBox="0 0 24 24" aria-label="可预览"><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);
const ftime = fmtTime(f.ctime || f.mtime);
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 class="file-meta">' + ico + '<span class="file-size">' + fmtSize(f.size) + '</span>' +
(ftime ? '<span class="file-time">' + ftime + '</span>' : '') + '</div>' +
'</div>' +
'</div>';
}).join('');
+14 -4
View File
@@ -36,13 +36,23 @@ function listTaskFiles(dir) {
const relPath = rel ? rel + '/' + e.name : e.name;
if (e.isDirectory()) rec(abs, relPath);
else if (e.isFile()) {
let size = null, mtime = null;
try { const st = fs.statSync(abs); size = st.size; mtime = st.mtimeMs; } catch (_) {}
out.push({ filename: relPath, size, mtime });
let size = null, mtime = null, ctime = null;
// birthtime 在部分文件系统不可用(返回 0),回退 mtime;新生成/上传的文件两者基本一致
try {
const st = fs.statSync(abs);
size = st.size; mtime = st.mtimeMs;
ctime = (st.birthtimeMs && st.birthtimeMs > 0 ? st.birthtimeMs : st.mtimeMs) || null;
} catch (_) {}
out.push({ filename: relPath, size, mtime, ctime });
}
}
})(dir, '');
out.sort(function (a, b) { return a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; });
// 按创建时间倒序(最新在前)方便查找;同一时刻按文件名升序保证稳定
out.sort(function (a, b) {
const ca = a.ctime || a.mtime || 0, cb = b.ctime || b.mtime || 0;
if (cb !== ca) return cb - ca;
return a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0;
});
return out;
}