|
@@ -3,14 +3,19 @@ import { useSystemStore } from "@/stores/useSystemStore";
|
|
|
import { Button, Popup } from "antd-mobile";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
import Image from "next/image";
|
|
|
-import { useEffect, useRef } from "react";
|
|
|
+import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
|
|
|
|
/**
|
|
|
* @description 检测pwa是否下载
|
|
|
* if 下载 不弹窗 , else 弹窗
|
|
|
*
|
|
|
*/
|
|
|
-const Desktop = () => {
|
|
|
+export interface DesktopRef {
|
|
|
+ onOpen: () => void;
|
|
|
+ onClose: () => void;
|
|
|
+}
|
|
|
+interface Props {}
|
|
|
+const Desktop = forwardRef<DesktopRef, Props>(function Desktop(props, ref) {
|
|
|
const prompt = useRef<Event | null>(null);
|
|
|
|
|
|
const t = useTranslations("HomePage");
|
|
@@ -49,6 +54,15 @@ const Desktop = () => {
|
|
|
};
|
|
|
return () => window.removeEventListener("beforeinstallprompt", initDesktop);
|
|
|
}, []);
|
|
|
+
|
|
|
+ useImperativeHandle(ref, () => {
|
|
|
+ return {
|
|
|
+ onClose: () => setHasDesktop(false),
|
|
|
+ onOpen: () => {
|
|
|
+ setHasDesktop(true);
|
|
|
+ },
|
|
|
+ };
|
|
|
+ });
|
|
|
return (
|
|
|
<Popup
|
|
|
visible={!!isHasDesktop}
|
|
@@ -90,5 +104,5 @@ const Desktop = () => {
|
|
|
</div>
|
|
|
</Popup>
|
|
|
);
|
|
|
-};
|
|
|
+});
|
|
|
export default Desktop;
|