Files
syops/frontend/src/features/admin/modules/departments/DepartmentsPage.vue
T
sophie 61693d014d refactor: 重构前端骨架,及admin模块子路由和懒加载
refactor: 优化多次请求,并使用pinia状态管理
2026-06-03 10:30:16 +08:00

164 lines
5.8 KiB
Vue

/**
* features/admin/modules/departments/DepartmentsPage.vue
* 部门管理独立页面。路由:/admin/departments
*/
<script setup lang="ts">
import { onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { Edit, Trash2 } from 'lucide-vue-next';
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog.vue';
import { useDepartmentsAdmin } from './composables/useDepartmentsAdmin';
const { t } = useI18n();
const {
departments,
editingDept,
isLoading,
showDeleteConfirmDialog,
deleteConfirmMessage,
loadAll,
resetForm,
editDepartment,
saveDepartment,
deleteDepartment,
closeDeleteConfirm,
confirmDelete,
} = useDepartmentsAdmin();
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 items-center justify-between">
<div>
<h2 class="section-title">{{ t('admin.dept.title') }}</h2>
<p class="section-desc mt-1">{{ t('admin.dept.subtitle') }}</p>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div class="lg:col-span-1 card p-6 shadow-sm h-fit">
<h3 class="font-bold text-primary mb-4">
{{ editingDept.id ? t('admin.dept.edit') : t('admin.dept.add') }}
</h3>
<div class="form-stack">
<div class="space-y-1.5">
<label class="label-field block">{{ t('admin.dept.fields.name') }}</label>
<input
v-model="editingDept.name"
class="input-field text-sm"
:placeholder="t('admin.dept.fields.namePlaceholder')"
/>
</div>
<div class="space-y-1.5">
<label class="label-field">{{ t('admin.dept.fields.code') }}</label>
<input
v-model="editingDept.code"
class="input-field text-sm"
:placeholder="t('admin.dept.fields.codePlaceholder')"
/>
</div>
<div class="space-y-1.5">
<label class="label-field">{{ t('admin.dept.fields.company') }}</label>
<input
v-model="editingDept.company"
class="input-field text-sm"
:placeholder="t('admin.dept.fields.companyPlaceholder')"
/>
</div>
<div class="space-y-1.5">
<label class="label-field">{{ t('admin.dept.fields.description') }}</label>
<textarea
v-model="editingDept.description"
rows="3"
class="input-field text-sm"
:placeholder="t('admin.dept.fields.descriptionPlaceholder')"
/>
</div>
<div class="flex justify-end gap-2 pt-2">
<button
v-if="editingDept.id"
type="button"
class="btn-ghost btn-sm"
@click="resetForm"
>
{{ t('admin.cancel') }}
</button>
<button type="button" class="btn-primary btn-sm" @click="saveDepartment">
{{ editingDept.id ? t('admin.update') : t('admin.add') }}
</button>
</div>
</div>
</div>
<div class="lg:col-span-2 admin-table-section">
<div v-if="departments.length === 0" class="p-8 text-center text-muted">
{{ t('admin.dept.noDepts') }}
</div>
<table v-else class="admin-table">
<thead>
<tr>
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase">
{{ t('admin.dept.headers.name') }}
</th>
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase">
{{ t('admin.dept.headers.code') }}
</th>
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase">
{{ t('admin.dept.headers.company') }}
</th>
<th class="px-6 py-3 text-xs font-semibold text-muted uppercase text-right">
{{ t('admin.dept.headers.actions') }}
</th>
</tr>
</thead>
<tbody class="divide-y divide-subtle">
<tr v-for="d in departments" :key="d.id">
<td class="px-6 py-4">
<div class="font-medium text-primary text-sm">{{ d.name }}</div>
<div class="text-xs text-muted truncate max-w-xs mt-0.5">{{ d.description }}</div>
</td>
<td class="px-6 py-4 text-sm text-muted font-mono">{{ d.code || '-' }}</td>
<td class="px-6 py-4 text-sm text-muted">{{ d.company || '-' }}</td>
<td class="px-6 py-4 text-right flex justify-end gap-2">
<button
type="button"
class="p-1.5 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors"
@click="editDepartment(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"
@click="deleteDepartment(d.id)"
>
<Trash2 class="w-4 h-4" />
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<DeleteConfirmDialog
v-model="showDeleteConfirmDialog"
:message="deleteConfirmMessage"
@cancel="closeDeleteConfirm"
@confirm="confirmDelete"
/>
</section>
</template>