fix: 日志日期优化

This commit is contained in:
wkeylin
2025-06-03 14:30:15 +08:00
parent 0650f35dbb
commit abf2364bf6
+8 -5
View File
@@ -1,5 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { isToday } from '@/@core/utils/index'
import dayjs from 'dayjs';
// 定义输入变量 // 定义输入变量
const props = defineProps<{ const props = defineProps<{
@@ -10,7 +12,7 @@ const props = defineProps<{
const { t } = useI18n() const { t } = useI18n()
// 已解析的日志列表 // 已解析的日志列表
const parsedLogs = ref<{ level: string; time: string; program: string; content: string }[]>([]) const parsedLogs = ref<{ level: string; date: string; time: string; program: string; content: string }[]>([])
// 表头 // 表头
const headers = [ const headers = [
@@ -56,11 +58,11 @@ function startSSELogging() {
// 解析新日志 // 解析新日志
const newParsedLogs = buffer const newParsedLogs = buffer
.map(log => { .map(log => {
const logPattern = /^【(.*?)】[0-9\-:]*\s(.*?)\s-\s(.*?)\s-\s(.*)$/ const logPattern = /^【(.*?)】\s*([\d]{4}-\d{2}-\d{2}(?:\s+\d{2}:\d{2})?)\s+(.*?)\s*-\s*(.*?)\s*-\s*(.*)$/
const matches = log.match(logPattern) const matches = log.match(logPattern)
if (matches) { if (matches) {
const [, level, time, program, content] = matches const [, level, date, time, program, content] = matches
return { level, time, program, content } return { level, date, time, program, content }
} }
return null return null
}) })
@@ -104,7 +106,8 @@ onBeforeUnmount(() => {
<VChip size="small" :color="getLogColor(item.level)" variant="elevated" v-text="item.level" /> <VChip size="small" :color="getLogColor(item.level)" variant="elevated" v-text="item.level" />
</template> </template>
<template #item.time="{ item }"> <template #item.time="{ item }">
<span class="text-sm">{{ item.time }}</span> <span class="text-sm">{{ isToday(dayjs(item.date).toDate()) ? item.time : `${item.date}
${item.time}` }}</span>
</template> </template>
<template #item.program="{ item }"> <template #item.program="{ item }">
<h6 class="text-sm font-weight-medium">{{ item.program }}</h6> <h6 class="text-sm font-weight-medium">{{ item.program }}</h6>