196 lines
7.3 KiB
Vue
196 lines
7.3 KiB
Vue
/**
|
|
* features/admin/modules/permissions/PermissionsPage.vue
|
|
* 用户权限矩阵独立页面。路由:/admin/permissions
|
|
*/
|
|
<script setup lang="ts">
|
|
import { onMounted } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { Download, FileText, Users } from 'lucide-vue-next';
|
|
import BatchPermissionModal from '@/features/admin/modules/users/components/BatchPermissionModal.vue';
|
|
import { usePermissionsAdmin } from './composables/usePermissionsAdmin';
|
|
|
|
const { t } = useI18n();
|
|
|
|
const {
|
|
agents,
|
|
permissionFilters,
|
|
selectedUserIds,
|
|
filteredUsers,
|
|
isLoading,
|
|
isSaving,
|
|
showBatchPermissionModal,
|
|
batchPermissionForm,
|
|
loadAll,
|
|
toggleUserSelection,
|
|
toggleAllUsers,
|
|
openBatchPermissionModal,
|
|
closeBatchPermissionModal,
|
|
submitBatchPermission,
|
|
toggleUserAgentPermission,
|
|
exportPermissions,
|
|
importPermissions,
|
|
} = usePermissionsAdmin();
|
|
|
|
onMounted(() => {
|
|
void loadAll();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<section class="section-gap animate-fade-in-up">
|
|
<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="flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
|
|
<div>
|
|
<h2 class="section-title">{{ t('admin.perm.title') }}</h2>
|
|
<p class="section-desc mt-1">{{ t('admin.perm.subtitle') }}</p>
|
|
</div>
|
|
<div class="flex gap-3">
|
|
<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"
|
|
@click="openBatchPermissionModal"
|
|
>
|
|
<Users class="w-4 h-4" />
|
|
<span class="font-medium">{{ t('admin.perm.batchAssign') }}</span>
|
|
</button>
|
|
<label
|
|
class="flex items-center gap-2 px-4 py-2 btn-secondary cursor-pointer text-sm font-medium transition-all shadow-sm"
|
|
>
|
|
<input type="file" accept=".csv" class="hidden" @change="importPermissions" />
|
|
<FileText class="w-4 h-4" />
|
|
{{ t('admin.perm.importCsv') }}
|
|
</label>
|
|
<button
|
|
type="button"
|
|
class="flex items-center gap-2 px-4 py-2 btn-secondary text-sm font-medium transition-all shadow-sm"
|
|
@click="exportPermissions"
|
|
>
|
|
<Download class="w-4 h-4" />
|
|
{{ t('admin.perm.exportCsv') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="admin-table-filters--inline">
|
|
<input
|
|
v-model="permissionFilters.username"
|
|
:placeholder="t('admin.perm.filterName')"
|
|
class="admin-table-filter-input w-48"
|
|
/>
|
|
<input
|
|
v-model="permissionFilters.department"
|
|
:placeholder="t('admin.perm.filterDept')"
|
|
class="admin-table-filter-input w-48"
|
|
/>
|
|
<select v-model="permissionFilters.role" class="admin-table-filter-input w-32">
|
|
<option value="">{{ t('admin.perm.allRoles') }}</option>
|
|
<option value="user">{{ t('admin.role.user') }}</option>
|
|
<option value="admin">{{ t('admin.role.admin') }}</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="admin-table-section admin-table-wrap">
|
|
<table class="admin-table">
|
|
<thead>
|
|
<tr>
|
|
<th class="px-4 py-4 w-12 text-center sticky left-0 admin-table-sticky-head z-20">
|
|
<input
|
|
type="checkbox"
|
|
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500"
|
|
:checked="selectedUserIds.length > 0 && selectedUserIds.length === filteredUsers.length"
|
|
@change="toggleAllUsers"
|
|
/>
|
|
</th>
|
|
<th
|
|
class="px-6 py-4 text-left text-sm sticky left-12 admin-table-sticky-head z-20 w-64 shadow-[2px_0_5px_-2px_rgba(0,0,0,0.1)]"
|
|
>
|
|
{{ t('admin.perm.headers.user') }}
|
|
</th>
|
|
<th
|
|
class="px-6 py-4 text-left text-sm sticky left-[19rem] admin-table-sticky-head z-20 w-40 border-r border-subtle shadow-[2px_0_5px_-2px_rgba(0,0,0,0.1)]"
|
|
>
|
|
{{ t('admin.perm.headers.dept') }}
|
|
</th>
|
|
<th
|
|
v-for="agent in agents"
|
|
:key="agent.id"
|
|
class="px-4 py-4 text-center text-sm min-w-[100px]"
|
|
>
|
|
<div class="flex flex-col items-center gap-1">
|
|
<span>{{ agent.name }}</span>
|
|
<span class="text-[10px] text-muted font-normal border border-default px-1 rounded">
|
|
{{ agent.type }}
|
|
</span>
|
|
</div>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="user in filteredUsers" :key="user.id">
|
|
<td class="px-4 py-4 text-center sticky left-0 admin-table-sticky-cell z-20">
|
|
<input
|
|
type="checkbox"
|
|
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500"
|
|
:checked="selectedUserIds.includes(user.id)"
|
|
@change="toggleUserSelection(user.id)"
|
|
/>
|
|
</td>
|
|
<td class="px-6 py-4 sticky left-12 admin-table-sticky-cell z-20 shadow-[2px_0_5px_-2px_rgba(0,0,0,0.05)]">
|
|
<div class="flex items-center gap-3">
|
|
<div
|
|
class="w-8 h-8 rounded-full bg-gradient-to-br from-brand-100 to-indigo-100 text-brand-600 flex items-center justify-center font-bold text-sm"
|
|
>
|
|
{{ user.username.charAt(0).toUpperCase() }}
|
|
</div>
|
|
<div class="truncate max-w-[150px]">
|
|
<div class="font-medium text-primary truncate" :title="user.username">
|
|
{{ user.username }}
|
|
</div>
|
|
<div class="text-xs text-muted truncate" :title="user.email">
|
|
{{ user.email }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td
|
|
class="px-6 py-4 sticky left-[19rem] admin-table-sticky-cell z-20 border-r border-subtle shadow-[2px_0_5px_-2px_rgba(0,0,0,0.05)]"
|
|
>
|
|
<div class="text-sm text-muted truncate" :title="user.department">
|
|
{{ user.department || '-' }}
|
|
</div>
|
|
</td>
|
|
<td
|
|
v-for="agent in agents"
|
|
:key="agent.id"
|
|
class="px-4 py-4 text-center border-l border-dashed border-subtle"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
class="admin-checkbox-lg"
|
|
:checked="user.agent_ids.includes(agent.id)"
|
|
@change="toggleUserAgentPermission(user, agent.id)"
|
|
/>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</template>
|
|
|
|
<BatchPermissionModal
|
|
:visible="showBatchPermissionModal"
|
|
:form="batchPermissionForm"
|
|
:agents="agents"
|
|
:selected-count="selectedUserIds.length"
|
|
:is-saving="isSaving"
|
|
@close="closeBatchPermissionModal"
|
|
@save="submitBatchPermission"
|
|
/>
|
|
</section>
|
|
</template>
|