feat: add LogsView component for displaying logs

- Introduced a new LogsView.vue component to present logs in a structured format.
- Implemented functionality to scroll to the bottom of the logs view for better user experience.
- Enhanced log processing to trim and format log entries for clarity.
This commit is contained in:
Marvin Zhang
2025-04-16 11:05:00 +08:00
parent 21df22fe24
commit 4e6b00c1b1
2 changed files with 47 additions and 1 deletions

1
.gitignore vendored
View File

@@ -2,7 +2,6 @@
.vscode/ .vscode/
.DS_Store .DS_Store
node_modules/ node_modules/
logs/
tmp/ tmp/
_book/ _book/
*.lock *.lock

View File

@@ -0,0 +1,47 @@
<script setup lang="ts">
import { ref, computed } from 'vue';
const props = defineProps<{
logs?: string[];
}>();
const content = computed(() => {
const { logs } = props;
const data: string[] = [];
logs?.forEach(l => {
l.trim()
.split(/[\n\r]/)
.map(line => {
data.push(line.trim());
});
});
return data.join('\n');
});
const logsViewRef = ref<HTMLDivElement>();
const scrollToBottom = () => {
logsViewRef.value?.scrollTo(0, logsViewRef.value?.scrollHeight);
};
defineExpose({
scrollToBottom,
});
defineOptions({ name: 'ClLogsView' });
</script>
<template>
<div class="logs-view" ref="logsViewRef">
<pre>{{ content }}</pre>
</div>
</template>
<style scoped>
.logs-view {
border: 1px solid rgb(244, 244, 245);
padding: 10px;
overflow: auto;
min-height: 480px;
max-height: 560px;
}
</style>