|
|
@@ -9,6 +9,7 @@ import type { IEventBookTreeOnchange } from "../../../components/corpus/BookTree
|
|
|
import PaliChapterListByTag from "../../../components/corpus/PaliChapterListByTag";
|
|
|
import BookViewer from "../../../components/corpus/BookViewer";
|
|
|
import { IChapterClickEvent } from "../../../components/corpus/PaliChapterList";
|
|
|
+import { IPaliBookListResponse } from "../../../components/api/Corpus";
|
|
|
|
|
|
const Widget = () => {
|
|
|
const { root, path, tag } = useParams();
|
|
|
@@ -20,6 +21,41 @@ const Widget = () => {
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
const [openPara, setOpenPara] = useState({ book: 0, para: 0 });
|
|
|
const [drawerTitle, setDrawerTitle] = useState("");
|
|
|
+ const [tocData, setTocData] = useState<IPaliBookListResponse[]>([]);
|
|
|
+
|
|
|
+ // 根据路径,遍历目录树,获取标签
|
|
|
+ const getTagByPath = (
|
|
|
+ _path?: string,
|
|
|
+ _tocData?: IPaliBookListResponse[]
|
|
|
+ ): string[] => {
|
|
|
+ if (typeof _path === "undefined" || _path === "") {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ if (typeof _tocData === "undefined" || _tocData.length === 0) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ const arrPath = _path ? _path.split("_") : [];
|
|
|
+ let currToc = _tocData;
|
|
|
+ let nextToc: IPaliBookListResponse[] | undefined;
|
|
|
+ let found = false;
|
|
|
+ let tags: string[] = [];
|
|
|
+ for (const itPath of arrPath) {
|
|
|
+ for (const itToc of currToc) {
|
|
|
+ if (itPath === itToc.name.toLowerCase()) {
|
|
|
+ found = true;
|
|
|
+ nextToc = itToc.children;
|
|
|
+ tags = itToc.tag;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (found && nextToc) {
|
|
|
+ currToc = nextToc;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tags;
|
|
|
+ };
|
|
|
|
|
|
useEffect(() => {
|
|
|
let currRoot: string | null;
|
|
|
@@ -35,10 +71,11 @@ const Widget = () => {
|
|
|
const arrPath = path ? path.split("_") : [];
|
|
|
setBookPath(arrPath);
|
|
|
setBookRoot(currRoot);
|
|
|
- console.log("index-load", root);
|
|
|
- }, [root, path, navigate]);
|
|
|
+ const currTags = getTagByPath(path, tocData);
|
|
|
+ setBookTag(currTags);
|
|
|
+ console.log("index-load", root, path, currTags);
|
|
|
+ }, [root, path, navigate, tocData]);
|
|
|
|
|
|
- // TODO
|
|
|
return (
|
|
|
<>
|
|
|
<Row>
|
|
|
@@ -77,8 +114,11 @@ const Widget = () => {
|
|
|
root={bookRoot}
|
|
|
path={bookPath}
|
|
|
onChange={(e: IEventBookTreeOnchange) => {
|
|
|
+ console.log("book tree list on change", e);
|
|
|
navigate(`/palicanon/list/${bookRoot}/${e.path.join("_")}`);
|
|
|
- setBookTag(e.tag);
|
|
|
+ }}
|
|
|
+ onTocLoad={(toc: IPaliBookListResponse[]) => {
|
|
|
+ setTocData(toc);
|
|
|
}}
|
|
|
/>
|
|
|
<PaliChapterListByTag
|
|
|
@@ -98,7 +138,7 @@ const Widget = () => {
|
|
|
/>
|
|
|
</Col>
|
|
|
<Col xs={0} sm={0} md={4}>
|
|
|
- 侧边栏 侧边栏 侧边栏 侧边栏 侧边栏
|
|
|
+ 侧边栏
|
|
|
</Col>
|
|
|
</Row>
|
|
|
</Col>
|