feat: 当天最热股票实时更新

- 后端: 交易时段(工作日9:15-15:05)/news按需重抓股票列, 60s节流; 其余4列仍每天8点
- 前端: 首页可见时每60s轮询 /relay/news, 隐藏暂停
- 非交易时段/失败不重抓, 不影响接口

测试7项+端到端66s轮询 ✓

CHANGELOG记录
This commit is contained in:
personal82555 committed 2026-10-13 22:40:22 +08:00
1 parent 56a15c02b4
commit f5862778e8
2 files changed
+21 -3

No files matched your search

+15 -3
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { IconDragDrop, IconHeart } from '@tabler/icons-vue';
import { useHead } from '@vueuse/head';
import { computed, onMounted, ref } from 'vue';
import { computed, onMounted, onUnmounted, ref } from 'vue';
import Draggable from 'vuedraggable';
import ColoredCard from '../components/ColoredCard.vue';
import ToolCard from '../components/ToolCard.vue';
@@ -43,10 +43,11 @@ onMounted(async () => {
catch { /* 无推荐则隐藏 */ }
});
// 每日 5 列资讯:GITHUB/国际新闻/AI资讯/IT最新技术/当天最热股票(relay 每天 08:00 抓取)
// 每日 5 列资讯:GITHUB/国际新闻/AI资讯/IT最新技术/当天最热股票
// 前 4 列 relay 每天 08:00 抓取;「当天最热股票」交易时段 60s 高频刷新
const newsCols = ref<any[]>([]);
const newsDate = ref('');
onMounted(async () => {
async function loadNews() {
try {
const res = await fetch('/relay/news');
const j = await res.json();
@@ -56,6 +57,17 @@ onMounted(async () => {
}
}
catch { /* 无资讯则隐藏 */ }
}
let newsTimer: ReturnType<typeof setInterval> | undefined;
onMounted(() => {
loadNews();
// 页面可见时每 60s 拉一次,拿到刷新后的股票列(非交易时段 relay 不重抓,开销可忽略)
newsTimer = setInterval(() => {
if (document.visibilityState === 'visible') loadNews();
}, 60000);
});
onUnmounted(() => {
if (newsTimer) clearInterval(newsTimer);
});
// map recent paths to tool objects (newest first, cap 8)