修复登录成功后页面卡在处理中的问题
This commit is contained in:
parent
42173615a5
commit
419712f1bf
@ -41,6 +41,8 @@ export default function Page() {
|
|||||||
// 系统通知状态
|
// 系统通知状态
|
||||||
const [notification, setNotification] = useState<{ enabled: boolean; title: string; content: string } | null>(null);
|
const [notification, setNotification] = useState<{ enabled: boolean; title: string; content: string } | null>(null);
|
||||||
const [showNotification, setShowNotification] = useState(false);
|
const [showNotification, setShowNotification] = useState(false);
|
||||||
|
const loginRedirectTimerRef = useRef<number | null>(null);
|
||||||
|
const loginRedirectFallbackTimerRef = useRef<number | null>(null);
|
||||||
|
|
||||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
|
|
||||||
@ -265,29 +267,58 @@ export default function Page() {
|
|||||||
|
|
||||||
// 处理登录状态变化
|
// 处理登录状态变化
|
||||||
useEffect(() => {
|
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") {
|
if (state.status === "failed") {
|
||||||
|
setIsSuccessful(false);
|
||||||
setIsHandlingToken(false);
|
setIsHandlingToken(false);
|
||||||
toast({
|
toast({
|
||||||
type: "error",
|
type: "error",
|
||||||
description: "邮箱或密码不正确",
|
description: "邮箱或密码不正确",
|
||||||
});
|
});
|
||||||
} else if (state.status === "invalid_data") {
|
} else if (state.status === "invalid_data") {
|
||||||
|
setIsSuccessful(false);
|
||||||
setIsHandlingToken(false);
|
setIsHandlingToken(false);
|
||||||
toast({
|
toast({
|
||||||
type: "error",
|
type: "error",
|
||||||
description: "提交的信息校验失败",
|
description: "提交的信息校验失败",
|
||||||
});
|
});
|
||||||
} else if (state.status === "success") {
|
} else if (state.status === "success") {
|
||||||
|
toast({ type: "success", description: "登录成功,正在进入首页" });
|
||||||
setIsSuccessful(true);
|
setIsSuccessful(true);
|
||||||
window.location.href = "/";
|
loginRedirectTimerRef.current = window.setTimeout(() => {
|
||||||
|
window.location.replace("/");
|
||||||
|
}, 120);
|
||||||
|
loginRedirectFallbackTimerRef.current = window.setTimeout(() => {
|
||||||
|
window.location.assign("/");
|
||||||
|
}, 1600);
|
||||||
}
|
}
|
||||||
}, [state.status]);
|
}, [state.status]);
|
||||||
|
|
||||||
const handleSubmit = (formData: FormData) => {
|
const handleSubmit = (formData: FormData) => {
|
||||||
|
setIsSuccessful(false);
|
||||||
setEmail(formData.get("email") as string);
|
setEmail(formData.get("email") as string);
|
||||||
formAction(formData);
|
formAction(formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (loginRedirectTimerRef.current) {
|
||||||
|
window.clearTimeout(loginRedirectTimerRef.current);
|
||||||
|
}
|
||||||
|
if (loginRedirectFallbackTimerRef.current) {
|
||||||
|
window.clearTimeout(loginRedirectFallbackTimerRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
// 根据组织名称启动钉钉登录(在 iframe 中打开)
|
// 根据组织名称启动钉钉登录(在 iframe 中打开)
|
||||||
const startDingTalkLoginForOrg = (orgName: string) => {
|
const startDingTalkLoginForOrg = (orgName: string) => {
|
||||||
// 清除 URL 中的 token 参数,避免干扰
|
// 清除 URL 中的 token 参数,避免干扰
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user