Skip to content

Commit c7d603e

Browse files
fix: resolve log loss in certain scenarios (#10111)
1 parent 4fcf845 commit c7d603e

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

frontend/src/components/log/file/index.vue

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,42 @@ const totalHeight = computed(() => logHeight * logCount.value);
149149
const containerHeight = ref(500);
150150
const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight));
151151
const startIndex = ref(0);
152+
const lastScrollTop = ref(0);
152153
153154
const visibleLogs = computed(() => {
154155
return logs.value.slice(startIndex.value, startIndex.value + visibleCount.value);
155156
});
156157
158+
let scrollTimer: ReturnType<typeof setTimeout> | null = null;
159+
157160
const onScroll = () => {
158-
if (logContainer.value) {
159-
const scrollTop = logContainer.value.scrollTop;
160-
if (scrollTop == 0) {
161+
if (!logContainer.value || isLoading.value) return;
162+
163+
const scrollTop = logContainer.value.scrollTop;
164+
const newStartIndex = Math.max(0, Math.floor(scrollTop / logHeight));
165+
166+
if (scrollTimer) {
167+
clearTimeout(scrollTimer);
168+
}
169+
170+
startIndex.value = newStartIndex;
171+
172+
scrollTimer = setTimeout(() => {
173+
if (scrollTop <= logHeight && minPage.value > 1) {
174+
const currentScrollTop = scrollTop;
161175
readReq.page = minPage.value - 1;
162-
if (readReq.page < 1) {
163-
return;
176+
if (readReq.page >= 1) {
177+
minPage.value = readReq.page;
178+
lastScrollTop.value = currentScrollTop;
179+
getContent(true);
164180
}
165-
minPage.value = readReq.page;
166-
getContent(true);
167181
}
168-
startIndex.value = Math.floor(scrollTop / logHeight);
169-
}
182+
183+
if (!tailLog.value && scrollTop + containerHeight.value >= totalHeight.value - logHeight && maxPage.value > 1) {
184+
readReq.page = maxPage.value;
185+
getContent(false);
186+
}
187+
}, 50);
170188
};
171189
172190
const changeLoading = () => {
@@ -276,11 +294,19 @@ const getContent = async (pre: boolean) => {
276294
}
277295
278296
nextTick(() => {
279-
if (pre) {
280-
logContainer.value.scrollTop = 2000;
281-
} else {
282-
logContainer.value.scrollTop = totalHeight.value;
283-
containerHeight.value = logContainer.value.getBoundingClientRect().height;
297+
if (logContainer.value) {
298+
if (pre) {
299+
if (!end.value) {
300+
const addedLines = newLogs.length;
301+
const newScrollPosition = lastScrollTop.value + addedLines * logHeight;
302+
logContainer.value.scrollTop = newScrollPosition;
303+
startIndex.value = Math.max(0, Math.floor(newScrollPosition / logHeight));
304+
}
305+
} else {
306+
logContainer.value.scrollTop = totalHeight.value;
307+
containerHeight.value = logContainer.value.getBoundingClientRect().height;
308+
startIndex.value = Math.max(0, logs.value.length - visibleCount.value);
309+
}
284310
}
285311
});
286312
}

frontend/src/views/cronjob/cronjob/record/index.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@
170170
:key="currentRecord?.taskID"
171171
@stop-reading="search(false)"
172172
:heightDiff="410"
173-
:config="{ type: 'task', taskID: currentRecord?.taskID, tail: true }"
173+
:config="{
174+
type: 'task',
175+
colorMode: 'task',
176+
taskID: currentRecord?.taskID,
177+
tail: true,
178+
}"
174179
/>
175180
</el-row>
176181
</el-form>

frontend/src/views/website/website/config/basic/php/composer/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const search = () => {
101101
loading.value = true;
102102
getWebsite(req.websiteID)
103103
.then((res) => {
104-
console.log(res.data);
105104
req.dir = res.data.sitePath + '/index';
106105
})
107106
.finally(() => {

0 commit comments

Comments
 (0)