96 lines
2.4 KiB
Vue
96 lines
2.4 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, onUnmounted, ref } from 'vue'
|
|
import { useTheme } from '@/composables/useTheme'
|
|
import { useProducts } from '@/composables/useProducts'
|
|
import { useAccounts } from '@/composables/useAccounts'
|
|
import { useScheduler } from '@/composables/useScheduler'
|
|
import { useLogs } from '@/composables/useLogs'
|
|
import { useActivity } from '@/composables/useActivity'
|
|
import AppShell from '@/components/layout/AppShell.vue'
|
|
import ToastContainer from '@/components/ToastContainer.vue'
|
|
import { GetTime, GetVersion } from '@wails/go/app/App'
|
|
|
|
const { initTheme } = useTheme()
|
|
const { loadProducts, restoreSelection: restoreProductSelection } = useProducts()
|
|
const { loadAccounts, restoreSelection: restoreAccountSelection } = useAccounts()
|
|
const { clearLogs, fetchServerLogs, checkResults } = useLogs()
|
|
const { restoreSchedule, setRunState } = useScheduler()
|
|
const { clearResults } = useLogs()
|
|
const { loadActivities } = useActivity()
|
|
|
|
const version = ref('')
|
|
const serverTime = ref('--')
|
|
|
|
// 轮询定时器
|
|
let timeTimer: number | null = null
|
|
let logTimer: number | null = null
|
|
let resultTimer: number | null = null
|
|
|
|
const updateTime = async () => {
|
|
try {
|
|
const d = await GetTime()
|
|
serverTime.value = d.serverTime || '--'
|
|
} catch {}
|
|
}
|
|
|
|
const startPolling = () => {
|
|
// 时间更新 - 每秒
|
|
timeTimer = window.setInterval(updateTime, 1000)
|
|
// 日志拉取 - 每2秒
|
|
logTimer = window.setInterval(fetchServerLogs, 2000)
|
|
// 结果检查 - 每2秒
|
|
resultTimer = window.setInterval(checkResults, 2000)
|
|
}
|
|
|
|
const stopPolling = () => {
|
|
if (timeTimer) clearInterval(timeTimer)
|
|
if (logTimer) clearInterval(logTimer)
|
|
if (resultTimer) clearInterval(resultTimer)
|
|
}
|
|
|
|
onMounted(async () => {
|
|
// 初始化主题
|
|
initTheme()
|
|
|
|
// 恢复本地缓存
|
|
restoreProductSelection()
|
|
restoreAccountSelection()
|
|
|
|
// 清空日志
|
|
clearLogs()
|
|
setRunState('等待操作')
|
|
|
|
// 加载数据
|
|
await loadAccounts()
|
|
await loadActivities()
|
|
await loadProducts(false)
|
|
|
|
// 获取版本号
|
|
try {
|
|
version.value = await GetVersion()
|
|
} catch {}
|
|
|
|
// 清空后端旧结果
|
|
await clearResults()
|
|
|
|
// 开始轮询
|
|
updateTime()
|
|
startPolling()
|
|
fetchServerLogs()
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
stopPolling()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<AppShell :version="version" :server-time="serverTime" />
|
|
<ToastContainer />
|
|
</template>
|
|
|
|
<style>
|
|
@import '@/styles/variables.css';
|
|
@import '@/styles/common.css';
|
|
</style>
|