2026-03-02 21:02:58 +08:00
|
|
|
<template>
|
|
|
|
|
<q-card class="q-mt-md shadow-2">
|
2026-03-02 21:13:26 +08:00
|
|
|
<q-card-section class="bg-blue-grey-1 cursor-pointer" @click="expanded = !expanded">
|
2026-03-02 21:02:58 +08:00
|
|
|
<div class="text-h6 text-blue-grey-9 flex items-center gap-2">
|
|
|
|
|
<q-icon name="terminal" />
|
|
|
|
|
运行日志
|
|
|
|
|
<q-space />
|
2026-03-02 21:13:26 +08:00
|
|
|
<q-icon :name="expanded ? 'expand_less' : 'expand_more'" />
|
2026-03-02 21:02:58 +08:00
|
|
|
</div>
|
|
|
|
|
</q-card-section>
|
2026-03-02 21:13:26 +08:00
|
|
|
<div v-show="expanded" class="q-pa-none">
|
2026-03-02 21:02:58 +08:00
|
|
|
<div ref="logContainer" class="log-container">
|
|
|
|
|
<div
|
|
|
|
|
v-for="(log, index) in logs"
|
|
|
|
|
:key="index"
|
|
|
|
|
:class="['log-line', `log-${log.level}`]"
|
|
|
|
|
>
|
|
|
|
|
<span class="log-time">{{ log.time }}</span>
|
|
|
|
|
<span class="log-message">{{ log.message }}</span>
|
|
|
|
|
</div>
|
2026-03-02 21:13:26 +08:00
|
|
|
<div v-if="logs.length === 0" class="log-empty">暂无日志</div>
|
2026-03-02 21:02:58 +08:00
|
|
|
</div>
|
2026-03-02 21:13:26 +08:00
|
|
|
</div>
|
2026-03-02 21:02:58 +08:00
|
|
|
</q-card>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, nextTick } from 'vue'
|
|
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
|
name: 'LogComponent'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
interface LogEntry {
|
|
|
|
|
level: 'info' | 'warning' | 'error' | 'debug'
|
|
|
|
|
time: string
|
|
|
|
|
message: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const logs = ref<LogEntry[]>([])
|
|
|
|
|
const logContainer = ref<HTMLElement | null>(null)
|
2026-03-02 21:13:26 +08:00
|
|
|
const expanded = ref(true)
|
2026-03-03 10:19:33 +08:00
|
|
|
const lastTripRates = ref<number[]>([])
|
2026-03-02 21:02:58 +08:00
|
|
|
|
|
|
|
|
const addLog = (level: LogEntry['level'], message: string) => {
|
|
|
|
|
const now = new Date()
|
|
|
|
|
const time = now.toLocaleTimeString('zh-CN', { hour12: false })
|
|
|
|
|
|
|
|
|
|
logs.value.push({ level, time, message })
|
|
|
|
|
|
2026-03-03 10:19:33 +08:00
|
|
|
// 解析跳闸率数值
|
|
|
|
|
const match = message.match(/不同相跳闸率是\[([\d.\s]+)\]/)
|
|
|
|
|
if (match) {
|
|
|
|
|
const values = match[1].trim().split(/\s+/).map(Number)
|
|
|
|
|
lastTripRates.value = values
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 21:02:58 +08:00
|
|
|
// 自动滚动到底部
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
if (logContainer.value) {
|
|
|
|
|
logContainer.value.scrollTop = logContainer.value.scrollHeight
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const clearLog = () => {
|
|
|
|
|
logs.value = []
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 14:26:58 +08:00
|
|
|
// 获取日志文本
|
|
|
|
|
const getLogsText = (): string => {
|
|
|
|
|
return logs.value.map(log => `[${log.time}] [${log.level.toUpperCase()}] ${log.message}`).join('\n')
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 21:02:58 +08:00
|
|
|
// 暴露方法给父组件
|
|
|
|
|
defineExpose({
|
|
|
|
|
addLog,
|
2026-03-03 10:19:33 +08:00
|
|
|
clearLog,
|
2026-03-03 14:26:58 +08:00
|
|
|
lastTripRates,
|
|
|
|
|
getLogsText
|
2026-03-02 21:02:58 +08:00
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.log-container {
|
|
|
|
|
max-height: 300px;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
background-color: #1e1e1e;
|
|
|
|
|
color: #d4d4d4;
|
|
|
|
|
font-family: 'Consolas', 'Monaco', monospace;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
user-select: text;
|
|
|
|
|
cursor: text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.log-line {
|
|
|
|
|
padding: 2px 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.log-time {
|
|
|
|
|
color: #6a9955;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.log-info .log-message {
|
|
|
|
|
color: #d4d4d4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.log-warning .log-message {
|
|
|
|
|
color: #dcdcaa;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.log-error .log-message {
|
|
|
|
|
color: #f48771;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.log-debug .log-message {
|
|
|
|
|
color: #9cdcfe;
|
|
|
|
|
}
|
2026-03-02 21:13:26 +08:00
|
|
|
|
|
|
|
|
.log-empty {
|
|
|
|
|
color: #666;
|
|
|
|
|
font-style: italic;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
}
|
2026-03-02 21:02:58 +08:00
|
|
|
</style>
|