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

feat:新增一个hooks

parent c2d4ec4e
This diff is collapsed.
import React, { useState } from 'react';
import { IApiRequest } from '@/utils/request';
export interface IHttpRequestReturn<T> {
data: T | null,
loading: boolean,
err: any,
run(params?: any)
}
/**
* 简易版本的useRequest hooks, 用于处理带有loading的业务场景
* @auth xjm
*/
export function useHttpRequest<T>(api: (params?, config?) => Promise<T>, config?: IApiRequest): IHttpRequestReturn<T> {
const [loading, setLoading] = useState(false)
const [data, setData] = useState<T | null>(null)
const [err, setErr] = useState()
const run = (params) => {
setLoading(true)
api(params).then((res: any) => {
setData(res.data)
}).catch(err => {
setErr(err)
}).finally(() => {
setTimeout(() => {
setLoading(false)
}, 200)
})
}
return {
data,
loading,
err,
run
}
}
\ No newline at end of file
......@@ -49,6 +49,7 @@ const CustomCheckbox = props => {
const CustomInput = props => {
const { help, ...restProps } = props
console.log(props)
return (
<AntdInput
{...restProps}
......@@ -89,7 +90,7 @@ const actions = createFormActions()
const UserRegistry = () => {
const [identityForm1] = Form.useForm();
const [licenseForm] = Form.useForm();
const [current, setCurrent] = useState(1)
const [current, setCurrent] = useState(0)
const [identityFormData, setIdentityFormData] = useState<IFormControllers[]>([])
const [licenseFormData, setLicenseFormData] = useState<IFormControllers[]>([])
const stepList = [
......@@ -309,6 +310,7 @@ const UserRegistry = () => {
pattern: v.rulePattern
}
})}
maxLength={field.fieldLength}
x-component-props={{ help: field.fieldRemark, placeholder: `请输入${field.fieldCNName}`, size: 'large'}}
x-component='CustomInput'
>
......
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