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,100 @@
|
||||
/**
|
||||
* features/admin/modules/requests/RequestsPage.vue
|
||||
* 权限申请管理独立页面。路由:/admin/requests
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ShieldCheck } from 'lucide-vue-next';
|
||||
import { useRequestsAdmin } from './composables/useRequestsAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
requests,
|
||||
isLoading,
|
||||
loadAll,
|
||||
approveRequest,
|
||||
rejectRequest,
|
||||
} = useRequestsAdmin();
|
||||
|
||||
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.request.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.request.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="requests.length === 0"
|
||||
class="flex flex-col items-center justify-center py-16 text-muted"
|
||||
>
|
||||
<div class="w-16 h-16 bg-surface-soft rounded-full flex items-center justify-center mb-4">
|
||||
<ShieldCheck class="w-8 h-8 text-muted" />
|
||||
</div>
|
||||
<p>{{ t('admin.request.noPending') }}</p>
|
||||
</div>
|
||||
|
||||
<table v-else class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.userId') }}</th>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.targetAgent') }}</th>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.reason') }}</th>
|
||||
<th class="px-8 py-4 text-xs">{{ t('admin.request.headers.status') }}</th>
|
||||
<th class="px-8 py-4 text-xs text-right">{{ t('admin.request.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="req in requests" :key="req.id">
|
||||
<td class="px-8 py-4 text-sm font-medium text-primary">{{ req.user_id }}</td>
|
||||
<td class="px-8 py-4 text-sm text-secondary">{{ req.agent_id }}</td>
|
||||
<td
|
||||
class="px-8 py-4 text-sm text-muted max-w-xs truncate"
|
||||
:title="req.reason"
|
||||
>
|
||||
{{ req.reason || '-' }}
|
||||
</td>
|
||||
<td class="px-8 py-4">
|
||||
<span
|
||||
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-50 text-yellow-700 border border-yellow-100"
|
||||
>
|
||||
{{ t('admin.status.' + req.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-8 py-4 text-right">
|
||||
<div class="flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
class="text-green-600 hover:text-green-800 text-sm font-medium hover:underline"
|
||||
@click="approveRequest(req.id)"
|
||||
>
|
||||
{{ t('admin.request.approve') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="text-red-500 hover:text-red-700 text-sm font-medium hover:underline"
|
||||
@click="rejectRequest(req.id)"
|
||||
>
|
||||
{{ t('admin.request.reject') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* features/admin/modules/requests/composables/useRequestsAdmin.ts
|
||||
* 权限申请管理:列表、通过、拒绝。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
approveAdminPermissionRequest,
|
||||
listAdminPermissionRequests,
|
||||
rejectAdminPermissionRequest,
|
||||
} from '@/api/admin';
|
||||
import { useMessage } from '@/composables/useMessage';
|
||||
import { useAdminNavBadges } from '@/features/admin/composables/useAdminNavBadges';
|
||||
import type { AdminPermissionRequestRow } from '@/features/admin/types/request.types';
|
||||
|
||||
export function useRequestsAdmin() {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const { refreshBadges } = useAdminNavBadges();
|
||||
|
||||
const requests = ref<AdminPermissionRequestRow[]>([]);
|
||||
const isLoading = ref(true);
|
||||
|
||||
const loadRequests = async (): Promise<void> => {
|
||||
try {
|
||||
requests.value = await listAdminPermissionRequests();
|
||||
} catch (e) {
|
||||
console.error('Error loading permission requests:', e);
|
||||
requests.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
await loadRequests();
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
const approveRequest = async (id: number): Promise<void> => {
|
||||
try {
|
||||
await approveAdminPermissionRequest(id);
|
||||
await loadRequests();
|
||||
await refreshBadges();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.failed'));
|
||||
}
|
||||
};
|
||||
|
||||
const rejectRequest = async (id: number): Promise<void> => {
|
||||
try {
|
||||
await rejectAdminPermissionRequest(id);
|
||||
await loadRequests();
|
||||
await refreshBadges();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.failed'));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
requests,
|
||||
isLoading,
|
||||
loadAll,
|
||||
approveRequest,
|
||||
rejectRequest,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user