统计不生效问题解决
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export function getDashboardStats() {
|
||||
return request.get('/api/app/dashboard/stats')
|
||||
}
|
||||
|
||||
export function getAdminDashboardStats() {
|
||||
return request.get('/api/admin/dashboard/stats')
|
||||
}
|
||||
@@ -3,22 +3,35 @@
|
||||
<h2 class="page-title">管理后台仪表盘</h2>
|
||||
<el-row :gutter="20" style="margin-top: var(--spacing-xl);">
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card"><el-statistic title="用户数" :value="0" /></el-card>
|
||||
<el-card class="stat-card"><el-statistic title="用户数" :value="stats.userCount" /></el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card"><el-statistic title="文章数" :value="0" /></el-card>
|
||||
<el-card class="stat-card"><el-statistic title="文章数" :value="stats.articleCount" /></el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card"><el-statistic title="评论数" :value="0" /></el-card>
|
||||
<el-card class="stat-card"><el-statistic title="评论数" :value="stats.commentCount" /></el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card class="stat-card"><el-statistic title="今日访问" :value="0" /></el-card>
|
||||
<el-card class="stat-card"><el-statistic title="今日访问" :value="stats.todayVisits" /></el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { getAdminDashboardStats } from '@/api/dashboard'
|
||||
|
||||
const stats = ref({ userCount: 0, articleCount: 0, commentCount: 0, todayVisits: 0 })
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const res = await getAdminDashboardStats()
|
||||
stats.value = res.data
|
||||
} catch (e) {
|
||||
console.error('Failed to load admin dashboard stats:', e)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
<el-col :span="8">
|
||||
<el-card class="stat-card">
|
||||
<el-icon class="stat-icon" size="24"><Document /></el-icon>
|
||||
<el-statistic title="我的文章" :value="0" />
|
||||
<el-statistic title="我的文章" :value="stats.articleCount" />
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-card class="stat-card">
|
||||
<el-icon class="stat-icon" size="24"><View /></el-icon>
|
||||
<el-statistic title="总浏览量" :value="0" />
|
||||
<el-statistic title="总浏览量" :value="stats.totalViews" />
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-card class="stat-card">
|
||||
<el-icon class="stat-icon" size="24"><Star /></el-icon>
|
||||
<el-statistic title="获赞数" :value="0" />
|
||||
<el-statistic title="获赞数" :value="stats.totalLikes" />
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -28,8 +28,23 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { getDashboardStats } from '@/api/dashboard'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const stats = ref({ articleCount: 0, totalViews: 0, totalLikes: 0 })
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
console.log('Dashboard: fetching stats...')
|
||||
const res = await getDashboardStats()
|
||||
console.log('Dashboard: stats response:', res)
|
||||
stats.value = res.data
|
||||
} catch (e) {
|
||||
console.error('Failed to load dashboard stats:', e)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user