优化前端
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<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 AppShell from '@/components/layout/AppShell.vue'
|
||||
import ToastContainer from '@/components/ToastContainer.vue'
|
||||
|
||||
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 version = ref('')
|
||||
const serverTime = ref('--')
|
||||
|
||||
// 轮询定时器
|
||||
let timeTimer: number | null = null
|
||||
let logTimer: number | null = null
|
||||
let resultTimer: number | null = null
|
||||
|
||||
const App = window.go.main.App
|
||||
|
||||
const updateTime = async () => {
|
||||
try {
|
||||
const d = await App.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 loadProducts(false)
|
||||
|
||||
// 获取版本号
|
||||
try {
|
||||
version.value = await App.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>
|
||||
Reference in New Issue
Block a user