fix: refine polling and settings layout

This commit is contained in:
2026-04-26 11:28:45 +08:00
parent 79047b5488
commit 85f24f8a84
3 changed files with 130 additions and 20 deletions
+66 -2
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from "vue";
import { computed, onBeforeUnmount, onMounted, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import apiClient, { getApiErrorMessage } from "@/api/client";
import { useViewport } from "@/composables/useViewport";
@@ -13,6 +13,7 @@ import {
} from "@/types";
const inheritValue = "__inherit__";
const AUTO_REFRESH_INTERVAL_MS = 15000;
const loading = ref(false);
const submitLoading = ref(false);
@@ -98,6 +99,7 @@ const importDialogWidth = computed(() => (isMobile.value ? "min(100vw - 24px, 72
const recordDialogWidth = computed(() => (isMobile.value ? "min(100vw - 24px, 440px)" : "440px"));
const settingsDialogWidth = computed(() => (isMobile.value ? "min(100vw - 24px, 720px)" : "720px"));
const deleteDialogWidth = computed(() => (isMobile.value ? "min(100vw - 24px, 560px)" : "clamp(480px, 46vw, 560px)"));
let autoRefreshTimer: number | null = null;
async function loadRooms() {
loading.value = true;
@@ -113,6 +115,59 @@ async function loadRooms() {
}
}
function shouldAutoRefreshRooms() {
return !document.hidden &&
!loading.value &&
!createDialogVisible.value &&
!importDialogVisible.value &&
!recordDialogVisible.value &&
!settingsDialogVisible.value &&
!deleteDialogVisible.value &&
selectedRooms.value.length === 0 &&
!submitLoading.value &&
!importLoading.value &&
!exportLoading.value &&
!batchActionLoading.value &&
!startLoading.value &&
!settingsLoading.value &&
!deletingRoom.value &&
!togglingRoomId.value;
}
async function autoRefreshRooms() {
if (!shouldAutoRefreshRooms()) {
return;
}
try {
const { data } = await apiClient.get<LiveRoom[]>("/live-rooms");
rooms.value = data;
loadError.value = "";
} catch {
// Keep the current view stable; the background poller will try again.
}
}
function startAutoRefresh() {
stopAutoRefresh();
autoRefreshTimer = window.setInterval(() => {
void autoRefreshRooms();
}, AUTO_REFRESH_INTERVAL_MS);
}
function stopAutoRefresh() {
if (autoRefreshTimer !== null) {
window.clearInterval(autoRefreshTimer);
autoRefreshTimer = null;
}
}
function handleVisibilityChange() {
if (!document.hidden) {
void autoRefreshRooms();
}
}
function openCreateDialog() {
createDialogVisible.value = true;
}
@@ -469,7 +524,16 @@ function nullableStringFromSelect(value: string | number) {
return value === inheritValue ? null : String(value);
}
onMounted(loadRooms);
onMounted(async () => {
await loadRooms();
startAutoRefresh();
document.addEventListener("visibilitychange", handleVisibilityChange);
});
onBeforeUnmount(() => {
stopAutoRefresh();
document.removeEventListener("visibilitychange", handleVisibilityChange);
});
</script>
<template>
+15 -9
View File
@@ -1094,19 +1094,27 @@ onMounted(loadSettings);
.settings-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(320px, 0.92fr);
grid-template-columns: minmax(0, 1fr);
align-items: start;
gap: 20px;
gap: 18px;
}
.settings-grid__full {
grid-column: 1 / -1;
grid-column: auto;
}
.settings-card :deep(.el-card__body) {
padding-top: 20px;
}
.settings-card :deep(.el-form) {
max-width: 1120px;
}
.settings-card :deep(.el-input-number) {
width: 100%;
}
.helper-panel {
margin-top: 14px;
padding: 14px 16px;
@@ -1359,12 +1367,6 @@ onMounted(loadSettings);
line-height: 1.7;
}
@media (max-width: 1100px) {
.settings-grid {
grid-template-columns: 1fr;
}
}
@media (max-width: 960px) {
.event-script-grid {
grid-template-columns: 1fr;
@@ -1391,6 +1393,10 @@ onMounted(loadSettings);
max-width: 100%;
}
.settings-card :deep(.el-form) {
max-width: none;
}
.event-script-example__row {
grid-template-columns: 1fr;
gap: 4px;