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

未设置onChange 默认打开章节

visuddhinanda 2 лет назад
Родитель
Сommit
4c0a8a5b93
1 измененных файлов с 19 добавлено и 1 удалено
  1. 19 1
      dashboard/src/components/corpus/TocPath.tsx

+ 19 - 1
dashboard/src/components/corpus/TocPath.tsx

@@ -1,6 +1,9 @@
+import { useNavigate } from "react-router-dom";
 import { Breadcrumb, Popover, Tag, Typography } from "antd";
+
 import PaliText from "../template/Wbw/PaliText";
 import React from "react";
+import { fullUrl } from "../../utils";
 
 export interface ITocPathNode {
   key?: string;
@@ -27,7 +30,8 @@ const TocPathWidget = ({
   channel,
   onChange,
 }: IWidgetTocPath): JSX.Element => {
-  console.log("path", data);
+  const navigate = useNavigate();
+
   const fullPath = (
     <Breadcrumb style={{ whiteSpace: "nowrap", width: "100%" }}>
       {data.map((item, id) => {
@@ -41,6 +45,20 @@ const TocPathWidget = ({
             ) => {
               if (typeof onChange !== "undefined") {
                 onChange(item, e);
+              } else {
+                if (item.book && item.paragraph) {
+                  const type = item.level < 8 ? "chapter" : "para";
+                  const param =
+                    type === "para"
+                      ? `&book=${item.book}&par=${item.paragraph}`
+                      : "";
+                  let url = `/article/${type}/${item.book}-${item.paragraph}?mode=read${param}`;
+                  if (e.ctrlKey || e.metaKey) {
+                    window.open(fullUrl(url), "_blank");
+                  } else {
+                    navigate(url);
+                  }
+                }
               }
             }}
             key={id}