a
This commit is contained in:
parent
971d4e3a39
commit
d6cdc2f055
|
|
@ -27,12 +27,20 @@ const AccountSelector = ({ onChanged, currentUser, viewingUserId: propViewingUse
|
||||||
user_id: item.user_id
|
user_id: item.user_id
|
||||||
}))
|
}))
|
||||||
setAccounts(accountsList)
|
setAccounts(accountsList)
|
||||||
// 自动选择第一个active账号
|
// 自动选择第一个active账号,并立即同步到localStorage和触发事件
|
||||||
const firstActive = accountsList.find((a) => String(a?.status || 'active') === 'active') || accountsList[0]
|
const firstActive = accountsList.find((a) => String(a?.status || 'active') === 'active') || accountsList[0]
|
||||||
if (firstActive) {
|
if (firstActive) {
|
||||||
const nextAccountId = parseInt(String(firstActive.id || ''), 10)
|
const nextAccountId = parseInt(String(firstActive.id || ''), 10)
|
||||||
if (Number.isFinite(nextAccountId) && nextAccountId > 0) {
|
if (Number.isFinite(nextAccountId) && nextAccountId > 0) {
|
||||||
|
// 立即更新localStorage和触发事件,确保其他页面能同步
|
||||||
|
setCurrentAccountId(nextAccountId)
|
||||||
setAccountId(nextAccountId)
|
setAccountId(nextAccountId)
|
||||||
|
// 立即触发事件,确保其他页面能立即响应
|
||||||
|
try {
|
||||||
|
window.dispatchEvent(new CustomEvent('ats:account:changed', { detail: { accountId: nextAccountId } }))
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -59,12 +67,20 @@ const AccountSelector = ({ onChanged, currentUser, viewingUserId: propViewingUse
|
||||||
user_id: item.user_id
|
user_id: item.user_id
|
||||||
}))
|
}))
|
||||||
setAccounts(accountsList)
|
setAccounts(accountsList)
|
||||||
// 自动选择第一个active账号
|
// 自动选择第一个active账号,并立即同步到localStorage和触发事件
|
||||||
const firstActive = accountsList.find((a) => String(a?.status || 'active') === 'active') || accountsList[0]
|
const firstActive = accountsList.find((a) => String(a?.status || 'active') === 'active') || accountsList[0]
|
||||||
if (firstActive) {
|
if (firstActive) {
|
||||||
const nextAccountId = parseInt(String(firstActive.id || ''), 10)
|
const nextAccountId = parseInt(String(firstActive.id || ''), 10)
|
||||||
if (Number.isFinite(nextAccountId) && nextAccountId > 0) {
|
if (Number.isFinite(nextAccountId) && nextAccountId > 0) {
|
||||||
|
// 立即更新localStorage和触发事件,确保其他页面能同步
|
||||||
|
setCurrentAccountId(nextAccountId)
|
||||||
setAccountId(nextAccountId)
|
setAccountId(nextAccountId)
|
||||||
|
// 立即触发事件,确保其他页面能立即响应
|
||||||
|
try {
|
||||||
|
window.dispatchEvent(new CustomEvent('ats:account:changed', { detail: { accountId: nextAccountId } }))
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user