ToolButtonToc.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { MenuOutlined } from "@ant-design/icons";
  2. import { Key } from "antd/lib/table/interface";
  3. import { ArticleType } from "./Article";
  4. import PaliTextToc from "./PaliTextToc";
  5. import ToolButton from "./ToolButton";
  6. interface IWidget {
  7. type?: ArticleType;
  8. articleId?: string;
  9. onSelect?: Function;
  10. }
  11. const ToolButtonTocWidget = ({ type, articleId, onSelect }: IWidget) => {
  12. let tocWidget = <></>;
  13. switch (type) {
  14. case "chapter":
  15. const id = articleId?.split("_");
  16. if (id && id.length > 0) {
  17. const sentId = id[0].split("-");
  18. if (sentId.length > 1) {
  19. tocWidget = (
  20. <PaliTextToc
  21. book={parseInt(sentId[0])}
  22. para={parseInt(sentId[1])}
  23. onSelect={(selectedKeys: Key[]) => {
  24. if (
  25. typeof onSelect !== "undefined" &&
  26. selectedKeys.length > 0
  27. ) {
  28. onSelect(selectedKeys[0]);
  29. }
  30. }}
  31. />
  32. );
  33. }
  34. }
  35. break;
  36. default:
  37. break;
  38. }
  39. return (
  40. <ToolButton title="目录" icon={<MenuOutlined />} content={tocWidget} />
  41. );
  42. };
  43. export default ToolButtonTocWidget;