Sfoglia il codice sorgente

把分享组件,改为函数调用

visuddhinanda 2 anni fa
parent
commit
2422d3cfee

+ 37 - 12
dashboard/src/components/anthology/AnthologyList.tsx

@@ -20,7 +20,7 @@ import { delete_, get } from "../../request";
 import { PublicityValueEnum } from "../../components/studio/table";
 import { useEffect, useRef, useState } from "react";
 import ShareModal from "../share/ShareModal";
-import { EResType } from "../share/Share";
+import Share, { EResType } from "../share/Share";
 import {
   IResNumberResponse,
   renderBadge,
@@ -110,6 +110,26 @@ const AnthologyListWidget = ({
       },
     });
   };
+
+  const [isModalOpen, setIsModalOpen] = useState(false);
+  const [shareResId, setShareResId] = useState<string>("");
+  const [shareResType, setShareResType] = useState<EResType>(
+    EResType.collection
+  );
+  const showShareModal = (resId: string, resType: EResType) => {
+    setShareResId(resId);
+    setShareResType(resType);
+    setIsModalOpen(true);
+  };
+
+  const handleOk = () => {
+    setIsModalOpen(false);
+  };
+
+  const handleCancel = () => {
+    setIsModalOpen(false);
+  };
+
   const ref = useRef<ActionType>();
   return (
     <>
@@ -221,15 +241,9 @@ const AnthologyListWidget = ({
                     },
                     {
                       key: "share",
-                      label: (
-                        <ShareModal
-                          trigger={intl.formatMessage({
-                            id: "buttons.share",
-                          })}
-                          resId={row.id}
-                          resType={EResType.collection}
-                        />
-                      ),
+                      label: intl.formatMessage({
+                        id: "buttons.share",
+                      }),
                       icon: <TeamOutlined />,
                     },
                     {
@@ -247,12 +261,12 @@ const AnthologyListWidget = ({
                         window.open(`/anthology/${row.id}`, "_blank");
                         break;
                       case "share":
+                        console.log("share");
+                        showShareModal(row.id, EResType.collection);
                         break;
                       case "remove":
                         showDeleteConfirm(row.id, row.title);
                         break;
-                      default:
-                        break;
                     }
                   },
                 }}
@@ -371,6 +385,17 @@ const AnthologyListWidget = ({
           },
         }}
       />
+
+      <Modal
+        destroyOnClose={true}
+        width={700}
+        title="协作"
+        open={isModalOpen}
+        onOk={handleOk}
+        onCancel={handleCancel}
+      >
+        <Share resId={shareResId} resType={shareResType} />
+      </Modal>
     </>
   );
 };

+ 34 - 10
dashboard/src/components/article/ArticleList.tsx

@@ -31,7 +31,7 @@ import { PublicityValueEnum } from "../../components/studio/table";
 import { useEffect, useRef, useState } from "react";
 import ArticleTplMaker from "../../components/article/ArticleTplMaker";
 import ShareModal from "../../components/share/ShareModal";
-import { EResType } from "../../components/share/Share";
+import Share, { EResType } from "../../components/share/Share";
 import AddToAnthology from "../../components/article/AddToAnthology";
 import AnthologySelect from "../../components/anthology/AnthologySelect";
 import StudioName, { IStudio } from "../../components/auth/StudioName";
@@ -142,6 +142,24 @@ const ArticleListWidget = ({
     });
   };
   const ref = useRef<ActionType>();
+
+  const [isModalOpen, setIsModalOpen] = useState(false);
+  const [shareResId, setShareResId] = useState<string>("");
+  const [shareResType, setShareResType] = useState<EResType>(EResType.article);
+  const showShareModal = (resId: string, resType: EResType) => {
+    setShareResId(resId);
+    setShareResType(resType);
+    setIsModalOpen(true);
+  };
+
+  const handleOk = () => {
+    setIsModalOpen(false);
+  };
+
+  const handleCancel = () => {
+    setIsModalOpen(false);
+  };
+
   return (
     <>
       <ProTable<DataItem>
@@ -269,15 +287,9 @@ const ArticleListWidget = ({
                       },
                       {
                         key: "share",
-                        label: (
-                          <ShareModal
-                            trigger={intl.formatMessage({
-                              id: "buttons.share",
-                            })}
-                            resId={row.id}
-                            resType={EResType.article}
-                          />
-                        ),
+                        label: intl.formatMessage({
+                          id: "buttons.share",
+                        }),
                         icon: <TeamOutlined />,
                       },
                       {
@@ -303,6 +315,7 @@ const ArticleListWidget = ({
                     onClick: (e) => {
                       switch (e.key) {
                         case "share":
+                          showShareModal(row.id, EResType.article);
                           break;
                         case "remove":
                           showDeleteConfirm(row.id, row.title);
@@ -479,6 +492,17 @@ const ArticleListWidget = ({
           },
         }}
       />
+
+      <Modal
+        destroyOnClose={true}
+        width={700}
+        title="协作"
+        open={isModalOpen}
+        onOk={handleOk}
+        onCancel={handleCancel}
+      >
+        <Share resId={shareResId} resType={shareResType} />
+      </Modal>
     </>
   );
 };