fix(notice): 修改管理控制台公告布局,并在首页滚动显示
This commit is contained in:
1 parent
ced7fbe085
commit
d4f629106f
18 files changed
+737
-105
No files matched your search
@@ -1,28 +1,43 @@
|
||||
/**
|
||||
* features/admin/modules/announcements/AnnouncementsPage.vue
|
||||
* 公告管理独立页面。路由:/admin/announcements
|
||||
* 公告管理独立页面:全宽表格列表 + 发布/编辑/详情居中弹窗。
|
||||
* 依赖:useAnnouncementsAdmin、AnnouncementFormModal、AnnouncementDetailModal、DeleteConfirmDialog。
|
||||
* 逻辑:路由 /admin/announcements 挂载本页;列表摘要截断,完整内容在详情弹窗查看。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Trash2 } from 'lucide-vue-next';
|
||||
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,
|
||||
newAnnouncement,
|
||||
form,
|
||||
viewingAnnouncement,
|
||||
isLoading,
|
||||
isSaving,
|
||||
showFormModal,
|
||||
showDetailModal,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
publishAnnouncement,
|
||||
openCreateModal,
|
||||
openEditModal,
|
||||
openDetailModal,
|
||||
closeFormModal,
|
||||
closeDetailModal,
|
||||
editFromDetail,
|
||||
saveAnnouncement,
|
||||
deleteAnnouncementItem,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
truncateAnnouncementPreview,
|
||||
formatPublishedAt,
|
||||
} = useAnnouncementsAdmin();
|
||||
|
||||
onMounted(() => {
|
||||
@@ -31,72 +46,102 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="section-gap animate-fade-in-up">
|
||||
<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>
|
||||
<h2 class="section-title">{{ t('admin.announcement.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.announcement.subtitle') }}</p>
|
||||
<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="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">{{ t('admin.announcement.add') }}</h3>
|
||||
<div class="space-y-4">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.announcement.fields.title') }}</label>
|
||||
<input v-model="newAnnouncement.title" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.announcement.fields.content') }}</label>
|
||||
<textarea v-model="newAnnouncement.content" rows="6" class="input-field text-sm" />
|
||||
</div>
|
||||
<div class="flex justify-end pt-2">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary btn-sm disabled:opacity-50"
|
||||
:disabled="isSaving"
|
||||
@click="publishAnnouncement"
|
||||
>
|
||||
{{ isSaving ? t('admin.save') + '...' : t('admin.announcement.publish') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="lg:col-span-2 card shadow-sm overflow-hidden">
|
||||
<div v-if="announcements.length === 0" class="p-8 text-center text-muted">
|
||||
{{ t('admin.announcement.noData') }}
|
||||
</div>
|
||||
<div v-else class="divide-y divide-subtle">
|
||||
<div
|
||||
v-for="ann in announcements"
|
||||
:key="ann.id"
|
||||
class="p-5 hover-surface-soft transition-colors"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<h4 class="font-semibold text-primary truncate">{{ ann.title }}</h4>
|
||||
<p class="text-xs text-muted mt-1">{{ new Date(ann.created_at).toLocaleString() }}</p>
|
||||
<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>
|
||||
<button
|
||||
type="button"
|
||||
class="p-1.5 text-red-600 hover:bg-red-50 rounded-lg transition-colors"
|
||||
@click="deleteAnnouncementItem(ann.id)"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-sm text-secondary mt-2 whitespace-pre-wrap">{{ ann.content }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</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"
|
||||
|
||||
Reference in new issue
Block a user