Преглед изворни кода

fix: formatTime 增加空值保护,避免 NaN-NaN 显示

当 createTime 为 null/undefined 或无效日期时,new Date() 会返回
Invalid Date,getFullYear() 等方法返回 NaN,导致显示 NaN-NaN-NaN。
现在增加判空和 isValid 检查,空值时返回 "-"。

Co-Authored-By: Claude <noreply@anthropic.com>
skyline пре 1 месец
родитељ
комит
09f1e92146
1 измењених фајлова са 2 додато и 0 уклоњено
  1. 2 0
      admin-h5/src/utils/index.js

+ 2 - 0
admin-h5/src/utils/index.js

@@ -5,7 +5,9 @@ export { storage } from './storage.js'
 export { fmtDictName, getDictColor } from './dict.js'
 
 export const formatTime = (time, format = 'YYYY-MM-DD HH:mm:ss') => {
+  if (!time) return '-'
   const date = new Date(time)
+  if (isNaN(date.getTime())) return '-'
   const year = date.getFullYear()
   const month = String(date.getMonth() + 1).padStart(2, '0')
   const day = String(date.getDate()).padStart(2, '0')