LecturerList.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //主讲人列表
  2. import { useNavigate } from "react-router";
  3. import { useEffect, useState } from "react";
  4. import { Card, List, message, Typography, Image } from "antd";
  5. import type {
  6. ICourseDataResponse,
  7. ICourseListResponse,
  8. } from "../../api/Course";
  9. import { API_HOST, get } from "../../request";
  10. import CourseNewLoading from "./CourseNewLoading";
  11. const { Meta } = Card;
  12. const { Paragraph } = Typography;
  13. const LecturerListWidget = () => {
  14. const [data, setData] = useState<ICourseDataResponse[]>();
  15. const [loading, setLoading] = useState(false);
  16. const navigate = useNavigate();
  17. useEffect(() => {
  18. const url = `/v2/course?view=new&limit=4`;
  19. console.info("course url", url);
  20. setLoading(true);
  21. get<ICourseListResponse>(url)
  22. .then((json) => {
  23. if (json.ok) {
  24. console.log(json.data);
  25. setData(json.data.rows);
  26. } else {
  27. message.error(json.message);
  28. }
  29. })
  30. .finally(() => setLoading(false));
  31. }, []);
  32. return loading ? (
  33. <CourseNewLoading />
  34. ) : (
  35. <List
  36. grid={{ gutter: 16, column: 4 }}
  37. dataSource={data}
  38. renderItem={(item) => (
  39. <List.Item>
  40. <Card
  41. hoverable
  42. style={{ width: "100%", height: 350 }}
  43. cover={
  44. <Image
  45. alt="example"
  46. src={
  47. item.cover_url && item.cover_url.length > 1
  48. ? item.cover_url[1]
  49. : undefined
  50. }
  51. preview={{
  52. src:
  53. item.cover_url && item.cover_url.length > 0
  54. ? item.cover_url[0]
  55. : undefined,
  56. }}
  57. width="240"
  58. height="200"
  59. fallback={`${API_HOST}/app/course/img/default.jpg`}
  60. />
  61. }
  62. onClick={(_e) => {
  63. navigate(`/course/show/${item.id}`);
  64. }}
  65. >
  66. <Meta
  67. title={item.title}
  68. description={
  69. <Paragraph ellipsis={{ rows: 2, expandable: false }}>
  70. {item.summary}
  71. </Paragraph>
  72. }
  73. />
  74. </Card>
  75. </List.Item>
  76. )}
  77. />
  78. );
  79. };
  80. export default LecturerListWidget;