From b51c4fa8560db6a8aba5286135df9128052002a8 Mon Sep 17 00:00:00 2001 From: besscroft Date: Sat, 20 Apr 2024 00:36:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8E=A7=E5=88=B6=E5=8F=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/page.tsx | 32 ++++++++++++++++++++++---------- server/lib/query.ts | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/app/admin/page.tsx b/app/admin/page.tsx index 78bec6b..f02fe64 100644 --- a/app/admin/page.tsx +++ b/app/admin/page.tsx @@ -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 (
照片数据 - 10张 + {data.total || 0}张 显示照片 - 1张 + {data.showTotal || 0}张 -
- 首页精选 - 3 张 -
-
- 首页精选 - 3 张 -
+ {data.result ? data.result.map((item: any) => ( +
+ {item?.tag} + {item?._count.tag} 张 +
+ )) + : + 暂无分类数据 + }
diff --git a/server/lib/query.ts b/server/lib/query.ts index b0f8b7c..0480b65 100644 --- a/server/lib/query.ts +++ b/server/lib/query.ts @@ -74,7 +74,9 @@ export async function fetchServerImagesListByTag(pageNum: number, tag: string) { } }, orderBy: { - sort: 'desc' + sort: 'desc', + create_time: 'desc', + update_time: 'desc' } }) @@ -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' } }) @@ -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 + } +}