File tree Expand file tree Collapse file tree
flow-pc-approval/src/components/flow-approval/components
flow-pc-form/src/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313 "@flow-engine/flow-types" : " workspace:*" ,
1414 "@flow-engine/flow-pc-design" : " workspace:*" ,
1515 "@flow-engine/flow-pc-ui" : " workspace:*" ,
16+ "@flow-engine/flow-pc-form" : " workspace:*" ,
1617 "@flow-engine/flow-pc-approval" :" workspace:*" ,
1718 "antd" : " ^6.2.1" ,
1819 "dayjs" : " ^1.11.19" ,
Original file line number Diff line number Diff line change 11import { ViewBindPlugin } from "@flow-engine/flow-types" ;
2- import { LeaveView } from "@/views/leave.tsx " ;
2+ import { FlowFormView } from "@flow-engine/flow-pc-form " ;
33
4- ViewBindPlugin . getInstance ( ) . register ( 'default' , LeaveView ) ;
4+ ViewBindPlugin . getInstance ( ) . register ( 'default' , FlowFormView ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1515 "build:app-pc" : " pnpm -F @flow-engine/app-pc build" ,
1616 "dev:app-pc" : " pnpm -F @flow-engine/app-pc dev" ,
1717 "dev:app-mobile" : " pnpm -F @flow-engine/app-mobile dev" ,
18- "watch:flow-design" : " pnpm -F @flow-engine/flow-design dev" ,
19- "watch:flow-form" : " pnpm -F @flow-engine/flow-form dev"
18+ "watch:flow-pc- design" : " pnpm -F @flow-engine/flow-pc -design dev" ,
19+ "watch:flow-pc- form" : " pnpm -F @flow-engine/flow-pc -form dev"
2020 },
2121 "keywords" : [],
2222 "author" : " " ,
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ interface FormViewComponentProps{
1010export const FormViewComponent : React . FC < FormViewComponentProps > = ( props ) => {
1111 const { state, context} = useApprovalContext ( ) ;
1212 const ViewComponent = ViewBindPlugin . getInstance ( ) . get ( state . flow ?. view || 'default' ) ;
13+
14+ const formMeta = state . flow ?. form ;
15+
1316 // 是否可合并审批
1417 const mergeable = state . flow ?. mergeable || false ;
1518 const todos = state . flow ?. todos || [ ] ;
@@ -41,7 +44,7 @@ export const FormViewComponent: React.FC<FormViewComponentProps> = (props) => {
4144 } ) ;
4245 } , [ ] ) ;
4346
44- if ( ViewComponent ) {
47+ if ( ViewComponent && formMeta ) {
4548 if ( mergeable ) {
4649 return (
4750 < div >
@@ -54,6 +57,7 @@ export const FormViewComponent: React.FC<FormViewComponentProps> = (props) => {
5457 { viewForms . map ( ( item , index ) => (
5558 < ViewComponent
5659 key = { index }
60+ meta = { formMeta }
5761 form = { item . instance as any }
5862 onValuesChange = { props . onValuesChange }
5963 />
Original file line number Diff line number Diff line change 1+ import { FlowFormFieldMeta } from "@flow-engine/flow-types" ;
2+ import React from "react" ;
3+
4+ import { FormItemString } from "@/components/item/string" ;
5+ import { FormItemNumber } from "@/components/item/number" ;
6+ import { FormItemFloat } from "@/components/item/float" ;
7+ import { FormItemBoolean } from "@/components/item/boolean" ;
8+
9+
10+ export class FormItemFactory {
11+
12+ private readonly cache :Map < string , React . ComponentType < FlowFormFieldMeta > > ;
13+
14+ private static instance :FormItemFactory = new FormItemFactory ( ) ;
15+
16+ private constructor ( ) {
17+ this . cache = new Map ( ) ;
18+ this . cache . set ( 'number' , FormItemNumber ) ;
19+ this . cache . set ( 'string' , FormItemString ) ;
20+ this . cache . set ( 'float' , FormItemFloat ) ;
21+ this . cache . set ( 'boolean' , FormItemBoolean ) ;
22+ }
23+
24+ public static getInstance ( ) :FormItemFactory {
25+ return FormItemFactory . instance ;
26+ }
27+
28+ public createFrom ( formType :string ) {
29+ return this . cache . get ( formType ) ;
30+ }
31+
32+ }
Original file line number Diff line number Diff line change 11import React from "react" ;
22import { type ViewComponentProps } from "@flow-engine/flow-types" ;
3- import { Form , Input } from "antd" ;
3+ import { Form } from "antd" ;
44import { ObjectUtils } from "@flow-engine/flow-core" ;
5+ import { FormItemFactory } from "@/components/factory/form-item-factory" ;
56
67export const FlowFormView : React . FC < ViewComponentProps > = ( props ) => {
78
89 const [ values , setValues ] = React . useState < any > ( { } ) ;
910
1011 const form = props . form ;
1112
13+ const meta = props . meta ;
14+
15+ const fields = meta . fields || [ ] ;
16+
1217 return (
1318 < Form
1419 form = { form as any }
1520 layout = { "vertical" }
16- onBlur = { ( ) => {
21+ onBlur = { ( ) => {
1722 const latestValues = form . getFieldsValue ( ) ;
18- if ( ObjectUtils . isEqual ( values , latestValues ) ) {
23+ if ( ObjectUtils . isEqual ( values , latestValues ) ) {
1924 return ;
2025 }
2126 setValues ( latestValues ) ;
2227 props . onValuesChange ?.( latestValues ) ;
2328 } }
2429 >
25- < Form . Item
26- name = { "days" }
27- label = { "请假天数" }
28- >
29- < Input />
30- </ Form . Item >
31-
32- < Form . Item
33- name = { "desc" }
34- label = { "请假理由" }
35- >
36- < Input />
37- </ Form . Item >
30+ { fields . map ( ( field , i ) => {
31+ const FormItem = FormItemFactory . getInstance ( ) . createFrom ( field . type ) ;
32+ if ( FormItem ) {
33+ return (
34+ < FormItem
35+ key = { field . id }
36+ { ...field }
37+ />
38+ ) ;
39+ }
40+ } ) }
3841 </ Form >
3942 )
4043} ;
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { Form , Switch } from "antd" ;
3+ import { FlowFormFieldMeta } from "@flow-engine/flow-types" ;
4+
5+ export const FormItemBoolean :React . FC < FlowFormFieldMeta > = ( props ) => {
6+
7+ const rules = props . required ?[
8+ {
9+ required : props . required ,
10+ message : `${ props . name } 不能为空`
11+ }
12+ ] :[ ] ;
13+
14+ const defaultValue = props . defaultValue === "true" || false ;
15+
16+ return (
17+ < Form . Item
18+ name = { props . code }
19+ label = { props . name }
20+ required = { props . required }
21+ rules = { rules }
22+ >
23+ < Switch defaultValue = { defaultValue } />
24+ </ Form . Item >
25+ )
26+ }
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { Form , Input } from "antd" ;
3+ import { FlowFormFieldMeta } from "@flow-engine/flow-types" ;
4+
5+ export const FormItemFloat :React . FC < FlowFormFieldMeta > = ( props ) => {
6+
7+ const rules = props . required ?[
8+ {
9+ required : props . required ,
10+ message : `${ props . name } 不能为空`
11+ }
12+ ] :[ ] ;
13+
14+ return (
15+ < Form . Item
16+ name = { props . code }
17+ label = { props . name }
18+ required = { props . required }
19+ rules = { rules }
20+ >
21+ < Input type = { "number" } defaultValue = { props . defaultValue } />
22+ </ Form . Item >
23+ )
24+ }
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { Form , Input } from "antd" ;
3+ import { FlowFormFieldMeta } from "@flow-engine/flow-types" ;
4+
5+ export const FormItemNumber :React . FC < FlowFormFieldMeta > = ( props ) => {
6+
7+ const rules = props . required ?[
8+ {
9+ required : props . required ,
10+ message : `${ props . name } 不能为空`
11+ }
12+ ] :[ ] ;
13+
14+ return (
15+ < Form . Item
16+ name = { props . code }
17+ label = { props . name }
18+ required = { props . required }
19+ rules = { rules }
20+ >
21+ < Input type = { "number" } defaultValue = { props . defaultValue } />
22+ </ Form . Item >
23+ )
24+ }
You can’t perform that action at this time.
0 commit comments