Skip to content

Commit 660dc62

Browse files
fix: Standardize logging component (#8054)
1 parent 4cfc343 commit 660dc62

File tree

50 files changed

+163
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+163
-130
lines changed

frontend/src/components/backup/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ import i18n from '@/lang';
119119
import { Backup } from '@/api/interface/backup';
120120
import router from '@/routers';
121121
import { MsgSuccess } from '@/utils/message';
122-
import TaskLog from '@/components/task-log/index.vue';
122+
import TaskLog from '@/components/log/task/index.vue';
123123
import { GlobalStore } from '@/store';
124124
const globalStore = GlobalStore();
125125

frontend/src/components/log-dialog/index.vue

Lines changed: 0 additions & 40 deletions
This file was deleted.

frontend/src/components/compose-log/index.vue renamed to frontend/src/components/log/compose/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import i18n from '@/lang';
2222
import { computed, onBeforeUnmount, ref, watch } from 'vue';
2323
import { GlobalStore } from '@/store';
2424
import screenfull from 'screenfull';
25-
import ContainerLog from '@/components/container-log/index.vue';
25+
import ContainerLog from '@/components/log/container/index.vue';
2626
2727
const open = ref(false);
2828
const resource = ref('');

frontend/src/views/container/container/log/index.vue renamed to frontend/src/components/log/container-drawer/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import i18n from '@/lang';
2727
import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue';
2828
import screenfull from 'screenfull';
2929
import { GlobalStore } from '@/store';
30+
import ContainerLog from '@/components/log/container/index.vue';
3031
3132
const logVisible = ref(false);
3233
const mobile = computed(() => {

frontend/src/components/container-log/index.vue renamed to frontend/src/components/log/container/index.vue

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@
2424
{{ $t('commons.button.clean') }}
2525
</el-button>
2626
</div>
27-
<!-- <div class="log-container" ref="logContainer">
28-
<DynamicScroller :items="logs" :min-item-size="32" v-if="logs.length">
29-
<template #default="{ item, active }">
30-
<DynamicScrollerItem :item="item" :active="active" :size-dependencies="[item]" :data-index="item">
31-
<hightlight :log="item" type="container"></hightlight>
32-
</DynamicScrollerItem>
33-
</template>
34-
</DynamicScroller>
35-
</div> -->
36-
3727
<div class="log-container" ref="logContainer">
3828
<div class="log-spacer" :style="{ height: `${totalHeight}px` }"></div>
3929
<div
@@ -54,7 +44,7 @@ import { dateFormatForName } from '@/utils/util';
5444
import { onUnmounted, reactive, ref } from 'vue';
5545
import { ElMessageBox } from 'element-plus';
5646
import { MsgError, MsgSuccess } from '@/utils/message';
57-
import hightlight from '@/components/hightlight/index.vue';
47+
import hightlight from '@/components/log/custom-hightlight/index.vue';
5848
5949
const props = defineProps({
6050
container: {
@@ -79,13 +69,15 @@ const logSearch = reactive({
7969
compose: '',
8070
});
8171
const logHeight = 20;
82-
const logCount = ref(0);
72+
const logCount = computed(() => logs.value.length);
8373
const totalHeight = computed(() => logHeight * logCount.value);
8474
const startIndex = ref(0);
8575
const containerHeight = ref(500);
86-
const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight));
76+
const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight) + 2);
8777
const visibleLogs = computed(() => {
88-
return logs.value.slice(startIndex.value, startIndex.value + visibleCount.value);
78+
const start = Math.max(0, startIndex.value - 1);
79+
const end = startIndex.value + visibleCount.value + 1;
80+
return logs.value.slice(start, end);
8981
});
9082
9183
const timeOptions = ref([
@@ -185,10 +177,22 @@ const onClean = async () => {
185177
});
186178
};
187179
180+
const handleScroll = () => {
181+
if (logContainer.value) {
182+
const scrollTop = logContainer.value.scrollTop;
183+
startIndex.value = Math.max(0, Math.floor(scrollTop / logHeight) - 1);
184+
}
185+
};
186+
188187
onUnmounted(() => {
189188
handleClose();
189+
if (logContainer.value) {
190+
logContainer.value.removeEventListener('scroll', handleScroll);
191+
}
190192
});
191193
194+
const resizeObserver = ref<ResizeObserver | null>(null);
195+
192196
onMounted(() => {
193197
logSearch.container = props.container;
194198
logSearch.compose = props.compose;
@@ -200,8 +204,12 @@ onMounted(() => {
200204
201205
nextTick(() => {
202206
if (logContainer.value) {
203-
logContainer.value.scrollTop = totalHeight.value;
204-
containerHeight.value = logContainer.value.getBoundingClientRect().height;
207+
containerHeight.value = logContainer.value.clientHeight;
208+
logContainer.value.addEventListener('scroll', handleScroll);
209+
resizeObserver.value = new ResizeObserver((entries) => {
210+
containerHeight.value = entries[0].contentRect.height;
211+
});
212+
resizeObserver.value.observe(logContainer.value);
205213
}
206214
});
207215
@@ -227,7 +235,7 @@ onMounted(() => {
227235
}
228236
229237
.log-container {
230-
height: calc(100vh - 405px);
238+
height: calc(100vh - 320px);
231239
overflow-y: auto;
232240
overflow-x: auto;
233241
position: relative;
File renamed without changes.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<template>
2+
<DrawerPro
3+
v-model="open"
4+
:header="$t('commons.button.log')"
5+
@close="handleClose"
6+
:size="globalStore.isFullScreen ? 'full' : 'large'"
7+
>
8+
<template #extra v-if="!mobile">
9+
<el-tooltip :content="loadTooltip()" placement="top">
10+
<el-button @click="toggleFullscreen" class="fullScreen" icon="FullScreen" plain></el-button>
11+
</el-tooltip>
12+
</template>
13+
<template #content>
14+
<LogFile :config="config" :height-diff="props.heightDiff"></LogFile>
15+
</template>
16+
</DrawerPro>
17+
</template>
18+
<script lang="ts" setup>
19+
import { ref } from 'vue';
20+
import LogFile from '@/components/log/file/index.vue';
21+
import { GlobalStore } from '@/store';
22+
import i18n from '@/lang';
23+
import screenfull from 'screenfull';
24+
25+
const globalStore = GlobalStore();
26+
interface LogProps {
27+
id: number;
28+
type: string;
29+
name: string;
30+
tail: boolean;
31+
}
32+
33+
const props = defineProps({
34+
heightDiff: {
35+
type: Number,
36+
default: 0,
37+
},
38+
style: {
39+
type: Object,
40+
default: () => ({}),
41+
},
42+
});
43+
44+
const open = ref(false);
45+
const config = ref();
46+
const em = defineEmits(['close']);
47+
48+
const handleClose = () => {
49+
open.value = false;
50+
globalStore.isFullScreen = false;
51+
em('close', false);
52+
};
53+
54+
const mobile = computed(() => {
55+
return globalStore.isMobile();
56+
});
57+
58+
function toggleFullscreen() {
59+
globalStore.isFullScreen = !globalStore.isFullScreen;
60+
}
61+
const loadTooltip = () => {
62+
return i18n.global.t('commons.button.' + (globalStore.isFullScreen ? 'quitFullscreen' : 'fullscreen'));
63+
};
64+
65+
watch(open, (val) => {
66+
if (screenfull.isEnabled && !val && !mobile.value) screenfull.exit();
67+
});
68+
69+
const acceptParams = (logProps: LogProps) => {
70+
config.value = logProps;
71+
open.value = true;
72+
};
73+
74+
onBeforeUnmount(() => {
75+
handleClose();
76+
});
77+
78+
defineExpose({ acceptParams });
79+
</script>
80+
81+
<style lang="scss">
82+
.fullScreen {
83+
border: none;
84+
}
85+
</style>

frontend/src/components/log-file/index.vue renamed to frontend/src/components/log/file/index.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<slot name="button"></slot>
1818
</span>
1919
</div>
20-
<div class="log-container" ref="logContainer" @scroll="onScroll">
20+
<div class="log-container" ref="logContainer" @scroll="onScroll" :style="containerStyle">
2121
<div class="log-spacer" :style="{ height: `${totalHeight}px` }"></div>
2222
<div
2323
v-for="(log, index) in visibleLogs"
@@ -36,7 +36,7 @@ import { downloadFile } from '@/utils/util';
3636
import { readByLine } from '@/api/modules/files';
3737
import { GlobalStore } from '@/store';
3838
import bus from '@/global/bus';
39-
import hightlight from '@/components/hightlight/index.vue';
39+
import hightlight from '@/components/log/custom-hightlight/index.vue';
4040
const globalStore = GlobalStore();
4141
4242
interface LogProps {
@@ -79,7 +79,7 @@ const props = defineProps({
7979
},
8080
heightDiff: {
8181
type: Number,
82-
default: 500,
82+
default: 420,
8383
},
8484
showTail: {
8585
type: Boolean,
@@ -311,6 +311,10 @@ const init = async () => {
311311
await getContent(false);
312312
};
313313
314+
const containerStyle = computed(() => ({
315+
height: `calc(100vh - ${props.heightDiff}px)`,
316+
}));
317+
314318
onMounted(async () => {
315319
firstLoading.value = true;
316320
await init();
@@ -330,7 +334,6 @@ defineExpose({ changeTail, onDownload, clearLog });
330334
</script>
331335
<style lang="scss" scoped>
332336
.log-container {
333-
height: calc(100vh - 420px);
334337
overflow-y: auto;
335338
overflow-x: auto;
336339
position: relative;
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)