fix(frontend): improve directory and timestamp display

This commit is contained in:
yukaidi
2026-06-10 21:22:29 +08:00
parent cbb442ceb6
commit 6ae5d998e6
4 changed files with 129 additions and 27 deletions

View File

@@ -511,6 +511,7 @@
files.forEach(file => {
const item = document.createElement('div');
const metaText = fileMetaText(file);
if (file.fileType === 'folder') {
// 文件夹
@@ -520,9 +521,7 @@
<i class="fas fa-folder"></i>
</div>
<div class="item-name">${file.fileName || '未命名文件夹'}</div>
<div class="item-meta">
${file.sizeStr || '0B'} · ${formatDate(file.createTime)}
</div>
${metaText ? `<div class="item-meta">${metaText}</div>` : ''}
`;
folderCount++;
@@ -541,9 +540,7 @@
<i class="fas ${fileTypeInfo.icon}"></i>
</div>
<div class="item-name">${file.fileName}</div>
<div class="item-meta">
${file.sizeStr || '0B'} · ${formatDate(file.createTime)}
</div>
${metaText ? `<div class="item-meta">${metaText}</div>` : ''}
`;
fileCount++;
@@ -675,19 +672,65 @@
renderBreadcrumb();
}
// 文件元信息
function fileMetaText(file) {
const parts = [];
if (file.fileType !== 'folder') {
parts.push(file.sizeStr || '0B');
}
const dateText = formatDate(file.createTime);
if (dateText) {
parts.push(dateText);
}
return parts.join(' · ');
}
function hasValidTime(value) {
if (value === null || value === undefined) return false;
if (typeof value !== 'string') return true;
const trimmedValue = value.trim();
return trimmedValue !== '' && trimmedValue !== 'null' && trimmedValue !== 'undefined';
}
function formatDateOnly(yearValue, monthValue, dayValue) {
const year = Number(yearValue);
const month = Number(monthValue);
const day = Number(dayValue);
const date = new Date(year, month - 1, day);
if (
date.getFullYear() !== year ||
date.getMonth() !== month - 1 ||
date.getDate() !== day
) {
return '';
}
return `${yearValue}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
}
// 格式化日期
function formatDate(dateString) {
if (!dateString) return '未知日期';
if (!hasValidTime(dateString)) return '';
try {
const date = new Date(dateString);
const value = typeof dateString === 'string' ? dateString.trim() : dateString;
if (typeof value === 'string') {
const dateOnly = value.match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/);
if (dateOnly) {
return formatDateOnly(dateOnly[1], dateOnly[2], dateOnly[3]);
}
const cnDateOnly = value.match(/^(\d{4})年\s*(\d{1,2})月\s*(\d{1,2})日$/);
if (cnDateOnly) {
return formatDateOnly(cnDateOnly[1], cnDateOnly[2], cnDateOnly[3]);
}
}
const date = new Date(value);
return isNaN(date.getTime())
? '未知日期'
? ''
: `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
} catch {
return '未知日期';
return '';
}
}
</script>
</body>
</html>
</html>