fix(admin): 管理控制台全面替换为element plus

This commit is contained in:
sophie committed 2026-10-22 19:27:03 +08:00
1 parent b69c725992
commit 627da80e65
72 files changed
+12370 -8437

No files matched your search

@@ -1,27 +1,32 @@
/**
* features/admin/modules/approvals/ApprovalsPage.vue
* 用户注册审批独立页面。路由:/admin/approvals
* 用途:用户注册审批列表。一张卡片里放标题和待审表格。
* 依赖:AdminListPage、useApprovalsAdmin、useElementProvider、element-plus、roleLabel。
* 逻辑:路由未挂进当前菜单。通过和拒绝由 composable 弹出 Element 确认框后调接口。
*/
<script setup lang="ts">
import { onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { ShieldCheck, Trash2 } from 'lucide-vue-next';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
import { CircleCheck, Delete } from '@element-plus/icons-vue';
import { ElButton, ElConfigProvider, ElTable, ElTableColumn, ElTag } from 'element-plus';
import 'element-plus/dist/index.css';
import 'element-plus/theme-chalk/dark/css-vars.css';
import '@/features/admin/styles/element-trial.css';
import AdminListPage from '@/features/admin/components/AdminListPage.vue';
import { useElementProvider } from '@/features/admin/composables/useElementProvider';
import { adminRoleLabel } from '@/features/admin/utils/roleLabel';
import type { AdminUserRow } from '@/features/admin/types/admin.types';
import { useApprovalsAdmin } from './composables/useApprovalsAdmin';
const { t } = useI18n();
const { elementLocale } = useElementProvider();
const {
pendingUsers,
isLoading,
showConfirmDialog,
confirmMessage,
loadAll,
approveUser,
rejectUser,
closeConfirm,
confirmActionHandler,
} = useApprovalsAdmin();
onMounted(() => {
@@ -30,80 +35,60 @@ onMounted(() => {
</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>
<ElConfigProvider :locale="elementLocale">
<AdminListPage :loading="isLoading">
<template #title>
<h2 class="section-title">{{ t('admin.approval.title') }}</h2>
<p class="section-desc">{{ t('admin.approval.subtitle') }}</p>
</template>
<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"
>
{{ adminRoleLabel(t, user.role, user.role_name) }}
</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>
<ElTable
class="hx-admin-table"
:data="pendingUsers"
row-key="id"
:empty-text="t('admin.approval.noPending')"
>
<ElTableColumn :label="t('admin.approval.headers.username')" min-width="200">
<template #default="{ row }">
<div>{{ (row as AdminUserRow).username }}</div>
<p class="hx-element-hint">{{ (row as AdminUserRow).email }}</p>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.approval.headers.nameId')" min-width="160">
<template #default="{ row }">
<div>{{ (row as AdminUserRow).real_name || '-' }}</div>
<p class="hx-element-hint">{{ (row as AdminUserRow).employee_id || '-' }}</p>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.approval.headers.contact')" min-width="140">
<template #default="{ row }">{{ (row as AdminUserRow).phone_number || '-' }}</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.approval.headers.role')" min-width="120">
<template #default="{ row }">
<ElTag effect="light" type="warning">
{{ adminRoleLabel(t, (row as AdminUserRow).role, (row as AdminUserRow).role_name) }}
</ElTag>
</template>
</ElTableColumn>
<ElTableColumn :label="t('admin.approval.headers.actions')" width="120" align="right">
<template #default="{ row }">
<ElButton
link
type="primary"
:icon="CircleCheck"
:title="t('admin.approval.confirmApprove')"
@click="approveUser((row as AdminUserRow).id)"
/>
<ElButton
link
type="danger"
:icon="Delete"
:title="t('admin.approval.confirmReject')"
@click="rejectUser((row as AdminUserRow).id)"
/>
</template>
</ElTableColumn>
</ElTable>
</AdminListPage>
</ElConfigProvider>
</template>
@@ -1,9 +1,12 @@
/**
* features/admin/modules/approvals/composables/useApprovalsAdmin.ts
* 用户注册审批:待审列表、通过、拒绝。
* 用途:用户注册审批的待审列表、通过和拒绝。
* 依赖:admin.api、useMessage、useAdminNavBadges、element-plus 的确认框。
* 逻辑:ApprovalsPage 调用本模块;通过和拒绝都先弹出 Element 确认框,成功后刷新列表和导航角标。
*/
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { ElMessageBox } from 'element-plus';
import { approveAdminUser, listAdminUsers, rejectAdminUser } from '@/features/admin/api/admin.api';
import { useMessage } from '@/shared/composables/useMessage';
import { useAdminNavBadges } from '@/features/admin/composables/useAdminNavBadges';
@@ -17,10 +20,6 @@ export function useApprovalsAdmin() {
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> => {
@@ -38,61 +37,61 @@ export function useApprovalsAdmin() {
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;
/**
* 弹出确认框。点取消时 Element 会拒绝 Promise,这里吞掉,不当成失败。
* @param message - 确认正文
* @returns 用户是否点了确定
*/
async function confirmAction(message: string): Promise<boolean> {
try {
await confirmAction();
} finally {
closeConfirm();
await ElMessageBox.confirm(message, t('common.deleteDialog.defaultTitle'), {
confirmButtonText: t('common.deleteDialog.confirm'),
cancelButtonText: t('common.deleteDialog.cancel'),
type: 'warning',
});
return true;
} catch {
return false;
}
};
}
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'));
}
});
};
/**
* 通过一条待审注册。先确认,再调审批接口并刷新角标。
* @param userId - 待审用户主键
*/
async function approveUser(userId: number): Promise<void> {
if (!(await confirmAction(t('admin.approval.confirmApprove')))) return;
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'));
}
});
};
/**
* 拒绝一条待审注册。先确认,再调拒绝接口并刷新角标。
* @param userId - 待审用户主键
*/
async function rejectUser(userId: number): Promise<void> {
if (!(await confirmAction(t('admin.approval.confirmReject')))) return;
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,
};
}