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

支持目录下数量的显示

visuddhinanda 1 год назад
Родитель
Сommit
0422bc568c
1 измененных файлов с 18 добавлено и 2 удалено
  1. 18 2
      dashboard-v4/dashboard/src/components/corpus/BookTree.tsx

+ 18 - 2
dashboard-v4/dashboard/src/components/corpus/BookTree.tsx

@@ -1,7 +1,7 @@
 import { useIntl } from "react-intl";
 import { useState, useEffect, Key } from "react";
 import { DownOutlined } from "@ant-design/icons";
-import { Button, Space, Switch, Tree } from "antd";
+import { Badge, Button, Space, Switch, Tree } from "antd";
 import { Typography } from "antd";
 
 import { get } from "../../request";
@@ -10,6 +10,7 @@ import { IPaliBookListResponse } from "../api/Corpus";
 import { ITocTree } from "./BookTreeList";
 import { PaliToEn } from "../../utils";
 import PaliText from "../template/Wbw/PaliText";
+import { ITagCount } from "../../reducers/fts-books-tag";
 
 const { Text } = Typography;
 
@@ -18,6 +19,7 @@ interface IWidgetBookTree {
   path?: string[];
   multiSelect?: boolean;
   multiSelectable?: boolean;
+  tags?: ITagCount[];
   onChange?: Function;
   onSelect?: Function;
   onRootChange?: Function;
@@ -27,6 +29,7 @@ const BookTreeWidget = ({
   path,
   multiSelect = false,
   multiSelectable = true,
+  tags,
   onChange,
   onSelect,
   onRootChange,
@@ -157,7 +160,20 @@ const BookTreeWidget = ({
         }}
         treeData={treeData}
         titleRender={(node: ITocTree) => {
-          return <PaliText text={node.title} />;
+          //标签数量
+          const tagName = node.tag?.slice(-1)[0];
+          const count = tags?.find((value) => value.name === tagName)?.count;
+          return (
+            <Space>
+              <PaliText text={node.title} />
+              <Badge
+                size="small"
+                color="gray"
+                count={count ?? 0}
+                showZero={false}
+              />
+            </Space>
+          );
         }}
       />
     </Space>