Skip to content

Commit 5d1cca9

Browse files
committed
fix ui
1 parent c5354f4 commit 5d1cca9

16 files changed

Lines changed: 137 additions & 65 deletions

File tree

frontend/packages/flow-core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from "./base64";
22
export * from "./dispatch";
33
export * from "./http";
44
export * from "./presenter";
5-
export * from "./hooks.ts";
5+
export * from "./hooks.ts";
6+
export * from "./object.ts";
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
export class ObjectUtils {
2+
3+
public static isEmptyObject(obj: any) {
4+
return Object.keys(obj).length === 0 && obj.constructor === Object;
5+
}
6+
7+
8+
public static cleanObject(obj: any, options = {
9+
removeNull: true,
10+
removeUndefined: true,
11+
removeEmptyString: true,
12+
removeEmptyArray: true,
13+
removeEmptyObject: true,
14+
}) {
15+
const {
16+
removeNull,
17+
removeUndefined,
18+
removeEmptyString,
19+
removeEmptyArray,
20+
removeEmptyObject,
21+
} = options;
22+
23+
let newObj: any = {};
24+
25+
for (const [key, value] of Object.entries(obj)) {
26+
// 跳过 null
27+
if (removeNull && value === null) continue;
28+
29+
// 跳过 undefined
30+
if (removeUndefined && value === undefined) continue;
31+
32+
// 跳过空字符串
33+
if (removeEmptyString && value === '') continue;
34+
35+
// 跳过空数组
36+
if (removeEmptyArray && Array.isArray(value) && value.length === 0) continue;
37+
38+
// 跳过空对象
39+
if (removeEmptyObject &&
40+
value &&
41+
typeof value === 'object' &&
42+
!Array.isArray(value) &&
43+
Object.keys(value).length === 0) continue;
44+
45+
// 递归处理嵌套对象
46+
if (value && typeof value === 'object' && !Array.isArray(value)) {
47+
const cleaned = ObjectUtils.cleanObject(value, options);
48+
// 只有当清理后的对象不为空时才保留
49+
if (Object.keys(cleaned).length > 0) {
50+
newObj[key] = cleaned;
51+
}
52+
} else {
53+
newObj[key] = value;
54+
}
55+
}
56+
return newObj;
57+
}
58+
}

frontend/packages/flow-design/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@reduxjs/toolkit": "^2.11.2",
2828
"antd": "^6.2.1",
2929
"dayjs": "^1.11.19",
30+
"immer": "^11.1.3",
3031
"react-redux": "^9.2.0"
3132
},
3233
"devDependencies": {

frontend/packages/flow-design/src/pages/design-list/index.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ActionType, Table, TableProps} from "@/components/table";
22
import React from "react";
33
import {DataType, DesignListProps} from "./types";
44
import {usePresenter} from "./hooks/use-presenter";
5-
import {Button,Space,Popconfirm,message} from "antd";
5+
import {Button, Space, Popconfirm, message} from "antd";
66
import {DesignPanel} from "@/pages/design-panel";
77
import dayjs from "dayjs";
88

@@ -37,20 +37,19 @@ export const DesignList: React.FC<DesignListProps> = (props) => {
3737
render: (value, record) => {
3838
return (
3939
<Space>
40-
<a onClick={()=>{
40+
<a onClick={() => {
4141
presenter.editCurrent(record.id);
4242
}}>编辑</a>
4343
<Popconfirm
4444
title={"确认要删除该流程吗?"}
45-
onConfirm={()=>{
46-
presenter.deleteRecord(record.id).then(()=>{
45+
onConfirm={() => {
46+
presenter.deleteRecord(record.id).then(() => {
4747
message.success('流程已删除.')
4848
});
4949
}}
5050
>
5151
<a>删除</a>
5252
</Popconfirm>
53-
5453
</Space>
5554
)
5655
}
@@ -60,13 +59,17 @@ export const DesignList: React.FC<DesignListProps> = (props) => {
6059
return (
6160
<div>
6261
<Table<DataType>
63-
key={"id"}
62+
rowKey={"id"}
6463
actionType={actionType}
6564
toolBarRender={() => {
6665
return [
67-
<Button type={'primary'} onClick={() => {
68-
presenter.showEditable();
69-
}}>创建流程</Button>
66+
<Button
67+
key={"create"}
68+
type={'primary'}
69+
onClick={() => {
70+
presenter.clearCurrent();
71+
presenter.showEditable();
72+
}}>创建流程</Button>
7073
]
7174
}}
7275
columns={columns}

frontend/packages/flow-design/src/pages/design-list/presenter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export class Presenter extends BasePresenter<State, DesignListApi> {
4141
})
4242
}
4343

44+
public clearCurrent() {
45+
this.dispatch(preState => {
46+
return {
47+
...preState,
48+
currentId: '',
49+
}
50+
})
51+
}
52+
4453
public editCurrent(id: string) {
4554
this.dispatch(preState => {
4655
return {

frontend/packages/flow-design/src/pages/design-panel/hooks/use-design-context.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const useDesignContext = () => {
1212
if (!context) {
1313
throw new Error("DesignPanelContext must be used within useContext");
1414
}
15-
console.log('useDesignContext state', state);
1615
return {
1716
state,
1817
context,

frontend/packages/flow-design/src/pages/design-panel/layout/body.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {TabFlow} from "@/pages/design-panel/tabs/flow";
88
export const Body = ()=>{
99
const {state} = useDesignContext();
1010
const tabPanelType = state.view.tabPanel;
11+
1112
return (
1213
<>
1314
{tabPanelType ==='form' && (

frontend/packages/flow-design/src/pages/design-panel/manager/workflow/form.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ export class WorkflowFormManager {
2121
}
2222

2323
public getFormFields(code:string){
24+
let result:FormField[] = [];
2425
for (const subForm of this.formList) {
2526
if (subForm.code == code) {
26-
return subForm.fields || [];
27+
result = subForm.fields || [];
2728
}
2829
}
29-
return [];
30+
return result;
3031
}
3132

3233
public removeSubForm(code:string){
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
import {ObjectUtils} from "@flow-engine/flow-core";
2+
13
export class WorkflowStrategyManager {
2-
private readonly strategies:any[];
34

45
public static TYPE_KEY = 'strategyType';
56

6-
public static KEY_INTERFERE_STRATEGY = 'InterfereStrategy';
7-
public static KEY_URGE_STRATEGY = 'UrgeStrategy';
8-
9-
constructor(strategies:any[]) {
10-
this.strategies = strategies;
7+
constructor() {
118
}
129

13-
public toForm(){
10+
public toForm(strategies: any[]): any {
1411
let value = {};
15-
for (const key in this.strategies){
16-
const currentValue = this.strategies[key];
12+
for (const key in strategies){
13+
const currentValue = strategies[key];
1714
value = Object.assign(value, {
1815
[currentValue[WorkflowStrategyManager.TYPE_KEY]]:{
1916
...currentValue
@@ -26,15 +23,21 @@ export class WorkflowStrategyManager {
2623
return value;
2724
}
2825

29-
public getStrategy(key: string): any {
30-
const strategies:any[] = this.strategies;
31-
for(const strategy of strategies){
32-
if(strategy[key]){
33-
return strategy;
34-
}
26+
27+
public toList(values: any) {
28+
if(ObjectUtils.isEmptyObject(values)){
29+
return null;
3530
}
36-
return null;
31+
const strategies:any[] = [];
32+
for (const key in values.strategies){
33+
const item = values.strategies[key];
34+
strategies.push({
35+
[WorkflowStrategyManager.TYPE_KEY]:key,
36+
...item,
37+
});
38+
}
39+
return {
40+
strategies: strategies
41+
};
3742
}
38-
39-
4043
}

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,35 @@ export class Presenter {
3737
},
3838
workflow: {
3939
...prevState.workflow,
40-
...values
40+
...values,
41+
form: {
42+
...prevState.workflow.form,
43+
...values,
44+
}
4145
}
4246
}
4347
});
4448
}
4549

46-
public removeWorkflowFormField(formCode:string,fieldCode:string){
50+
public removeWorkflowFormField(formCode: string, fieldCode: string) {
4751
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
4852
const form = workflowFormManager.removeField(formCode, fieldCode);
49-
console.log(form);
5053
this.updateWorkflowForm(form);
5154
}
5255

5356
public removeWorkflowSubForm(code: string) {
5457
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
5558
const form = workflowFormManager.removeSubForm(code);
56-
console.log(form);
5759
this.updateWorkflowForm(form);
5860
}
5961

60-
public addWorkflowSubForm(values:any){
62+
public addWorkflowSubForm(values: any) {
6163
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
6264
const form = workflowFormManager.addSubForm(values);
63-
console.log(form);
6465
this.updateWorkflowForm(form);
6566
}
6667

67-
private updateWorkflowForm(form:any) {
68+
private updateWorkflowForm(form: any) {
6869
this.dispatch((prevState: State) => {
6970
return {
7071
...prevState,
@@ -76,10 +77,9 @@ export class Presenter {
7677
});
7778
}
7879

79-
public updateWorkflowFormField(code:string,values:any){
80+
public updateWorkflowFormField(code: string, values: any) {
8081
const workflowFormManager = new WorkflowFormManager(this.state.workflow.form);
81-
const form = workflowFormManager.mergeValue(code,values);
82-
console.log(form);
82+
const form = workflowFormManager.mergeValue(code, values);
8383
this.updateWorkflowForm(form);
8484
}
8585

@@ -115,14 +115,12 @@ export class Presenter {
115115
}
116116

117117
public loadDesign(id: string) {
118-
console.log('load design...',id);
119118
this.api.load(id).then(result => {
120119
this.updateWorkflow(result);
121120
});
122121
}
123122

124123
public createDesign() {
125-
console.log('create design...');
126124
this.api.create().then(result => {
127125
this.updateWorkflow(result);
128126
});

0 commit comments

Comments
 (0)