Преглед на файлове

用单个参数代替prop

visuddhinanda преди 3 години
родител
ревизия
119fe95113
променени са 1 файла, в които са добавени 56 реда и са изтрити 43 реда
  1. 56 43
      dashboard/src/components/corpus/TocPath.tsx

+ 56 - 43
dashboard/src/components/corpus/TocPath.tsx

@@ -2,55 +2,68 @@ import { Link } from "react-router-dom";
 import { Breadcrumb } from "antd";
 import { Breadcrumb } from "antd";
 
 
 export interface ITocPathNode {
 export interface ITocPathNode {
-	book: number;
-	paragraph: number;
-	title: string;
-	paliTitle?: string;
-	level: number;
+  book: number;
+  paragraph: number;
+  title: string;
+  paliTitle?: string;
+  level: number;
 }
 }
 
 
 export declare type ELinkType = "none" | "blank" | "self";
 export declare type ELinkType = "none" | "blank" | "self";
 
 
 interface IWidgetTocPath {
 interface IWidgetTocPath {
-	data: ITocPathNode[];
-	link?: ELinkType;
-	channel?: string;
-	onChange?: Function;
+  data: ITocPathNode[];
+  link?: ELinkType;
+  channel?: string[];
+  onChange?: Function;
 }
 }
-const Widget = (prop: IWidgetTocPath) => {
-	const link: ELinkType = prop.link ? prop.link : "blank";
-	const path = prop.data.map((item, id) => {
-		const linkChapter = `/article/index.php?view=chapter&book=${item.book}&par=${item.paragraph}`;
-		let oneItem = <></>;
-		switch (link) {
-			case "none":
-				oneItem = <>{item.title}</>;
-				break;
-			case "blank":
-				oneItem = <Link to={linkChapter}>{item.title}</Link>;
-				break;
-			case "self":
-				oneItem = <Link to={linkChapter}>{item.title}</Link>;
-				break;
-		}
-		return (
-			<Breadcrumb.Item
-				onClick={() => {
-					if (typeof prop.onChange !== "undefined") {
-						prop.onChange({ book: item.book, para: item.paragraph });
-					}
-				}}
-				key={id}
-			>
-				{oneItem}
-			</Breadcrumb.Item>
-		);
-	});
-	return (
-		<>
-			<Breadcrumb>{path}</Breadcrumb>
-		</>
-	);
+const Widget = ({
+  data,
+  link = "blank",
+  channel,
+  onChange,
+}: IWidgetTocPath) => {
+  let sChannel = "";
+  if (typeof channel !== "undefined" && channel.length > 0) {
+    sChannel = "_" + channel.join("_");
+  }
+
+  const path = data.map((item, id) => {
+    const linkChapter = `/article/chapter/${item.book}-${item.paragraph}${sChannel}`;
+    let oneItem = <></>;
+    switch (link) {
+      case "none":
+        oneItem = <>{item.title}</>;
+        break;
+      case "blank":
+        oneItem = (
+          <Link to={linkChapter} target="_blank">
+            {item.title}
+          </Link>
+        );
+        break;
+      case "self":
+        oneItem = <Link to={linkChapter}>{item.title}</Link>;
+        break;
+    }
+    return (
+      <Breadcrumb.Item
+        onClick={() => {
+          if (typeof onChange !== "undefined") {
+            onChange({ book: item.book, para: item.paragraph });
+          }
+        }}
+        key={id}
+      >
+        {oneItem}
+      </Breadcrumb.Item>
+    );
+  });
+  return (
+    <>
+      <Breadcrumb>{path}</Breadcrumb>
+    </>
+  );
 };
 };
 
 
 export default Widget;
 export default Widget;