From d60253fdf82ccb2b16e310c0da866851bccbd75a Mon Sep 17 00:00:00 2001 From: Rao <1227431568@qq.com> Date: Thu, 27 Feb 2025 12:28:03 +0800 Subject: [PATCH] rht --- .../courses/components/CoursesContainer.tsx | 3 +- apps/web/src/app/main/my-duty/page.tsx | 3 +- .../path/components/PathListContainer.tsx | 3 +- .../models/course/card/PostCard.tsx | 127 ++++++++++++++++++ 4 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 apps/web/src/components/models/course/card/PostCard.tsx diff --git a/apps/web/src/app/main/courses/components/CoursesContainer.tsx b/apps/web/src/app/main/courses/components/CoursesContainer.tsx index 237e8b3..944620f 100644 --- a/apps/web/src/app/main/courses/components/CoursesContainer.tsx +++ b/apps/web/src/app/main/courses/components/CoursesContainer.tsx @@ -3,6 +3,7 @@ import { PostType, Prisma } from "@nice/common"; import PostList from "@web/src/components/models/course/list/PostList"; import { useMemo } from "react"; import CourseCard from "./CourseCard"; +import PostCard from "@web/src/components/models/course/card/PostCard"; export function CoursesContainer() { const { searchValue, selectedTerms } = useMainContext(); @@ -18,7 +19,7 @@ export function CoursesContainer() { return ( <> } + renderItem={(post) => } params={{ pageSize: 12, where: { diff --git a/apps/web/src/app/main/my-duty/page.tsx b/apps/web/src/app/main/my-duty/page.tsx index 64a529f..a22e105 100644 --- a/apps/web/src/app/main/my-duty/page.tsx +++ b/apps/web/src/app/main/my-duty/page.tsx @@ -1,6 +1,7 @@ import PostList from "@web/src/components/models/course/list/PostList"; import { useAuth } from "@web/src/providers/auth-provider"; import CourseCard from "../courses/components/CourseCard"; +import PostCard from "@web/src/components/models/course/card/PostCard"; export default function MyDutyPage() { const { user } = useAuth(); @@ -8,7 +9,7 @@ export default function MyDutyPage() { <>
} + renderItem={post=>} params={{ pageSize: 12, diff --git a/apps/web/src/app/main/path/components/PathListContainer.tsx b/apps/web/src/app/main/path/components/PathListContainer.tsx index 125d9e8..41f67c5 100644 --- a/apps/web/src/app/main/path/components/PathListContainer.tsx +++ b/apps/web/src/app/main/path/components/PathListContainer.tsx @@ -3,6 +3,7 @@ import { useMainContext } from "../../layout/MainProvider"; import { PostType, Prisma } from "@nice/common"; import { useMemo } from "react"; import PathCard from "./PathCard"; +import PostCard from "@web/src/components/models/course/card/PostCard"; export function PathListContainer() { const { searchValue, selectedTerms } = useMainContext(); @@ -18,7 +19,7 @@ export function PathListContainer() { return ( <> } + renderItem={(post) => } params={{ pageSize: 12, where: { diff --git a/apps/web/src/components/models/course/card/PostCard.tsx b/apps/web/src/components/models/course/card/PostCard.tsx new file mode 100644 index 0000000..369fbeb --- /dev/null +++ b/apps/web/src/components/models/course/card/PostCard.tsx @@ -0,0 +1,127 @@ +import { Card, Tag, Typography, Button } from "antd"; +import { + BookOutlined, + EyeOutlined, + PlayCircleOutlined, + TeamOutlined, +} from "@ant-design/icons"; +import { CourseDto, PostDto, TaxonomySlug } from "@nice/common"; +import { useNavigate } from "react-router-dom"; +import { useEffect } from "react"; + +interface PostCardProps { + course?: CourseDto; + path?: PostDto +} +const { Title, Text } = Typography; +export default function PostCard({ course = null, path = null }: PostCardProps) { + const navigate = useNavigate(); + const handleClick = (course: CourseDto) => { + if (course) { + navigate(`/course/${course.id}/detail`); + } else if (path) { + navigate(`/path/editor/${path.id}`); + } + window.scrollTo({ top: 0, behavior: "smooth", }) + }; + 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 && ( + <> +
+ + + )} +
+ }> +
+
+
+ {course?.terms?.map((term) => { + return ( + <> + + {term.name} + + + ); + })} +
+
+ + + <button> {course?.title}</button> + +
+ +
+ + {course?.depts?.length > 1 + ? `${course.depts[0].name}等` + : course?.depts?.[0]?.name} + {/* {course?.depts?.map((dept) => {return dept.name.length > 1 ?`${dept.name.slice}等`: dept.name})} */} + {/* {course?.depts?.map((dept)=>{return dept.name})} */} + + +
+ {!course && ( + <> + + {path?.meta?.views + ? `观看次数 ${path?.meta?.views}` + : null} + + + )} +
+ {course && ( +
+ + + {`观看次数 ${course?.meta?.views || 0}`} + + + + {`学习人数 ${course?.studentIds?.length || 0}`} + +
+ )} +
+ +
+
+ + ); +}