year 3 هفته پیش
والد
کامیت
8ee8ad24fe
2فایلهای تغییر یافته به همراه46 افزوده شده و 6 حذف شده
  1. 16 6
      src/app/[locale]/(TabBar)/deposit/component/deposit/index.tsx
  2. 30 0
      src/utils/index.ts

+ 16 - 6
src/app/[locale]/(TabBar)/deposit/component/deposit/index.tsx

@@ -13,6 +13,7 @@ import { useEventPoint } from "@/hooks/useEventPoint";
 import { useRouter } from "@/i18n/routing";
 import { useSystemStore } from "@/stores/useSystemStore";
 import { useWalletStore } from "@/stores/useWalletStore";
+import { goBlankPage } from "@/utils";
 import { Button, Dialog, Form, Input, Toast } from "antd-mobile";
 import BigNumber from "bignumber.js";
 import clsx from "clsx";
@@ -228,15 +229,24 @@ const Deposit = () => {
             formInstanceRef.current?.resetFields();
             tipModelRef.current?.onClose();
             setAmount("");
-            // const url =
-            //     "https://caixa.pay4z.com/brl/qrcode.html?tradeNo=T2501180056ijk21kJ&amount=20&payAmount=20&currency=BRL&expiredAt=2025-01-18%2001%3A11%3A31&expire=1737173491282&raw=00020101021226870014br.gov.bcb.pix2565qrcode.santsbank.com%2Fdynamic%2Fdc8cf003-1616-47f8-94e6-16be500d05b45204000053039865802BR5907LF%20LTDA6009Sao%20Paulo62070503***6304DF54&type=QRCODE";
-
+            const url =
+                "https://caixa.pay4z.com/brl/qrcode.html?tradeNo=T2501180056ijk21kJ&amount=20&payAmount=20&currency=BRL&expiredAt=2025-01-18%2001%3A11%3A31&expire=1737173491282&raw=00020101021226870014br.gov.bcb.pix2565qrcode.santsbank.com%2Fdynamic%2Fdc8cf003-1616-47f8-94e6-16be500d05b45204000053039865802BR5907LF%20LTDA6009Sao%20Paulo62070503***6304DF54&type=QRCODE";
+            // const a = document.createElement("a");
+            // a.target = "_blank";
+            // a.href = url;
+            // document.body.append(a);
+            // setTimeout(() => {
+            //     a.click();
+            //     // window.open(url);
+            // }, 300);
+            goBlankPage(url, "_blank");
             if (res.data.pay_url) {
                 eventInitiate();
+
                 // fix: ios 限制
-                setTimeout(() => {
-                    window.open(res.data.pay_url);
-                }, 0);
+                // setTimeout(() => {
+                //     window.open(res.data.pay_url);
+                // }, 0);
             } else {
                 Toast.show({ icon: "success", content: t("code.200"), maskClickable: false });
             }

+ 30 - 0
src/utils/index.ts

@@ -71,3 +71,33 @@ export const formatAmount = (amount: string | number) => {
 
     return new BigNumber(amount).toFormat(2);
 };
+export const goBlankPage = async (handler: Function | string, target = "_self") => {
+    const isFunHanlder = typeof handler === "function";
+    let newTab: any = null;
+    const isSafariMobileBrowser =
+        /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent);
+
+    if (isFunHanlder && target === "_blank" && isSafariMobileBrowser) {
+        newTab = window.open("about:blank");
+    }
+    let href = "";
+    try {
+        href = isFunHanlder ? await handler() : handler;
+    } catch (e) {
+        if (newTab) newTab.close();
+    }
+    if (!href) return;
+
+    if (newTab && isSafariMobileBrowser) {
+        newTab.location.href = href;
+    } else {
+        const a = document.createElement("a");
+        a.target = target;
+        a.href = href;
+        document.body.append(a);
+        setTimeout(() => {
+            a.href = href;
+            a.click();
+        }, 300);
+    }
+};