refactor: 重构前端骨架,及admin模块子路由和懒加载
refactor: 优化多次请求,并使用pinia状态管理
This commit is contained in:
1 parent
f877f61efd
commit
61693d014d
74 files changed
+9493
-6418
No files matched your search
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* features/admin/modules/approvals/ApprovalsPage.vue
|
||||
* 用户注册审批独立页面。路由:/admin/approvals
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ShieldCheck, Trash2 } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog.vue';
|
||||
import { useApprovalsAdmin } from './composables/useApprovalsAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
pendingUsers,
|
||||
isLoading,
|
||||
showConfirmDialog,
|
||||
confirmMessage,
|
||||
loadAll,
|
||||
approveUser,
|
||||
rejectUser,
|
||||
closeConfirm,
|
||||
confirmActionHandler,
|
||||
} = useApprovalsAdmin();
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section">
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.approval.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.approval.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-8 py-4 text-left text-xs">{{ t('admin.approval.headers.username') }}</th>
|
||||
<th class="px-8 py-4 text-left text-xs">{{ t('admin.approval.headers.nameId') }}</th>
|
||||
<th class="px-8 py-4 text-left text-xs">{{ t('admin.approval.headers.contact') }}</th>
|
||||
<th class="px-8 py-4 text-left text-xs">{{ t('admin.approval.headers.role') }}</th>
|
||||
<th class="px-8 py-4 text-right text-xs">{{ t('admin.approval.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="pendingUsers.length === 0">
|
||||
<td colspan="5" class="px-8 admin-table-empty">{{ t('admin.approval.noPending') }}</td>
|
||||
</tr>
|
||||
<tr v-for="user in pendingUsers" :key="user.id">
|
||||
<td class="px-8 py-5 text-sm font-medium text-primary">
|
||||
<div>{{ user.username }}</div>
|
||||
<div class="text-xs text-muted font-normal">{{ user.email }}</div>
|
||||
</td>
|
||||
<td class="px-8 py-5 text-sm text-muted">
|
||||
<div>{{ user.real_name || '-' }}</div>
|
||||
<div class="text-xs text-muted font-mono">{{ user.employee_id || '-' }}</div>
|
||||
</td>
|
||||
<td class="px-8 py-5 text-sm text-muted">{{ user.phone_number || '-' }}</td>
|
||||
<td class="px-8 py-5">
|
||||
<span
|
||||
class="px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800 border border-yellow-200"
|
||||
>
|
||||
{{ t('admin.role.' + user.role) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-8 py-5 text-right flex items-center justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 text-green-600 bg-green-50 rounded-lg hover:bg-green-100 transition-colors"
|
||||
:title="t('admin.approval.confirmApprove')"
|
||||
@click="approveUser(user.id)"
|
||||
>
|
||||
<ShieldCheck class="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 text-red-600 bg-red-50 rounded-lg hover:bg-red-100 transition-colors"
|
||||
:title="t('admin.approval.confirmReject')"
|
||||
@click="rejectUser(user.id)"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showConfirmDialog"
|
||||
:message="confirmMessage"
|
||||
@cancel="closeConfirm"
|
||||
@confirm="confirmActionHandler"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* features/admin/modules/approvals/composables/useApprovalsAdmin.ts
|
||||
* 用户注册审批:待审列表、通过、拒绝。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { approveAdminUser, listAdminUsers, rejectAdminUser } from '@/api/admin';
|
||||
import { useMessage } from '@/composables/useMessage';
|
||||
import { useAdminNavBadges } from '@/features/admin/composables/useAdminNavBadges';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
|
||||
export function useApprovalsAdmin() {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const { refreshBadges } = useAdminNavBadges();
|
||||
|
||||
const users = ref<AdminUserRow[]>([]);
|
||||
const isLoading = ref(true);
|
||||
|
||||
const showConfirmDialog = ref(false);
|
||||
const confirmMessage = ref('');
|
||||
let confirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
const pendingUsers = computed(() => users.value.filter((u) => u.status === 'pending'));
|
||||
|
||||
const loadUsers = async (): Promise<void> => {
|
||||
try {
|
||||
users.value = await listAdminUsers();
|
||||
} catch (e) {
|
||||
console.error('Error loading users:', e);
|
||||
users.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
await loadUsers();
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
const openConfirm = (message: string, action: () => Promise<void> | void): void => {
|
||||
confirmMessage.value = message;
|
||||
confirmAction = action;
|
||||
showConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
const closeConfirm = (): void => {
|
||||
showConfirmDialog.value = false;
|
||||
confirmAction = null;
|
||||
};
|
||||
|
||||
const confirmActionHandler = async (): Promise<void> => {
|
||||
if (!confirmAction) return;
|
||||
try {
|
||||
await confirmAction();
|
||||
} finally {
|
||||
closeConfirm();
|
||||
}
|
||||
};
|
||||
|
||||
const approveUser = (userId: number): void => {
|
||||
openConfirm(t('admin.approval.confirmApprove'), async () => {
|
||||
try {
|
||||
await approveAdminUser(userId);
|
||||
await loadUsers();
|
||||
await refreshBadges();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.failed'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const rejectUser = (userId: number): void => {
|
||||
openConfirm(t('admin.approval.confirmReject'), async () => {
|
||||
try {
|
||||
await rejectAdminUser(userId);
|
||||
await loadUsers();
|
||||
await refreshBadges();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
pendingUsers,
|
||||
isLoading,
|
||||
showConfirmDialog,
|
||||
confirmMessage,
|
||||
loadAll,
|
||||
approveUser,
|
||||
rejectUser,
|
||||
closeConfirm,
|
||||
confirmActionHandler,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user