NodePanel add AutoComplete
This commit is contained in:
1 parent
c02fc34d7f
commit
fc089927ad
2 files changed
+47
-12
No files matched your search
@@ -10,6 +10,7 @@ const { Item } = Form;
|
|||||||
interface NodePanelProps {
|
interface NodePanelProps {
|
||||||
model: BehaviorNodeModel;
|
model: BehaviorNodeModel;
|
||||||
settings: Settings;
|
settings: Settings;
|
||||||
|
updateNode: (id: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NodePanelState {
|
interface NodePanelState {
|
||||||
@@ -23,30 +24,36 @@ export default class NodePanel extends React.Component<NodePanelProps> {
|
|||||||
const { model, settings } = this.props;
|
const { model, settings } = this.props;
|
||||||
this.formRef.current.setFieldsValue({
|
this.formRef.current.setFieldsValue({
|
||||||
name: model.name,
|
name: model.name,
|
||||||
|
desc: model.desc,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onFinish = (values: any) => {
|
onFinish = (values: any) => {
|
||||||
console.log('Success:', values);
|
console.log('Success:', values);
|
||||||
|
const { updateNode, model } = this.props;
|
||||||
|
model.desc = values.desc;
|
||||||
|
updateNode(model.id.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
onFinishFailed = (errorInfo: any) => {
|
onFinishFailed = (errorInfo: any) => {
|
||||||
console.log('Failed:', errorInfo);
|
console.log('Failed:', errorInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleSubmit = () => {
|
||||||
|
console.log("handleSubmit");
|
||||||
|
this.formRef.current.submit();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { model, settings } = this.props;
|
const { model, settings } = this.props;
|
||||||
const conf = settings.getNodeConf(model.name);
|
const conf = settings.getNodeConf(model.name);
|
||||||
console.log("model", model, conf);
|
|
||||||
const title = conf.desc;
|
const title = conf.desc;
|
||||||
|
|
||||||
const names: string[] = [];
|
const options: any = [];
|
||||||
settings.nodeConfig.map((e) => {
|
settings.nodeConfig.map((e) => {
|
||||||
names.push(e.name);
|
options.push({ label: `${e.name}(${e.desc})`, value: e.name });
|
||||||
})
|
})
|
||||||
|
|
||||||
const name = model.name;
|
|
||||||
|
|
||||||
const layout = {
|
const layout = {
|
||||||
labelCol: { span: 4 },
|
labelCol: { span: 4 },
|
||||||
wrapperCol: { span: 20 },
|
wrapperCol: { span: 20 },
|
||||||
@@ -57,6 +64,10 @@ export default class NodePanel extends React.Component<NodePanelProps> {
|
|||||||
{...layout}
|
{...layout}
|
||||||
name="basic"
|
name="basic"
|
||||||
onFinish={this.onFinish}
|
onFinish={this.onFinish}
|
||||||
|
initialValues={{
|
||||||
|
name: model.name,
|
||||||
|
desc: model.desc,
|
||||||
|
}}
|
||||||
ref={this.formRef}
|
ref={this.formRef}
|
||||||
>
|
>
|
||||||
<Item
|
<Item
|
||||||
@@ -69,14 +80,19 @@ export default class NodePanel extends React.Component<NodePanelProps> {
|
|||||||
name="name"
|
name="name"
|
||||||
>
|
>
|
||||||
<AutoComplete
|
<AutoComplete
|
||||||
dataSource={names}
|
options={options}
|
||||||
filterOption={(inputValue, option: any) =>
|
onBlur={this.handleSubmit}
|
||||||
option.props.children.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
|
filterOption={(inputValue: string, option: any) => {
|
||||||
}
|
return option.label.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
|
||||||
onChange={this.onFinish}
|
}}
|
||||||
defaultValue={name}
|
|
||||||
/>
|
/>
|
||||||
</Item>
|
</Item>
|
||||||
|
<Item
|
||||||
|
label="节点说明"
|
||||||
|
name="desc"
|
||||||
|
>
|
||||||
|
<Input onBlur={this.handleSubmit} />
|
||||||
|
</Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -279,6 +279,11 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateNode(id: string) {
|
||||||
|
this.graph.changeData();
|
||||||
|
this.graph.layout();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
console.log("render editor")
|
console.log("render editor")
|
||||||
const { curNodeId, treeModel, settings } = this.state;
|
const { curNodeId, treeModel, settings } = this.state;
|
||||||
@@ -295,7 +300,21 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
ref={this.ref}
|
ref={this.ref}
|
||||||
/>
|
/>
|
||||||
<Col span={6} className="editorSidebar">
|
<Col span={6} className="editorSidebar">
|
||||||
{curNode ? <NodePanel model={curNode} settings={settings} /> : <TreePanel model={treeModel} />}
|
{
|
||||||
|
curNode ?
|
||||||
|
<NodePanel
|
||||||
|
model={curNode}
|
||||||
|
settings={settings}
|
||||||
|
updateNode={id => {
|
||||||
|
const item = this.graph.findById(id);
|
||||||
|
item.draw();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
:
|
||||||
|
<TreePanel
|
||||||
|
model={treeModel}
|
||||||
|
/>
|
||||||
|
}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user