1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 00:09:16 +08:00

fix: 解决日志审计-网站日志不显示的问题 (#2520)

This commit is contained in:
zhengkunwang 2023-10-11 22:46:31 -05:00 committed by GitHub
parent 5d9e5baec1
commit 8dfb4854a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 21 deletions

View File

@ -65,7 +65,7 @@
theme="cobalt"
:styleActiveLine="true"
:extensions="extensions"
v-model="data.content"
v-model="content"
:disabled="true"
@ready="handleReady"
/>
@ -90,11 +90,6 @@ const extensions = [javascript(), oneDark];
const loading = ref(false);
const websites = ref();
const logReq = reactive({
id: undefined,
operate: 'get',
logType: 'access.log',
});
const data = ref({
enable: false,
content: '',
@ -103,6 +98,19 @@ const confirmDialogRef = ref();
const tailLog = ref(false);
let timer: NodeJS.Timer | null = null;
const content = ref('');
const end = ref(false);
const lastContent = ref('');
const editorContainer = ref<HTMLDivElement | null>(null);
const logReq = reactive({
id: undefined,
operate: 'get',
logType: 'access.log',
page: 0,
pageSize: 500,
});
const getWebsites = async () => {
loading.value = true;
await ListWebsites()
@ -111,6 +119,17 @@ const getWebsites = async () => {
if (websites.value.length > 0) {
logReq.id = websites.value[0].id;
search();
nextTick(() => {
let editorElement = editorContainer.value.querySelector('.cm-editor');
let scrollerElement = editorElement.querySelector('.cm-scroller') as HTMLElement;
if (scrollerElement) {
scrollerElement.addEventListener('scroll', function () {
if (isScrolledToBottom(scrollerElement)) {
search();
}
});
}
});
}
})
.finally(() => {
@ -121,6 +140,7 @@ const getWebsites = async () => {
const view = shallowRef();
const handleReady = (payload) => {
view.value = payload.view;
editorContainer.value = payload.container;
};
const changeType = (type: string) => {
@ -131,21 +151,34 @@ const changeType = (type: string) => {
};
const search = () => {
loading.value = true;
OpWebsiteLog(logReq)
.then((res) => {
data.value = res.data;
nextTick(() => {
const state = view.value.state;
view.value.dispatch({
selection: { anchor: state.doc.length, head: state.doc.length },
scrollIntoView: true,
});
if (!end.value) {
logReq.page += 1;
}
OpWebsiteLog(logReq).then((res) => {
if (!end.value && res.data.end) {
lastContent.value = content.value;
}
data.value = res.data;
if (res.data.content != '') {
if (end.value) {
content.value = lastContent.value + '\n' + res.data.content;
} else {
if (content.value == '') {
content.value = res.data.content;
} else {
content.value = content.value + '\n' + res.data.content;
}
}
}
end.value = res.data.end;
nextTick(() => {
const state = view.value.state;
view.value.dispatch({
selection: { anchor: state.doc.length, head: state.doc.length },
});
})
.finally(() => {
loading.value = false;
view.value.focus();
});
});
};
const onClean = async () => {
@ -195,9 +228,12 @@ const onSubmitClean = async () => {
});
};
function isScrolledToBottom(element: HTMLElement): boolean {
return element.scrollTop + element.clientHeight === element.scrollHeight;
}
onMounted(() => {
logReq.logType = 'access.log';
getWebsites();
console.log(logReq.logType);
});
</script>

View File

@ -174,7 +174,6 @@ const getDirConfig = async () => {
const res = await GetDirConfig({ id: props.id });
dirs.value = res.data.dirs;
dirConfig.value = res.data;
console.log(res);
} catch (error) {}
};