用户管理与数据操作

This commit is contained in:
tianmo committed 2026-10-27 11:03:36 +08:00
1 parent ed0f20b754
commit 51d3acfbb5
14 files changed
+256 -33

No files matched your search

+47
View File
@@ -7,6 +7,7 @@ interface AdminUser {
role: 'admin' | 'user'
created_at: string
password_reset: number
disabled_at: string | null
usage?: {
imageBytes: number
videoBytes: number
@@ -31,6 +32,7 @@ const loading = ref(false)
const deleteTarget = ref<AdminUser | null>(null)
const deleteConfirm = ref('')
const deleting = ref(false)
const statusBusyId = ref<number | null>(null)
const canDelete = computed(() =>
Boolean(
@@ -76,6 +78,34 @@ async function clearPassword(user: AdminUser) {
}
}
async function toggleDisabled(user: AdminUser) {
if (user.role === 'admin' || statusBusyId.value !== null) return
const disabled = !user.disabled_at
statusBusyId.value = user.id
try {
await $fetch(`/api/admin/users/${user.id}/status`, {
method: 'POST',
credentials: 'include',
body: { disabled }
})
toast.add({
title: t(disabled ? 'users.disableSuccess' : 'users.enableSuccess', {
name: user.username
}),
color: 'success'
})
await loadUsers()
} catch (error: unknown) {
handleAuthError(error)
toast.add({
title: getFetchErrorMessage(error, t('users.statusFailed')),
color: 'error'
})
} finally {
statusBusyId.value = null
}
}
function openDeleteDialog(user: AdminUser) {
if (user.role === 'admin') return
deleteTarget.value = user
@@ -226,6 +256,14 @@ onMounted(async () => {
v-if="user.role !== 'admin'"
class="flex items-center gap-2"
>
<UBadge
v-if="user.disabled_at"
color="error"
variant="subtle"
size="sm"
>
{{ t('users.disabled') }}
</UBadge>
<UBadge
v-if="user.password_reset === 1"
color="warning"
@@ -234,6 +272,15 @@ onMounted(async () => {
>
{{ t('users.resetPending') }}
</UBadge>
<UButton
variant="outline"
:color="user.disabled_at ? 'primary' : 'warning'"
size="sm"
:label="user.disabled_at ? t('users.enable') : t('users.disable')"
:loading="statusBusyId === user.id"
:disabled="statusBusyId !== null && statusBusyId !== user.id"
@click="toggleDisabled(user)"
/>
<UButton
v-if="user.password_reset !== 1"
variant="outline"