| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { MenuOutlined } from "@ant-design/icons";
- import { Key } from "antd/lib/table/interface";
- import AnthologyTocTree from "../anthology/AnthologyTocTree";
- import { ArticleType } from "./Article";
- import PaliTextToc from "./PaliTextToc";
- import ToolButton from "./ToolButton";
- import TextBookToc from "../anthology/TextBookToc";
- interface IWidget {
- type?: ArticleType;
- articleId?: string;
- anthologyId?: string | null;
- courseId?: string | null;
- channels?: string[];
- onSelect?: Function;
- }
- const ToolButtonTocWidget = ({
- type,
- articleId,
- anthologyId,
- courseId,
- channels,
- onSelect,
- }: IWidget) => {
- //TODO 都放return里面
- let tocWidget = <></>;
- if (type === "chapter" || type === "para") {
- if (articleId) {
- const sentId = articleId.split("-");
- if (sentId.length > 1) {
- tocWidget = (
- <PaliTextToc
- book={parseInt(sentId[0])}
- para={parseInt(sentId[1])}
- onSelect={(selectedKeys: Key[]) => {
- if (typeof onSelect !== "undefined" && selectedKeys.length > 0) {
- onSelect(selectedKeys[0]);
- }
- }}
- />
- );
- }
- }
- } else if (type === "article") {
- if (anthologyId) {
- tocWidget = (
- <AnthologyTocTree
- anthologyId={anthologyId}
- channels={channels}
- onClick={(anthology: string, article: string, target: string) => {
- if (typeof onSelect !== "undefined") {
- onSelect(article, target);
- }
- }}
- />
- );
- }
- } else if (type === "textbook") {
- tocWidget = (
- <TextBookToc
- courseId={courseId}
- channels={channels}
- onClick={(article: string, target: string) => {
- console.debug("TextBookToc onClick", article);
- if (typeof onSelect !== "undefined") {
- onSelect(article, target);
- }
- }}
- />
- );
- }
- return (
- <ToolButton title="目录" icon={<MenuOutlined />} content={tocWidget} />
- );
- };
- export default ToolButtonTocWidget;
|