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

巴利文组件支持用term数据替换

visuddhinanda 3 лет назад
Родитель
Сommit
f1a0505344

+ 4 - 0
dashboard/src/components/corpus/BookTree.tsx

@@ -8,6 +8,7 @@ import TocStyleSelect from "./TocStyleSelect";
 import { IPaliBookListResponse } from "../api/Corpus";
 import { ITocTree } from "./BookTreeList";
 import { PaliToEn } from "../../utils";
+import PaliText from "../template/Wbw/PaliText";
 
 const { Text } = Typography;
 
@@ -127,6 +128,9 @@ const Widget = ({
           }
         }}
         treeData={treeData}
+        titleRender={(node: ITocTree) => {
+          return <PaliText text={node.title} />;
+        }}
       />
     </Space>
   );

+ 27 - 11
dashboard/src/components/corpus/BookViewer.tsx

@@ -4,6 +4,7 @@ import PaliChapterChannelList from "./PaliChapterChannelList";
 import PaliChapterListByPara from "./PaliChapterListByPara";
 import PaliChapterHead from "./PaliChapterHead";
 import { IChapterClickEvent } from "./PaliChapterList";
+import { Tabs } from "antd";
 
 export interface IChapter {
   book: number;
@@ -15,31 +16,46 @@ interface IWidget {
   onChange?: Function;
 }
 const Widget = ({ chapter, onChange }: IWidget) => {
-  const [currChapter, setCurrChpater] = useState(chapter);
+  const [currChapter, setCurrChapter] = useState(chapter);
   useEffect(() => {
     if (typeof onChange !== "undefined") {
       onChange(currChapter);
     }
-  }, [currChapter]);
+  }, [currChapter, onChange]);
 
   useEffect(() => {
-    setCurrChpater(chapter);
+    setCurrChapter(chapter);
   }, [chapter]);
   return (
     <>
       <PaliChapterHead
         onChange={(e: IChapter) => {
-          setCurrChpater(e);
+          setCurrChapter(e);
         }}
         para={currChapter}
       />
-      <PaliChapterChannelList para={currChapter} />
-      <PaliChapterListByPara
-        chapter={currChapter}
-        onChapterClick={(e: IChapterClickEvent) => {
-          setCurrChpater({ book: e.para.Book, para: e.para.Paragraph });
-          console.log("PaliChapterListByPara", "onchange", e);
-        }}
+      <Tabs
+        size="small"
+        items={[
+          {
+            label: `目录`,
+            key: "toc",
+            children: (
+              <PaliChapterListByPara
+                chapter={currChapter}
+                onChapterClick={(e: IChapterClickEvent) => {
+                  setCurrChapter({ book: e.para.Book, para: e.para.Paragraph });
+                  console.log("PaliChapterListByPara", "onchange", e);
+                }}
+              />
+            ),
+          },
+          {
+            label: `资源`,
+            key: "res",
+            children: <PaliChapterChannelList para={currChapter} />,
+          },
+        ]}
       />
     </>
   );

+ 10 - 0
dashboard/src/components/template/Wbw/PaliText.tsx

@@ -7,6 +7,7 @@ import { roman_to_my, my_to_roman } from "../../code/my";
 import { roman_to_si } from "../../code/si";
 import { roman_to_thai } from "../../code/thai";
 import { roman_to_taitham } from "../../code/tai-tham";
+import { getTerm } from "../../../reducers/term-vocabulary";
 
 interface IWidget {
   text?: string;
@@ -16,6 +17,15 @@ interface IWidget {
 const Widget = ({ text, code = "roman", primary = true }: IWidget) => {
   const [paliText, setPaliText] = useState<string>();
   const settings = useAppSelector(settingInfo);
+  const terms = useAppSelector(getTerm);
+
+  useEffect(() => {
+    const lowerCase = paliText?.toLowerCase();
+    const localName = terms?.find((item) => item.word === lowerCase)?.meaning;
+    if (localName) {
+      setPaliText(localName);
+    }
+  }, [paliText, terms]);
 
   useEffect(() => {
     const _paliCode1 = GetUserSetting("setting.pali.script.primary", settings);

+ 7 - 0
dashboard/src/load.ts

@@ -101,6 +101,13 @@ const init = () => {
       }
     }
   );
+  get<ITermResponse>(
+    `/v2/term-vocabulary?view=community&lang=` + getLang()
+  ).then((json) => {
+    if (json.ok) {
+      store.dispatch(push(json.data.rows));
+    }
+  });
   //获取nissaya ending 表
   get<INissayaEndingResponse>(`/v2/nissaya-ending-vocabulary?lang=my`).then(
     (json) => {