185 lines
6.4 KiB
Vue
185 lines
6.4 KiB
Vue
/**
|
||
* features/admin/modules/departments/DepartmentsPage.vue
|
||
* 用途:部门管理独立页面——全宽表格列表 + 列排序 + 创建/编辑居中弹窗。
|
||
* 依赖:useDepartmentsAdmin、SortableTableHeader、DepartmentFormModal、DeleteConfirmDialog。
|
||
* 逻辑:路由 /admin/departments;表头排序复用 shared SortableTableHeader + useTableSort。
|
||
*/
|
||
<script setup lang="ts">
|
||
import { onMounted } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { Edit, Plus, Search, Trash2 } from 'lucide-vue-next';
|
||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||
import SortableTableHeader from '@/shared/components/SortableTableHeader.vue';
|
||
import DepartmentFormModal from './components/DepartmentFormModal.vue';
|
||
import { useDepartmentsAdmin } from './composables/useDepartmentsAdmin';
|
||
|
||
const { t } = useI18n();
|
||
|
||
const {
|
||
filteredDepartments,
|
||
form,
|
||
searchQuery,
|
||
sortKey,
|
||
sortDir,
|
||
isLoading,
|
||
isSaving,
|
||
showFormModal,
|
||
showDeleteConfirmDialog,
|
||
deleteConfirmMessage,
|
||
loadAll,
|
||
toggleSort,
|
||
openCreateModal,
|
||
openEditModal,
|
||
closeFormModal,
|
||
saveDepartment,
|
||
deleteDepartment,
|
||
closeDeleteConfirm,
|
||
confirmDelete,
|
||
} = useDepartmentsAdmin();
|
||
|
||
onMounted(() => {
|
||
void loadAll();
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<section class="admin-table-section 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="admin-table-header admin-table-header--stacked">
|
||
<div>
|
||
<h2 class="section-title">{{ t('admin.dept.title') }}</h2>
|
||
<p class="section-desc mt-1">{{ t('admin.dept.subtitle') }}</p>
|
||
</div>
|
||
<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="openCreateModal"
|
||
>
|
||
<Plus class="w-4 h-4" />
|
||
<span>{{ t('admin.dept.add') }}</span>
|
||
</button>
|
||
</div>
|
||
|
||
<div class="admin-table-filters--inline gap-3">
|
||
<div class="relative flex-1 min-w-[200px] max-w-sm">
|
||
<Search class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted pointer-events-none" />
|
||
<input
|
||
v-model="searchQuery"
|
||
type="search"
|
||
class="admin-table-filter-input w-full pl-9"
|
||
:placeholder="t('admin.dept.searchPlaceholder')"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="admin-table-wrap">
|
||
<!-- 列宽:名称 / 编码 / 公司 / 操作 -->
|
||
<table class="admin-table table-fixed">
|
||
<colgroup>
|
||
<col class="w-[25%]" />
|
||
<col class="w-[20%]" />
|
||
<col class="w-[35%]" />
|
||
<col class="w-[15%]" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr>
|
||
<th class="px-6 py-4 text-left text-xs">
|
||
<SortableTableHeader
|
||
column-key="name"
|
||
:label="t('admin.dept.headers.name')"
|
||
:active-key="sortKey"
|
||
:direction="sortDir"
|
||
@sort="toggleSort"
|
||
/>
|
||
</th>
|
||
<th class="px-6 py-4 text-left text-xs">
|
||
<SortableTableHeader
|
||
column-key="code"
|
||
:label="t('admin.dept.headers.code')"
|
||
:active-key="sortKey"
|
||
:direction="sortDir"
|
||
@sort="toggleSort"
|
||
/>
|
||
</th>
|
||
<th class="px-6 py-4 text-left text-xs">
|
||
<SortableTableHeader
|
||
column-key="company"
|
||
:label="t('admin.dept.headers.company')"
|
||
:active-key="sortKey"
|
||
:direction="sortDir"
|
||
@sort="toggleSort"
|
||
/>
|
||
</th>
|
||
<th class="px-6 py-4 text-right text-xs">{{ t('admin.dept.headers.actions') }}</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-if="filteredDepartments.length === 0">
|
||
<td colspan="4" class="px-6 admin-table-empty">
|
||
{{ searchQuery.trim() ? t('admin.dept.noSearchResults') : t('admin.dept.noDepts') }}
|
||
</td>
|
||
</tr>
|
||
<tr v-for="d in filteredDepartments" :key="d.id" class="group">
|
||
<td class="px-6 py-4">
|
||
<div class="font-medium text-primary text-sm truncate" :title="d.name">{{ d.name }}</div>
|
||
<div
|
||
v-if="d.description"
|
||
class="text-xs text-muted truncate mt-0.5"
|
||
:title="d.description"
|
||
>
|
||
{{ d.description }}
|
||
</div>
|
||
</td>
|
||
<td class="px-6 py-4 text-sm text-muted font-mono whitespace-nowrap truncate" :title="d.code || '-'">
|
||
{{ d.code || '-' }}
|
||
</td>
|
||
<td class="px-6 py-4 text-sm text-muted truncate" :title="d.company || '-'">
|
||
{{ d.company || '-' }}
|
||
</td>
|
||
<td class="px-6 py-4">
|
||
<div class="flex justify-end gap-1">
|
||
<button
|
||
type="button"
|
||
class="p-1.5 text-indigo-600 hover:bg-indigo-50 rounded-lg transition-colors"
|
||
:title="t('admin.dept.actions.edit')"
|
||
@click="openEditModal(d)"
|
||
>
|
||
<Edit class="w-4 h-4" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="p-1.5 text-red-600 hover:bg-red-50 rounded-lg transition-colors"
|
||
:title="t('admin.dept.actions.delete')"
|
||
@click="deleteDepartment(d.id)"
|
||
>
|
||
<Trash2 class="w-4 h-4" />
|
||
</button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</template>
|
||
|
||
<DepartmentFormModal
|
||
:visible="showFormModal"
|
||
:form="form"
|
||
:is-saving="isSaving"
|
||
@close="closeFormModal"
|
||
@save="saveDepartment"
|
||
/>
|
||
|
||
<DeleteConfirmDialog
|
||
v-model="showDeleteConfirmDialog"
|
||
:message="deleteConfirmMessage"
|
||
@cancel="closeDeleteConfirm"
|
||
@confirm="confirmDelete"
|
||
/>
|
||
</section>
|
||
</template>
|