Compare commits

...

2 Commits

Author SHA1 Message Date
7f6da1fa10 fix: 恢复使用服务器本地时间,不硬编码时区
- logger.ts: 使用 new Date() 服务器本地时间
- logs.ts: 统计使用服务器本地时间
- 时区显示由客户端处理
2026-06-08 15:37:21 +08:00
3ce5ff4b65 fix: 日志时区修复 + 日期选择器
- logger.ts: 使用 UTC+8 时区记录日志
- logs.ts: 统计使用 UTC+8 今日日期
- logs.vue: 日期选择器改用 picker 组件
- 移除未使用的 showDatePicker 变量
2026-06-08 15:35:50 +08:00
3 changed files with 21 additions and 9 deletions

View File

@@ -53,10 +53,12 @@
<view class="query-section"> <view class="query-section">
<view class="query-header"> <view class="query-header">
<text class="section-title">日志查询</text> <text class="section-title">日志查询</text>
<view class="date-picker" @tap="showDatePicker = true"> <picker mode="date" :value="selectedDate" @change="onDateChange">
<view class="date-picker">
<Icon name="calendar" :size="28" color="#8B7E7E" /> <Icon name="calendar" :size="28" color="#8B7E7E" />
<text class="date-text">{{ selectedDate }}</text> <text class="date-text">{{ selectedDate }}</text>
</view> </view>
</picker>
</view> </view>
<!-- 筛选条件 --> <!-- 筛选条件 -->
@@ -109,7 +111,6 @@ const logLines = ref<string[]>([])
const loading = ref(false) const loading = ref(false)
const page = ref(1) const page = ref(1)
const total = ref(0) const total = ref(0)
const showDatePicker = ref(false)
const noMore = computed(() => logLines.value.length >= total.value && total.value > 0) const noMore = computed(() => logLines.value.length >= total.value && total.value > 0)
@@ -178,6 +179,12 @@ function selectDate(date: string) {
loadLogs() loadLogs()
} }
function onDateChange(e: any) {
selectedDate.value = e.detail.value
page.value = 1
loadLogs()
}
function getBarWidth(count: number): number { function getBarWidth(count: number): number {
if (!stats.value) return 0 if (!stats.value) return 0
const max = Math.max(...stats.value.daily.map(d => d.total), 1) const max = Math.max(...stats.value.daily.map(d => d.total), 1)

View File

@@ -8,13 +8,13 @@ if (!fs.existsSync(LOG_DIR)) {
fs.mkdirSync(LOG_DIR, { recursive: true }) fs.mkdirSync(LOG_DIR, { recursive: true })
} }
/** 获取当前日期字符串 YYYY-MM-DD */ /** 获取当前日期字符串 YYYY-MM-DD(服务器本地时间) */
function getDateStr(): string { function getDateStr(): string {
const d = new Date() const d = new Date()
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}` return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
} }
/** 格式化时间 HH:mm:ss.SSS */ /** 格式化时间 HH:mm:ss.SSS(服务器本地时间) */
function formatTime(date: Date): string { function formatTime(date: Date): string {
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:${String(date.getSeconds()).padStart(2, '0')}.${String(date.getMilliseconds()).padStart(3, '0')}` return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:${String(date.getSeconds()).padStart(2, '0')}.${String(date.getMilliseconds()).padStart(3, '0')}`
} }

View File

@@ -7,6 +7,12 @@ import { requireAdmin } from '../middleware/requireAdmin'
const router = Router() const router = Router()
const LOG_DIR = path.resolve(process.env.LOG_DIR || './logs') const LOG_DIR = path.resolve(process.env.LOG_DIR || './logs')
/** 获取今日日期字符串 YYYY-MM-DD服务器本地时间 */
function getTodayStr(): string {
const d = new Date()
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
}
/** 获取日志列表最近7天 */ /** 获取日志列表最近7天 */
router.get('/files', requireAdmin, (_req, res) => { router.get('/files', requireAdmin, (_req, res) => {
try { try {
@@ -45,8 +51,7 @@ router.get('/stats', requireAdmin, (_req, res) => {
return res.json({ code: 0, data: { today: { total: 0, errors: 0, slow: 0 }, files: [] } }) return res.json({ code: 0, data: { today: { total: 0, errors: 0, slow: 0 }, files: [] } })
} }
const today = new Date() const dateStr = getTodayStr()
const dateStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`
const todayFile = path.join(LOG_DIR, `${dateStr}.log`) const todayFile = path.join(LOG_DIR, `${dateStr}.log`)
let todayStats = { total: 0, errors: 0, slow: 0, warns: 0 } let todayStats = { total: 0, errors: 0, slow: 0, warns: 0 }