diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index 76e7875..9f15454 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -41,6 +41,8 @@ export default function Page() { // 系统通知状态 const [notification, setNotification] = useState<{ enabled: boolean; title: string; content: string } | null>(null); const [showNotification, setShowNotification] = useState(false); + const loginRedirectTimerRef = useRef(null); + const loginRedirectFallbackTimerRef = useRef(null); const iframeRef = useRef(null); @@ -265,29 +267,58 @@ export default function Page() { // 处理登录状态变化 useEffect(() => { + if (loginRedirectTimerRef.current) { + window.clearTimeout(loginRedirectTimerRef.current); + loginRedirectTimerRef.current = null; + } + if (loginRedirectFallbackTimerRef.current) { + window.clearTimeout(loginRedirectFallbackTimerRef.current); + loginRedirectFallbackTimerRef.current = null; + } + if (state.status === "failed") { + setIsSuccessful(false); setIsHandlingToken(false); toast({ type: "error", description: "邮箱或密码不正确", }); } else if (state.status === "invalid_data") { + setIsSuccessful(false); setIsHandlingToken(false); toast({ type: "error", description: "提交的信息校验失败", }); } else if (state.status === "success") { + toast({ type: "success", description: "登录成功,正在进入首页" }); setIsSuccessful(true); - window.location.href = "/"; + loginRedirectTimerRef.current = window.setTimeout(() => { + window.location.replace("/"); + }, 120); + loginRedirectFallbackTimerRef.current = window.setTimeout(() => { + window.location.assign("/"); + }, 1600); } }, [state.status]); const handleSubmit = (formData: FormData) => { + setIsSuccessful(false); setEmail(formData.get("email") as string); formAction(formData); }; + useEffect(() => { + return () => { + if (loginRedirectTimerRef.current) { + window.clearTimeout(loginRedirectTimerRef.current); + } + if (loginRedirectFallbackTimerRef.current) { + window.clearTimeout(loginRedirectFallbackTimerRef.current); + } + }; + }, []); + // 根据组织名称启动钉钉登录(在 iframe 中打开) const startDingTalkLoginForOrg = (orgName: string) => { // 清除 URL 中的 token 参数,避免干扰