add frontend

This commit is contained in:
voltsrage
2026-06-19 17:42:09 +08:00
parent 49973271e5
commit 5f69ce1a95
53 changed files with 6591 additions and 0 deletions
@@ -0,0 +1,8 @@
import { useSettingsStore } from '@/stores/settings'
import { storeToRefs } from 'pinia'
export function useDarkMode() {
const settings = useSettingsStore()
const { darkMode } = storeToRefs(settings)
return { darkMode, toggle: settings.toggleDarkMode }
}
@@ -0,0 +1,35 @@
import { ref, onMounted, onBeforeUnmount } from 'vue'
export function usePolling(fetchFn, intervalMs = 10_000) {
const data = ref(null)
const loading = ref(false)
const error = ref(null)
let timer = null
async function poll() {
loading.value = true
try {
data.value = await fetchFn()
error.value = null
} catch (e) {
error.value = e.message
} finally {
loading.value = false
}
}
function start() {
poll()
timer = setInterval(poll, intervalMs)
}
function stop() {
if (timer) clearInterval(timer)
timer = null
}
onMounted(start)
onBeforeUnmount(stop)
return { data, loading, error, poll, stop }
}