diff --git a/backend/mpc-system/services/service-party-app/src/pages/Join.tsx b/backend/mpc-system/services/service-party-app/src/pages/Join.tsx index 96b9fc7a..15d6d13f 100644 --- a/backend/mpc-system/services/service-party-app/src/pages/Join.tsx +++ b/backend/mpc-system/services/service-party-app/src/pages/Join.tsx @@ -12,6 +12,12 @@ interface SessionInfo { totalParticipants?: number; } +// 生成默认参与者名称 +function generateParticipantName(): string { + const timestamp = Date.now().toString(36).slice(-4); + return `参与者-${timestamp}`; +} + interface ValidateResult { success: boolean; error?: string; @@ -24,13 +30,14 @@ export default function Join() { const navigate = useNavigate(); const [code, setCode] = useState(inviteCode || ''); - const [participantName, setParticipantName] = useState(''); + const [participantName] = useState(generateParticipantName()); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [sessionInfo, setSessionInfo] = useState(null); const [joinToken, setJoinToken] = useState(null); const [partyId, setPartyId] = useState(null); const [step, setStep] = useState<'input' | 'confirm' | 'joining'>('input'); + const [autoJoinAttempted, setAutoJoinAttempted] = useState(false); useEffect(() => { if (inviteCode) { @@ -38,6 +45,22 @@ export default function Join() { } }, [inviteCode]); + // 自动加入:验证成功后自动加入会话 + useEffect(() => { + if ( + step === 'confirm' && + sessionInfo && + joinToken && + partyId && + participantName && + !autoJoinAttempted && + !isLoading + ) { + setAutoJoinAttempted(true); + handleJoinSession(); + } + }, [step, sessionInfo, joinToken, partyId, participantName, autoJoinAttempted, isLoading]); + const handleValidateCode = async (codeToValidate: string) => { if (!codeToValidate.trim()) { setError('请输入邀请码'); @@ -76,8 +99,8 @@ export default function Join() { }; const handleJoinSession = async () => { - if (!sessionInfo || !participantName.trim()) { - setError('请输入参与者名称'); + if (!sessionInfo) { + setError('会话信息不完整'); return; } @@ -204,42 +227,42 @@ export default function Join() { -
- - setParticipantName(e.target.value)} - placeholder="输入您的名称(其他参与者可见)" - className={styles.input} - disabled={isLoading} - /> -
- - {error &&
{error}
} - -
- - -
+ {error ? ( + <> +
{error}
+
+ + +
+ + ) : ( +
+
+

正在自动加入会话...

+
+ )} )}