218 lines
6.2 KiB
Vue
218 lines
6.2 KiB
Vue
<template>
|
||
<div class="log-wrap">
|
||
<div class="log-head">
|
||
<div class="log-title">
|
||
<i v-if="!isStatic" class="status" :class="store.wsOn ? 'on' : 'off'" :title="store.wsOn ? '实时连接正常' : '连接已中断'"></i>
|
||
<span>{{ isStatic ? '历史回看' : '运行日志' }}</span>
|
||
<RunIndicator v-if="store.running && !isStatic" variant="tag" label="LIVE" />
|
||
<span v-else-if="visibleLogs.length" class="count">{{ visibleLogs.length }} 条</span>
|
||
</div>
|
||
|
||
<div class="log-tools">
|
||
<el-radio-group v-model="level" size="small">
|
||
<el-radio-button v-for="l in LEVELS" :key="l" :value="l">{{ l }}</el-radio-button>
|
||
</el-radio-group>
|
||
<el-button size="small" :icon="CopyDocument" circle title="复制日志" :disabled="!visibleLogs.length"
|
||
@click="copy" />
|
||
<el-button size="small" :icon="pause ? VideoPlay : VideoPause" circle :title="pause ? '继续滚动' : '暂停滚动'"
|
||
@click="pause = !pause" />
|
||
<el-button v-if="!isStatic" size="small" plain :disabled="!store.logs.length" @click="confirmClear">清空</el-button>
|
||
</div>
|
||
</div>
|
||
<div ref="box" class="log-box">
|
||
<div v-if="!visibleLogs.length" class="log-empty">
|
||
<template v-if="isStatic">
|
||
<b>该次运行没有日志记录</b><span>可能是执行过快,或插件没有输出日志</span>
|
||
</template>
|
||
<template v-else-if="store.logs.length">
|
||
<b>当前级别无日志</b><span>切换到「全部」可以看完整输出</span>
|
||
</template>
|
||
<template v-else>
|
||
<b>暂无日志</b><span>点击「一键执行」后,输出会实时滚动到这里</span>
|
||
</template>
|
||
</div>
|
||
<div v-for="(l, i) in visibleLogs" :key="i" class="log-line">
|
||
<span class="t">{{ l.time || l.t || '' }}</span>
|
||
<span class="lv" :class="'s-' + (l.level || 'INFO')">[{{ l.level || 'INFO' }}]</span>
|
||
<span>{{ l.msg }}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { nextTick, ref, watch, computed } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { CopyDocument, VideoPause, VideoPlay } from '@element-plus/icons-vue'
|
||
import { store, clearLogs } from '../store'
|
||
import RunIndicator from './RunIndicator.vue'
|
||
|
||
const props = defineProps({
|
||
// 历史回看模式:传入后显示该次运行的静态日志(替代 store.logs),并隐藏清空/LIVE
|
||
staticLogs: { type: Array, default: null },
|
||
})
|
||
|
||
const isStatic = computed(() => Array.isArray(props.staticLogs))
|
||
|
||
const LEVELS = ['全部', 'INFO', 'WARN', 'ERROR']
|
||
const level = ref('全部')
|
||
const pause = ref(false)
|
||
const box = ref(null)
|
||
|
||
const visibleLogs = computed(() => {
|
||
const src = isStatic.value ? props.staticLogs : store.logs
|
||
if (level.value === '全部') return src
|
||
return src.filter((l) => l.level === level.value)
|
||
})
|
||
|
||
// 日志变化或过滤切换时,若未暂停则自动滚到最新
|
||
watch(
|
||
[() => store.logs.length, () => props.staticLogs?.length, level],
|
||
async () => {
|
||
if (pause.value) return
|
||
await nextTick()
|
||
if (box.value) box.value.scrollTop = box.value.scrollHeight
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
|
||
function confirmClear() {
|
||
ElMessageBox.confirm('确认清空全部运行日志?', '清空日志', {
|
||
confirmButtonText: '清空',
|
||
cancelButtonText: '取消',
|
||
type: 'warning',
|
||
})
|
||
.then(() => { clearLogs(); ElMessage.success('日志已清空') })
|
||
.catch(() => { })
|
||
}
|
||
|
||
async function copy() {
|
||
const text = visibleLogs.value.map((l) => `[${l.time}] [${l.level || 'INFO'}] ${l.msg}`).join('\n')
|
||
try {
|
||
await navigator.clipboard.writeText(text)
|
||
ElMessage.success(`已复制 ${visibleLogs.value.length} 条日志`)
|
||
} catch (_) {
|
||
ElMessage.error('复制失败')
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.log-wrap {
|
||
display: flex;
|
||
flex-direction: column;
|
||
flex: 1 1 auto; /* 由父级(运行台「运行日志」标签页)给高度 */
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
position: relative;
|
||
}
|
||
|
||
/* ---------- 头部:标题 + 级别过滤 + 工具 ---------- */
|
||
.log-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: var(--space-3);
|
||
padding: 0 0 10px;
|
||
border-bottom: 1px solid var(--line-soft);
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.log-title {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--space-2);
|
||
font: 600 13px/18px var(--f-cn);
|
||
color: var(--t1);
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.status {
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.status.on {
|
||
background: var(--good);
|
||
box-shadow: 0 0 0 3px var(--good-soft);
|
||
}
|
||
|
||
.status.off {
|
||
background: var(--t5);
|
||
}
|
||
|
||
.count {
|
||
padding: 3px 8px;
|
||
border-radius: var(--r-pill);
|
||
background: var(--field);
|
||
font: 500 11px/1 var(--f-num);
|
||
color: var(--t4);
|
||
}
|
||
|
||
.log-tools {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--space-1-5);
|
||
}
|
||
|
||
.log-tools .el-button+.el-button {
|
||
margin-left: 0;
|
||
}
|
||
|
||
/* ---------- 日志区:暗色控制台(壳子 --con-* 系列) ---------- */
|
||
.log-box {
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
overflow: auto;
|
||
margin: 12px 0 0;
|
||
padding: 10px 0;
|
||
background: var(--con);
|
||
border: 1px solid var(--con-line);
|
||
border-radius: var(--r-sub);
|
||
font-family: var(--f-mono);
|
||
font-size: 11.5px;
|
||
line-height: 1.85;
|
||
color: var(--con-t1);
|
||
}
|
||
|
||
.log-box::-webkit-scrollbar-thumb { background: var(--con-bg2); border-radius: 3px; }
|
||
|
||
.log-line {
|
||
display: grid;
|
||
grid-template-columns: 64px 56px minmax(0, 1fr);
|
||
gap: 8px;
|
||
padding: 1px 14px;
|
||
border-left: 2px solid transparent;
|
||
}
|
||
|
||
.log-line:hover {
|
||
background: var(--con-bg2);
|
||
border-left-color: var(--brand);
|
||
}
|
||
|
||
.log-line .t { color: var(--con-t2); user-select: none; }
|
||
.log-line .lv { font-weight: 600; }
|
||
.log-line .s-INFO { color: var(--con-info); }
|
||
.log-line .s-WARN { color: var(--con-warn); }
|
||
.log-line .s-ERROR { color: var(--con-err); }
|
||
|
||
/* 空态:暗底居中,一句标题 + 一句说明 */
|
||
.log-empty {
|
||
height: 100%;
|
||
min-height: 88px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px;
|
||
padding: var(--space-4);
|
||
text-align: center;
|
||
font: 400 12px/18px var(--f-cn);
|
||
color: var(--con-t2);
|
||
}
|
||
|
||
.log-empty b { color: var(--con-t1); font-weight: 500; }
|
||
.log-empty span { font-size: 11.5px; }
|
||
</style> |