更新前端ui

This commit is contained in:
2025-12-16 00:04:02 +08:00
parent ec2f3a29cd
commit 548ea34238
2 changed files with 71 additions and 31 deletions

View File

@@ -42,7 +42,12 @@
<div class="header">
<h2 style="margin:0; color: #333;">📈 量化策略控制台</h2>
<n-space align="center">
<!-- 1. 刷新频率选择器 -->
<!-- [核心修改] 1. 显示 Git 版本信息 -->
<n-tag :bordered="false" type="default" size="small">
📦 Version: {{ gitInfo }}
</n-tag>
<!-- 刷新频率选择器 -->
<n-select
v-model:value="refreshInterval"
:options="intervalOptions"
@@ -50,7 +55,7 @@
style="width: 130px"
></n-select>
<!-- 2. 手动刷新按钮 -->
<!-- 手动刷新按钮 -->
<n-button type="primary" size="small" @click="fetchStatus" :loading="loading">
刷新状态
</n-button>
@@ -120,18 +125,18 @@
const loading = ref(false);
const lastUpdated = ref('-');
// --- 修改点:默认值为 0 (仅手动) ---
const refreshInterval = ref(0);
// [核心修改] 2. 为 Git 信息创建一个 ref
const gitInfo = ref('Loading...');
const refreshInterval = ref(0);
const intervalOptions = [
{ label: '✋ 仅手动', value: 0 }, // 建议将手动选项放在第一个
{ label: '✋ 仅手动', value: 0 },
{ label: '⚡ 3秒自动', value: 3000 },
{ label: '⏱ 5秒自动', value: 5000 },
{ label: '🐢 10秒自动', value: 10000 }
];
let timer = null;
// --- 核心数据获取 ---
const fetchStatus = async () => {
if (loading.value) return;
loading.value = true;
@@ -140,6 +145,10 @@
if (!res.ok) throw new Error("Error");
const data = await res.json();
strategies.value = data.strategies;
// [核心修改] 3. 更新 Git 信息
gitInfo.value = data.git_info || 'N/A';
lastUpdated.value = new Date().toLocaleTimeString();
} catch (e) {
message.error("连接服务器失败");
@@ -148,16 +157,13 @@
}
};
// --- 定时器管理 ---
const resetTimer = () => {
if (timer) clearInterval(timer);
// 只有大于 0 才启动定时器
if (refreshInterval.value > 0) {
timer = setInterval(fetchStatus, refreshInterval.value);
}
};
// 监听下拉框变化
watch(refreshInterval, () => {
resetTimer();
if (refreshInterval.value > 0) {
@@ -168,7 +174,6 @@
}
});
// --- 其他逻辑 ---
const handleAction = (name, action) => {
const map = { start: '启动', stop: '停止', restart: '重启' };
dialog.warning({
@@ -216,8 +221,8 @@
};
onMounted(() => {
fetchStatus(); // 页面加载时请求一次
resetTimer(); // 初始化定时器当前为0所以不启动
fetchStatus();
resetTimer();
});
onUnmounted(() => {
@@ -226,6 +231,7 @@
return {
strategies, loading, lastUpdated,
gitInfo, // [核心修改] 4. 将 gitInfo 暴露给模板
refreshInterval, intervalOptions,
showLogModal, currentLogKey, logLines, logLoading,
fetchStatus, handleAction, viewLogs, fetchLogs