perf: 日志查看自动滚动到底部

pull/244/head^2^2
xiaojunnuo 2024-11-15 14:32:22 +08:00
parent e9f18b79ea
commit 4a2f7ebf87
1 changed files with 27 additions and 2 deletions

View File

@ -8,7 +8,7 @@
<pi-status-show :status="item.node.status?.result" type="icon"></pi-status-show>
</div>
</template>
<div class="pi-task-view-logs" style="overflow: auto">
<div class="pi-task-view-logs" :class="item.node.id" style="overflow: auto">
<template v-for="(logItem, index) of item.logs" :key="index">
<span :class="logItem.color"> {{ logItem.time }}</span> <span>{{ logItem.content }}</span>
</template>
@ -19,7 +19,7 @@
</template>
<script lang="ts">
import { computed, inject, Ref, ref } from "vue";
import { computed, inject, nextTick, Ref, ref, watch } from "vue";
import { RunHistory } from "../../type";
import PiStatusShow from "/@/views/certd/pipeline/pipeline/component/status-show.vue";
@ -61,6 +61,7 @@ export default {
if (currentHistory?.value?.logs != null) {
node.logs = computed(() => {
if (currentHistory?.value?.logs && currentHistory.value?.logs[node.node.id] != null) {
console.log("log changed", node.node.id);
const logs = currentHistory.value?.logs[node.node.id];
const list = [];
for (let log of logs) {
@ -78,6 +79,30 @@ export default {
}
return [];
});
watch(
() => {
return node.logs.value.length;
},
async () => {
let el = document.querySelector(`.pi-task-view-logs.${node.node.id}`);
console.log("el", el);
//
const isBottom = el ? el.scrollHeight - el.scrollTop === el.clientHeight : true;
await nextTick();
el = document.querySelector(`.pi-task-view-logs.${node.node.id}`);
//
if (isBottom && el) {
el?.scrollTo({
top: el.scrollHeight,
behavior: "smooth"
});
}
},
{
immediate: true
}
);
}
}