select node

This commit is contained in:
zhandouxiaojiji committed 2020-10-19 17:50:37 +08:00
1 parent 46123a9b83
commit d2b0584c24
3 files changed
+34 -14

No files matched your search

+2 -3
View File
@@ -33,11 +33,10 @@ class BehaviorTree extends React.Component<BehaviorTreeProps> {
initGraph(graph: Graph) { initGraph(graph: Graph) {
const { onSelectNode } = this.props; const { onSelectNode } = this.props;
graph.on('click', (ev: GraphEvent) => { graph.on('click', (ev: GraphEvent) => {
console.log("click", ev);
if (!ev.item) { if (!ev.item) {
onSelectNode(null); onSelectNode(null);
} else if (ev.item) { } else if (ev.item.getType() == "node") {
onSelectNode(ev.item); onSelectNode(ev.item as INode);
} }
}); });
+15 -7
View File
@@ -2,10 +2,10 @@ import React from 'react';
import { Card } from 'antd'; import { Card } from 'antd';
import { DetailPanel, withEditorContext } from 'gg-editor'; import { DetailPanel, withEditorContext } from 'gg-editor';
import { EditorContextProps } from 'gg-editor/lib/components/EditorContext'; import { EditorContextProps } from 'gg-editor/lib/components/EditorContext';
import { INode } from '@antv/g6/lib/interface/item';
interface NodePanelProps extends EditorContextProps { interface NodePanelProps extends EditorContextProps {
curNode: INode | null;
} }
interface NodePanelState { interface NodePanelState {
@@ -14,16 +14,24 @@ interface NodePanelState {
class Panel extends React.Component<NodePanelProps> { class Panel extends React.Component<NodePanelProps> {
componentDidMount() { componentDidMount() {
console.log(this.props);
this.props.graph.on("click", (ev: any) => {
console.log("on click", ev);
})
} }
renderNode() {
console.log("NodePanel render", this.props);
const { curNode } = this.props;
return (
<div>
{curNode.getModel().label}
</div>
)
}
render() { render() {
console.log("NodePanel render", this.props); console.log("NodePanel render", this.props);
const { curNode } = this.props;
return ( return (
<Card title="节点信息" style={{ height: "100%" }}> <Card title="节点信息" style={{ height: "100%" }}>
未选中fefqwefqwefwewef {curNode ? this.renderNode() : "未选中"}
</Card> </Card>
) )
} }
+17 -4
View File
@@ -3,6 +3,7 @@ import GGEditor, { Mind, RegisterNode, withEditorContext } from 'gg-editor';
import { Row, Col } from 'antd'; import { Row, Col } from 'antd';
import NodePanel from './NodePanel'; import NodePanel from './NodePanel';
import BehaviorTree from './BehaviorTree'; import BehaviorTree from './BehaviorTree';
import { INode } from '@antv/g6/lib/interface/item';
import './Editor.css'; import './Editor.css';
@@ -10,7 +11,15 @@ export interface EditorProps {
filepath: string; filepath: string;
} }
export default class Editor extends React.Component<EditorProps> { interface EditorState {
curNode: INode | null;
}
export default class Editor extends React.Component<EditorProps, EditorState> {
state: EditorState = {
curNode: null
}
componentWillMount() { componentWillMount() {
} }
@@ -19,18 +28,22 @@ export default class Editor extends React.Component<EditorProps> {
} }
render() { render() {
const { curNode } = this.state;
return ( return (
<GGEditor className="editor"> <GGEditor className="editor">
<Row className="editorBd"> <Row className="editorBd">
<Col span={18} className="editorContent"> <Col span={18} className="editorContent">
<BehaviorTree <BehaviorTree
onSelectNode={(node) => { onSelectNode={(node) => {
console.log("onSelectNode", node) console.log("onSelectNode", node);
this.setState({ curNode: node });
}} }}
/> />
</Col> </Col>
<Col span={6} className="editorSidebar"> <Col span={6} className="editorSidebar">
<NodePanel /> <NodePanel
curNode={curNode}
/>
</Col> </Col>
</Row> </Row>
</GGEditor> </GGEditor>