Skip to content

Commit 626bc1e

Browse files
committed
condition
1 parent 10462bc commit 626bc1e

15 files changed

Lines changed: 527 additions & 88 deletions

File tree

frontend/packages/flow-pc/flow-pc-design/src/components/script/components/condition/components/condition-panel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {GroovyScriptPreview} from "@/components/script/components/groovy-script-preview";
3-
import {ConditionRelation} from "@/components/script/components/condition/components/condition-relation";
3+
import {RelationPanel} from "@/components/script/components/condition/components/condition-relation";
44
import {Group} from "@/components/script/components/condition/components/condition-group";
55
import {GroovyScriptConvertorUtil} from "@flow-engine/flow-core";
66
import {SCRIPT_DEFAULT_CONDITION} from "@/components/script/default-script";
@@ -30,7 +30,7 @@ export const ConditionPanel:React.FC<ConditionPanelProps> = (props)=>{
3030
</div>
3131
<div>
3232
关系
33-
<ConditionRelation/>
33+
<RelationPanel/>
3434
</div>
3535
<div>
3636
条件

frontend/packages/flow-pc/flow-pc-design/src/components/script/components/condition/components/condition-relation.tsx

Lines changed: 0 additions & 82 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {PlusCircleOutlined} from "@ant-design/icons";
2+
import React from "react";
3+
import {ConditionRelationProps} from "@/components/script/components/condition/typings";
4+
import { Dropdown } from "antd";
5+
import {
6+
useDropdownMenus
7+
} from "@/components/script/components/condition/components/condition-relation/hooks/use-dropdown-menus";
8+
9+
export const RelationAction: React.FC<ConditionRelationProps> = (props) => {
10+
const items = useDropdownMenus(props);
11+
12+
return (
13+
<Dropdown
14+
menu={{items}}>
15+
<PlusCircleOutlined
16+
style={{
17+
cursor: 'pointer',
18+
}}
19+
/>
20+
</Dropdown>
21+
)
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import {ConditionRelationProps} from "@/components/script/components/condition/typings";
3+
import {Dropdown, Tag} from "antd";
4+
import {
5+
useDropdownMenus
6+
} from "@/components/script/components/condition/components/condition-relation/hooks/use-dropdown-menus";
7+
8+
export const RelationAnd: React.FC<ConditionRelationProps> = (props) => {
9+
const items = useDropdownMenus(props);
10+
return (
11+
<Dropdown
12+
menu={{items}}>
13+
<Tag style={{
14+
cursor: "pointer",
15+
}}>
16+
{props.current.label}
17+
</Tag>
18+
</Dropdown>
19+
)
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import {ConditionRelationProps} from "@/components/script/components/condition/typings";
3+
import {
4+
useDropdownMenus
5+
} from "@/components/script/components/condition/components/condition-relation/hooks/use-dropdown-menus";
6+
import {Dropdown, Tag} from "antd";
7+
8+
export const RelationCondition: React.FC<ConditionRelationProps> = (props) => {
9+
const items = useDropdownMenus(props);
10+
return (
11+
<Dropdown
12+
menu={{items}}>
13+
<Tag style={{
14+
cursor: "pointer",
15+
}}>
16+
{props.current.label}
17+
</Tag>
18+
</Dropdown>
19+
)
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {Dropdown, Tag} from "antd";
2+
import React from "react";
3+
import {ConditionRelationProps, LogicalRelation} from "@/components/script/components/condition/typings";
4+
import {
5+
useDropdownMenus
6+
} from "@/components/script/components/condition/components/condition-relation/hooks/use-dropdown-menus";
7+
import {RelationRender} from "@/components/script/components/condition/components/condition-relation/render";
8+
9+
export const RelationGroup: React.FC<ConditionRelationProps> = (props) => {
10+
const items = useDropdownMenus(props);
11+
12+
const relations = React.useMemo(() => {
13+
const list: LogicalRelation[] = [];
14+
if (props.current.children) {
15+
list.push(...props.current.children);
16+
}
17+
list.push({
18+
type: 'action'
19+
})
20+
return list;
21+
}, [props.current.children]);
22+
23+
return (
24+
<>
25+
<Dropdown
26+
menu={{items}}>
27+
<Tag
28+
style={{
29+
cursor: "pointer",
30+
}}
31+
></Tag>
32+
</Dropdown>
33+
{RelationRender.getInstance().renderList(relations)}
34+
<Dropdown
35+
menu={{items}}>
36+
<Tag
37+
style={{
38+
cursor: "pointer",
39+
}}
40+
></Tag>
41+
</Dropdown>
42+
</>
43+
)
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import {ConditionGroup, LogicalRelation} from "@/components/script/components/condition/typings";
2+
import React from "react";
3+
import {ConditionRelationPresenter} from "@/components/script/components/condition/presenters/relation-presenter";
4+
import {GroupConvertor} from "@/components/script/components/condition/convertor/group";
5+
import {IdUtils} from "@/utils";
6+
7+
export class MenuRelation {
8+
9+
private readonly leftRelation?: LogicalRelation;
10+
private readonly current: LogicalRelation;
11+
private readonly menuList: any[];
12+
private readonly groups: ConditionGroup[];
13+
private readonly presenter: ConditionRelationPresenter;
14+
15+
constructor(presenter: ConditionRelationPresenter,
16+
current: LogicalRelation,
17+
groups: ConditionGroup[],
18+
leftRelation?: LogicalRelation) {
19+
this.presenter = presenter;
20+
this.leftRelation = leftRelation;
21+
this.current = current;
22+
this.groups = groups;
23+
this.menuList = [];
24+
this.initMenus();
25+
}
26+
27+
private initMenus() {
28+
const currentType = this.current.type;
29+
if (currentType === 'action') {
30+
if (this.leftRelation) {
31+
const leftType = this.leftRelation.type;
32+
if (leftType === 'and' || leftType === 'or') {
33+
this.menuList.push(this.createGroup());
34+
if (this.groups.length > 0) {
35+
this.menuList.push(this.createCondition());
36+
}
37+
}
38+
if (leftType === 'group' || leftType === 'condition') {
39+
this.menuList.push(this.createAnd());
40+
this.menuList.push(this.createOr());
41+
}
42+
} else {
43+
this.menuList.push(this.createGroup());
44+
if (this.groups.length > 0) {
45+
this.menuList.push(this.createCondition());
46+
}
47+
}
48+
return;
49+
}
50+
51+
this.menuList.push(this.createRemove());
52+
}
53+
54+
55+
private createOr() {
56+
return {
57+
key: 'or',
58+
label: (
59+
<a>
60+
或者
61+
</a>
62+
),
63+
onClick: () => {
64+
this.addRelation({
65+
type: 'or',
66+
id: IdUtils.generateId(),
67+
label: '或者'
68+
});
69+
}
70+
}
71+
}
72+
73+
private createCondition() {
74+
const children = this.groups.map(item => {
75+
const convert = new GroupConvertor(item)
76+
return {
77+
label: convert.getLabel(),
78+
value: item.id,
79+
key: item.id,
80+
onClick: () => {
81+
this.addRelation({
82+
id: IdUtils.generateId(),
83+
type: 'condition',
84+
label: convert.getLabel(),
85+
groupId: item.id
86+
});
87+
}
88+
}
89+
});
90+
91+
return {
92+
key: 'condition',
93+
label: (
94+
<a>
95+
条件
96+
</a>
97+
),
98+
children: children
99+
}
100+
}
101+
102+
private createRemove() {
103+
return {
104+
key: 'remove',
105+
danger: true,
106+
label: (
107+
<a>
108+
删除
109+
</a>
110+
),
111+
onClick: () => {
112+
this.removeRelation();
113+
}
114+
}
115+
}
116+
117+
private createGroup() {
118+
return {
119+
key: 'group',
120+
label: (
121+
<a>
122+
括号
123+
</a>
124+
),
125+
onClick: () => {
126+
this.addRelation({
127+
type: 'group',
128+
id: IdUtils.generateId(),
129+
label: '括号',
130+
children: []
131+
});
132+
}
133+
}
134+
}
135+
136+
private createAnd() {
137+
return {
138+
key: 'and',
139+
label: (
140+
<a>
141+
并且
142+
</a>
143+
),
144+
onClick: () => {
145+
this.addRelation({
146+
type: 'and',
147+
id: IdUtils.generateId(),
148+
label: '并且'
149+
});
150+
}
151+
}
152+
}
153+
154+
private removeRelation = () => {
155+
const currentId = this.current.id;
156+
if (currentId) {
157+
this.presenter.removeRelation(currentId);
158+
}
159+
}
160+
161+
private addRelation = (target: LogicalRelation) => {
162+
const currentId = this.current.id;
163+
this.presenter.addRelation(
164+
target,
165+
currentId
166+
);
167+
}
168+
169+
public getMenus() {
170+
return this.menuList;
171+
}
172+
}

0 commit comments

Comments
 (0)