diff --git a/pages/mine/index.vue b/pages/mine/index.vue index 5714cb5..858a307 100644 --- a/pages/mine/index.vue +++ b/pages/mine/index.vue @@ -889,29 +889,40 @@ export default { }, // Utils + toDate(input) { + if (!input) return null + if (input instanceof Date) return isNaN(input.getTime()) ? null : input + if (typeof input === 'number') { + if (!Number.isFinite(input)) return null + const ms = input > 1e12 ? input : input * 1000 + const d = new Date(ms) + return isNaN(d.getTime()) ? null : d + } + const s = String(input || '').trim() + if (!s) return null + if (/^\d+$/.test(s)) { + const n = Number(s) + return this.toDate(n) + } + const c1 = s + const c2 = s.replace(/([+-]\d{2}):(\d{2})$/, '$1$2') + const c3 = c2.replace(/-/g, '/').replace('T', ' ') + const c4 = s.replace(/-/g, '/').replace('T', ' ') + const candidates = [c1, c2, c3, c4] + for (let i = 0; i < candidates.length; i++) { + const d = new Date(candidates[i]) + if (!isNaN(d.getTime())) return d + } + return null + }, formatDate(ts) { - if (!ts) return '' - const d = new Date(ts * 1000) + const d = this.toDate(ts) + if (!d) return '' return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}` }, formatDateTime(ts) { - if (!ts) return '' - // Convert string timestamp (e.g. "2023-01-01T...") to timestamp if needed - let d - if (typeof ts === 'string') { - // iOS compatibility for ISO strings - const safeTs = ts.replace(/-/g, '/') - d = new Date(safeTs) - if (isNaN(d.getTime())) { - // Fallback for non-ISO strings or just numbers as strings - const n = Number(ts) - if (!isNaN(n)) d = new Date(n * 1000) - } - } else { - d = new Date(ts * 1000) - } - - if (!d || isNaN(d.getTime())) return '' + const d = this.toDate(ts) + if (!d) return '' return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')} ${String(d.getHours()).padStart(2,'0')}:${String(d.getMinutes()).padStart(2,'0')}` }