diff --git a/frontend/src/components/MailBox.vue b/frontend/src/components/MailBox.vue index 125f47f98..4e3be74ee 100644 --- a/frontend/src/components/MailBox.vue +++ b/frontend/src/components/MailBox.vue @@ -50,11 +50,10 @@ const props = defineProps({ }) const { - isDark, mailboxSplitSize, indexTab, loading, useUTCDate, + isDark, mailboxSplitSize, indexTab, loading, useUTCDate, autoRefresh, configAutoRefreshInterval, useIframeShowMail, sendMailModel, preferShowTextMail } = useGlobalState() -const autoRefresh = ref(false) -const autoRefreshInterval = ref(30) +const autoRefreshInterval = ref(configAutoRefreshInterval.value) const data = ref([]) const timer = ref(null) @@ -119,14 +118,16 @@ const { t } = useI18n({ }); const setupAutoRefresh = async (autoRefresh) => { - // auto refresh every 30 seconds - autoRefreshInterval.value = 30; + // auto refresh every configAutoRefreshInterval seconds + autoRefreshInterval.value = configAutoRefreshInterval.value; if (autoRefresh) { + clearInterval(timer.value); timer.value = setInterval(async () => { + if (loading.value) return; autoRefreshInterval.value--; if (autoRefreshInterval.value <= 0) { - autoRefreshInterval.value = 30; - await refresh(); + autoRefreshInterval.value = configAutoRefreshInterval.value; + await backFirstPageAndRefresh(); } }, 1000) } else { @@ -137,7 +138,7 @@ const setupAutoRefresh = async (autoRefresh) => { watch(autoRefresh, async (autoRefresh, old) => { setupAutoRefresh(autoRefresh) -}) +}, { immediate: true }) watch([page, pageSize], async ([page, pageSize], [oldPage, oldPageSize]) => { if (page !== oldPage || pageSize !== oldPageSize) { @@ -170,6 +171,11 @@ const refresh = async () => { } }; +const backFirstPageAndRefresh = async () =>{ + page.value = 1; + await refresh(); +} + const clickRow = async (row) => { if (multiActionMode.value) { row.checked = !row.checked; @@ -366,7 +372,7 @@ onBeforeUnmount(() => { {{ t('autoRefresh') }} - + {{ t('refresh') }} @@ -476,7 +482,7 @@ onBeforeUnmount(() => { {{ t('autoRefresh') }} - + {{ t('refresh') }} diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 4f229a488..b28f562d1 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -72,6 +72,8 @@ export const useGlobalState = createGlobalState( const globalTabplacement = useStorage('globalTabplacement', 'top'); const useSideMargin = useStorage('useSideMargin', true); const useUTCDate = useStorage('useUTCDate', false); + const autoRefresh = useStorage('autoRefresh', false); + const configAutoRefreshInterval = useStorage("configAutoRefreshInterval", 60); const userOpenSettings = ref({ fetched: false, enable: false, @@ -130,6 +132,8 @@ export const useGlobalState = createGlobalState( globalTabplacement, useSideMargin, useUTCDate, + autoRefresh, + configAutoRefreshInterval, telegramApp, isTelegram, showAdminPage, diff --git a/frontend/src/views/common/Appearance.vue b/frontend/src/views/common/Appearance.vue index 3395194df..ce5c990e2 100644 --- a/frontend/src/views/common/Appearance.vue +++ b/frontend/src/views/common/Appearance.vue @@ -5,7 +5,7 @@ import { useIsMobile } from '../../utils/composables' import { useGlobalState } from '../../store' const { - mailboxSplitSize, useIframeShowMail, preferShowTextMail, + mailboxSplitSize, useIframeShowMail, preferShowTextMail, configAutoRefreshInterval, globalTabplacement, useSideMargin, useUTCDate } = useGlobalState() const isMobile = useIsMobile() @@ -23,6 +23,7 @@ const { t } = useI18n({ right: 'right', bottom: 'bottom', useUTCDate: 'Use UTC Date', + autoRefreshInterval: 'Auto Refresh Interval(Sec)', }, zh: { mailboxSplitSize: '邮箱界面分栏大小', @@ -35,6 +36,7 @@ const { t } = useI18n({ right: '右侧', bottom: '底部', useUTCDate: '使用 UTC 时间', + autoRefreshInterval: '自动刷新间隔(秒)', } } }); @@ -50,6 +52,11 @@ const { t } = useI18n({ 0.75: '0.75' }" /> + + +