ArticleView.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { Typography, Divider, Button } from "antd";
  2. import { ReloadOutlined } from "@ant-design/icons";
  3. import MdView from "../template/MdView";
  4. import TocPath, { ITocPathNode } from "../corpus/TocPath";
  5. import PaliChapterChannelList from "../corpus/PaliChapterChannelList";
  6. import { ArticleType } from "./Article";
  7. const { Paragraph, Title, Text } = Typography;
  8. export interface IWidgetArticleData {
  9. id?: string;
  10. title?: string;
  11. subTitle?: string;
  12. summary?: string;
  13. content?: string;
  14. html?: string;
  15. path?: ITocPathNode[];
  16. created_at?: string;
  17. updated_at?: string;
  18. channels?: string[];
  19. type?: ArticleType;
  20. articleId?: string;
  21. }
  22. const Widget = ({
  23. id,
  24. title = "",
  25. subTitle,
  26. summary,
  27. content,
  28. html,
  29. path = [],
  30. created_at,
  31. updated_at,
  32. channels,
  33. type,
  34. articleId,
  35. }: IWidgetArticleData) => {
  36. let currChannelList = <></>;
  37. switch (type) {
  38. case "chapter":
  39. const chapterProps = articleId?.split("_");
  40. if (typeof chapterProps === "object" && chapterProps.length > 0) {
  41. const para = chapterProps[0].split("-");
  42. const channels =
  43. chapterProps.length > 1 ? chapterProps.slice(1) : undefined;
  44. if (typeof para === "object" && para.length > 1) {
  45. currChannelList = (
  46. <PaliChapterChannelList
  47. para={{ book: parseInt(para[0]), para: parseInt(para[1]) }}
  48. channelId={channels}
  49. openTarget="_self"
  50. />
  51. );
  52. }
  53. }
  54. break;
  55. default:
  56. break;
  57. }
  58. return (
  59. <>
  60. <Button shape="round" size="small" icon={<ReloadOutlined />}>
  61. 刷新
  62. </Button>
  63. <div>
  64. <TocPath data={path} channel={channels} />
  65. <Title level={4}>
  66. <div
  67. dangerouslySetInnerHTML={{
  68. __html: title ? title : "",
  69. }}
  70. />
  71. </Title>
  72. <Text type="secondary">{subTitle}</Text>
  73. {currChannelList}
  74. <Paragraph ellipsis={{ rows: 2, expandable: true, symbol: "more" }}>
  75. {summary}
  76. </Paragraph>
  77. <Divider />
  78. </div>
  79. <div>
  80. <MdView html={html ? html : content} />
  81. </div>
  82. </>
  83. );
  84. };
  85. export default Widget;