From 5301a8c840c526d3ca1bfe4b3176c726c4a2df9f Mon Sep 17 00:00:00 2001 From: personal82555 Date: Tue, 13 Oct 2026 23:00:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=82=A1=E7=A5=A8=E5=88=97=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=87=AA=E9=80=89=E9=80=89=E9=A1=B9=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 最热/自选选项卡; 输入6位代码添加(校验位数/重复), 行内名称+涨跌幅+现价, ✕移出, 红涨绿跌 - 新端点 GET /relay/stock/quotes?codes=... (东财批量行情, 20s缓存, 非法过滤) - it-tools-my-stocks 纳入云同步(并集合并) - 60s轮询同步刷新自选 - fix: ref(箭头函数)不执行致.map报错 -> 显式调用取初值 验证: 切换/校验/增删/切回最热10条/云键写入 ✓, 视觉整齐 ✓, 控制台无报错 ✓ CHANGELOG记录 --- CHANGELOG.md | 9 ++ src/composable/cloud-sync.ts | 3 +- src/pages/Home.page.vue | 234 ++++++++++++++++++++++++++++++++--- 3 files changed, 231 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bc4de5..1323d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. See [standa ## Version 2026.10.12-it-tools-pro +### 📇 股票列新增「自选」选项卡 +- 「当天最热股票」列顶部加 **最热 / 自选** 选项卡 +- 自选面板:输入 6 位代码即可添加(校验位数/重复),行内显示 名称·代码·涨跌幅 + 现价,✕ 一键移出;**A股红涨绿跌**着色 +- 行情走新端点 `GET /relay/stock/quotes?codes=...`(东方财富批量行情,20s 缓存,非法代码自动过滤) +- 自选列表存 `it-tools-my-stocks` 并纳入云同步(并集合并,换电脑登录即恢复) +- 交易时段首页 60s 轮询时同步刷新自选行情 +- 修复:`ref(箭头函数)` 不会执行函数导致 `.map` 报错(改为显式调用取初值) +- 验证:选项卡切换/非法代码校验/添加 2 只/删除/切回最热 10 条/云同步键写入 ✓,视觉布局整齐 ✓,控制台无报错 ✓ + ### 📈 「当天最热股票」实时更新 - 后端:交易时段(周一至周五 9:15-15:05 北京时间)`/news` 按需重抓股票列,**60 秒节流**;其余 4 列仍每天 08:00 更新 - 前端:首页可见时**每 60 秒自动轮询** `/relay/news`,拿到最新涨幅;标签页隐藏时暂停 diff --git a/src/composable/cloud-sync.ts b/src/composable/cloud-sync.ts index e229870..5f523bf 100644 --- a/src/composable/cloud-sync.ts +++ b/src/composable/cloud-sync.ts @@ -8,6 +8,7 @@ const SYNC_KEYS = [ 'menu-tool-option:collapsed-categories', 'it-tools-ai-chat-convs', 'it-tools-ai-chat-deleted', // 对话删除墓碑 + 'it-tools-my-stocks', // 自选股 ]; function collectLocal(): Record { @@ -131,7 +132,7 @@ function mergeData(server: Record, mine: Record): Reco } else if (typeof v === 'string' && typeof out[k] === 'string') { // prefer the larger/newer list per key - if (k === 'favoriteToolsName' || k === 'it-tools-recent-tools' || k === 'it-tools-bookmarks:sites') { + if (k === 'favoriteToolsName' || k === 'it-tools-recent-tools' || k === 'it-tools-bookmarks:sites' || k === 'it-tools-my-stocks') { out[k] = mergeJsonArrays(out[k], v, k === 'it-tools-recent-tools' ? 'path' : null); } else if (k === 'it-tools-ai-chat-convs') { diff --git a/src/pages/Home.page.vue b/src/pages/Home.page.vue index 9a2b5b1..0a166ff 100644 --- a/src/pages/Home.page.vue +++ b/src/pages/Home.page.vue @@ -63,13 +63,88 @@ onMounted(() => { loadNews(); // 页面可见时每 60s 拉一次,拿到刷新后的股票列(非交易时段 relay 不重抓,开销可忽略) newsTimer = setInterval(() => { - if (document.visibilityState === 'visible') loadNews(); + if (document.visibilityState !== 'visible') return; + loadNews(); + if (stockTab.value === 'mine') loadMyQuotes(); }, 60000); }); onUnmounted(() => { if (newsTimer) clearInterval(newsTimer); }); +// ===== 股票列选项卡:最热 / 自选(自选实时行情,登录后随云同步)===== +const MY_STOCKS_KEY = 'it-tools-my-stocks'; +const stockTab = ref<'hot' | 'mine'>('hot'); +const stockInput = ref(''); +const stockErr = ref(''); +const myQuotes = ref([]); +// 注意:ref(函数) 不会执行函数(那是 computed 的语义),必须显式调用取初值 +function loadMyStocksList(): string[] { + try { + const a = JSON.parse(localStorage.getItem(MY_STOCKS_KEY) || '[]'); + return Array.isArray(a) ? a : []; + } + catch { return []; } +} +const myStocks = ref(loadMyStocksList()); + +function saveMyStocks() { + localStorage.setItem(MY_STOCKS_KEY, JSON.stringify(myStocks.value)); + loadMyQuotes(); +} + +async function loadMyQuotes() { + if (!myStocks.value.length) { + myQuotes.value = []; + return; + } + try { + const res = await fetch('/relay/stock/quotes?codes=' + myStocks.value.join(',')); + const j = await res.json(); + if (j.code === 200 && Array.isArray(j.data?.items)) myQuotes.value = j.data.items; + } + catch { /* 网络失败保留上次行情 */ } +} + +function addMyStock() { + const code = stockInput.value.trim(); + if (!/^\d{6}$/.test(code)) { + stockErr.value = '请输入 6 位股票代码'; + return; + } + if (myStocks.value.includes(code)) { + stockErr.value = '该股票已在自选中'; + return; + } + myStocks.value = [...myStocks.value, code]; + stockInput.value = ''; + stockErr.value = ''; + saveMyStocks(); +} + +function removeMyStock(code: string) { + myStocks.value = myStocks.value.filter(c => c !== code); + saveMyStocks(); +} + +function switchStockTab(t: 'hot' | 'mine') { + stockTab.value = t; + if (t === 'mine') loadMyQuotes(); +} + +// 按自选顺序渲染;行情没返回的代码给占位(仍可删除) +const myList = computed(() => myStocks.value.map((code) => { + const q = myQuotes.value.find(x => x.code === code); + return q || { + code, + name: code, + title: `${code} 暂无数据`, + desc: '', + pct: 0, + url: `https://quote.eastmoney.com/${code}.html`, + }; +})); + // map recent paths to tool objects (newest first, cap 8) const recentToolList = computed(() => { const byPath = new Map(toolStore.tools.map(t => [t.path, t])); @@ -114,20 +189,43 @@ function onUpdateFavoriteTools() { {{ col.icon }} {{ col.title }} +
+ + +
@@ -566,6 +664,114 @@ function onUpdateFavoriteTools() { opacity: 0.45; padding: 8px 2px; } + + // 股票列:最热 / 自选 选项卡 + .stock-tabs { + display: flex; + gap: 6px; + padding: 6px 10px 0; + } + .stock-tab { + flex: 1; + font-size: 11.5px; + padding: 3px 0; + border: 1px solid rgba(0, 0, 0, 0.08); + border-radius: 999px; + background: #fff; + color: rgba(0, 0, 0, 0.55); + cursor: pointer; + transition: all 0.15s; + + &.on { + background: rgba(24, 160, 88, 0.12); + border-color: rgba(24, 160, 88, 0.45); + color: #18a058; + font-weight: 700; + } + } + + // 自选面板 + .mystock-add { + display: flex; + gap: 6px; + padding: 2px 0 6px; + } + .mystock-input { + flex: 1; + min-width: 0; + font-size: 11.5px; + padding: 4px 7px; + border: 1px solid rgba(0, 0, 0, 0.12); + border-radius: 6px; + outline: none; + + &:focus { + border-color: #18a058; + } + } + .mystock-btn { + font-size: 11.5px; + padding: 4px 9px; + border: none; + border-radius: 6px; + background: #18a058; + color: #fff; + cursor: pointer; + + &:hover { + opacity: 0.88; + } + } + .mystock-err { + font-size: 11px; + color: #d03050; + padding-bottom: 4px; + } + .mystock-item { + display: flex; + align-items: center; + gap: 4px; + padding: 7px 8px; + border-radius: 8px; + + &:hover { + background: rgba(0, 0, 0, 0.035); + } + .mystock-main { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + gap: 2px; + text-decoration: none; + color: inherit; + } + .news-title { + &.up { + color: #d03050; // A股红涨 + } + &.down { + color: #18a058; // 绿跌 + } + } + .mystock-x { + flex-shrink: 0; + width: 18px; + height: 18px; + border: none; + border-radius: 50%; + background: transparent; + color: rgba(0, 0, 0, 0.3); + font-size: 11px; + line-height: 1; + cursor: pointer; + + &:hover { + background: rgba(208, 48, 80, 0.12); + color: #d03050; + } + } + } } .height-enter-active,