245 lines
9.8 KiB
Vue
245 lines
9.8 KiB
Vue
/**
|
|
* features/admin/modules/users/UsersPage.vue
|
|
* 用户管理独立页面。路由:/admin/users
|
|
*/
|
|
<script setup lang="ts">
|
|
import { onMounted } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { Edit, Plus, Trash2, Users } from 'lucide-vue-next';
|
|
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
|
import BatchEditUserModal from './components/BatchEditUserModal.vue';
|
|
import BatchPermissionModal from './components/BatchPermissionModal.vue';
|
|
import UserFormModal from './components/UserFormModal.vue';
|
|
import { useUsersAdmin } from './composables/useUsersAdmin';
|
|
|
|
const { t } = useI18n();
|
|
|
|
const {
|
|
agents,
|
|
departments,
|
|
isLoading,
|
|
isSaving,
|
|
userFilters,
|
|
hideRejected,
|
|
selectedUserIds,
|
|
filteredUsers,
|
|
showUserModal,
|
|
editingUser,
|
|
showBatchEditModal,
|
|
batchEditForm,
|
|
showBatchPermissionModal,
|
|
batchPermissionForm,
|
|
showDeleteConfirmDialog,
|
|
deleteConfirmMessage,
|
|
loadAll,
|
|
openCreateUserModal,
|
|
openEditUserModal,
|
|
saveUser,
|
|
cleanRejectedUsers,
|
|
batchDeleteUsers,
|
|
toggleUserSelection,
|
|
toggleAllUsers,
|
|
openBatchEditModal,
|
|
openBatchPermissionModal,
|
|
submitBatchEdit,
|
|
submitBatchPermission,
|
|
closeDeleteConfirm,
|
|
confirmDelete,
|
|
} = useUsersAdmin();
|
|
|
|
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 admin-table-header--stacked">
|
|
<div>
|
|
<h2 class="section-title">{{ t('admin.user.title') }}</h2>
|
|
<p class="section-desc mt-1">{{ t('admin.user.subtitle') }}</p>
|
|
</div>
|
|
<div class="flex flex-wrap gap-3">
|
|
<button
|
|
type="button"
|
|
class="flex items-center gap-2 px-4 py-2 bg-red-50 text-red-600 rounded-xl hover:bg-red-100 transition-all border border-red-200 text-sm font-medium"
|
|
@click="cleanRejectedUsers"
|
|
>
|
|
<Trash2 class="w-4 h-4" />
|
|
<span>{{ t('admin.user.cleanRejected') }}</span>
|
|
</button>
|
|
<button
|
|
v-if="selectedUserIds.length > 0"
|
|
type="button"
|
|
class="flex items-center gap-2 px-4 py-2 bg-red-600 text-white rounded-xl hover:bg-red-700 transition-all shadow-lg shadow-red-200 active:scale-95 text-sm font-medium"
|
|
@click="batchDeleteUsers"
|
|
>
|
|
<Trash2 class="w-4 h-4" />
|
|
<span>{{ t('admin.user.batchDelete') }} ({{ selectedUserIds.length }})</span>
|
|
</button>
|
|
<button
|
|
v-if="selectedUserIds.length > 0"
|
|
type="button"
|
|
class="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-xl hover:bg-indigo-700 transition-all shadow-lg shadow-indigo-200 active:scale-95 text-sm font-medium"
|
|
@click="openBatchEditModal"
|
|
>
|
|
<Edit class="w-4 h-4" />
|
|
<span>{{ t('admin.user.batchEdit') }} ({{ selectedUserIds.length }})</span>
|
|
</button>
|
|
<button
|
|
v-if="selectedUserIds.length > 0"
|
|
type="button"
|
|
class="flex items-center gap-2 px-4 py-2 bg-purple-600 text-white rounded-xl hover:bg-purple-700 transition-all shadow-lg shadow-purple-200 active:scale-95 text-sm font-medium"
|
|
@click="openBatchPermissionModal"
|
|
>
|
|
<Users class="w-4 h-4" />
|
|
<span>{{ t('admin.user.batchPermission') }} ({{ selectedUserIds.length }})</span>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="flex items-center gap-2 px-4 py-2 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-all shadow-lg shadow-brand-200 active:scale-95 text-sm font-medium"
|
|
@click="openCreateUserModal"
|
|
>
|
|
<Plus class="w-4 h-4" />
|
|
<span class="font-medium">{{ t('admin.user.addUser') }}</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="admin-table-filters grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5">
|
|
<input v-model="userFilters.username" :placeholder="t('admin.user.filterUsername')" class="admin-table-filter-input" />
|
|
<input v-model="userFilters.email" :placeholder="t('admin.user.filterEmail')" class="admin-table-filter-input" />
|
|
<select v-model="userFilters.department" class="admin-table-filter-input">
|
|
<option value="">{{ t('admin.user.allDepts') }}</option>
|
|
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
|
|
</select>
|
|
<input v-model="userFilters.role" :placeholder="t('admin.user.filterRole')" class="admin-table-filter-input" />
|
|
<div class="flex items-center gap-2">
|
|
<input id="hideRejectedUsers" v-model="hideRejected" type="checkbox" class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 border-default" />
|
|
<label for="hideRejectedUsers" class="text-sm text-secondary select-none">{{ t('admin.user.hideRejected') }}</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="admin-table-wrap">
|
|
<table class="admin-table">
|
|
<thead>
|
|
<tr>
|
|
<th class="px-6 py-4 w-12 text-center">
|
|
<input
|
|
type="checkbox"
|
|
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 cursor-pointer border-default"
|
|
:checked="selectedUserIds.length === filteredUsers.length && filteredUsers.length > 0"
|
|
@change="toggleAllUsers(filteredUsers)"
|
|
/>
|
|
</th>
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.headers.user') }}</th>
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.headers.role') }}</th>
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.headers.dept') }}</th>
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.headers.status') }}</th>
|
|
<th class="px-6 py-4 text-right text-xs">{{ t('admin.user.headers.actions') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-if="filteredUsers.length === 0">
|
|
<td colspan="6" class="px-6 admin-table-empty">{{ t('admin.user.noUsers') }}</td>
|
|
</tr>
|
|
<tr v-for="user in filteredUsers" :key="user.id" class="group">
|
|
<td class="px-6 py-4 text-center">
|
|
<input
|
|
type="checkbox"
|
|
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500 cursor-pointer border-default"
|
|
:checked="selectedUserIds.includes(user.id)"
|
|
@change="toggleUserSelection(user.id)"
|
|
/>
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<div class="flex items-center">
|
|
<div class="h-9 w-9 rounded-full bg-gradient-to-br from-brand-500 to-indigo-600 text-white flex items-center justify-center text-xs font-bold shadow-sm">
|
|
{{ user.username.charAt(0).toUpperCase() }}
|
|
</div>
|
|
<div class="ml-3">
|
|
<div class="text-sm font-medium text-primary">{{ user.username }}</div>
|
|
<div class="text-xs text-muted">{{ user.email }}</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<span
|
|
class="px-2.5 py-0.5 rounded-full text-xs font-medium border"
|
|
:class="user.role === 'admin' ? 'bg-purple-50 text-purple-700 border-purple-100' : 'bg-blue-50 text-blue-700 border-blue-100'"
|
|
>
|
|
{{ t('admin.role.' + user.role) }}
|
|
</span>
|
|
</td>
|
|
<td class="px-6 py-4 text-sm text-muted">{{ user.department || '-' }}</td>
|
|
<td class="px-6 py-4">
|
|
<span
|
|
class="px-2.5 py-0.5 rounded-full text-xs font-medium border"
|
|
:class="{
|
|
'bg-green-50 text-green-700 border-green-100': user.status === 'active',
|
|
'bg-yellow-50 text-yellow-700 border-yellow-100': user.status === 'pending',
|
|
'bg-red-50 text-red-700 border-red-100': user.status === 'disabled' || user.status === 'rejected',
|
|
}"
|
|
>
|
|
{{ t('admin.status.' + user.status) }}
|
|
</span>
|
|
</td>
|
|
<td class="px-6 py-4 text-right">
|
|
<button
|
|
type="button"
|
|
class="text-brand-600 hover:text-brand-900 font-medium text-xs px-3 py-1.5 rounded-lg hover:bg-brand-50 transition-colors"
|
|
@click="openEditUserModal(user)"
|
|
>
|
|
{{ t('admin.edit') }}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</template>
|
|
|
|
<UserFormModal
|
|
:visible="showUserModal"
|
|
:form="editingUser"
|
|
:agents="agents"
|
|
:departments="departments"
|
|
:is-saving="isSaving"
|
|
@close="showUserModal = false"
|
|
@save="saveUser"
|
|
/>
|
|
|
|
<BatchEditUserModal
|
|
:visible="showBatchEditModal"
|
|
:form="batchEditForm"
|
|
:departments="departments"
|
|
:selected-count="selectedUserIds.length"
|
|
:is-saving="isSaving"
|
|
@close="showBatchEditModal = false"
|
|
@save="submitBatchEdit"
|
|
/>
|
|
|
|
<BatchPermissionModal
|
|
:visible="showBatchPermissionModal"
|
|
:form="batchPermissionForm"
|
|
:agents="agents"
|
|
:selected-count="selectedUserIds.length"
|
|
:is-saving="isSaving"
|
|
@close="showBatchPermissionModal = false"
|
|
@save="submitBatchPermission"
|
|
/>
|
|
|
|
<DeleteConfirmDialog
|
|
v-model="showDeleteConfirmDialog"
|
|
:message="deleteConfirmMessage"
|
|
@confirm="confirmDelete"
|
|
@cancel="closeDeleteConfirm"
|
|
/>
|
|
</section>
|
|
</template>
|