Просмотр исходного кода

Merge pull request #1467 from visuddhinanda/agile

文集目录添加add按钮
visuddhinanda 2 лет назад
Родитель
Сommit
5621e86f73

+ 2 - 2
dashboard/src/components/anthology/EditableTocTree.tsx

@@ -1,6 +1,6 @@
 import { Button, message } from "antd";
 import { useEffect, useState } from "react";
-import { FileAddOutlined } from "@ant-design/icons";
+import { FolderOpenOutlined } from "@ant-design/icons";
 
 import { get as getUiLang } from "../../locales";
 
@@ -101,7 +101,7 @@ const EditableTocTreeWidget = ({
         addFileButton={
           <ArticleListModal
             studioName={studioName}
-            trigger={<Button icon={<FileAddOutlined />}>添加</Button>}
+            trigger={<Button icon={<FolderOpenOutlined />}>添加</Button>}
             multiple={false}
             onSelect={(id: string, title: string) => {
               console.log("add article", id);

+ 30 - 1
dashboard/src/components/article/EditableTree.tsx

@@ -4,6 +4,8 @@ import { message, Tree } from "antd";
 import type { DataNode, TreeProps } from "antd/es/tree";
 import { Key } from "antd/lib/table/interface";
 import { DeleteOutlined, SaveOutlined } from "@ant-design/icons";
+import { FileAddOutlined } from "@ant-design/icons";
+
 import { Button, Divider, Space } from "antd";
 import { useIntl } from "react-intl";
 import EditableTreeNode from "./EditableTreeNode";
@@ -293,7 +295,34 @@ const EditableTreeWidget = ({
     <>
       <Space>
         {addFileButton}
-
+        <Button
+          icon={<FileAddOutlined />}
+          onClick={async () => {
+            if (typeof onAppend !== "undefined") {
+              const newNode = await onAppend({
+                key: "",
+                title: "",
+                children: [],
+                level: 0,
+              });
+              console.log("newNode", newNode);
+              if (newNode) {
+                const append = [...gData, newNode];
+                setGData(append);
+                const list = treeToList(append);
+                setListTreeData(list);
+                return true;
+              } else {
+                message.error("添加失败");
+                return false;
+              }
+            } else {
+              return false;
+            }
+          }}
+        >
+          添加
+        </Button>
         <Button
           icon={<DeleteOutlined />}
           danger

+ 3 - 10
dashboard/src/components/article/PaliTextToc.tsx

@@ -30,24 +30,17 @@ const PaliTextTocWidget = ({ book, para, channel, onSelect }: IWidget) => {
       });
       setTocList(toc);
       if (json.data.rows.length > 0) {
-        let currLevel = 0;
         let path: string[] = [];
         for (let index = json.data.rows.length - 1; index >= 0; index--) {
           const element = json.data.rows[index];
-          if (element.book === book && element.paragraph === para) {
-            currLevel = parseInt(element.level);
-          }
-          if (
-            parseInt(element.level) === 1 ||
-            (element.book === book && parseInt(element.level) < currLevel)
-          ) {
-            currLevel = parseInt(element.level);
+          if (element.book === book && para && element.paragraph <= para) {
             path.push(`${element.book}-${element.paragraph}`);
+            break;
           }
         }
         setExpandedKeys(path);
+        setSelectedKeys(path);
       }
-      setSelectedKeys([`${book}-${para}`]);
     });
   }, [book, para]);
 

+ 1 - 1
dashboard/src/components/article/TocTree.tsx

@@ -107,7 +107,6 @@ const TocTreeWidget = ({
   const [selected, setSelected] = useState<Key[]>();
 
   useEffect(() => {
-    console.log("new tree data", treeData);
     if (treeData && treeData.length > 0) {
       const data = tocGetTreeData(treeData);
       setTree(data);
@@ -125,6 +124,7 @@ const TocTreeWidget = ({
       treeData={tree}
       expandedKeys={expanded}
       selectedKeys={selected}
+      autoExpandParent
       onExpand={(expandedKeys: Key[]) => {
         setExpanded(expandedKeys);
       }}

+ 24 - 33
dashboard/src/components/article/ToolButtonToc.tsx

@@ -19,45 +19,36 @@ const ToolButtonTocWidget = ({
   onSelect,
 }: IWidget) => {
   let tocWidget = <></>;
-  switch (type) {
-    case "chapter":
-      const id = articleId?.split("_");
-      if (id && id.length > 0) {
-        const sentId = id[0].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]);
-                }
-              }}
-            />
-          );
-        }
-      }
-      break;
-    case "article":
-      if (anthologyId) {
+  if (type === "chapter" || type === "para") {
+    if (articleId) {
+      const sentId = articleId.split("-");
+      if (sentId.length > 1) {
         tocWidget = (
-          <AnthologyTocTree
-            anthologyId={anthologyId}
-            onArticleSelect={(anthologyId: string, keys: string[]) => {
-              if (typeof onSelect !== "undefined" && keys.length > 0) {
-                onSelect(keys[0]);
+          <PaliTextToc
+            book={parseInt(sentId[0])}
+            para={parseInt(sentId[1])}
+            onSelect={(selectedKeys: Key[]) => {
+              if (typeof onSelect !== "undefined" && selectedKeys.length > 0) {
+                onSelect(selectedKeys[0]);
               }
             }}
           />
         );
       }
-      break;
-    default:
-      break;
+    }
+  } else if (type === "article") {
+    if (anthologyId) {
+      tocWidget = (
+        <AnthologyTocTree
+          anthologyId={anthologyId}
+          onArticleSelect={(anthologyId: string, keys: string[]) => {
+            if (typeof onSelect !== "undefined" && keys.length > 0) {
+              onSelect(keys[0]);
+            }
+          }}
+        />
+      );
+    }
   }
 
   return (