2024-07-03 19:59:39 +08:00
|
|
|
|
import { checkAuth } from "@/utils/auth";
|
2024-07-31 18:16:25 +08:00
|
|
|
|
import { useRouter, usePathname, useSearchParams } from "next/navigation";
|
2024-07-19 16:22:43 +08:00
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { get } from "@/utils/storeInfo";
|
2024-12-13 18:24:36 +08:00
|
|
|
|
import { Dialog, Toast } from "antd-mobile";
|
2024-08-06 16:21:34 +08:00
|
|
|
|
import { save } from "@/utils/storeInfo";
|
|
|
|
|
import { removeUserInfo } from "@/utils/storeInfo";
|
2024-12-17 17:31:50 +08:00
|
|
|
|
import { openUrlWithBrowser } from "@/utils/tools";
|
2024-07-03 19:59:39 +08:00
|
|
|
|
export default function WithAuth(WrappedComponent) {
|
2024-07-19 16:22:43 +08:00
|
|
|
|
const router = useRouter();
|
2024-07-31 18:16:25 +08:00
|
|
|
|
|
2024-07-22 14:38:59 +08:00
|
|
|
|
const pathname = usePathname();
|
2024-07-31 18:16:25 +08:00
|
|
|
|
const searchParams = useSearchParams();
|
2024-07-19 16:22:43 +08:00
|
|
|
|
useEffect(() => {
|
2024-12-13 18:24:36 +08:00
|
|
|
|
var ua = navigator.userAgent.toLowerCase();
|
2024-12-17 17:31:50 +08:00
|
|
|
|
if (
|
|
|
|
|
(ua.indexOf("quark") > -1 || ua.indexOf("mqqbrowser") > -1) &&
|
|
|
|
|
ua.indexOf("iphone") > -1
|
|
|
|
|
) {
|
2024-12-13 18:24:36 +08:00
|
|
|
|
// 夸克浏览器
|
|
|
|
|
Dialog.show({
|
|
|
|
|
title: "提示",
|
|
|
|
|
content: "暂时不支持此浏览器,请使用Safari访问铁粉空间!",
|
|
|
|
|
// buttonText: "确认",
|
|
|
|
|
bodyStyle: {
|
|
|
|
|
maxHeight: "none",
|
|
|
|
|
width: "80vw",
|
|
|
|
|
position: "fixed",
|
|
|
|
|
top: "200px",
|
|
|
|
|
left: "10vw",
|
|
|
|
|
"--text-color": "#fff",
|
|
|
|
|
color: "#fff",
|
|
|
|
|
},
|
|
|
|
|
// cancelText:"确认",
|
|
|
|
|
// confirmText:"取消",
|
|
|
|
|
style: {
|
|
|
|
|
"--text-color": "#fff",
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-12-17 17:51:08 +08:00
|
|
|
|
openUrlWithBrowser(pathname);
|
2024-08-02 22:12:54 +08:00
|
|
|
|
}
|
2024-12-13 18:24:36 +08:00
|
|
|
|
}, []);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// if (searchParams.get("inviter")) {
|
|
|
|
|
// save("inviter", Number(searchParams.get("inviter")));
|
|
|
|
|
// }
|
2024-08-06 16:21:34 +08:00
|
|
|
|
if (!pathname.includes("webView") && !pathname.includes("login")) {
|
2024-07-22 17:55:52 +08:00
|
|
|
|
checkLogin();
|
|
|
|
|
}
|
2024-08-06 16:21:34 +08:00
|
|
|
|
|
2024-07-22 17:55:52 +08:00
|
|
|
|
// console.log("isLogin",!pathname.includes("webView") && !pathname.includes("login"))
|
2024-07-22 14:38:59 +08:00
|
|
|
|
}, [pathname]);
|
2024-07-19 16:22:43 +08:00
|
|
|
|
const checkLogin = async () => {
|
2024-07-22 14:38:59 +08:00
|
|
|
|
const hasToken = await get("token");
|
2024-09-12 18:19:31 +08:00
|
|
|
|
if (pathname.includes("wxpay_h5")) {
|
|
|
|
|
return;
|
2024-08-12 18:02:42 +08:00
|
|
|
|
}
|
2024-07-19 16:22:43 +08:00
|
|
|
|
if (hasToken) {
|
2024-08-06 16:21:34 +08:00
|
|
|
|
const currentIsLogin = await checkAuth();
|
|
|
|
|
if (!currentIsLogin) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: "当前登录失效,请重新登录",
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
removeUserInfo();
|
|
|
|
|
router.push("/login");
|
|
|
|
|
} else {
|
|
|
|
|
if (pathname.includes("login")) {
|
|
|
|
|
router.push("/");
|
2024-07-19 16:22:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-06 16:21:34 +08:00
|
|
|
|
} else if (!searchParams.get("forgetPassword")) {
|
|
|
|
|
removeUserInfo();
|
2024-07-22 14:38:59 +08:00
|
|
|
|
router.push("/login");
|
2024-07-19 16:22:43 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return WrappedComponent;
|
2024-08-06 16:21:34 +08:00
|
|
|
|
}
|