Skip to content

Commit

Permalink
fix: 控制台数据
Browse files Browse the repository at this point in the history
  • Loading branch information
besscroft committed Apr 19, 2024
1 parent 201e505 commit b51c4fa
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
32 changes: 22 additions & 10 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,41 @@ import { Card, CardBody } from '@nextui-org/card'
import { Button } from '@nextui-org/react'
import Link from 'next/link'
import { Star, MessageSquareHeart } from 'lucide-react'
import { fetchImagesAnalysis } from '~/server/lib/query'

export default async function Admin() {
const getData = async () => {
'use server'
return await fetchImagesAnalysis()
}

const data = await getData() as {
total: number
showTotal: number
result: any[]
};

return (
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 sm:gap-6 md:gap-8 mt-4">
<Card isBlurred shadow="sm" className="h-48">
<CardBody className="flex flex-col p2 space-y-4">
<span className="font-light">照片数据</span>
<span className="text-xl font-semibold">10张</span>
<span className="text-xl font-semibold">{data.total || 0}</span>
<span className="font-light">显示照片</span>
<span className="text-xl font-semibold">1张</span>
<span className="text-xl font-semibold">{data.showTotal || 0}</span>
</CardBody>
</Card>
<Card isBlurred shadow="sm" className="h-48">
<CardBody className="grid grid-cols-2 gap-4">
<div className="flex flex-col space-y-4">
<span className="font-light">首页精选</span>
<span className="text-xl font-semibold">3 张</span>
</div>
<div className="flex flex-col space-y-4">
<span className="font-light">首页精选</span>
<span className="text-xl font-semibold">3 张</span>
</div>
{data.result ? data.result.map((item: any) => (
<div className="flex flex-col space-y-4">
<span className="font-light">{item?.tag}</span>
<span className="text-xl font-semibold">{item?._count.tag}</span>
</div>
))
:
<span>暂无分类数据</span>
}
</CardBody>
</Card>
<Card isBlurred shadow="sm" className="h-48">
Expand Down
39 changes: 37 additions & 2 deletions server/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export async function fetchServerImagesListByTag(pageNum: number, tag: string) {
}
},
orderBy: {
sort: 'desc'
sort: 'desc',
create_time: 'desc',
update_time: 'desc'
}
})

Expand Down Expand Up @@ -119,7 +121,9 @@ export async function fetchClientImagesListByTag(pageNum: number, tag: string) {
show: 0
},
orderBy: {
sort: 'desc'
sort: 'desc',
create_time: 'desc',
update_time: 'desc'
}
})

Expand Down Expand Up @@ -150,3 +154,34 @@ export async function fetchTagsShow() {

return findAll;
}

export async function fetchImagesAnalysis() {
const total = await db.images.count({
where: {
del: 0
},
});

const showTotal = await db.images.count({
where: {
del: 0,
show: 0
},
})

const result = await db.images.groupBy({
by: ['tag'],
_count: {
tag: true
},
where: {
del: 0
}
});

return {
total,
showTotal,
result
}
}

0 comments on commit b51c4fa

Please sign in to comment.