添加报表页面,更新用户管理和注册功能
This commit is contained in:
@@ -4,21 +4,26 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import {
|
||||
adminResetUserPassword,
|
||||
approveUser,
|
||||
deleteUser,
|
||||
fetchAllUsers,
|
||||
approveUser,
|
||||
rejectUser,
|
||||
removeUserVip,
|
||||
setUserVip,
|
||||
} from '../api/users'
|
||||
import { approvePasswordReset, fetchPasswordResets, rejectPasswordReset } from '../api/passwordResets'
|
||||
import { parseSqliteDateTime } from '../utils/datetime'
|
||||
import { validatePasswordStrength } from '../utils/password'
|
||||
|
||||
const refreshStats = inject('refreshStats', null)
|
||||
const refreshNavBadges = inject('refreshNavBadges', null)
|
||||
|
||||
const loading = ref(false)
|
||||
const users = ref([])
|
||||
|
||||
const resetLoading = ref(false)
|
||||
const passwordResets = ref([])
|
||||
|
||||
function isVip(user) {
|
||||
const expire = user?.vip_expire_time
|
||||
if (!expire) return false
|
||||
@@ -38,9 +43,8 @@ function vipLabel(user) {
|
||||
}
|
||||
|
||||
function statusMeta(status) {
|
||||
if (status === 'approved') return { label: '已通过', type: 'success' }
|
||||
if (status === 'rejected') return { label: '已拒绝', type: 'danger' }
|
||||
return { label: '待审核', type: 'warning' }
|
||||
if (status === 'rejected') return { label: '禁用', type: 'danger' }
|
||||
return { label: '正常', type: 'success' }
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
@@ -54,10 +58,27 @@ async function loadUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
async function onApprove(row) {
|
||||
async function loadResets() {
|
||||
resetLoading.value = true
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定通过用户「${row.username}」的注册申请吗?`, '审核通过', {
|
||||
confirmButtonText: '通过',
|
||||
const list = await fetchPasswordResets()
|
||||
passwordResets.value = Array.isArray(list) ? list : []
|
||||
} catch {
|
||||
passwordResets.value = []
|
||||
} finally {
|
||||
resetLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshAll() {
|
||||
await Promise.all([loadUsers(), loadResets()])
|
||||
await refreshNavBadges?.({ pendingResets: passwordResets.value.length })
|
||||
}
|
||||
|
||||
async function onEnableUser(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定启用用户「${row.username}」吗?启用后用户可正常登录。`, '启用用户', {
|
||||
confirmButtonText: '启用',
|
||||
cancelButtonText: '取消',
|
||||
type: 'success',
|
||||
})
|
||||
@@ -67,7 +88,7 @@ async function onApprove(row) {
|
||||
|
||||
try {
|
||||
await approveUser(row.id)
|
||||
ElMessage.success('用户审核通过')
|
||||
ElMessage.success('用户已启用')
|
||||
await loadUsers()
|
||||
await refreshStats?.()
|
||||
} catch {
|
||||
@@ -75,10 +96,10 @@ async function onApprove(row) {
|
||||
}
|
||||
}
|
||||
|
||||
async function onReject(row) {
|
||||
async function onDisableUser(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定拒绝用户「${row.username}」的注册申请吗?`, '拒绝申请', {
|
||||
confirmButtonText: '拒绝',
|
||||
await ElMessageBox.confirm(`确定禁用用户「${row.username}」吗?禁用后用户将无法登录。`, '禁用用户', {
|
||||
confirmButtonText: '禁用',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
@@ -88,7 +109,7 @@ async function onReject(row) {
|
||||
|
||||
try {
|
||||
await rejectUser(row.id)
|
||||
ElMessage.success('已拒绝用户')
|
||||
ElMessage.success('用户已禁用')
|
||||
await loadUsers()
|
||||
await refreshStats?.()
|
||||
} catch {
|
||||
@@ -96,6 +117,48 @@ async function onReject(row) {
|
||||
}
|
||||
}
|
||||
|
||||
async function onApproveReset(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定批准「${row.username}」的密码重置申请吗?`, '批准重置', {
|
||||
confirmButtonText: '批准',
|
||||
cancelButtonText: '取消',
|
||||
type: 'success',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await approvePasswordReset(row.id)
|
||||
ElMessage.success(res?.message || '密码重置申请已批准')
|
||||
await loadResets()
|
||||
await refreshNavBadges?.({ pendingResets: passwordResets.value.length })
|
||||
} catch {
|
||||
// handled by interceptor
|
||||
}
|
||||
}
|
||||
|
||||
async function onRejectReset(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定拒绝「${row.username}」的密码重置申请吗?`, '拒绝重置', {
|
||||
confirmButtonText: '拒绝',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await rejectPasswordReset(row.id)
|
||||
ElMessage.success(res?.message || '密码重置申请已拒绝')
|
||||
await loadResets()
|
||||
await refreshNavBadges?.({ pendingResets: passwordResets.value.length })
|
||||
} catch {
|
||||
// handled by interceptor
|
||||
}
|
||||
}
|
||||
|
||||
async function onDelete(row) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
@@ -200,7 +263,7 @@ async function onResetPassword(row) {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadUsers)
|
||||
onMounted(refreshAll)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -208,7 +271,7 @@ onMounted(loadUsers)
|
||||
<div class="app-page-title">
|
||||
<h2>用户</h2>
|
||||
<div>
|
||||
<el-button @click="loadUsers">刷新</el-button>
|
||||
<el-button @click="refreshAll">刷新</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -239,17 +302,20 @@ onMounted(loadUsers)
|
||||
<el-table-column label="时间" min-width="220">
|
||||
<template #default="{ row }">
|
||||
<div>{{ row.created_at }}</div>
|
||||
<div v-if="row.approved_at" class="app-muted">审核: {{ row.approved_at }}</div>
|
||||
<div v-if="row.vip_expire_time" class="app-muted">VIP到期: {{ row.vip_expire_time }}</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作" width="280" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<div class="actions">
|
||||
<template v-if="row.status === 'pending'">
|
||||
<el-button type="success" size="small" @click="onApprove(row)">通过</el-button>
|
||||
<el-button type="warning" size="small" @click="onReject(row)">拒绝</el-button>
|
||||
</template>
|
||||
<el-button
|
||||
v-if="row.status === 'rejected'"
|
||||
type="success"
|
||||
size="small"
|
||||
@click="onEnableUser(row)"
|
||||
>启用</el-button>
|
||||
<el-button v-else type="warning" size="small" @click="onDisableUser(row)">禁用</el-button>
|
||||
|
||||
<el-dropdown trigger="click">
|
||||
<el-button size="small">VIP</el-button>
|
||||
@@ -272,6 +338,27 @@ onMounted(loadUsers)
|
||||
</el-table>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" :body-style="{ padding: '16px' }" class="card">
|
||||
<h3 class="section-title">密码重置申请</h3>
|
||||
<div class="table-wrap">
|
||||
<el-table :data="passwordResets" v-loading="resetLoading" style="width: 100%">
|
||||
<el-table-column prop="id" label="申请ID" width="90" />
|
||||
<el-table-column prop="username" label="用户名" min-width="200" />
|
||||
<el-table-column prop="email" label="邮箱" min-width="220">
|
||||
<template #default="{ row }">{{ row.email || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="申请时间" min-width="180" />
|
||||
<el-table-column label="操作" width="180" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="success" size="small" @click="onApproveReset(row)">批准</el-button>
|
||||
<el-button type="danger" size="small" @click="onRejectReset(row)">拒绝</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<div class="help app-muted">当未启用邮件找回密码时,用户会提交申请,由管理员在此处处理。</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -287,6 +374,17 @@ onMounted(loadUsers)
|
||||
border: 1px solid var(--app-border);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 0 0 12px;
|
||||
font-size: 14px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.help {
|
||||
margin-top: 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user