mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-15 18:07:29 +00:00
fix(frontend): improve directory and timestamp display
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user