Преглед изворни кода

按照书是否包含全部目录标签计算

visuddhinanda пре 1 година
родитељ
комит
c18c033f69

+ 14 - 10
dashboard-v4/dashboard/src/components/corpus/BookTree.tsx

@@ -11,6 +11,7 @@ import { ITocTree } from "./BookTreeList";
 import { PaliToEn } from "../../utils";
 import { PaliToEn } from "../../utils";
 import PaliText from "../template/Wbw/PaliText";
 import PaliText from "../template/Wbw/PaliText";
 import { ITagCount } from "./BookTreeWithTags";
 import { ITagCount } from "./BookTreeWithTags";
+import { IFtsData } from "../fts/FtsBookList";
 
 
 const { Text } = Typography;
 const { Text } = Typography;
 
 
@@ -19,7 +20,7 @@ interface IWidgetBookTree {
   path?: string[];
   path?: string[];
   multiSelect?: boolean;
   multiSelect?: boolean;
   multiSelectable?: boolean;
   multiSelectable?: boolean;
-  tags?: ITagCount[];
+  books?: IFtsData[];
   onChange?: Function;
   onChange?: Function;
   onSelect?: Function;
   onSelect?: Function;
   onRootChange?: Function;
   onRootChange?: Function;
@@ -29,7 +30,7 @@ const BookTreeWidget = ({
   path,
   path,
   multiSelect = false,
   multiSelect = false,
   multiSelectable = true,
   multiSelectable = true,
-  tags,
+  books,
   onChange,
   onChange,
   onSelect,
   onSelect,
   onRootChange,
   onRootChange,
@@ -161,17 +162,20 @@ const BookTreeWidget = ({
         treeData={treeData}
         treeData={treeData}
         titleRender={(node: ITocTree) => {
         titleRender={(node: ITocTree) => {
           //标签数量
           //标签数量
-          const tagName = node.tag?.slice(-1)[0];
-          const count = tags?.find((value) => value.name === tagName)?.count;
+          const tags = books?.filter((book) => {
+            return node.tag.every((el) => {
+              return book.tags?.map((item) => item.name).includes(el);
+            });
+          });
+          const count = tags?.length;
           return (
           return (
             <Space>
             <Space>
               <PaliText text={node.title} />
               <PaliText text={node.title} />
-              <Badge
-                size="small"
-                color="gray"
-                count={count ?? 0}
-                showZero={false}
-              />
+              {count ? (
+                <Badge size="small" color="gray" count={count} dot={false} />
+              ) : (
+                <></>
+              )}
             </Space>
             </Space>
           );
           );
         }}
         }}

+ 4 - 18
dashboard-v4/dashboard/src/components/corpus/BookTreeWithTags.tsx

@@ -1,7 +1,7 @@
 import { useEffect, useState } from "react";
 import { useEffect, useState } from "react";
 import BookTree from "./BookTree";
 import BookTree from "./BookTree";
 import { get } from "../../request";
 import { get } from "../../request";
-import { IFtsResponse } from "../fts/FtsBookList";
+import { IFtsData, IFtsResponse } from "../fts/FtsBookList";
 import { ISearchView } from "../fts/FullTextSearchResult";
 import { ISearchView } from "../fts/FullTextSearchResult";
 
 
 export interface ITagCount {
 export interface ITagCount {
@@ -29,7 +29,7 @@ const BookTreeWithTags = ({
   multiSelectable = true,
   multiSelectable = true,
   onChange,
   onChange,
 }: IWidget) => {
 }: IWidget) => {
-  const [tags, setTags] = useState<ITagCount[]>();
+  const [books, setBooks] = useState<IFtsData[]>();
   useEffect(() => {
   useEffect(() => {
     let words;
     let words;
     let api = "";
     let api = "";
@@ -46,21 +46,7 @@ const BookTreeWithTags = ({
     get<IFtsResponse>(url).then((json) => {
     get<IFtsResponse>(url).then((json) => {
       console.info("api response", json);
       console.info("api response", json);
       if (json.ok) {
       if (json.ok) {
-        let tagsMap = new Map<string, number>();
-        json.data.rows.forEach((value) => {
-          value.tags?.forEach((tag) => {
-            if (tag.name) {
-              const old = tagsMap.get(tag.name);
-              tagsMap.set(tag.name, old ? old + 1 : 1);
-            }
-          });
-        });
-        let _tags: ITagCount[] = [];
-        tagsMap.forEach((value, key) => {
-          _tags.push({ name: key, count: value });
-        });
-        console.log("_tags", _tags);
-        setTags(_tags);
+        setBooks(json.data.rows);
       }
       }
     });
     });
   }, [keyWord, keyWords, view]);
   }, [keyWord, keyWords, view]);
@@ -70,7 +56,7 @@ const BookTreeWithTags = ({
       multiSelectable={multiSelectable}
       multiSelectable={multiSelectable}
       root={root}
       root={root}
       path={path}
       path={path}
-      tags={tags}
+      books={books}
       onChange={onChange}
       onChange={onChange}
     />
     />
   );
   );

+ 1 - 1
dashboard-v4/dashboard/src/components/fts/FtsBookList.tsx

@@ -8,7 +8,7 @@ import { ISearchView } from "./FullTextSearchResult";
 import { ITag } from "../api/Tag";
 import { ITag } from "../api/Tag";
 
 
 const { Text } = Typography;
 const { Text } = Typography;
-interface IFtsData {
+export interface IFtsData {
   book: number;
   book: number;
   paragraph: number;
   paragraph: number;
   title?: string;
   title?: string;