Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfisher committed Aug 21, 2024
1 parent cfea788 commit 021fb58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions example/src/forms/network/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Network = createForm({
dns:[
{ name:"masterDns", title:"DNS服务器",value:"8.8.8.8"},
{ name:"slaveDns" , title:"备用DNS服务器",value:"4.4.4.4"}
],
] ,
wifi: {
title: "无线配置",
visible: computed<boolean>((net: any) => {
Expand All @@ -90,7 +90,7 @@ const Network = createForm({
validate: (value: string) => value.length > 3,
},
signal: {
value: true,
value: 1,
placeholder: "无线网络",
validate: (value: string) => value.length > 3,
},
Expand Down
2 changes: 1 addition & 1 deletion example/src/forms/network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const NetworkForm = ()=>{
</Field>
} }
</Network.Field2>
<Network.Field2 name="dns.1">
<Network.Field2 name="dns.2">
{({title,value,required,visible,validate,enable,placeholder,sync})=>{
console.log(required,visible,validate,enable)
return <Field visible={visible} label={title}>
Expand Down
49 changes: 26 additions & 23 deletions packages/core/src/field2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,17 @@ type FormFieldState<Fields extends Dict> = {
)
: never
)
}
}

// 生成每一个字段路径对应的声明类型,如{fields.xxx:{value,...}}
type FormFieldNames<State extends Dict> = {
[Key in keyof Record<Paths<FormFieldState<State['fields']>>,any>]: {
render? : FieldRender<GetTypeByPath<State,`fields.${Key}`>>
children?: FieldRender<GetTypeByPath<State,`fields.${Key}`>>
children?: FieldRender<GetTypeByPath<State,`fields.${Key}`> >
| FieldRender<GetTypeByPath<State,`fields.${Key}`>>[];
}
}



export type FieldProps3<State extends Dict> = MutableRecord<FormFieldNames<State>,'name'> & {
name: Paths<FormFieldState<State['fields']>>
Expand Down Expand Up @@ -185,23 +184,27 @@ export function createFieldComponent2<State extends Dict >(store: FormStore<Stat
}


// const f={
// fields:{
// ss1:{execute:1},
// name:{value:"zhang"},
// age:{value:18},
// wifi:{
// ssid:{value:""},
// password:{value:1},
// ss1:{execute:1},
// ss2:{execute:1}
// },
// dns:[
// {value:"192.168.1.1",a:1},
// {value:1,a:2}
// ]
// }
// }
// type Net = FormFieldState<typeof f>
// type NETL = Paths<FormFieldState<typeof f>['fields']>
// type NETL2 = FormFieldNames<FormFieldState<typeof f>,never>
const f={
fields:{
ss1:{execute:1},
name:{value:"zhang"},
age:{value:18},
wifi:{
ssid:{value:""},
password:{value:1},
ss1:{execute:1},
ss2:{execute:1}
},
dns:[
{value:"192.168.1.1",a:1},
{value:1,a:2},
{
a:{value:1,a:2},
b:{value:1,a:2},
}
]
}
}
type Net = FormFieldState<typeof f>
type NETL = Paths<FormFieldState<typeof f>['fields']>
type NETL2 = FormFieldNames<FormFieldState<typeof f>>

0 comments on commit 021fb58

Please sign in to comment.