fix: 修复音乐编辑时长丢失及日期格式问题

This commit is contained in:
ikmkj
2026-04-09 20:17:59 +08:00
parent aa1eabfeb7
commit 395c75d3fb
5 changed files with 23 additions and 3 deletions

View File

@@ -270,7 +270,8 @@ const submitForm = async () => {
singer: form.value.singer,
album: form.value.album,
typeIds: form.value.types,
lyric: form.value.lyric
lyric: form.value.lyric,
duration: form.value.duration
},
form.value.file,
form.value.cover

View File

@@ -13,6 +13,20 @@ const collectMusicList = ref([])
// 加载状态
const loading = ref(false)
// 格式化日期时间兼容后端返回的多种格式ISO、yyyy-MM-dd HH:mm:ss、yyyy-MM-dd
const formatDate = (dateStr) => {
if (!dateStr) return ''
const date = new Date(dateStr)
// 检查是否为有效日期
if (isNaN(date.getTime())) return dateStr
return date.getFullYear() + '-' +
String(date.getMonth() + 1).padStart(2, '0') + '-' +
String(date.getDate()).padStart(2, '0') + ' ' +
String(date.getHours()).padStart(2, '0') + ':' +
String(date.getMinutes()).padStart(2, '0') + ':' +
String(date.getSeconds()).padStart(2, '0')
}
// 获取收藏的音乐列表
const fetchCollectMusic = async () => {
loading.value = true
@@ -31,7 +45,7 @@ const fetchCollectMusic = async () => {
duration: item.duration || 0,
cover: processImageUrl(item.cover),
url: item.url,
collectTime: item.collectTime ? new Date(item.collectTime).toLocaleDateString() : '未知'
collectTime: item.collectTime ? formatDate(item.collectTime) : '未知'
}))
} else {
ElMessage.error(res.message || '获取收藏的音乐列表失败')