|
@@ -5,28 +5,27 @@
|
|
|
```tsx
|
|
|
import React, { useState, Key } from "react";
|
|
|
import { message } from "antd";
|
|
|
-import { DataNode } from "antd/es/tree";
|
|
|
-import { DageTreeActions } from "@dage/pc-components";
|
|
|
+import { DageTreeActions, DageTreeActionData } from "@dage/pc-components";
|
|
|
|
|
|
-let key = 0;
|
|
|
+let id = 4;
|
|
|
|
|
|
export default () => {
|
|
|
const [data, setData] = useState([
|
|
|
{
|
|
|
- title: "parent 1",
|
|
|
- key: "0",
|
|
|
+ name: "parent 1",
|
|
|
+ id: 0,
|
|
|
children: [
|
|
|
{
|
|
|
- title: "leaf 1",
|
|
|
- key: "0-0",
|
|
|
+ name: "leaf 1",
|
|
|
+ id: 1,
|
|
|
},
|
|
|
{
|
|
|
- title: "leaf 2",
|
|
|
- key: "0-1",
|
|
|
+ name: "leaf 2",
|
|
|
+ id: 2,
|
|
|
children: [
|
|
|
{
|
|
|
- title: "leaf 2-1",
|
|
|
- key: "0-1-0",
|
|
|
+ name: "leaf 2-1",
|
|
|
+ id: 3,
|
|
|
},
|
|
|
],
|
|
|
},
|
|
@@ -34,11 +33,11 @@ export default () => {
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
- const handleAddNode = async (item: DataNode, path: number[]) => {
|
|
|
+ const handleAddNode = async (item: DageTreeActionData, path: number[]) => {
|
|
|
return new Promise((res) => {
|
|
|
setTimeout(() => {
|
|
|
const temp = [...data];
|
|
|
- let _item: DataNode = temp;
|
|
|
+ let _item: DageTreeActionData = temp;
|
|
|
|
|
|
while (path.length) {
|
|
|
_item = _item[path.shift()];
|
|
@@ -50,14 +49,14 @@ export default () => {
|
|
|
if (!_item.children) {
|
|
|
_item.children = [
|
|
|
{
|
|
|
- title: "add leaf " + key,
|
|
|
- key: "add-" + key++,
|
|
|
+ name: "add leaf " + id,
|
|
|
+ id: id++,
|
|
|
},
|
|
|
];
|
|
|
} else {
|
|
|
_item.children.push({
|
|
|
- title: "add leaf " + key,
|
|
|
- key: "add-" + key++,
|
|
|
+ name: "add leaf " + id,
|
|
|
+ id: id++,
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -67,15 +66,15 @@ export default () => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- const handleEditNode = (item: DataNode, path: number[]) => {
|
|
|
+ const handleEditNode = (item: DageTreeActionData, path: number[]) => {
|
|
|
message.info("编辑节点路径:" + JSON.stringify(path));
|
|
|
};
|
|
|
|
|
|
- const handleDeleteNode = (item: DataNode, path: number[]) => {
|
|
|
+ const handleDeleteNode = (item: DageTreeActionData, path: number[]) => {
|
|
|
return new Promise((res) => {
|
|
|
setTimeout(() => {
|
|
|
const temp = [...data];
|
|
|
- let _item: DataNode = temp;
|
|
|
+ let _item: DageTreeActionData = temp;
|
|
|
|
|
|
while (path.length) {
|
|
|
if (path.length === 1) {
|
|
@@ -120,16 +119,16 @@ export default () => {
|
|
|
|
|
|
### findNodeLevel 获取节点层级
|
|
|
|
|
|
-| Name | Description | Type | Default |
|
|
|
-| --------- | ----------- | ------------ | ------------ |
|
|
|
-| nodes | -- | `DataNode[]` | `(required)` |
|
|
|
-| targetKey | 目标 key | `React.Key` | `(required)` |
|
|
|
-| curLevel | 当前层级 | `number` | `--` |
|
|
|
+| Name | Description | Type | Default |
|
|
|
+| --------- | ----------- | ---------------------- | ------------ |
|
|
|
+| nodes | -- | `DageTreeActionData[]` | `(required)` |
|
|
|
+| targetKey | 目标 key | `React.Key` | `(required)` |
|
|
|
+| curLevel | 当前层级 | `number` | `--` |
|
|
|
|
|
|
### findKeyPath 获取节点路径
|
|
|
|
|
|
-| Name | Description | Type | Default |
|
|
|
-| --------- | ----------- | ------------ | ------------ |
|
|
|
-| nodes | -- | `DataNode[]` | `(required)` |
|
|
|
-| targetKey | 目标 key | `React.Key` | `(required)` |
|
|
|
-| path | 路径 | `number[]` | `[]` |
|
|
|
+| Name | Description | Type | Default |
|
|
|
+| --------- | ----------- | ---------------------- | ------------ |
|
|
|
+| nodes | -- | `DageTreeActionData[]` | `(required)` |
|
|
|
+| targetKey | 目标 key | `React.Key` | `(required)` |
|
|
|
+| path | 路径 | `number[]` | `[]` |
|