153 lines
5.4 KiB
Vue
153 lines
5.4 KiB
Vue
/**
|
|
* features/admin/modules/announcements/AnnouncementsPage.vue
|
|
* 公告管理独立页面:全宽表格列表 + 发布/编辑/详情居中弹窗。
|
|
* 依赖:useAnnouncementsAdmin、AnnouncementFormModal、AnnouncementDetailModal、DeleteConfirmDialog。
|
|
* 逻辑:路由 /admin/announcements 挂载本页;列表摘要截断,完整内容在详情弹窗查看。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { onMounted } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { Edit, Eye, Plus, Trash2 } from 'lucide-vue-next';
|
|
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
|
import AnnouncementDetailModal from './components/AnnouncementDetailModal.vue';
|
|
import AnnouncementFormModal from './components/AnnouncementFormModal.vue';
|
|
import { useAnnouncementsAdmin } from './composables/useAnnouncementsAdmin';
|
|
|
|
const { t } = useI18n();
|
|
|
|
const {
|
|
announcements,
|
|
form,
|
|
viewingAnnouncement,
|
|
isLoading,
|
|
isSaving,
|
|
showFormModal,
|
|
showDetailModal,
|
|
showDeleteConfirmDialog,
|
|
deleteConfirmMessage,
|
|
loadAll,
|
|
openCreateModal,
|
|
openEditModal,
|
|
openDetailModal,
|
|
closeFormModal,
|
|
closeDetailModal,
|
|
editFromDetail,
|
|
saveAnnouncement,
|
|
deleteAnnouncementItem,
|
|
closeDeleteConfirm,
|
|
confirmDelete,
|
|
truncateAnnouncementPreview,
|
|
formatPublishedAt,
|
|
} = useAnnouncementsAdmin();
|
|
|
|
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.announcement.title') }}</h2>
|
|
<p class="section-desc mt-1">{{ t('admin.announcement.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.announcement.add') }}</span>
|
|
</button>
|
|
</div>
|
|
|
|
<div class="admin-table-wrap">
|
|
<table class="admin-table">
|
|
<thead>
|
|
<tr>
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.announcement.headers.title') }}</th>
|
|
<th class="px-6 py-4 text-left text-xs w-44">{{ t('admin.announcement.headers.publishedAt') }}</th>
|
|
<th class="px-6 py-4 text-left text-xs">{{ t('admin.announcement.headers.preview') }}</th>
|
|
<th class="px-6 py-4 text-right text-xs w-36">{{ t('admin.announcement.headers.actions') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-if="announcements.length === 0">
|
|
<td colspan="4" class="px-6 admin-table-empty">{{ t('admin.announcement.noData') }}</td>
|
|
</tr>
|
|
<tr v-for="ann in announcements" :key="ann.id" class="group">
|
|
<td class="px-6 py-4">
|
|
<div class="font-medium text-primary text-sm">{{ ann.title }}</div>
|
|
</td>
|
|
<td class="px-6 py-4 text-sm text-muted whitespace-nowrap">
|
|
{{ formatPublishedAt(ann.created_at) }}
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<p class="text-sm text-secondary truncate max-w-md" :title="ann.content">
|
|
{{ truncateAnnouncementPreview(ann.content) }}
|
|
</p>
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<div class="flex justify-end gap-1">
|
|
<button
|
|
type="button"
|
|
class="p-1.5 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors"
|
|
:title="t('admin.announcement.actions.view')"
|
|
@click="openDetailModal(ann)"
|
|
>
|
|
<Eye class="w-4 h-4" />
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="p-1.5 text-indigo-600 hover:bg-indigo-50 rounded-lg transition-colors"
|
|
:title="t('admin.announcement.actions.edit')"
|
|
@click="openEditModal(ann)"
|
|
>
|
|
<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.announcement.actions.delete')"
|
|
@click="deleteAnnouncementItem(ann.id)"
|
|
>
|
|
<Trash2 class="w-4 h-4" />
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</template>
|
|
|
|
<AnnouncementFormModal
|
|
:visible="showFormModal"
|
|
:form="form"
|
|
:is-saving="isSaving"
|
|
@close="closeFormModal"
|
|
@save="saveAnnouncement"
|
|
/>
|
|
|
|
<AnnouncementDetailModal
|
|
:visible="showDetailModal"
|
|
:announcement="viewingAnnouncement"
|
|
@close="closeDetailModal"
|
|
@edit="editFromDetail"
|
|
/>
|
|
|
|
<DeleteConfirmDialog
|
|
v-model="showDeleteConfirmDialog"
|
|
:message="deleteConfirmMessage"
|
|
@cancel="closeDeleteConfirm"
|
|
@confirm="confirmDelete"
|
|
/>
|
|
</section>
|
|
</template>
|