Skip to content

Commit

Permalink
perf: 浏览器失去焦点停止查询、节省开销 (#1256)
Browse files Browse the repository at this point in the history
  • Loading branch information
nightzjp authored Jun 5, 2023
1 parent 75fa498 commit 5e3e580
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions frontend/src/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const isSafety = ref();
const chartOption = ref('network');
let timer: NodeJS.Timer | null = null;
let isInit = ref<boolean>(true);
let isActive = ref(true);
const ioReadBytes = ref<Array<number>>([]);
const ioWriteBytes = ref<Array<number>>([]);
Expand Down Expand Up @@ -353,12 +354,14 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
const res = await loadBaseInfo(searchInfo.ioOption, searchInfo.netOption);
baseInfo.value = res.data;
currentInfo.value = baseInfo.value.currentInfo;
onLoadCurrentInfo();
await onLoadCurrentInfo();
statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
appRef.value.acceptParams();
if (isInit) {
timer = setInterval(async () => {
onLoadCurrentInfo();
if (isActive.value) {
await onLoadCurrentInfo();
}
}, 3000);
}
};
Expand Down Expand Up @@ -511,6 +514,12 @@ const loadSafeStatus = async () => {
};
onMounted(() => {
window.addEventListener('focus', () => {
isActive.value = true;
});
window.addEventListener('blur', () => {
isActive.value = false;
});
loadSafeStatus();
loadUpgradeStatus();
onLoadNetworkOptions();
Expand Down

0 comments on commit 5e3e580

Please sign in to comment.