The error occurs when uncommenting the following code:
<GoCaptcha.Slide
data={slideData}
ref={domRef}
config={config}
/>
Is it due to incompatibility? Does GoCaptcha require React version 18 or above? My project is using React version 17.0.2. I'm using the Arco Design framework. Could this be the cause?
The error occurs when uncommenting the following code: <GoCaptcha.Slide data={slideData} ref={domRef} config={config} />
Is it due to incompatibility? Does GoCaptcha require React version 18 or above? My project is using React version 17.0.2. I'm using the Arco Design framework. Could this be the cause?
import { Form, Input, Checkbox, Link, Button, Space, } from '@arco-design/web-react';
import GoCaptcha from 'go-captcha-react'; //滑块验证码s import { FormInstance } from '@arco-design/web-react/es/Form'; import { IconLock, IconUser } from '@arco-design/web-react/icon'; import React, { useEffect, useRef, useState } from 'react'; import useStorage from '@/utils/useStorage'; import useLocale from '@/utils/useLocale'; import locale from './locale'; import styles from './style/index.module.less'; import { get, post } from '@/http/http' import ApiManager from '@/http/ApiManager'; import { CodeImageInfo, QrCodeStatus } from '@/http/types'; import { SlidePoint } from 'go-captcha-react/dist/components/Slide/meta/data'; import { SlideData, defaultSlideData } from './meta/data'; import { defaultConfig, SlideConfig } from './meta/config'; import { SlideEvent } from './meta/event';
export default function LoginForm() { const formRef = useRef();
const [errorMessage, setErrorMessage] = useState('');
const [loading, setLoading] = useState(false);
const [loginParams, setLoginParams, removeLoginParams] =
useStorage('loginParams');
const api = ApiManager.getInstance();
const t = useLocale(locale);
const [rememberPassword, setRememberPassword] = useState(!!loginParams);
function afterLoginSuccess(params) { // 记住密码 if (rememberPassword) { setLoginParams(JSON.stringify(params)); } else { removeLoginParams(); } // 记录登录状态 localStorage.setItem('userStatus', 'login'); // 跳转首页 window.location.href = '/'; }
function login(params) { setErrorMessage(''); setLoading(true); // api.get("/app/login/captcha/slide", {}).then((res) => { // }); get("app/login/captcha/slide", {}).then(res => { console.log(res); }) }
function onSubmitClick() { formRef.current.validate().then((values) => { console.log("------", values); // login(values); }); }
const [activeType, setActiveType] = useState(1); function changeType(type) { console.log(type); setActiveType(type); }
const [codeImageInfo, setCodeImageInfo] = useState({ qrcodeUrl: '', qrcodeId: '' });
const getLoginCode = () => {
api.getLoginQrCode().then((res: CodeImageInfo) => {
setCodeImageInfo(res); // 更新状态
})
}
//检查登录状态 const checkQrStatus = () => { console.log(codeImageInfo); api.checkQrStatus(codeImageInfo.qrcodeId).then((res: QrCodeStatus) => { }) }
// 读取 localStorage,设置初始值 useEffect(() => { const rememberPassword = !!loginParams; setRememberPassword(rememberPassword); if (formRef.current && rememberPassword) { const parseParams = JSON.parse(loginParams); formRef.current.setFieldsValue(parseParams); } getLoginCode(); }, [loginParams, activeType]);
useEffect(() => { // 设置定时器定期检查登录状态 if (activeType == 2) { console.log("----------", codeImageInfo.qrcodeId); // const intervalId = setInterval(() => { if (codeImageInfo.qrcodeId) { checkQrStatus(); // 每隔一段时间检查一次登录状态 } // }, 10000); // return () => clearInterval(intervalId); } // 清除定时器,避免内存泄漏 }, [codeImageInfo.qrcodeId])
const [slideData, setSlideData] = useState(defaultSlideData);
const config = defaultConfig();
useEffect(() => {
// 在组件挂载后调用 refresh 方法
if (domRef.current) {
domRef.current.refresh();
}
api.getSlideParms().then((res: any) => {
const slideData: SlideData = {
thumbWidth: res.tile_width,
thumbHeight: res.tile_height,
thumbX: res.tile_x,
thumbY: res.tile_y,
image: res.image_base64,
thumb: res.tile_base64
}
setSlideData(slideData);
});
}, [])
const domRef = useRef(null);
const event: SlideEvent = { refresh: () => console.log('Captcha refreshed'), close: () => console.log('Captcha closed'), move: (x: number, y: number) => { console.log(x, y, "======拖动"); }, confirm(point, reset) { console.log(point, "点"); // reset(); }, }
return ( <div className={styles['login-form-wrapper']}>
); }