index.jsx 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { getPostsDetail } from "@/services/posts";
  2. import { useNavigate, useSearchParams } from "react-router-dom";
  3. import { Card, Typography, Button } from "antd";
  4. import { useEffect, useState } from "react";
  5. const { Title } = Typography;
  6. export default (props) => {
  7. const [searchParams] = useSearchParams();
  8. const id = searchParams.get("id");
  9. const [data, setData] = useState({});
  10. const [url, setUrl] = useState("");
  11. const navigate = useNavigate();
  12. useEffect(() => {
  13. if (id) {
  14. getPostsDetail(id).then((res) => {
  15. setData(res);
  16. setUrl(res.filesList[0]?.fileAddr);
  17. });
  18. }
  19. }, [id]);
  20. return (
  21. <Card title={<Button onClick={() => navigate(-1)}> 返回</Button>}>
  22. <Title level={2} style={{ marginBottom: "2em" }}>
  23. {data.title}
  24. </Title>
  25. <div dangerouslySetInnerHTML={{ __html: data?.detail }}></div>
  26. {url && (
  27. <div style={{ marginTop: "2em" }}>
  28. <a
  29. href={`${url}`}
  30. download
  31. // rel="noopener noreferrer"
  32. // key="link"
  33. >
  34. {url?.substring(url?.lastIndexOf("/") + 1)}
  35. </a>
  36. </div>
  37. )}
  38. </Card>
  39. );
  40. };