feat: 修复弹窗失败问题
This commit is contained in:
@@ -35,11 +35,6 @@ import AuthHeader from './AuthHeader';
|
|||||||
import VerificationCodeInput from './VerificationCodeInput';
|
import VerificationCodeInput from './VerificationCodeInput';
|
||||||
import WechatRegister from './WechatRegister';
|
import WechatRegister from './WechatRegister';
|
||||||
|
|
||||||
// API配置
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
|
||||||
// 使用空字符串让请求通过 webpack proxy,避免跨域 cookie 问题
|
|
||||||
const API_BASE_URL = "";
|
|
||||||
|
|
||||||
// 统一配置对象
|
// 统一配置对象
|
||||||
const AUTH_CONFIG = {
|
const AUTH_CONFIG = {
|
||||||
// UI文本
|
// UI文本
|
||||||
|
|||||||
@@ -18,6 +18,18 @@ export default function VerificationCodeInput({
|
|||||||
colorScheme = "green",
|
colorScheme = "green",
|
||||||
isRequired = true
|
isRequired = true
|
||||||
}) {
|
}) {
|
||||||
|
// 包装 onSendCode,确保所有错误都被捕获,防止被 ErrorBoundary 捕获
|
||||||
|
const handleSendCode = async () => {
|
||||||
|
try {
|
||||||
|
if (onSendCode) {
|
||||||
|
await onSendCode();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// 错误已经在父组件处理,这里只需要防止未捕获的 Promise rejection
|
||||||
|
console.error('Send code error (caught in VerificationCodeInput):', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormControl isRequired={isRequired} isInvalid={!!error}>
|
<FormControl isRequired={isRequired} isInvalid={!!error}>
|
||||||
<HStack>
|
<HStack>
|
||||||
@@ -30,7 +42,7 @@ export default function VerificationCodeInput({
|
|||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
colorScheme={colorScheme}
|
colorScheme={colorScheme}
|
||||||
onClick={onSendCode}
|
onClick={handleSendCode}
|
||||||
isDisabled={countdown > 0 || isLoading}
|
isDisabled={countdown > 0 || isLoading}
|
||||||
isLoading={isSending}
|
isLoading={isSending}
|
||||||
minW="120px"
|
minW="120px"
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ export default function WechatRegister() {
|
|||||||
/**
|
/**
|
||||||
* 获取微信二维码
|
* 获取微信二维码
|
||||||
*/
|
*/
|
||||||
const getWechatQRCode = async () => {
|
const getWechatQRCode = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
@@ -211,12 +211,12 @@ export default function WechatRegister() {
|
|||||||
throw new Error('服务器无响应');
|
throw new Error('服务器无响应');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.auth_url) {
|
if (response.code !== 0) {
|
||||||
throw new Error('获取二维码失败');
|
throw new Error(response.message || '获取二维码失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
setWechatAuthUrl(response.auth_url);
|
setWechatAuthUrl(response.data.auth_url);
|
||||||
setWechatSessionId(response.session_id);
|
setWechatSessionId(response.data.session_id);
|
||||||
setWechatStatus(WECHAT_STATUS.WAITING);
|
setWechatStatus(WECHAT_STATUS.WAITING);
|
||||||
|
|
||||||
// 启动轮询检查扫码状态
|
// 启动轮询检查扫码状态
|
||||||
@@ -231,7 +231,19 @@ export default function WechatRegister() {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}, [startPolling, showError]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全的按钮点击处理,确保所有错误都被捕获,防止被 ErrorBoundary 捕获
|
||||||
|
*/
|
||||||
|
const handleGetQRCodeClick = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
await getWechatQRCode();
|
||||||
|
} catch (error) {
|
||||||
|
// 错误已经在 getWechatQRCode 中处理,这里只需要防止未捕获的 Promise rejection
|
||||||
|
console.error('QR code button click error (caught in handler):', error);
|
||||||
|
}
|
||||||
|
}, [getWechatQRCode]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组件卸载时清理定时器和标记组件状态
|
* 组件卸载时清理定时器和标记组件状态
|
||||||
@@ -425,7 +437,7 @@ export default function WechatRegister() {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
colorScheme="green"
|
colorScheme="green"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={getWechatQRCode}
|
onClick={handleGetQRCodeClick}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
leftIcon={<Icon as={FaQrcode} />}
|
leftIcon={<Icon as={FaQrcode} />}
|
||||||
_hover={{ bg: "green.50" }}
|
_hover={{ bg: "green.50" }}
|
||||||
|
|||||||
Reference in New Issue
Block a user