|
@@ -3,17 +3,13 @@ import { useEffect } from "react";
|
|
|
import { Tree, Typography } from "antd";
|
|
import { Tree, Typography } from "antd";
|
|
|
import type { DataNode, TreeProps } from "antd/es/tree";
|
|
import type { DataNode, TreeProps } from "antd/es/tree";
|
|
|
import { Key } from "antd/lib/table/interface";
|
|
import { Key } from "antd/lib/table/interface";
|
|
|
-import {
|
|
|
|
|
- FileAddOutlined,
|
|
|
|
|
- DeleteOutlined,
|
|
|
|
|
- SaveOutlined,
|
|
|
|
|
-} from "@ant-design/icons";
|
|
|
|
|
|
|
+import { DeleteOutlined, SaveOutlined } from "@ant-design/icons";
|
|
|
import { Button, Divider, Space } from "antd";
|
|
import { Button, Divider, Space } from "antd";
|
|
|
import { useIntl } from "react-intl";
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
|
|
|
const { Text } = Typography;
|
|
const { Text } = Typography;
|
|
|
|
|
|
|
|
-interface TreeNodeData {
|
|
|
|
|
|
|
+export interface TreeNodeData {
|
|
|
key: string;
|
|
key: string;
|
|
|
title: string | React.ReactNode;
|
|
title: string | React.ReactNode;
|
|
|
children: TreeNodeData[];
|
|
children: TreeNodeData[];
|
|
@@ -119,24 +115,42 @@ function treeToList(treeNode: TreeNodeData[]): ListNodeData[] {
|
|
|
|
|
|
|
|
return arrTocTree;
|
|
return arrTocTree;
|
|
|
}
|
|
}
|
|
|
-interface IWidgetEditableTree {
|
|
|
|
|
|
|
+interface IWidget {
|
|
|
treeData: ListNodeData[];
|
|
treeData: ListNodeData[];
|
|
|
|
|
+ addFileButton?: React.ReactNode;
|
|
|
|
|
+ addOnArticle?: TreeNodeData;
|
|
|
onChange?: Function;
|
|
onChange?: Function;
|
|
|
onSelect?: Function;
|
|
onSelect?: Function;
|
|
|
onSave?: Function;
|
|
onSave?: Function;
|
|
|
|
|
+ onAddFile?: Function;
|
|
|
}
|
|
}
|
|
|
const EditableTreeWidget = ({
|
|
const EditableTreeWidget = ({
|
|
|
treeData,
|
|
treeData,
|
|
|
|
|
+ addFileButton,
|
|
|
|
|
+ addOnArticle,
|
|
|
onChange,
|
|
onChange,
|
|
|
onSelect,
|
|
onSelect,
|
|
|
onSave,
|
|
onSave,
|
|
|
-}: IWidgetEditableTree) => {
|
|
|
|
|
|
|
+ onAddFile,
|
|
|
|
|
+}: IWidget) => {
|
|
|
const intl = useIntl();
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const [gData, setGData] = useState<TreeNodeData[]>([]);
|
|
const [gData, setGData] = useState<TreeNodeData[]>([]);
|
|
|
const [listTreeData, setListTreeData] = useState<ListNodeData[]>();
|
|
const [listTreeData, setListTreeData] = useState<ListNodeData[]>();
|
|
|
const [keys, setKeys] = useState<Key>("");
|
|
const [keys, setKeys] = useState<Key>("");
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (typeof addOnArticle === "undefined") {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log("add ", addOnArticle);
|
|
|
|
|
+
|
|
|
|
|
+ const newTreeData = [...gData, addOnArticle];
|
|
|
|
|
+ setGData(newTreeData);
|
|
|
|
|
+ const list = treeToList(newTreeData);
|
|
|
|
|
+ setListTreeData(list);
|
|
|
|
|
+ }, [addOnArticle]);
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const data = tocGetTreeData(treeData);
|
|
const data = tocGetTreeData(treeData);
|
|
|
console.log("tree data", data);
|
|
console.log("tree data", data);
|
|
@@ -223,7 +237,8 @@ const EditableTreeWidget = ({
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
<Space>
|
|
<Space>
|
|
|
- <Button icon={<FileAddOutlined />}>添加</Button>
|
|
|
|
|
|
|
+ {addFileButton}
|
|
|
|
|
+
|
|
|
<Button
|
|
<Button
|
|
|
icon={<DeleteOutlined />}
|
|
icon={<DeleteOutlined />}
|
|
|
danger
|
|
danger
|