diff --git a/apps/server/src/queue/models/post/utils.ts b/apps/server/src/queue/models/post/utils.ts index 7f2b69d..0b25170 100644 --- a/apps/server/src/queue/models/post/utils.ts +++ b/apps/server/src/queue/models/post/utils.ts @@ -7,11 +7,18 @@ import { VisitType, } from '@nice/common'; export async function updateTotalCourseViewCount(type: VisitType) { - const courses = await db.post.findMany({ - where: { type: PostType.COURSE }, - select: { id: true }, + const posts = await db.post.findMany({ + where: { + type: { in: [PostType.COURSE, PostType.LECTURE] }, + deletedAt: null, + }, + select: { id: true, type: true }, }); - const courseIds = courses.map((course) => course.id); + + const courseIds = posts + .filter((post) => post.type === PostType.COURSE) + .map((course) => course.id); + const lectures = posts.filter((post) => post.type === PostType.LECTURE); const totalViews = await db.visit.aggregate({ _sum: { views: true, @@ -30,6 +37,10 @@ export async function updateTotalCourseViewCount(type: VisitType) { meta: true, }, }); + const staffs = await db.staff.count({ + where: { deletedAt: null }, + }); + const baseSeting = appConfig.meta as BaseSetting; await db.appConfig.update({ where: { @@ -38,7 +49,15 @@ export async function updateTotalCourseViewCount(type: VisitType) { data: { meta: { ...baseSeting, - reads: totalViews._sum.views, + appConfig: { + ...(baseSeting?.appConfig || {}), + statistics: { + reads: totalViews._sum.views || 0, + courses: courseIds?.length || 0, + staffs: staffs || 0, + lectures: lectures?.length || 0, + }, + }, }, }, }); diff --git a/apps/web/src/app/main/home/components/HeroSection.tsx b/apps/web/src/app/main/home/components/HeroSection.tsx index 5a58d12..0399c32 100755 --- a/apps/web/src/app/main/home/components/HeroSection.tsx +++ b/apps/web/src/app/main/home/components/HeroSection.tsx @@ -45,16 +45,16 @@ const carouselItems: CarouselItem[] = [ }, ]; -const platformStats: PlatformStat[] = [ - { icon: , value: "50,000+", label: "注册学员" }, - { icon: , value: "1,000+", label: "精品课程" }, - // { icon: , value: '98%', label: '好评度' }, - { icon: , value: "100万+", label: "观看次数" }, -]; - const HeroSection = () => { const carouselRef = useRef(null); + const { statistics, baseSetting } = useAppConfig(); + const platformStats: PlatformStat[] = [ + { icon: , value: "50,000+", label: "注册学员" }, + { icon: , value: "1,000+", label: "精品课程" }, + // { icon: , value: '98%', label: '好评度' }, + { icon: , value: "4552", label: "观看次数" }, + ]; const handlePrev = useCallback(() => { carouselRef.current?.prev(); }, []); @@ -74,8 +74,8 @@ const HeroSection = () => { dots={{ className: "carousel-dots !bottom-32 !z-20", }}> - {Array.isArray(carouselItems)? - (carouselItems.map((item, index) => ( + {Array.isArray(carouselItems) ? ( + carouselItems.map((item, index) => (
{ {/* Content Container */}
- ))) - :( -
- ) - } + )) + ) : ( +
+ )} {/* Navigation Buttons */} diff --git a/apps/web/src/app/main/layout/UserMenu/types.ts b/apps/web/src/app/main/layout/UserMenu/types.ts index f21be44..dfe4b00 100644 --- a/apps/web/src/app/main/layout/UserMenu/types.ts +++ b/apps/web/src/app/main/layout/UserMenu/types.ts @@ -1,6 +1,6 @@ -import React from "react"; +import React, { ReactNode } from "react"; export interface MenuItemType { - icon: React.; + icon: ReactNode; label: string; action: () => void; } diff --git a/apps/web/src/components/models/course/detail/CourseDetailSkeleton.tsx b/apps/web/src/components/models/course/detail/CourseDetailSkeleton.tsx index 95b1049..ad58cb8 100755 --- a/apps/web/src/components/models/course/detail/CourseDetailSkeleton.tsx +++ b/apps/web/src/components/models/course/detail/CourseDetailSkeleton.tsx @@ -2,6 +2,7 @@ import { SkeletonItem, SkeletonSection, } from "@web/src/components/presentation/Skeleton"; +import { api } from "packages/client/dist"; export const CourseDetailSkeleton = () => { return ( diff --git a/apps/web/src/hooks/useTusUpload.ts b/apps/web/src/hooks/useTusUpload.ts index a4589a5..3f6d038 100755 --- a/apps/web/src/hooks/useTusUpload.ts +++ b/apps/web/src/hooks/useTusUpload.ts @@ -15,7 +15,7 @@ export function useTusUpload() { >({}); const [isUploading, setIsUploading] = useState(false); const [uploadError, setUploadError] = useState(null); - + const getFileId = (url: string) => { const parts = url.split("/"); const uploadIndex = parts.findIndex((part) => part === "upload"); diff --git a/packages/client/src/api/hooks/useAppConfig.ts b/packages/client/src/api/hooks/useAppConfig.ts index 5be578e..f38b6de 100755 --- a/packages/client/src/api/hooks/useAppConfig.ts +++ b/packages/client/src/api/hooks/useAppConfig.ts @@ -10,6 +10,7 @@ export function useAppConfig() { api.app_config.findFirst.useQuery({ where: { slug: AppConfigSlug.BASE_SETTING }, }); + const handleMutationSuccess = useCallback(() => { utils.app_config.invalidate(); }, [utils]); @@ -26,7 +27,8 @@ export function useAppConfig() { }); useEffect(() => { if (data?.meta) { - setBaseSetting(JSON.parse(data?.meta)); + // console.log(JSON.parse(data?.meta)); + setBaseSetting(data?.meta); } }, [data, isLoading]); const splashScreen = useMemo(() => { @@ -38,6 +40,16 @@ export function useAppConfig() { const slides = useMemo(() => { return baseSetting?.appConfig?.slides || []; }, [baseSetting]); + const statistics = useMemo(() => { + return ( + baseSetting?.appConfig?.statistics || { + reads: 0, + staffs: 0, + courses: 0, + lectures: 0, + } + ); + }, [baseSetting]); return { create, deleteMany, @@ -47,5 +59,6 @@ export function useAppConfig() { devDept, isLoading, slides, + statistics, }; } diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 2a081c0..0207fb7 100755 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -44,7 +44,12 @@ export interface BaseSetting { splashScreen?: string; devDept?: string; slides?: []; - reads?: number; + statistics?: { + reads?: number; + courses?: number; + lectures?: number; + staffs?: number; + }; }; } export type RowModelResult = {