Commit 22afb944 authored by 前端-许佳敏's avatar 前端-许佳敏

新增详情页时需初始化表单数据,修复异步下拉框在异常时的loading状态

parent 14174428
...@@ -23,6 +23,9 @@ export const useAsyncSelect = (name, service: () => Promise<any[]>) => { ...@@ -23,6 +23,9 @@ export const useAsyncSelect = (name, service: () => Promise<any[]>) => {
name, name,
payload: res payload: res
}) })
}).catch(err => {
linkage.loaded(name)
linkage.enum(name, [])
}) })
}) })
} }
\ No newline at end of file
import { usePageStatus } from '@/hooks/usePageStatus'
import { useEffect, useState } from 'react'
/**
* 初始化表单数据, 可传入给NiceForm的initialValues
* @param service 必须保证返回数据中有data属性 并且匹配NiceForm
*/
export const useInitValue = (service) => {
const { id } = usePageStatus()
const [state, setState] = useState<any>(null)
useEffect(() => {
if (id) {
service({id}).then(({data}) => {
setState(data)
})
}
}, [])
return state
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment