fix(frontend): 同步账号本地移除后的分页状态
This commit is contained in:
@@ -716,12 +716,38 @@ const mergeRuntimeFields = (oldAccount: Account, updatedAccount: Account): Accou
|
|||||||
current_window_cost: updatedAccount.current_window_cost ?? oldAccount.current_window_cost,
|
current_window_cost: updatedAccount.current_window_cost ?? oldAccount.current_window_cost,
|
||||||
active_sessions: updatedAccount.active_sessions ?? oldAccount.active_sessions
|
active_sessions: updatedAccount.active_sessions ?? oldAccount.active_sessions
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const syncPaginationAfterLocalRemoval = () => {
|
||||||
|
const nextTotal = Math.max(0, pagination.total - 1)
|
||||||
|
pagination.total = nextTotal
|
||||||
|
pagination.pages = nextTotal > 0 ? Math.ceil(nextTotal / pagination.page_size) : 0
|
||||||
|
|
||||||
|
const maxPage = Math.max(1, pagination.pages || 1)
|
||||||
|
let shouldReload = false
|
||||||
|
|
||||||
|
if (pagination.page > maxPage) {
|
||||||
|
pagination.page = maxPage
|
||||||
|
shouldReload = nextTotal > 0
|
||||||
|
} else if (nextTotal > 0) {
|
||||||
|
const displayedEnd = (pagination.page - 1) * pagination.page_size + accounts.value.length
|
||||||
|
// 当前页条目变少时,若后续还有数据则补齐,避免空页/少一条直到手动刷新。
|
||||||
|
shouldReload = displayedEnd < nextTotal
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldReload) {
|
||||||
|
load().catch((error) => {
|
||||||
|
console.error('Failed to refresh accounts after local removal:', error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const patchAccountInList = (updatedAccount: Account) => {
|
const patchAccountInList = (updatedAccount: Account) => {
|
||||||
const index = accounts.value.findIndex(account => account.id === updatedAccount.id)
|
const index = accounts.value.findIndex(account => account.id === updatedAccount.id)
|
||||||
if (index === -1) return
|
if (index === -1) return
|
||||||
const mergedAccount = mergeRuntimeFields(accounts.value[index], updatedAccount)
|
const mergedAccount = mergeRuntimeFields(accounts.value[index], updatedAccount)
|
||||||
if (!accountMatchesCurrentFilters(mergedAccount)) {
|
if (!accountMatchesCurrentFilters(mergedAccount)) {
|
||||||
accounts.value = accounts.value.filter(account => account.id !== mergedAccount.id)
|
accounts.value = accounts.value.filter(account => account.id !== mergedAccount.id)
|
||||||
|
syncPaginationAfterLocalRemoval()
|
||||||
selIds.value = selIds.value.filter(id => id !== mergedAccount.id)
|
selIds.value = selIds.value.filter(id => id !== mergedAccount.id)
|
||||||
if (menu.acc?.id === mergedAccount.id) {
|
if (menu.acc?.id === mergedAccount.id) {
|
||||||
menu.show = false
|
menu.show = false
|
||||||
|
|||||||
Reference in New Issue
Block a user