From 2d9adddb9124df3bcb0eb626001cc6fbb4987dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Wed, 21 Jan 2026 14:17:21 +0800 Subject: [PATCH] a --- frontend/src/App.jsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index e9faecd..8495801 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -8,7 +8,7 @@ import Recommendations from './components/Recommendations' import LogMonitor from './components/LogMonitor' import AccountSelector from './components/AccountSelector' import Login from './components/Login' -import { api, clearAuthToken } from './services/api' +import { api, clearAuthToken, setCurrentAccountId, getCurrentAccountId } from './services/api' import './App.css' function App() { @@ -19,6 +19,25 @@ function App() { try { const u = await api.me() setMe(u) + + // 普通用户:登录后默认选择“自己的账号” + // 规则:若可见账号列表里存在 account_id == user.id,则优先选它;否则选第一个可见账号。 + try { + if ((u?.role || '') !== 'admin') { + const list = await api.getAccounts() + const accounts = Array.isArray(list) ? list : [] + const uid = parseInt(String(u?.id || ''), 10) + const match = accounts.find((a) => parseInt(String(a?.id || ''), 10) === uid) + const target = match?.id || accounts[0]?.id + if (target) { + const cur = getCurrentAccountId() + const next = parseInt(String(target), 10) + if (Number.isFinite(next) && next > 0 && cur !== next) setCurrentAccountId(next) + } + } + } catch (e) { + // ignore + } } catch (e) { setMe(null) } finally {