From 434e32d7ed96179a672e84731bfcd414f038b37b Mon Sep 17 00:00:00 2001 From: yezian Date: Tue, 10 Dec 2024 19:02:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=86=85=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E7=94=A8webview=E5=B1=95=E7=A4=BA=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E9=A1=B5=EF=BC=8C=E6=B5=8F=E8=A7=88=E5=99=A8=E5=88=99=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/zone/[user_id]/[any]/page.jsx | 265 +++--------------------------- app/zone/[user_id]/page.jsx | 265 +++--------------------------- 2 files changed, 42 insertions(+), 488 deletions(-) diff --git a/app/zone/[user_id]/[any]/page.jsx b/app/zone/[user_id]/[any]/page.jsx index 17499b9..b002e62 100644 --- a/app/zone/[user_id]/[any]/page.jsx +++ b/app/zone/[user_id]/[any]/page.jsx @@ -1,262 +1,39 @@ "use client"; import React, { useState, useEffect } from "react"; -import { Toast, Modal } from "antd-mobile"; -import baseRequest from "@/utils/baseRequest"; -import { generateSignature } from "@/utils/crypto"; -import copy from "@/utils/copy"; -import { setCookie } from "cookies-next"; -import InOtherApp from "@/components/InOtherApp"; import { useRouter } from "next/navigation"; export default function Zone({ params }) { const router = useRouter(); - const [deviceType, setDeviceType] = useState(""); + const [isInOtherApp, setIsInOtherApp] = useState(false); + useEffect(() => { - const userAgent = navigator.userAgent; - //区分设备类型 - if (/Android/i.test(userAgent)) { - setDeviceType("Android"); - } else if (/iPhone|iPad|iPod/i.test(userAgent)) { - setDeviceType("ios"); - } else { - setDeviceType("pc"); + const userAgent = navigator.userAgent.toLowerCase(); + let temIsInOtherApp = + userAgent.match(/MicroMessenger/i) == "micromessenger" || + userAgent.match(/WeiBo/i) == "weibo" || + (userAgent.indexOf("qq") !== -1 && + userAgent.indexOf("mqqbrowser") === -1) || + /alipay/gi.test(userAgent) || + userAgent.indexOf("dingtalk") !== -1; + if (temIsInOtherApp) { + setIsInOtherApp(true); + return; } + router.replace(`https://tiefen.fun/zone/${params?.user_id}`); }, []); - //页面数据 - const [data, setData] = useState({}); - useEffect(() => { - const getData = async () => { - try { - const base = baseRequest(); - const body = { - user_id: parseInt(params.user_id, 10), - ...base, - }; - const signature = generateSignature(body); - const _response = await fetch( - `/api/zone/list_by_user_id_from_outside?signature=${signature}`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - } - ); - const _data = await _response.json(); - if (_data.ret === -1) { - Toast.show({ - content: _data.msg, - }); - return; - } - setData(_data.data.list[0]); - } catch (error) { - console.error(error); - } - }; - getData(); - }, []); - - //将主播链接复制到剪贴板,并存cookie,并打开modal - const showModal = () => { - setCookie("inviter", data?.streamer_ext?.user_id); - copy( - `【${data?.streamer_ext?.name}】『ID:${data?.streamer_ext?.user_id}』,复制此条消息,打开铁粉空间APP,查看详情https://tiefen.fun/zone/${data?.streamer_ext?.user_id}` - ); - Modal.show( - deviceType === "ios" - ? { - showCloseButton: true, - closeOnAction: true, - actions: [ - { - key: "download", - text: "前往下载", - primary: true, - onClick: () => router.push("https://tiefen.fun"), - }, - { - key: "web", - text: "手机网页版", - onClick: () => - router.push( - `https://app.tiefen.fun?inviter=${data?.streamer_ext?.user_id}` - ), - }, - ], - content: ( -
-

- {`请打开或下载【铁粉空间】APP,根据APP内弹窗指引加入空间。如未弹出,请在APP搜索ID:${data?.streamer_ext?.user_id},加入空间。`} -

-
- ), - } - : { - showCloseButton: true, - closeOnAction: true, - actions: [ - { - key: "download", - text: "前往下载", - primary: true, - onClick: () => router.push("https://tiefen.fun"), - }, - ], - content: ( -
-

- {`请打开或下载【铁粉空间】APP,根据APP内弹窗指引加入空间。如未弹出,请在APP搜索ID:${data?.streamer_ext?.user_id},加入空间。`} -

-
- ), - } - ); - }; - return ( -
- -
- -
-
-
- + {isInOtherApp && ( +
+