feat: update page

This commit is contained in:
yanghao05
2025-04-09 21:03:23 +08:00
parent 2346983d67
commit 1f27611dc7
7 changed files with 203 additions and 105 deletions

View File

@@ -39,6 +39,11 @@ const mediaTypeOptions = ref([
const globalFilterValue = ref('');
const loading = ref(false);
const searchTimeout = ref(null);
const filters = ref({
global: { value: null, matchMode: 'contains' },
status: { value: null, matchMode: 'equals' },
mediaTypes: { value: null, matchMode: 'equals' }
});
// Sample data - in a real app, this would come from an API
const posts = ref([]);
@@ -50,9 +55,8 @@ const total = ref(0); // 总记录数
// Status mapping
const statusMap = {
1: '发布',
2: '草稿',
3: '已下架'
0: '发布',
1: '草稿',
};
// Transform assets to media types
@@ -90,9 +94,22 @@ const confirmDelete = (post) => {
icon: 'pi pi-exclamation-triangle',
acceptClass: 'p-button-danger',
accept: () => {
// In a real app, you would call an API to delete the post
posts.value = posts.value.filter(p => p.id !== post.id);
toast.add({ severity: 'success', summary: '成功', detail: '文章已删除', life: 3000 });
// // In a real app, you would call an API to delete the post
// posts.value = posts.value.filter(p => p.id !== post.id);
// toast.add({ severity: 'success', summary: '成功', detail: '文章已删除', life: 3000 });
// call remote delete
postService.deletePost(post.id)
.then(() => {
// toast success
toast.add({ severity: 'success', summary: '成功', detail: '文章已删除', life: 3000 });
fetchPosts();
})
.catch(error => {
console.error('Delete error:', error); // Debug log
toast.add({ severity: 'error', summary: '错误', detail: '删除文章失败', life: 3000 });
});
}
});
};
@@ -217,9 +234,8 @@ const formatMediaTypes = (mediaTypes) => {
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
:rowsPerPageOptions="[10, 20, 50]"
currentPageReportTemplate="显示第 {first} 到 {last} 条,共 {totalRecords} 条结果" dataKey="id"
:globalFilterFields="['title', 'description', 'status']"
:filters="{ global: { value: globalFilterValue, matchMode: 'contains' } }" stripedRows removableSort
class="p-datatable-sm" responsiveLayout="scroll">
:globalFilterFields="['title', 'description', 'status']" :filters="filters.value" stripedRows
removableSort class="p-datatable-sm" responsiveLayout="scroll">
<template #empty>
<div class="text-center p-4">未找到文章</div>