Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
linweijiong
jinfa-platform
Commits
2fb11c20
Commit
2fb11c20
authored
Aug 06, 2020
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入多级菜单联动逻辑
parent
1865b76e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
0 deletions
+90
-0
linkEnum.ts
src/components/NiceForm/linkages/linkEnum.ts
+90
-0
No files found.
src/components/NiceForm/linkages/linkEnum.ts
0 → 100644
View file @
2fb11c20
import
{
useValueLinkageEffect
,
FormPath
,
FormEffectHooks
}
from
'@formily/antd'
/**
* 联动逻辑, 主要用于处理省市区等联动, 必须手动设置 originData
* @param childKey 子集菜单key
* @param [transformFn] 用于是否转化label和value的字段,可不传
* @author xjm
* @example `
<NiceForm
onSubmit={values => console.log(values)}
actions = {actions}
effects={($, {setFieldState}) => {
onFormMount$().subscribe(() => {
mockData().then((data:any) => {
setFieldState('a', state => {
state.originData = data
state.props.enum = data.map(v => ({
label: v.name,
value: v.id
}))
})
})
})
useLinkEnumEffect(data => data.map(v => ({
label: v.name,
value: v.id
})), 'children')
}}
schema={{
type: 'object',
properties: {
a: {
type: 'string',
enum: [],
"x-linkages": [
{
type: 'value:linkage',
condition: "{{!!$value}}",
origin: 'a',
target: 'b',
}
]
},
b: {
type: 'string',
enum: [],
"x-linkages": [
{
type: 'value:linkage',
condition: "{{!!$value}}",
origin: 'b',
target: 'c'
}
]
},
c: {
type: 'string',
enum: []
}
}
}}
/>
*
* `
*/
export
const
useLinkEnumEffect
=
(
childKey
,
transformFn
?)
=>
{
useValueLinkageEffect
({
type
:
'value:linkage'
,
resolve
:
({
origin
,
target
},
{
setFieldState
,
getFieldState
})
=>
{
getFieldState
(
origin
,
state
=>
{
const
{
originData
=
[]
}
=
state
setFieldState
(
target
,
targetState
=>
{
const
result
=
originData
.
find
(
v
=>
v
.
id
===
state
.
value
)[
childKey
]
||
[]
targetState
.
value
=
''
targetState
.
originData
=
result
targetState
.
props
.
enum
=
transformFn
?
transformFn
(
result
)
:
result
})
})
},
reject
:
({
target
},
{
setFieldState
,
getFieldState
})
=>
{
setFieldState
(
target
,
targetState
=>
{
targetState
.
value
=
''
targetState
.
props
.
enum
=
[]
})
}
})
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment