Skip to content

Commit fd33efd

Browse files
committed
fix ui
1 parent a349365 commit fd33efd

6 files changed

Lines changed: 294 additions & 44 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import {FlowForm, FormField} from "../../types";
2+
3+
export class WorkflowFormManager {
4+
5+
private readonly form: FlowForm;
6+
private readonly formList: FlowForm[];
7+
8+
constructor(form: FlowForm) {
9+
this.form = form;
10+
this.formList = [];
11+
this.loadFormList();
12+
}
13+
14+
private loadFormList(): void {
15+
this.formList.push(this.form);
16+
if(this.form.subForms && this.form.subForms.length>0) {
17+
for (const subForm of this.form.subForms) {
18+
this.formList.push(subForm);
19+
}
20+
}
21+
}
22+
23+
public getFormFields(code:string){
24+
for (const subForm of this.formList) {
25+
if (subForm.code == code) {
26+
return subForm.fields || [];
27+
}
28+
}
29+
return [];
30+
}
31+
32+
public removeSubForm(code:string){
33+
const currentSubForms = this.form.subForms || [];
34+
const subForms = currentSubForms.filter(subForm => subForm.code !== code);
35+
return {
36+
...this.form,
37+
subForms:subForms
38+
}
39+
}
40+
41+
public addSubForm(values:any){
42+
const subForms = [...this.form.subForms || []];
43+
subForms.push(values);
44+
return {
45+
...this.form,
46+
subForms:subForms
47+
}
48+
}
49+
50+
public mergeValue(code: string, values: any):FlowForm {
51+
const currentFields = this.getFormFields(code);
52+
const currentCode = values['code'];
53+
const list:FormField[] = [];
54+
let exist = false;
55+
for (const field of currentFields) {
56+
if(field.code == currentCode) {
57+
list.push(values);
58+
exist = true;
59+
}else {
60+
list.push(field);
61+
}
62+
}
63+
if(!exist){
64+
list.push(values);
65+
}
66+
const mainCode = this.form.code;
67+
if(code==mainCode){
68+
return {
69+
...this.form,
70+
fields:list,
71+
}
72+
}else {
73+
return {
74+
...this.form,
75+
fields:list,
76+
subForms:this.form.subForms.map(item=>{
77+
if(item.code===code){
78+
return {
79+
...item,
80+
fields:list
81+
}
82+
}else {
83+
return item;
84+
}
85+
}),
86+
}
87+
}
88+
}
89+
90+
public removeField(formCode: string, fieldCode: string) {
91+
const currentFields = this.getFormFields(formCode) || [];
92+
const fields = [...currentFields];
93+
const list = fields.filter(file => file.code !== fieldCode);
94+
const mainCode = this.form.code;
95+
if(formCode==mainCode){
96+
return {
97+
...this.form,
98+
fields:list,
99+
}
100+
}else {
101+
return {
102+
...this.form,
103+
fields:list,
104+
subForms:this.form.subForms.map(item=>{
105+
if(item.code===formCode){
106+
return {
107+
...item,
108+
fields:list
109+
}
110+
}else {
111+
return item;
112+
}
113+
}),
114+
}
115+
}
116+
}
117+
118+
119+
}

frontend/packages/flow-design/src/pages/design-panel/manager/workflow/index.ts renamed to frontend/packages/flow-design/src/pages/design-panel/manager/workflow/strategy.ts

File renamed without changes.

frontend/packages/flow-design/src/pages/design-panel/presenters/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {DesignPanelApi, initStateData, State, TabPanelType} from "../types";
22
import {Dispatch} from "@flow-engine/flow-core";
33
import {FormActionContext} from "@/pages/design-panel/presenters/form";
4+
import {WorkflowFormManager} from "@/pages/design-panel/manager/workflow/form";
45

56
export class Presenter {
67

@@ -42,6 +43,46 @@ export class Presenter {
4243
});
4344
}
4445

46+
public removeWorkflowFormField(formCode:string,fieldCode:string){
47+
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
48+
const form = workflowFormManager.removeField(formCode, fieldCode);
49+
console.log(form);
50+
this.updateWorkflowForm(form);
51+
}
52+
53+
public removeWorkflowSubForm(code: string) {
54+
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
55+
const form = workflowFormManager.removeSubForm(code);
56+
console.log(form);
57+
this.updateWorkflowForm(form);
58+
}
59+
60+
public addWorkflowSubForm(values:any){
61+
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
62+
const form = workflowFormManager.addSubForm(values);
63+
console.log(form);
64+
this.updateWorkflowForm(form);
65+
}
66+
67+
private updateWorkflowForm(form:any) {
68+
this.dispatch((prevState: State) => {
69+
return {
70+
...prevState,
71+
workflow: {
72+
...prevState.workflow,
73+
form
74+
}
75+
}
76+
});
77+
}
78+
79+
public updateWorkflowFormField(code:string,values:any){
80+
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
81+
const form = workflowFormManager.mergeValue(code,values);
82+
console.log(form);
83+
this.updateWorkflowForm(form);
84+
}
85+
4586
public save() {
4687
const values = this.formActionContext.save();
4788
this.updateWorkflow(values);

0 commit comments

Comments
 (0)