import React, { useRef } from 'react'; import { Typography, Tag, Carousel } from 'antd'; import { StarFilled, UserOutlined, ReadOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons'; const { Title, Text } = Typography; interface Teacher { name: string; title: string; avatar: string; courses: number; students: number; rating: number; description: string; } const featuredTeachers: Teacher[] = [ { name: '张教授', title: '资深前端开发专家', avatar: '/images/teacher1.jpg', courses: 12, students: 25000, rating: 4.9, description: '前 BAT 高级工程师,10年+开发经验' }, { name: '李教授', title: '算法与数据结构专家', avatar: '/images/teacher2.jpg', courses: 8, students: 18000, rating: 4.8, description: '计算机博士,专注算法教育8年' }, { name: '王博士', title: '人工智能研究员', avatar: '/images/teacher3.jpg', courses: 15, students: 30000, rating: 4.95, description: '人工智能领域专家,曾主导多个大型AI项目' }, { name: '陈教授', title: '云计算架构师', avatar: '/images/teacher4.jpg', courses: 10, students: 22000, rating: 4.85, description: '知名云服务提供商技术总监,丰富的实战经验' }, { name: '郑老师', title: '移动开发专家', avatar: '/images/teacher5.jpg', courses: 14, students: 28000, rating: 4.88, description: '资深移动端开发者,著名互联网公司技术专家' } ]; const generateGradientColors = (name: string) => { // 优化的哈希函数 const hash = name.split('').reduce((acc, char, index) => { return char.charCodeAt(0) + ((acc << 5) - acc) + index; }, 0); // 定义蓝色色相范围(210-240) const blueHueStart = 210; const blueHueRange = 30; // 基础蓝色色相 - 将哈希值映射到蓝色范围内 const baseHue = blueHueStart + Math.abs(hash % blueHueRange); // 生成第二个蓝色色相,保持在蓝色范围内 let secondHue = baseHue + 15; // 在基础色相的基础上略微偏移 if (secondHue > blueHueStart + blueHueRange) { secondHue -= blueHueRange; } // 基于输入字符串的特征调整饱和度和亮度 const nameLength = name.length; const saturation = Math.max(65, Math.min(85, 75 + (nameLength % 10))); // 65-85%范围 const lightness = Math.max(45, Math.min(65, 55 + (hash % 10))); // 45-65%范围 // 为第二个颜色稍微调整饱和度和亮度,创造层次感 const saturation2 = Math.max(60, saturation - 5); const lightness2 = Math.min(70, lightness + 5); return { from: `hsl(${Math.round(baseHue)}, ${Math.round(saturation)}%, ${Math.round(lightness)}%)`, to: `hsl(${Math.round(secondHue)}, ${Math.round(saturation2)}%, ${Math.round(lightness2)}%)` }; }; const FeaturedTeachersSection: React.FC = () => { const carouselRef = useRef(null); const settings = { dots: true, infinite: true, speed: 500, slidesToShow: 4, slidesToScroll: 1, autoplay: true, autoplaySpeed: 5000, responsive: [ { breakpoint: 1024, settings: { slidesToShow: 2, slidesToScroll: 1 } }, { breakpoint: 640, settings: { slidesToShow: 1, slidesToScroll: 1 } } ] }; const TeacherCard = ({ teacher }: { teacher: Teacher }) => { const gradientColors = generateGradientColors(teacher.name); return (
{teacher.name}
{teacher.name} {teacher.title}
{teacher.description}
{teacher.courses}
课程
{(teacher.students / 1000).toFixed(1)}k
学员
{teacher.rating}
评分
); }; return (
优秀讲师 业界专家实战分享,传授独家经验
{featuredTeachers.map((teacher, index) => ( ))}
); }; export default FeaturedTeachersSection;