ToolButtonToc.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { MenuOutlined } from "@ant-design/icons";
  2. import { Key } from "antd/lib/table/interface";
  3. import AnthologyTocTree from "../anthology/AnthologyTocTree";
  4. import { ArticleType } from "./Article";
  5. import PaliTextToc from "./PaliTextToc";
  6. import ToolButton from "./ToolButton";
  7. import TextBookToc from "../anthology/TextBookToc";
  8. interface IWidget {
  9. type?: ArticleType;
  10. articleId?: string;
  11. anthologyId?: string | null;
  12. courseId?: string | null;
  13. channels?: string[];
  14. onSelect?: Function;
  15. }
  16. const ToolButtonTocWidget = ({
  17. type,
  18. articleId,
  19. anthologyId,
  20. courseId,
  21. channels,
  22. onSelect,
  23. }: IWidget) => {
  24. //TODO 都放return里面
  25. let tocWidget = <></>;
  26. if (type === "chapter" || type === "para") {
  27. if (articleId) {
  28. const sentId = articleId.split("-");
  29. if (sentId.length > 1) {
  30. tocWidget = (
  31. <PaliTextToc
  32. book={parseInt(sentId[0])}
  33. para={parseInt(sentId[1])}
  34. onSelect={(selectedKeys: Key[]) => {
  35. if (typeof onSelect !== "undefined" && selectedKeys.length > 0) {
  36. onSelect(selectedKeys[0]);
  37. }
  38. }}
  39. />
  40. );
  41. }
  42. }
  43. } else if (type === "article") {
  44. if (anthologyId) {
  45. tocWidget = (
  46. <AnthologyTocTree
  47. anthologyId={anthologyId}
  48. channels={channels}
  49. onClick={(anthology: string, article: string, target: string) => {
  50. if (typeof onSelect !== "undefined") {
  51. onSelect(article, target);
  52. }
  53. }}
  54. />
  55. );
  56. }
  57. } else if (type === "textbook") {
  58. tocWidget = (
  59. <TextBookToc
  60. courseId={courseId}
  61. channels={channels}
  62. onClick={(article: string, target: string) => {
  63. console.debug("TextBookToc onClick", article);
  64. if (typeof onSelect !== "undefined") {
  65. onSelect(article, target);
  66. }
  67. }}
  68. />
  69. );
  70. }
  71. return (
  72. <ToolButton title="目录" icon={<MenuOutlined />} content={tocWidget} />
  73. );
  74. };
  75. export default ToolButtonTocWidget;