a
This commit is contained in:
parent
9bc73b63a3
commit
2d9adddb91
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user