a
This commit is contained in:
parent
156acc92e0
commit
352d36e7a5
|
|
@ -31,7 +31,14 @@ const AccountSelector = ({ onChanged, currentUser }) => {
|
|||
if (isAdmin && selectedUserId) {
|
||||
api.getUserAccounts(selectedUserId)
|
||||
.then((list) => {
|
||||
const accountsList = Array.isArray(list) ? list : []
|
||||
// 转换数据格式:后端返回 {account_id, account_name, account_status},前端期望 {id, name, status}
|
||||
const accountsList = (Array.isArray(list) ? list : []).map((item) => ({
|
||||
id: item.account_id || item.id,
|
||||
name: item.account_name || item.name || '',
|
||||
status: item.account_status || item.status || 'active',
|
||||
role: item.role || 'viewer',
|
||||
user_id: item.user_id
|
||||
}))
|
||||
setAccounts(accountsList)
|
||||
// 自动选择第一个active账号
|
||||
const firstActive = accountsList.find((a) => String(a?.status || 'active') === 'active') || accountsList[0]
|
||||
|
|
|
|||
|
|
@ -448,6 +448,8 @@ const ConfigPanel = ({ currentUser }) => {
|
|||
return () => clearInterval(timer)
|
||||
}, [])
|
||||
|
||||
// 当accountId变化时,重新加载相关数据(避免重复调用,已在onChanged和定时器中处理)
|
||||
|
||||
const loadAccountsAdmin = async () => {
|
||||
try {
|
||||
const list = await api.getAccounts()
|
||||
|
|
@ -484,18 +486,30 @@ const ConfigPanel = ({ currentUser }) => {
|
|||
useEffect(() => {
|
||||
const onChanged = (e) => {
|
||||
const next = parseInt(String(e?.detail?.accountId || ''), 10)
|
||||
if (Number.isFinite(next) && next > 0) setAccountId(next)
|
||||
if (Number.isFinite(next) && next > 0 && next !== accountId) {
|
||||
setAccountId(next)
|
||||
// 立即重新加载相关数据
|
||||
loadConfigs()
|
||||
loadAccountTradingStatus()
|
||||
loadCurrentAccountMeta()
|
||||
}
|
||||
}
|
||||
window.addEventListener('ats:account:changed', onChanged)
|
||||
return () => window.removeEventListener('ats:account:changed', onChanged)
|
||||
}, [])
|
||||
}, [accountId])
|
||||
|
||||
// 顶部导航切换账号时(localStorage更新),这里做一个轻量同步
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
const cur = getCurrentAccountId()
|
||||
|
||||
if (cur !== accountId) setAccountId(cur)
|
||||
if (cur !== accountId) {
|
||||
setAccountId(cur)
|
||||
// 同步时也重新加载数据
|
||||
loadConfigs()
|
||||
loadAccountTradingStatus()
|
||||
loadCurrentAccountMeta()
|
||||
}
|
||||
}, 1000)
|
||||
return () => clearInterval(timer)
|
||||
}, [accountId])
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user