diff --git a/apps/web/src/app/main/courses/components/CourseCard.tsx b/apps/web/src/app/main/courses/components/CourseCard.tsx index 5d7c3cd..84688f3 100755 --- a/apps/web/src/app/main/courses/components/CourseCard.tsx +++ b/apps/web/src/app/main/courses/components/CourseCard.tsx @@ -1,49 +1,90 @@ -import { Card, Rate, Tag } from 'antd'; +import { Card, Rate, Tag ,Typography,Button} from 'antd'; import { Course } from '../mockData'; -import { UserOutlined, ClockCircleOutlined } from '@ant-design/icons'; +import { UserOutlined, ClockCircleOutlined, PlayCircleOutlined, TeamOutlined } from '@ant-design/icons'; import { CourseDto } from '@nice/common'; +import { useNavigate } from 'react-router-dom'; + interface CourseCardProps { course: CourseDto; } - +const { Title, Text } = Typography; export default function CourseCard({ course }: CourseCardProps) { + const navigate = useNavigate(); + const handleClick = (course: CourseDto) => { + navigate(`/course/${course.id}/detail`); + } return ( - handleClick(course)} + key={course.id} + hoverable + className="group overflow-hidden rounded-2xl border border-gray-200 bg-white + shadow-xl hover:shadow-2xl transition-all duration-300 transform hover:-translate-y-2" + cover={ +
+
- } - > -
-

- {course.title} -

-

{course.subTitle}

-
- - {course.rating} -
-
-
- - {course.enrollments?.length} 人在学 -
-
- - {course.duration} -
-
-
- {course.terms[0].name} - {course.terms[1].name} -
+
+
- + } + > +
+
+ + {course.terms[0].name} + + + {course.terms[1].name} + +
+ + <button > {course.title}</button> + + +
+ +
+ + {course?.depts[0]?.name} + +
+ + 观看次数{course?.meta?.views}次 + +
+ + +
+ +
+ +
+ ); } diff --git a/apps/web/src/app/main/home/components/CoursesSection.tsx b/apps/web/src/app/main/home/components/CoursesSection.tsx index b4938b0..ec2e759 100755 --- a/apps/web/src/app/main/home/components/CoursesSection.tsx +++ b/apps/web/src/app/main/home/components/CoursesSection.tsx @@ -1,6 +1,6 @@ import React, { useState, useMemo, useEffect } from 'react'; -import { useNavigate, useParams, useSearchParams } from 'react-router-dom'; -import { Button, Card, Typography, Tag, Progress, Spin, Empty } from 'antd'; +import { useNavigate } from 'react-router-dom'; +import { Button, Card, Typography, Tag, Spin, Empty } from 'antd'; import { PlayCircleOutlined, UserOutlined, @@ -12,7 +12,6 @@ import { } from '@ant-design/icons'; import { CourseDto, TaxonomySlug, TermDto } from '@nice/common'; import { api } from '@nice/client'; -// const {courseId} = useParams(); interface GetTaxonomyProps { categories: string[]; isLoading: boolean; @@ -39,6 +38,7 @@ function useGetTaxonomy({ type }): GetTaxonomyProps { }, [data]); return { categories, isLoading } } + // 不同分类跳转 function useFetchCoursesByCategory(category: string) { const isAll = category === '全部'; @@ -52,7 +52,8 @@ function useFetchCoursesByCategory(category: string) { }, take: 8, include: { - terms: true + terms: true, + depts:true } }); @@ -83,12 +84,9 @@ interface CoursesSectionProps { initialVisibleCoursesCount?: number; } - const CoursesSection: React.FC = ({ title, description, - courses, - isLoading, initialVisibleCoursesCount = 8, }) => { const navigate = useNavigate(); @@ -97,10 +95,11 @@ const CoursesSection: React.FC = ({ const gateGory: GetTaxonomyProps = useGetTaxonomy({ type: TaxonomySlug.CATEGORY, }) + const { data, isLoading: isDataLoading } = useFetchCoursesByCategory(selectedCategory); - useEffect(() => { - console.log('data:', data) - }) + // useEffect(() => { + // console.log('data:', data) + // }) const handleClick = (course: CourseDto) => { navigate(`/course/${course.id}/detail`); } @@ -108,6 +107,20 @@ const CoursesSection: React.FC = ({ useEffect(() => { console.log('data:', data) }) + + // const { data: depts, isLoading: isDeptLoading }: { data: CourseDto[], isLoading: boolean } = api.post.findMany.useQuery({ + // where: {}, + // include: { + // depts: true, + // }, + // orderBy: { + // createdAt: 'desc' // 按创建时间降序排列 + // }, + // take: 8 // 只获取前8个课程 + // }); + + + const filteredCourses = useMemo(() => { return selectedCategory === '全部' ? data @@ -115,6 +128,7 @@ const CoursesSection: React.FC = ({ }, [selectedCategory, data]); const displayedCourses = isDataLoading ? [] : filteredCourses?.slice(0, visibleCourses); + return (
@@ -170,8 +184,8 @@ const CoursesSection: React.FC = ({
- {displayedCourses.length=== 0 ? ( -
+ {displayedCourses.length === 0 ? ( +
) : displayedCourses?.map((course) => ( @@ -223,14 +237,16 @@ const CoursesSection: React.FC = ({
- + + {course?.depts[0]?.name}
- - - 观看次数{course?.meta?.views}次 + + 观看次数{course?.meta?.views}次
+ +