CMVR-BID/src/views/inspection/runTask/task-log.vue

73 lines
1.6 KiB
Vue
Raw Normal View History

2026-06-05 16:53:40 +08:00
<template>
2026-06-05 17:18:47 +08:00
<div class="log-container" :style="{ 'height': height + 'px' }" ref="messageContainer">
2026-06-05 16:53:40 +08:00
<div class="log" v-for="log, index in list">
<div class="time">{{ formatDate(log.logTime) }}</div>
<div class="context">{{ log.logContent }}</div>
</div>
</div>
</template>
<script setup>
import { formatDate } from "@/utils/index";
import { watch } from "vue";
const props = defineProps({
list: {
type: Array,
default: () => []
2026-06-05 17:18:47 +08:00
},
height: {
type: Number,
default: 150
2026-06-05 16:53:40 +08:00
}
})
const messageContainer = ref(null)
const SCROLL_DELAY = 100
const scrollToBottom = () => {
console.log(123, messageContainer.value)
nextTick(() => {
setTimeout(() => {
if (messageContainer.value) {
console.log('messageContainer.value.scrollHeight', messageContainer.value.scrollHeight)
messageContainer.value.scrollTop = messageContainer.value.scrollHeight
}
}, SCROLL_DELAY)
})
}
watch(() => props.list, () => {
scrollToBottom()
}, { deep: true })
onMounted(() => {
scrollToBottom()
})
</script>
<style lang="scss" scoped>
.log-container {
margin-top: 12px;
overflow-y: auto;
background: #fff;
border: 1px solid #eee;
border-radius: 8px;
padding: 12px;
.log {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 8px;
.time {
color: #999;
font-size: 14px;
}
.context {
color: #333;
font-size: 14px;
}
}
}
</style>