|
|
@ -1,4 +1,4 @@ |
|
|
|
import React, { memo, useCallback, useEffect, useState } from 'react' |
|
|
|
import React, { forwardRef, memo, useCallback, useEffect, useState, useImperativeHandle } from 'react' |
|
|
|
import { Popover, message } from 'antd' |
|
|
|
import GoCaptcha from 'go-captcha-react' |
|
|
|
import { SlideCaptchaCheckData } from './types.ts' |
|
|
@ -17,7 +17,18 @@ export interface SlideCaptProps { |
|
|
|
onChange?: (value?: string) => void |
|
|
|
} |
|
|
|
|
|
|
|
const SlideCapt = ({ config, api, value, onChange }: SlideCaptProps) => { |
|
|
|
export type SlideCaptRef = { |
|
|
|
reset: () => void |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const SlideCapt = forwardRef<SlideCaptRef | undefined, SlideCaptProps>(( |
|
|
|
{ |
|
|
|
config, |
|
|
|
api, |
|
|
|
value, |
|
|
|
onChange, |
|
|
|
}: SlideCaptProps, ref) => { |
|
|
|
|
|
|
|
const { styles } = useStyle() |
|
|
|
const [ open, setOpen ] = useState(false) |
|
|
@ -85,7 +96,20 @@ const SlideCapt = ({ config, api, value, onChange }: SlideCaptProps) => { |
|
|
|
}, 1000) |
|
|
|
}) |
|
|
|
|
|
|
|
}, [ api.checkCaptcha, setData, state, setState, setOpen, innerKey, fetchCaptcha ]) |
|
|
|
}, [ api.checkCaptcha, setData, state, setState, setOpen, innerKey, onChange, fetchCaptcha ]) |
|
|
|
|
|
|
|
useImperativeHandle(ref, () => { |
|
|
|
return { |
|
|
|
reset() { |
|
|
|
setState(prevState => ({ |
|
|
|
...prevState, type: 'default', title: '点击进行校验', |
|
|
|
})) |
|
|
|
setKey(undefined) |
|
|
|
onChange?.(undefined) |
|
|
|
refresh() |
|
|
|
} |
|
|
|
} |
|
|
|
}, [ fetchCaptcha, setState, setKey ]) |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
@ -134,6 +158,6 @@ const SlideCapt = ({ config, api, value, onChange }: SlideCaptProps) => { |
|
|
|
</Popover> |
|
|
|
</div> |
|
|
|
) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
export default memo(SlideCapt) |