Przeglądaj źródła

从外部打开modal

visuddhinanda 2 lat temu
rodzic
commit
dcec027a91
1 zmienionych plików z 15 dodań i 5 usunięć
  1. 15 5
      dashboard/src/components/term/TermModal.tsx

+ 15 - 5
dashboard/src/components/term/TermModal.tsx

@@ -1,10 +1,11 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
 import { Modal } from "antd";
 import { Modal } from "antd";
 import TermEdit from "./TermEdit";
 import TermEdit from "./TermEdit";
 import { ITermDataResponse } from "../api/Term";
 import { ITermDataResponse } from "../api/Term";
 
 
 interface IWidget {
 interface IWidget {
   trigger?: React.ReactNode;
   trigger?: React.ReactNode;
+  open?: boolean;
   id?: string;
   id?: string;
   word?: string;
   word?: string;
   studioName?: string;
   studioName?: string;
@@ -16,6 +17,7 @@ interface IWidget {
 }
 }
 const TermModalWidget = ({
 const TermModalWidget = ({
   trigger,
   trigger,
+  open = false,
   id,
   id,
   word,
   word,
   studioName,
   studioName,
@@ -25,9 +27,17 @@ const TermModalWidget = ({
   onUpdate,
   onUpdate,
   onClose,
   onClose,
 }: IWidget) => {
 }: IWidget) => {
-  const [isModalOpen, setIsModalOpen] = useState(false);
+  const [isModalOpen, setIsModalOpen] = useState(open);
 
 
-  const modalClone = () => {
+  useEffect(() => {
+    if (open) {
+      showModal();
+    } else {
+      modalClose();
+    }
+  }, [open]);
+
+  const modalClose = () => {
     setIsModalOpen(false);
     setIsModalOpen(false);
     if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
     if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
       document.getElementsByTagName("body")[0].removeAttribute("style");
       document.getElementsByTagName("body")[0].removeAttribute("style");
@@ -38,14 +48,14 @@ const TermModalWidget = ({
   };
   };
 
 
   const handleOk = () => {
   const handleOk = () => {
-    modalClone();
+    modalClose();
     if (typeof onClose !== "undefined") {
     if (typeof onClose !== "undefined") {
       onClose();
       onClose();
     }
     }
   };
   };
 
 
   const handleCancel = () => {
   const handleCancel = () => {
-    modalClone();
+    modalClose();
     if (typeof onClose !== "undefined") {
     if (typeof onClose !== "undefined") {
       onClose();
       onClose();
     }
     }