This commit is contained in:
Li1304553726 2025-02-25 10:58:35 +08:00
parent 4fda0ecdef
commit 9db19fa02a
1 changed files with 37 additions and 63 deletions

View File

@ -39,8 +39,7 @@ function useGetTaxonomy({ type }): GetTaxonomyProps {
}, [data]);
return { categories, isLoading }
}
// 修改useGetName中的查询条件
// 不同分类跳转
function useFetchCoursesByCategory(category: string) {
const isAll = category === '全部';
const { data, isLoading }: { data: CourseDto[], isLoading: boolean } = api.post.findMany.useQuery({
@ -60,7 +59,7 @@ function useFetchCoursesByCategory(category: string) {
return { data, isLoading };
}
// 不同分类跳转
const { Title, Text } = Typography;
@ -102,29 +101,6 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
useEffect(() => {
console.log('data:', data)
})
// const { data } = api.post.findMany.useQuery({
// where: {}, // 必选参数
// include: { // 关联查询
// instructors: true
// },
// orderBy: { // 排序规则
// createdAt: 'desc'
// },
// take: 8
// })
// useEffect(() => {
// // 添加空值保护
// if (data && data.length > 0) {
// console.log('有效数据:', data)
// // 执行后续操作
// } else {
// console.log('无数据或加载中')
// }
// }, [data])
// const formatted = data?.map(course => ({
// id: course.id,
// title: course.title
// }));
const handleClick = (course: CourseDto) => {
navigate(`/course/${course.id}/detail`);
}
@ -168,13 +144,7 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
: 'bg-white text-gray-600 hover:bg-gray-100'
}`}
></Tag>
{gateGory.categories.length === 0 && (
<Empty
description="暂无课程分类"
image={Empty.PRESENTED_IMAGE_DEFAULT}
/>
)}:{
gateGory.categories.map((category) => (
{gateGory.categories.map((category) => (
<Tag
key={category}
color={selectedCategory === category ? 'blue' : 'default'}
@ -190,6 +160,7 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
>
{category}
</Tag>
))
}
@ -199,7 +170,11 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8">
{displayedCourses?.map((course) => (
{displayedCourses.length=== 0 ? (
<div className="col-span-full">
<Empty description="暂无课程" image={Empty.PRESENTED_IMAGE_DEFAULT} />
</div>
) : displayedCourses?.map((course) => (
<Card
onClick={() => handleClick(course)}
key={course.id}
@ -249,7 +224,6 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
<TeamOutlined className="text-blue-500 text-lg transform group-hover:scale-110 transition-transform duration-300" />
<div className="ml-2 flex items-center flex-grow">
<Text className="font-medium text-blue-500 hover:text-blue-600 transition-colors duration-300">
{/* {course.} */}
</Text>
</div>
<span className="flex items-center bg-blue-100 px-2 py-1 rounded-full text-blue-600 hover:bg-blue-200 transition-colors duration-300">