mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 09:50:21 +08:00
Fix admin users pagination review issues
This commit is contained in:
@@ -274,6 +274,7 @@ import type {
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
open: boolean
|
open: boolean
|
||||||
|
usersVersion: number
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -299,6 +300,7 @@ const editingGroupId = ref<string | null>(null)
|
|||||||
const memberUserIds = ref<string[]>([])
|
const memberUserIds = ref<string[]>([])
|
||||||
const USER_OPTIONS_CACHE_TTL_MS = 30 * 1000
|
const USER_OPTIONS_CACHE_TTL_MS = 30 * 1000
|
||||||
let dialogUsersLoadedAt = 0
|
let dialogUsersLoadedAt = 0
|
||||||
|
let dialogUsersLoadedVersion = -1
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
name: '',
|
name: '',
|
||||||
@@ -361,12 +363,17 @@ async function loadDialogData(): Promise<void> {
|
|||||||
|
|
||||||
async function ensureDialogUsers(): Promise<void> {
|
async function ensureDialogUsers(): Promise<void> {
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
if (dialogUsersLoadedAt > 0 && now - dialogUsersLoadedAt < USER_OPTIONS_CACHE_TTL_MS) {
|
if (
|
||||||
|
dialogUsersLoadedVersion === props.usersVersion
|
||||||
|
&& dialogUsersLoadedAt > 0
|
||||||
|
&& now - dialogUsersLoadedAt < USER_OPTIONS_CACHE_TTL_MS
|
||||||
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogUsers.value = await usersStore.listAllUsers({ cacheTtlMs: USER_OPTIONS_CACHE_TTL_MS })
|
dialogUsers.value = await usersStore.listAllUsers({ cacheTtlMs: USER_OPTIONS_CACHE_TTL_MS })
|
||||||
dialogUsersLoadedAt = Date.now()
|
dialogUsersLoadedAt = Date.now()
|
||||||
|
dialogUsersLoadedVersion = props.usersVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
async function selectGroup(groupId: string): Promise<void> {
|
async function selectGroup(groupId: string): Promise<void> {
|
||||||
|
|||||||
@@ -843,6 +843,7 @@
|
|||||||
|
|
||||||
<UserGroupsDialog
|
<UserGroupsDialog
|
||||||
:open="showUserGroupsDialog"
|
:open="showUserGroupsDialog"
|
||||||
|
:users-version="userOptionsVersion"
|
||||||
@close="showUserGroupsDialog = false"
|
@close="showUserGroupsDialog = false"
|
||||||
@changed="handleUserGroupsChanged"
|
@changed="handleUserGroupsChanged"
|
||||||
/>
|
/>
|
||||||
@@ -1572,6 +1573,7 @@ const showWalletActionDialogState = ref(false)
|
|||||||
const walletActionTarget = ref<{ user: User; wallet: AdminWallet } | null>(null)
|
const walletActionTarget = ref<{ user: User; wallet: AdminWallet } | null>(null)
|
||||||
const showUserBatchDialog = ref(false)
|
const showUserBatchDialog = ref(false)
|
||||||
const showUserGroupsDialog = ref(false)
|
const showUserGroupsDialog = ref(false)
|
||||||
|
const userOptionsVersion = ref(0)
|
||||||
|
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
const filterRole = ref<'all' | User['role']>('all')
|
const filterRole = ref<'all' | User['role']>('all')
|
||||||
@@ -1596,20 +1598,7 @@ const USERS_PAGE_CACHE_TTL_MS = 10 * 1000
|
|||||||
const USER_WALLETS_CACHE_TTL_MS = 10 * 1000
|
const USER_WALLETS_CACHE_TTL_MS = 10 * 1000
|
||||||
let userWalletsRequestId = 0
|
let userWalletsRequestId = 0
|
||||||
|
|
||||||
const filteredUsers = computed(() => {
|
const filteredUsers = computed(() => usersStore.users)
|
||||||
let filtered = [...usersStore.users]
|
|
||||||
|
|
||||||
// 当前页仍按原有视觉规则排序;筛选和分页由后端处理,避免只搜索首批 100 个用户。
|
|
||||||
filtered.sort((a, b) => {
|
|
||||||
const roleRank = (role: string) => role === 'admin' ? 0 : role === 'audit_admin' ? 1 : 2
|
|
||||||
const roleDiff = roleRank(a.role) - roleRank(b.role)
|
|
||||||
if (roleDiff !== 0) return roleDiff
|
|
||||||
// 同角色按创建时间倒序(新用户在前)
|
|
||||||
return new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
|
|
||||||
})
|
|
||||||
|
|
||||||
return filtered
|
|
||||||
})
|
|
||||||
|
|
||||||
const paginatedUsers = computed(() => filteredUsers.value)
|
const paginatedUsers = computed(() => filteredUsers.value)
|
||||||
|
|
||||||
@@ -1731,6 +1720,10 @@ async function handleUserBatchCompleted(_result: UserBatchActionResponse): Promi
|
|||||||
resetBatchSelection(true)
|
resetBatchSelection(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function invalidateUserOptions(): void {
|
||||||
|
userOptionsVersion.value += 1
|
||||||
|
}
|
||||||
|
|
||||||
function formatDate(dateString: string) {
|
function formatDate(dateString: string) {
|
||||||
return new Date(dateString).toLocaleDateString('zh-CN')
|
return new Date(dateString).toLocaleDateString('zh-CN')
|
||||||
}
|
}
|
||||||
@@ -1896,6 +1889,8 @@ async function toggleUserStatus(user: User) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await usersStore.updateUser(user.id, { is_active: !user.is_active })
|
await usersStore.updateUser(user.id, { is_active: !user.is_active })
|
||||||
|
invalidateUserOptions()
|
||||||
|
await refreshUsers()
|
||||||
success(`用户已${action}`)
|
success(`用户已${action}`)
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
error(parseApiError(err, '未知错误'), `${action}用户失败`)
|
error(parseApiError(err, '未知错误'), `${action}用户失败`)
|
||||||
@@ -1946,6 +1941,7 @@ async function handleUserFormSubmit(data: UserFormData & { password?: string; un
|
|||||||
updateData.password = data.password
|
updateData.password = data.password
|
||||||
}
|
}
|
||||||
await usersStore.updateUser(data.id, updateData)
|
await usersStore.updateUser(data.id, updateData)
|
||||||
|
invalidateUserOptions()
|
||||||
success('用户信息已更新')
|
success('用户信息已更新')
|
||||||
} else {
|
} else {
|
||||||
// 创建用户
|
// 创建用户
|
||||||
@@ -1963,6 +1959,7 @@ async function handleUserFormSubmit(data: UserFormData & { password?: string; un
|
|||||||
if (data.is_active === false && newUser) {
|
if (data.is_active === false && newUser) {
|
||||||
await usersStore.updateUser(newUser.id, { is_active: false })
|
await usersStore.updateUser(newUser.id, { is_active: false })
|
||||||
}
|
}
|
||||||
|
invalidateUserOptions()
|
||||||
success('用户创建成功')
|
success('用户创建成功')
|
||||||
}
|
}
|
||||||
closeUserFormDialog()
|
closeUserFormDialog()
|
||||||
@@ -2270,6 +2267,7 @@ async function deleteUser(user: User) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await usersStore.deleteUser(user.id)
|
await usersStore.deleteUser(user.id)
|
||||||
|
invalidateUserOptions()
|
||||||
if (usersStore.users.length === 0 && currentPage.value > 1) {
|
if (usersStore.users.length === 0 && currentPage.value > 1) {
|
||||||
currentPage.value -= 1
|
currentPage.value -= 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user