diff --git a/apps/web/src/app/main/courses/components/CourseCard.tsx b/apps/web/src/app/main/courses/components/CourseCard.tsx index 45dc274..7b6cae1 100755 --- a/apps/web/src/app/main/courses/components/CourseCard.tsx +++ b/apps/web/src/app/main/courses/components/CourseCard.tsx @@ -16,6 +16,7 @@ export default function CourseCard({ course }: CourseCardProps) { const navigate = useNavigate(); const handleClick = (course: CourseDto) => { navigate(`/course/${course.id}/detail`); + window.scrollTo({top: 0,behavior: "smooth",}) }; return ( diff --git a/apps/web/src/app/main/courses/components/FilterSection.tsx b/apps/web/src/app/main/courses/components/FilterSection.tsx index 203e1d1..01ffba6 100755 --- a/apps/web/src/app/main/courses/components/FilterSection.tsx +++ b/apps/web/src/app/main/courses/components/FilterSection.tsx @@ -7,6 +7,7 @@ import { api } from "@nice/client"; import { useSearchParams } from "react-router-dom"; import TermSelect from "@web/src/components/models/term/term-select"; import { useMainContext } from "../../layout/MainProvider"; +import TermParentSelector from "@web/src/components/models/term/term-parent-selector"; export default function FilterSection() { const { data: taxonomies } = api.taxonomy.getAll.useQuery({}); @@ -28,7 +29,19 @@ export default function FilterSection() {

{tax?.name}

- + handleTermChange( + tax?.slug, + selected as string[] + ) + } + taxonomyId={tax?.id} + > + {/* {index < taxonomies.length - 1 && ( - )} + )} */} ); })} diff --git a/apps/web/src/app/main/home/components/HeroSection.tsx b/apps/web/src/app/main/home/components/HeroSection.tsx index 10ecbfe..17aa228 100755 --- a/apps/web/src/app/main/home/components/HeroSection.tsx +++ b/apps/web/src/app/main/home/components/HeroSection.tsx @@ -1,10 +1,9 @@ -import React, { useRef, useCallback, useEffect } from "react"; -import { Button, Carousel, Typography } from "antd"; +import React, { useRef, useCallback, useEffect, useMemo, useState } from "react"; +import { Carousel, Typography } from "antd"; import { TeamOutlined, BookOutlined, StarOutlined, - ClockCircleOutlined, LeftOutlined, RightOutlined, EyeOutlined, @@ -24,36 +23,22 @@ interface CarouselItem { interface PlatformStat { icon: React.ReactNode; - value: string; + value: number; label: string; } -const carouselItems: CarouselItem[] = [ - { - title: "探索编程世界", - desc: "从零开始学习编程,开启你的技术之旅", - image: "/images/banner1.jpg", - action: "立即开始", - color: "from-blue-600/90", - }, - { - title: "人工智能课程", - desc: "掌握AI技术,引领未来发展", - image: "/images/banner2.jpg", - action: "了解更多", - color: "from-purple-600/90", - }, -]; - const HeroSection = () => { const carouselRef = useRef(null); - const { statistics, baseSetting } = useAppConfig(); - const platformStats: PlatformStat[] = [ - { icon: , value: statistics.staffs.toString(), label: "注册学员" }, - { icon: , value: statistics.courses.toString(), label: "精品课程" }, - { icon: , value: statistics.lectures.toString(), label: '课程章节' }, - { icon: , value: statistics.reads.toString(), label: "观看次数" }, - ]; + const { statistics, slides } = useAppConfig(); + const [countStatistics, setCountStatistics] = useState(0) + const platformStats: PlatformStat[] = useMemo(() => { + return [ + { icon: , value: statistics.staffs, label: "注册学员" }, + { icon: , value: statistics.courses, label: "精品课程" }, + { icon: , value: statistics.lectures, label: '课程章节' }, + { icon: , value: statistics.reads, label: "观看次数" }, + ]; + }, [statistics]); const handlePrev = useCallback(() => { carouselRef.current?.prev(); }, []); @@ -61,11 +46,16 @@ const HeroSection = () => { const handleNext = useCallback(() => { carouselRef.current?.next(); }, []); - const { slides } = useAppConfig() + + const countNonZeroValues = (statistics: Record): number => { + return Object.values(statistics).filter(value => value !== 0).length; + }; + useEffect(() => { - //slides.push(('https://s.cn.bing.net/th?id=OHR.GiantCuttlefish_ZH-CN0670915878_1920x1080.webp&qlt=50')) - //console.log(slides) - }, []) + const count = countNonZeroValues(statistics); + console.log(count); + setCountStatistics(count); + }, [statistics]); return (
@@ -77,7 +67,7 @@ const HeroSection = () => { dots={{ className: "carousel-dots !bottom-32 !z-20", }}> - {Array.isArray(slides)? + {Array.isArray(slides) ? (slides.map((item, index) => (
{
)) - ) : ( -
- )} + ) : ( +
+ )} {/* Navigation Buttons */} @@ -118,25 +108,31 @@ const HeroSection = () => {
{/* Stats Container */} -
-
- {platformStats.map((stat, index) => ( -
-
- {stat.icon} -
-
- {stat.value} -
-
- {stat.label} -
+ { + countStatistics > 1 && ( +
+
+ {platformStats.map((stat, index) => { + return stat.value + ? (
+
+ {stat.icon} +
+
+ {stat.value} +
+
+ {stat.label} +
+
+ ) : null + })}
- ))} -
-
+
+ ) + }
); }; diff --git a/apps/web/src/components/models/term/term-parent-selector.tsx b/apps/web/src/components/models/term/term-parent-selector.tsx new file mode 100644 index 0000000..f4b365d --- /dev/null +++ b/apps/web/src/components/models/term/term-parent-selector.tsx @@ -0,0 +1,55 @@ +import { api } from "@nice/client/"; +import { Checkbox, Form } from "antd"; +import { TermDto } from "@nice/common"; +import { useCallback, useEffect, useState } from "react"; + +export default function TermParentSelector({ + value, + onChange, + className, + placeholder = "选择分类", + multiple = true, + taxonomyId, + domainId, + style, +}: any) { + const utils = api.useUtils(); + const [selectedValues, setSelectedValues] = useState([]); // 用于存储选中的值 + const [termsData, setTermsData] = useState([]); + + + const { + data, + isLoading, + }: { data: TermDto[]; isLoading: boolean } = api.term.findMany.useQuery({ + where: { + taxonomy: { + id: taxonomyId, + }, + parentId: null + }, + }); + const handleCheckboxChange = (checkedValues: string[]) => { + setSelectedValues(checkedValues); // 更新选中的值 + if (onChange) { + onChange(checkedValues); // 调用外部传入的 onChange 回调 + } + }; + return ( +
+
+ + + {data?.map((category) => ( +
+ + {category.name} + +
+ ))} +
+
+
+
+ ) +} \ No newline at end of file diff --git a/apps/web/src/routes/index.tsx b/apps/web/src/routes/index.tsx index 07c7c9c..7592489 100755 --- a/apps/web/src/routes/index.tsx +++ b/apps/web/src/routes/index.tsx @@ -68,11 +68,11 @@ export const routes: CustomRouteObject[] = [ path: "profiles", }, - // 课程预览页面 - { - path: "coursePreview/:id?", - element: , - }, + // // 课程预览页面 + // { + // path: "coursePreview/:id?", + // element: , + // }, ], }, {