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
陈智峰
jinfa-platform
Commits
6b964f12
Commit
6b964f12
authored
Aug 05, 2020
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增异步回填formily下拉框hook
parent
17a037df
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
0 deletions
+41
-0
useAsyncSelect.ts
src/formSchema/effects/useAsyncSelect.ts
+29
-0
addRepository.tsx
src/pages/repositories/addRepository.tsx
+12
-0
index.ts
src/services/index.ts
+0
-0
No files found.
src/formSchema/effects/useAsyncSelect.ts
0 → 100644
View file @
6b964f12
import
{
createFormActions
,
FormEffectHooks
,
FormPath
}
from
'@formily/antd'
import
{
useLinkageUtils
}
from
'@/utils/formEffectUtils'
const
{
onFormInit$
}
=
FormEffectHooks
/**
* @description 处理异步请求的下拉选择
* @param name 待处理的表单路径
* @param service 触发的异步函数, 需返回一个{label: any, value: any}形式的数组
*/
export
const
useAsyncSelect
=
(
name
,
service
:
()
=>
Promise
<
any
[]
>
)
=>
{
const
{
dispatch
,
setFieldState
}
=
createFormActions
()
const
linkage
=
useLinkageUtils
()
onFormInit$
().
subscribe
(()
=>
{
setFieldState
(
name
,
state
=>
{
FormPath
.
setIn
(
state
,
'props.x-props.hasFeedback'
,
true
)
})
linkage
.
loading
(
name
)
service
().
then
(
res
=>
{
linkage
.
loaded
(
name
)
linkage
.
enum
(
name
,
res
)
//请求结束可以dispatch一个自定义事件收尾,方便后续针对该事件做联动
dispatch
(
'requestAsyncSelect'
,
{
name
,
payload
:
res
})
})
})
}
\ No newline at end of file
src/pages/repositories/addRepository.tsx
View file @
6b964f12
...
...
@@ -21,6 +21,7 @@ import EyePreview from '@/components/EyePreview'
import
{
findItemAndDelete
}
from
'@/utils'
import
{
PublicApi
}
from
'@/services/api'
import
{
useRowSelectionTable
}
from
'@/hooks/useRowSelectionTable'
import
{
useAsyncSelect
}
from
'@/formSchema/effects/useAsyncSelect'
const
{
Item
}:
any
=
Form
...
...
@@ -43,6 +44,14 @@ const fetchProductList = async (params) => {
return
res
.
data
}
const
fetchWarehouseAll
=
async
()
=>
{
const
{
data
}
=
await
PublicApi
.
getWarehouseWarehouseAll
()
return
data
.
map
(
v
=>
({
value
:
v
.
id
,
label
:
v
.
name
}))
}
const
addSchemaAction
=
createFormActions
()
const
AddRepository
:
React
.
FC
<
{}
>
=
(
props
)
=>
{
...
...
@@ -222,6 +231,9 @@ const AddRepository:React.FC<{}> = (props) => {
tableAddButton
,
connectProduct
}
}
effects=
{
()
=>
{
useAsyncSelect
(
'warehouseId'
,
fetchWarehouseAll
)
}
}
onSubmit=
{
handleSubmit
}
actions=
{
addSchemaAction
}
schema=
{
repositDetailSchema
}
...
...
src/services/index.ts
View file @
6b964f12
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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