ArticleCard.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { useNavigate } from "react-router";
  2. import { Button, Card, Dropdown, Space } from "antd";
  3. import { MoreOutlined, ReloadOutlined } from "@ant-design/icons";
  4. import type { MenuProps } from "antd";
  5. import type { IWidgetArticleData } from "./ArticleView"
  6. import ArticleCardMainMenu from "./ArticleCardMainMenu";
  7. import ModeSwitch from "./ModeSwitch";
  8. interface IWidgetArticleCard {
  9. type?: string;
  10. articleId?: string;
  11. data?: IWidgetArticleData;
  12. children?: React.ReactNode;
  13. onModeChange?: Function;
  14. openInCol?: Function;
  15. showCol?: Function;
  16. }
  17. const ArticleCardWidget = ({
  18. type,
  19. articleId,
  20. data,
  21. children,
  22. onModeChange,
  23. showCol,
  24. }: IWidgetArticleCard) => {
  25. const navigate = useNavigate();
  26. const onClick: MenuProps["onClick"] = (e) => {
  27. console.log("click ", e);
  28. switch (e.key) {
  29. case "showCol":
  30. if (typeof showCol !== "undefined") {
  31. showCol();
  32. }
  33. break;
  34. default:
  35. break;
  36. }
  37. };
  38. const items: MenuProps["items"] = [
  39. {
  40. key: "showCol",
  41. label: "显示分栏",
  42. },
  43. ];
  44. const contextMenu = (
  45. <Dropdown menu={{ items, onClick }} placement="bottomRight">
  46. <Button shape="circle" size="small" icon={<MoreOutlined />}></Button>
  47. </Dropdown>
  48. );
  49. return (
  50. <Card
  51. size="small"
  52. title={
  53. <Space>
  54. {<ArticleCardMainMenu type={type} articleId={articleId} />}
  55. {data?.title}
  56. </Space>
  57. }
  58. extra={
  59. <Space>
  60. <ModeSwitch
  61. channel={null}
  62. onModeChange={(mode: string) => {
  63. if (typeof onModeChange !== "undefined") {
  64. onModeChange(mode);
  65. }
  66. navigate(`/article/${type}/${articleId}/${mode}`);
  67. }}
  68. />
  69. <Button
  70. shape="circle"
  71. size="small"
  72. icon={<ReloadOutlined />}
  73. ></Button>
  74. {contextMenu}
  75. </Space>
  76. }
  77. bodyStyle={{ height: `calc(100vh - 94px)`, overflowY: "scroll" }}
  78. >
  79. {children}
  80. </Card>
  81. );
  82. };
  83. export default ArticleCardWidget;