mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-17 03:04:46 +08:00
fix: 解决日志审计-网站日志不显示的问题 (#2520)
This commit is contained in:
parent
5d9e5baec1
commit
8dfb4854a8
@ -65,7 +65,7 @@
|
|||||||
theme="cobalt"
|
theme="cobalt"
|
||||||
:styleActiveLine="true"
|
:styleActiveLine="true"
|
||||||
:extensions="extensions"
|
:extensions="extensions"
|
||||||
v-model="data.content"
|
v-model="content"
|
||||||
:disabled="true"
|
:disabled="true"
|
||||||
@ready="handleReady"
|
@ready="handleReady"
|
||||||
/>
|
/>
|
||||||
@ -90,11 +90,6 @@ const extensions = [javascript(), oneDark];
|
|||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const websites = ref();
|
const websites = ref();
|
||||||
const logReq = reactive({
|
|
||||||
id: undefined,
|
|
||||||
operate: 'get',
|
|
||||||
logType: 'access.log',
|
|
||||||
});
|
|
||||||
const data = ref({
|
const data = ref({
|
||||||
enable: false,
|
enable: false,
|
||||||
content: '',
|
content: '',
|
||||||
@ -103,6 +98,19 @@ const confirmDialogRef = ref();
|
|||||||
const tailLog = ref(false);
|
const tailLog = ref(false);
|
||||||
let timer: NodeJS.Timer | null = null;
|
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 () => {
|
const getWebsites = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
await ListWebsites()
|
await ListWebsites()
|
||||||
@ -111,6 +119,17 @@ const getWebsites = async () => {
|
|||||||
if (websites.value.length > 0) {
|
if (websites.value.length > 0) {
|
||||||
logReq.id = websites.value[0].id;
|
logReq.id = websites.value[0].id;
|
||||||
search();
|
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(() => {
|
.finally(() => {
|
||||||
@ -121,6 +140,7 @@ const getWebsites = async () => {
|
|||||||
const view = shallowRef();
|
const view = shallowRef();
|
||||||
const handleReady = (payload) => {
|
const handleReady = (payload) => {
|
||||||
view.value = payload.view;
|
view.value = payload.view;
|
||||||
|
editorContainer.value = payload.container;
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeType = (type: string) => {
|
const changeType = (type: string) => {
|
||||||
@ -131,21 +151,34 @@ const changeType = (type: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const search = () => {
|
const search = () => {
|
||||||
loading.value = true;
|
if (!end.value) {
|
||||||
OpWebsiteLog(logReq)
|
logReq.page += 1;
|
||||||
.then((res) => {
|
}
|
||||||
data.value = res.data;
|
OpWebsiteLog(logReq).then((res) => {
|
||||||
nextTick(() => {
|
if (!end.value && res.data.end) {
|
||||||
const state = view.value.state;
|
lastContent.value = content.value;
|
||||||
view.value.dispatch({
|
}
|
||||||
selection: { anchor: state.doc.length, head: state.doc.length },
|
data.value = res.data;
|
||||||
scrollIntoView: true,
|
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 },
|
||||||
});
|
});
|
||||||
})
|
view.value.focus();
|
||||||
.finally(() => {
|
|
||||||
loading.value = false;
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClean = async () => {
|
const onClean = async () => {
|
||||||
@ -195,9 +228,12 @@ const onSubmitClean = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isScrolledToBottom(element: HTMLElement): boolean {
|
||||||
|
return element.scrollTop + element.clientHeight === element.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
logReq.logType = 'access.log';
|
logReq.logType = 'access.log';
|
||||||
getWebsites();
|
getWebsites();
|
||||||
console.log(logReq.logType);
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -174,7 +174,6 @@ const getDirConfig = async () => {
|
|||||||
const res = await GetDirConfig({ id: props.id });
|
const res = await GetDirConfig({ id: props.id });
|
||||||
dirs.value = res.data.dirs;
|
dirs.value = res.data.dirs;
|
||||||
dirConfig.value = res.data;
|
dirConfig.value = res.data;
|
||||||
console.log(res);
|
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user