This commit is contained in:
薇薇安 2026-01-22 09:11:20 +08:00
parent 156acc92e0
commit 352d36e7a5
2 changed files with 25 additions and 4 deletions

View File

@ -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]

View File

@ -448,6 +448,8 @@ const ConfigPanel = ({ currentUser }) => {
return () => clearInterval(timer)
}, [])
// accountIdonChanged
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])