Files
syops/frontend/src/features/admin/modules/users/UsersPage.vue
T

289 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* features/admin/modules/users/UsersPage.vue
* 用途:用户管理独立页面(服务端筛选分页、用户/部门列排序、批量操作)。
* 依赖:useUsersAdmin、SortableTableHeader、PaginationBar、用户相关 Modal。
* 逻辑:路由 /admin/users;列表经 listAdminUsersPage 按页拉取,表头排序复用 shared 组件。
*/
<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 PaginationBar from '@/shared/components/PaginationBar.vue';
import SortableTableHeader from '@/shared/components/SortableTableHeader.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,
isListLoading,
isSaving,
userFilters,
sortKey,
sortDir,
// hideRejected,
selectedUserIds,
users,
usersTotal,
userPage,
userPageSize,
userPageSizeOptions,
usersPages,
allPaginatedUsersSelected,
showUserModal,
editingUser,
showBatchEditModal,
batchEditForm,
showBatchPermissionModal,
batchPermissionForm,
showDeleteConfirmDialog,
deleteConfirmMessage,
loadAll,
toggleSort,
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--inline gap-3">
<input v-model="userFilters.username" :placeholder="t('admin.user.filterUsername')" class="admin-table-filter-input w-40" />
<input v-model="userFilters.real_name" :placeholder="t('admin.user.filterRealName')" class="admin-table-filter-input w-44" />
<select v-model="userFilters.department" class="admin-table-filter-input w-40">
<option value="">{{ t('admin.user.allDepts') }}</option>
<option v-for="d in departments" :key="d.id" :value="d.name">{{ d.name }}</option>
</select>
<!-- 暂隐藏:隐藏已拒绝
<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 relative">
<div
v-if="isListLoading"
class="absolute inset-0 z-10 flex items-center justify-center rounded-2xl bg-surface/60"
>
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600" />
</div>
<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="allPaginatedUsersSelected"
@change="toggleAllUsers(users)"
/>
</th>
<th class="px-6 py-4 text-left text-xs">
<SortableTableHeader
column-key="username"
:label="t('admin.user.headers.user')"
:active-key="sortKey"
:direction="sortDir"
@sort="toggleSort"
/>
</th>
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.fields.realName') }}</th>
<th class="px-6 py-4 text-left text-xs">
<SortableTableHeader
column-key="department"
:label="t('admin.user.headers.dept')"
:active-key="sortKey"
:direction="sortDir"
@sort="toggleSort"
/>
</th>
<th class="px-6 py-4 text-left text-xs">{{ t('admin.user.headers.role') }}</th>
<th class="px-6 py-4 text-right text-xs">{{ t('admin.user.headers.actions') }}</th>
</tr>
</thead>
<tbody>
<tr v-if="usersTotal === 0 && !isListLoading">
<td colspan="6" class="px-6 admin-table-empty">{{ t('admin.user.noUsers') }}</td>
</tr>
<tr v-for="user in users" :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 text-sm font-medium text-primary">{{ user.username }}</div>
</div>
</td>
<td class="px-6 py-4 text-sm text-primary">{{ user.real_name || '-' }}</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="user.role === 'admin'
? 'bg-purple-50 text-purple-700 border-purple-100'
: user.role === 'hr'
? 'bg-emerald-50 text-emerald-700 border-emerald-100'
: 'bg-blue-50 text-blue-700 border-blue-100'"
>
{{ t('admin.role.' + user.role) }}
</span>
<div v-if="user.feature_permissions?.training_hr_manage" class="mt-2">
<span class="inline-flex rounded-full border border-brand-100 bg-brand-50 px-2.5 py-0.5 text-xs font-medium text-brand-700">
{{ t('admin.user.fields.trainingHrManage') }}
</span>
</div>
</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>
<div class="px-4 pb-4 pt-2">
<PaginationBar
v-model:page="userPage"
v-model:page-size="userPageSize"
:total="usersTotal"
:pages="usersPages"
:page-size-options="[...userPageSizeOptions]"
/>
</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>