Bläddra i källkod

fix: 初始化window 错误

Before 6 månader sedan
förälder
incheckning
e8703d6a35

+ 6 - 2
src/app/[locale]/(wheel)/cashWheel/CashWheelClient.tsx

@@ -421,7 +421,9 @@ const ShareClient = forwardRef<{ open: () => void }, {}>(function ShareClient(pr
     const [currentPhoneIndex, setCurrentPhoneIndex] = useState(0);
 
     const pathname = usePathname();
-    const BASE_URL = window.location.href.replace(pathname, "");
+    // const BASE_URL = window.location.href.replace(pathname, "");
+    const [BASE_URL, setBaseUrl] = useState("");
+
     const shareUrl = `${BASE_URL}/sharecwbr?turntable=${currentWheel.id}&user=${user.id}&time=${currentWheel.end_time}`;
     const url = encodeURIComponent(`${shareUrl}`);
     const text = encodeURIComponent(`Receba 100 BRL de graça,Pix SAQUE RÁPIDO`);
@@ -468,7 +470,9 @@ const ShareClient = forwardRef<{ open: () => void }, {}>(function ShareClient(pr
         const phoneNumber = `sms:${wheel.phones?.join(",")}?body=${currentWheel.note + url}`;
         window.location.href = phoneNumber;
     };
-
+    useEffect(() => {
+        setBaseUrl(window.location.href.replace(pathname, ""));
+    }, []);
     return (
         <>
             <div className={"px-[0.26rem] py-[0.1389rem]"}>

+ 9 - 1
src/app/[locale]/affiliate/summary/page.tsx

@@ -173,16 +173,20 @@ const App: FC<Props> = (props) => {
 
     const [visible, setVisible] = useState(false);
 
+    const [BASE_URL, setBaseUrl] = useState("");
+
     const todayModalRef = useRef<ModalProps>(null);
     const totalModalRef = useRef<ModalProps>(null);
     const { userInfo } = useUserInfoStore();
     const token = getToken();
 
     // 生成分享链接
-    const BASE_URL = window.location.href.replace(pathname, "");
+    // const BASE_URL = window.location.href.replace(pathname, "");
+
     const shareUrl = `${BASE_URL}/${userInfo ? userInfo.referrer_code : "xxxxxx"}`;
 
     const url = encodeURIComponent(`${shareUrl}`);
+
     const SHARE_SOURCE = [
         {
             icon: "/summary/Facebook.png",
@@ -330,6 +334,10 @@ const App: FC<Props> = (props) => {
             Toast.show(t("receive"));
         }
     };
+
+    useEffect(() => {
+        setBaseUrl(window.location.href.replace(pathname, ""));
+    }, []);
     return (
         <div className="content">
             <div className="summary referral-router-view">

+ 1 - 0
src/app/[locale]/providers.tsx

@@ -12,6 +12,7 @@ import { setupFontSize } from "@/utils";
 import { useDebounceEffect } from "ahooks";
 import { initializeApp } from "firebase/app";
 import { getMessaging, getToken, onMessage } from "firebase/messaging";
+
 export interface ProvidersProps {
     children: ReactNode;
     themeProps?: Omit<ThemeProviderProps, "children">;