CourseNewList.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //主讲人列表
  2. import { useNavigate } from "react-router";
  3. import { useEffect, useState } from "react";
  4. import { Card, List, message, Typography } from "antd";
  5. import type {
  6. ICourseDataResponse,
  7. ICourseListResponse,
  8. } from "../../api/Course";
  9. import { API_HOST, get } from "../../request";
  10. const { Paragraph } = Typography;
  11. const CourseNewListWidget = () => {
  12. const [data, setData] = useState<ICourseDataResponse[]>();
  13. const navigate = useNavigate();
  14. useEffect(() => {
  15. get<ICourseListResponse>(`/v2/course?view=new&limit=4`).then((json) => {
  16. if (json.ok) {
  17. console.log(json.data);
  18. setData(json.data.rows);
  19. } else {
  20. message.error(json.message);
  21. }
  22. });
  23. }, []);
  24. return (
  25. <List
  26. size="small"
  27. split={false}
  28. dataSource={data}
  29. renderItem={(item) => (
  30. <List.Item>
  31. <Card
  32. style={{ width: "100%", height: 200, borderRadius: 20 }}
  33. hoverable
  34. onClick={(_e) => {
  35. navigate(`/course/show/${item.id}`);
  36. }}
  37. >
  38. <div style={{ display: "flex" }}>
  39. <div style={{ flex: 3 }}>
  40. <img
  41. alt="example"
  42. src={API_HOST + "/" + item.cover_url}
  43. width="150"
  44. height="150"
  45. />
  46. </div>
  47. <div style={{ flex: 7 }}>
  48. <h3>{item.title}</h3>
  49. <Paragraph ellipsis={{ rows: 2, expandable: false }}>
  50. {item.summary}
  51. </Paragraph>
  52. </div>
  53. </div>
  54. </Card>
  55. </List.Item>
  56. )}
  57. />
  58. );
  59. };
  60. export default CourseNewListWidget;