diff --git a/frontend/src/components/content_value/ContentSlog.vue b/frontend/src/components/content_value/ContentSlog.vue index 7daa063..cbdaa80 100644 --- a/frontend/src/components/content_value/ContentSlog.vue +++ b/frontend/src/components/content_value/ContentSlog.vue @@ -6,6 +6,8 @@ import { useI18n } from 'vue-i18n' import { useThemeVars } from 'naive-ui' import dayjs from 'dayjs' import useBrowserStore from 'stores/browser.js' +import { timeout } from '@/utils/promise.js' +import AutoRefreshForm from '@/components/common/AutoRefreshForm.vue' const themeVars = useThemeVars() @@ -21,12 +23,16 @@ const props = defineProps({ }, }) +const autoRefresh = reactive({ + on: false, + interval: 5, +}) + const data = reactive({ list: [], sortOrder: 'descend', listLimit: 20, loading: false, - autoLoading: false, client: '', keyword: '', }) @@ -133,19 +139,37 @@ const _loadSlowLog = () => { } const loadSlowLog = debounce(_loadSlowLog, 1000, { leading: true, trailing: true }) -let intervalID -onMounted(() => { - loadSlowLog() - intervalID = setInterval(() => { - if (data.autoLoading === true) { - loadSlowLog() +const startAutoRefresh = async () => { + let lastExec = Date.now() + do { + if (!autoRefresh.on) { + break } - }, 5000) -}) + await timeout(100) + if (data.loading || Date.now() - lastExec < autoRefresh.interval * 1000) { + continue + } + lastExec = Date.now() + loadSlowLog() + } while (true) + stopAutoRefresh() +} -onUnmounted(() => { - clearInterval(intervalID) -}) +const stopAutoRefresh = () => { + autoRefresh.on = false +} + +onMounted(() => loadSlowLog()) + +onUnmounted(() => stopAutoRefresh()) + +const onToggleRefresh = (on) => { + if (on) { + startAutoRefresh() + } else { + stopAutoRefresh() + } +} const onListLimitChanged = (limit) => { loadSlowLog() @@ -162,23 +186,28 @@ const onListLimitChanged = (limit) => { style="width: 120px" @update:value="onListLimitChanged" /> - - + + - - {{ $t('slog.refresh') }} + - - - - + +