/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Modal, Button, Input, Typography, Tabs, TabPane, Space, Spin, } from '@douyinfe/semi-ui'; /** * 通用安全验证模态框组件 * 配合 useSecureVerification Hook 使用 * @param {Object} props * @param {boolean} props.visible - 是否显示模态框 * @param {Object} props.verificationMethods - 可用的验证方式 * @param {Object} props.verificationState - 当前验证状态 * @param {Function} props.onVerify - 验证回调 * @param {Function} props.onCancel - 取消回调 * @param {Function} props.onCodeChange - 验证码变化回调 * @param {Function} props.onMethodSwitch - 验证方式切换回调 * @param {string} props.title - 模态框标题 * @param {string} props.description - 验证描述文本 */ const SecureVerificationModal = ({ visible, verificationMethods, verificationState, onVerify, onCancel, onCodeChange, onMethodSwitch, title, description, }) => { const { t } = useTranslation(); const [isAnimating, setIsAnimating] = useState(false); const [verifySuccess, setVerifySuccess] = useState(false); const { has2FA, hasPasskey, passkeySupported } = verificationMethods; const { method, loading, code } = verificationState; useEffect(() => { if (visible) { setIsAnimating(true); setVerifySuccess(false); } else { setIsAnimating(false); } }, [visible]); const handleKeyDown = (e) => { if (e.key === 'Enter' && code.trim() && !loading && method === '2fa') { onVerify(method, code); } if (e.key === 'Escape' && !loading) { onCancel(); } }; // 如果用户没有启用任何验证方式 if (visible && !has2FA && !hasPasskey) { return ( {t('确定')}} width={500} style={{ maxWidth: '90vw' }} >
{t('需要安全验证')} {t('您需要先启用两步验证或 Passkey 才能查看敏感信息。')}
{t('请前往个人设置 → 安全设置进行配置。')}
); } return (
{/* 描述信息 */} {description && ( {description} )} {/* 验证方式选择 */} {has2FA && (
} style={{ width: '100%' }} />
{t('从认证器应用中获取验证码,或使用备用码')}
)} {hasPasskey && passkeySupported && (
{t('使用 Passkey 验证')} {t('点击验证按钮,使用您的生物特征或安全密钥')}
)}
); }; export default SecureVerificationModal;