feat: update backend

This commit is contained in:
yanghao05
2025-04-01 16:21:43 +08:00
parent 473f9d8e31
commit f696dfdfe8
17 changed files with 1958 additions and 43 deletions

View File

@@ -0,0 +1,135 @@
<template>
<div class="home-page">
<h1>仪表盘</h1>
<div class="statistics-container">
<div class="stat-card" @click="navigateTo('/posts')">
<div class="stat-icon">
<i class="fa fa-file-text"></i>
</div>
<div class="stat-content">
<h2>文章数量</h2>
<div class="stat-value">{{ postCount }}</div>
</div>
</div>
<div class="stat-card" @click="navigateTo('/medias')">
<div class="stat-icon">
<i class="fa fa-image"></i>
</div>
<div class="stat-content">
<h2>媒体数量</h2>
<div class="stat-value">{{ mediaCount }}</div>
</div>
</div>
</div>
<div v-if="error" class="error-message">
{{ error }}
</div>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { statisticsService } from '../api/statisticsService';
const router = useRouter();
const postCount = ref(0);
const mediaCount = ref(0);
const error = ref('');
const loading = ref(false);
const fetchStatistics = async () => {
loading.value = true;
error.value = '';
try {
// Option 1: Make parallel requests using our service
const [postsData, mediasData] = await Promise.all([
statisticsService.getPostsCount(),
statisticsService.getMediasCount()
]);
postCount.value = postsData.count;
mediaCount.value = mediasData.count;
// Option 2: If you have a combined endpoint
// const data = await statisticsService.getAllStatistics();
// postCount.value = data.posts;
// mediaCount.value = data.medias;
} catch (err) {
console.error('Error fetching statistics:', err);
error.value = '获取统计数据时出错';
} finally {
loading.value = false;
}
};
const navigateTo = (path) => {
router.push(path);
};
onMounted(() => {
fetchStatistics();
});
</script>
<style scoped>
.home-page {
padding: 20px;
}
.statistics-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-top: 20px;
}
.stat-card {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 20px;
display: flex;
min-width: 250px;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
transform: translateY(-5px);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}
.stat-icon {
font-size: 2.5rem;
margin-right: 20px;
color: #3498db;
display: flex;
align-items: center;
}
.stat-content h2 {
margin: 0 0 10px 0;
font-size: 1.2rem;
color: #555;
}
.stat-value {
font-size: 2rem;
font-weight: bold;
color: #333;
}
.error-message {
margin-top: 20px;
padding: 10px;
background-color: #ffecec;
color: #f44336;
border-radius: 4px;
border-left: 4px solid #f44336;
}
</style>