feat: 修复弹窗失败问题

This commit is contained in:
zdl
2025-10-16 16:08:43 +08:00
parent 081eb3c5c3
commit 52bec7ce8a
3 changed files with 33 additions and 14 deletions

View File

@@ -196,7 +196,7 @@ export default function WechatRegister() {
/**
* 获取微信二维码
*/
const getWechatQRCode = async () => {
const getWechatQRCode = useCallback(async () => {
try {
setIsLoading(true);
@@ -210,13 +210,13 @@ export default function WechatRegister() {
if (!response) {
throw new Error('服务器无响应');
}
if (!response.auth_url) {
throw new Error('获取二维码失败');
if (response.code !== 0) {
throw new Error(response.message || '获取二维码失败');
}
setWechatAuthUrl(response.auth_url);
setWechatSessionId(response.session_id);
setWechatAuthUrl(response.data.auth_url);
setWechatSessionId(response.data.session_id);
setWechatStatus(WECHAT_STATUS.WAITING);
// 启动轮询检查扫码状态
@@ -231,7 +231,19 @@ export default function WechatRegister() {
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"
colorScheme="green"
size="sm"
onClick={getWechatQRCode}
onClick={handleGetQRCodeClick}
isLoading={isLoading}
leftIcon={<Icon as={FaQrcode} />}
_hover={{ bg: "green.50" }}