fix: correct local datetime display and remove false devtools detection
This commit is contained in:
@@ -623,8 +623,14 @@ createApp({
|
||||
}
|
||||
|
||||
list.sort((a, b) => {
|
||||
const getTime = s => s.created_at ? new Date(s.created_at).getTime() : 0;
|
||||
const getExpire = s => s.expires_at ? new Date(s.expires_at).getTime() : Number.MAX_SAFE_INTEGER;
|
||||
const getTime = (s) => {
|
||||
const date = this.parseDateValue(s?.created_at);
|
||||
return date ? date.getTime() : 0;
|
||||
};
|
||||
const getExpire = (s) => {
|
||||
const date = this.parseDateValue(s?.expires_at);
|
||||
return date ? date.getTime() : Number.MAX_SAFE_INTEGER;
|
||||
};
|
||||
|
||||
switch (this.shareFilters.sort) {
|
||||
case 'created_asc':
|
||||
@@ -657,8 +663,10 @@ createApp({
|
||||
}
|
||||
|
||||
list.sort((a, b) => {
|
||||
const ta = a.created_at ? new Date(a.created_at).getTime() : 0;
|
||||
const tb = b.created_at ? new Date(b.created_at).getTime() : 0;
|
||||
const da = this.parseDateValue(a?.created_at);
|
||||
const db = this.parseDateValue(b?.created_at);
|
||||
const ta = da ? da.getTime() : 0;
|
||||
const tb = db ? db.getTime() : 0;
|
||||
return tb - ta;
|
||||
});
|
||||
|
||||
@@ -3006,7 +3014,8 @@ handleDragLeave(e) {
|
||||
formatExpireTime(expiresAt) {
|
||||
if (!expiresAt) return '永久有效';
|
||||
|
||||
const expireDate = new Date(expiresAt);
|
||||
const expireDate = this.parseDateValue(expiresAt);
|
||||
if (!expireDate) return String(expiresAt);
|
||||
const now = new Date();
|
||||
const diffMs = expireDate - now;
|
||||
const diffMinutes = Math.floor(diffMs / (1000 * 60));
|
||||
@@ -3040,7 +3049,8 @@ handleDragLeave(e) {
|
||||
// 判断是否即将过期(3天内)
|
||||
isExpiringSoon(expiresAt) {
|
||||
if (!expiresAt) return false;
|
||||
const expireDate = new Date(expiresAt);
|
||||
const expireDate = this.parseDateValue(expiresAt);
|
||||
if (!expireDate) return false;
|
||||
const now = new Date();
|
||||
const diffMs = expireDate - now;
|
||||
const diffDays = diffMs / (1000 * 60 * 60 * 24);
|
||||
@@ -3050,7 +3060,8 @@ handleDragLeave(e) {
|
||||
// 判断是否已过期
|
||||
isExpired(expiresAt) {
|
||||
if (!expiresAt) return false;
|
||||
const expireDate = new Date(expiresAt);
|
||||
const expireDate = this.parseDateValue(expiresAt);
|
||||
if (!expireDate) return false;
|
||||
const now = new Date();
|
||||
return expireDate <= now;
|
||||
},
|
||||
@@ -3148,8 +3159,8 @@ handleDragLeave(e) {
|
||||
// 格式化时间
|
||||
formatDateTime(value) {
|
||||
if (!value) return '--';
|
||||
const d = new Date(value);
|
||||
if (Number.isNaN(d.getTime())) return value;
|
||||
const d = this.parseDateValue(value);
|
||||
if (!d) return value;
|
||||
return d.toLocaleString();
|
||||
},
|
||||
|
||||
@@ -4141,14 +4152,41 @@ handleDragLeave(e) {
|
||||
return '不自动重置';
|
||||
},
|
||||
|
||||
parseDateValue(value) {
|
||||
if (!value) return null;
|
||||
if (value instanceof Date) {
|
||||
return Number.isNaN(value.getTime()) ? null : value;
|
||||
}
|
||||
|
||||
const raw = String(value).trim();
|
||||
if (!raw) return null;
|
||||
|
||||
const localMatch = raw.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/);
|
||||
if (localMatch) {
|
||||
const year = Number(localMatch[1]);
|
||||
const month = Number(localMatch[2]);
|
||||
const day = Number(localMatch[3]);
|
||||
const hour = Number(localMatch[4] || 0);
|
||||
const minute = Number(localMatch[5] || 0);
|
||||
const second = Number(localMatch[6] || 0);
|
||||
|
||||
const localDate = new Date(year, month - 1, day, hour, minute, second);
|
||||
return Number.isNaN(localDate.getTime()) ? null : localDate;
|
||||
}
|
||||
|
||||
const normalized = raw.includes('T') ? raw : raw.replace(' ', 'T');
|
||||
const parsed = new Date(normalized);
|
||||
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
||||
},
|
||||
|
||||
toDateTimeLocalInput(dateString) {
|
||||
if (!dateString) return '';
|
||||
const normalized = String(dateString).trim().replace(' ', 'T');
|
||||
const match = normalized.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})/);
|
||||
if (match) return match[1];
|
||||
|
||||
const parsed = new Date(normalized);
|
||||
if (Number.isNaN(parsed.getTime())) return '';
|
||||
const parsed = this.parseDateValue(dateString);
|
||||
if (!parsed) return '';
|
||||
const year = parsed.getFullYear();
|
||||
const month = String(parsed.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(parsed.getDate()).padStart(2, '0');
|
||||
@@ -4169,16 +4207,9 @@ handleDragLeave(e) {
|
||||
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return '-';
|
||||
|
||||
// SQLite 返回的是 UTC 时间字符串,需要显式处理
|
||||
// 如果字符串不包含时区信息,手动添加 'Z' 标记为 UTC
|
||||
let dateStr = dateString;
|
||||
if (!dateStr.includes('Z') && !dateStr.includes('+') && !dateStr.includes('T')) {
|
||||
// SQLite 格式: "2025-11-13 16:37:19" -> ISO格式: "2025-11-13T16:37:19Z"
|
||||
dateStr = dateStr.replace(' ', 'T') + 'Z';
|
||||
}
|
||||
|
||||
const date = new Date(dateStr);
|
||||
|
||||
const date = this.parseDateValue(dateString);
|
||||
if (!date) return String(dateString);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
@@ -4511,7 +4542,8 @@ handleDragLeave(e) {
|
||||
|
||||
formatLogTime(timestamp) {
|
||||
if (!timestamp) return '';
|
||||
const date = new Date(timestamp);
|
||||
const date = this.parseDateValue(timestamp);
|
||||
if (!date) return String(timestamp);
|
||||
return date.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
|
||||
Reference in New Issue
Block a user