Browse Source

用tabs 切换右侧面板

visuddhinanda 2 years ago
parent
commit
96be27d6ec

+ 66 - 45
dashboard/src/components/article/RightPanel.tsx

@@ -1,19 +1,20 @@
-import { Affix } from "antd";
+import { Affix, Button, Tabs } from "antd";
 import { useEffect, useState } from "react";
 import { useEffect, useState } from "react";
+import { CloseOutlined } from "@ant-design/icons";
+
 import { IChannel } from "../channel/Channel";
 import { IChannel } from "../channel/Channel";
 import ChannelPickerTable from "../channel/ChannelPickerTable";
 import ChannelPickerTable from "../channel/ChannelPickerTable";
-
 import DictComponent from "../dict/DictComponent";
 import DictComponent from "../dict/DictComponent";
 import { ArticleType } from "./Article";
 import { ArticleType } from "./Article";
 
 
-export type TPanelName = "dict" | "channel" | "close";
+export type TPanelName = "dict" | "channel" | "close" | "open";
 interface IWidget {
 interface IWidget {
   curr?: TPanelName;
   curr?: TPanelName;
   type: ArticleType;
   type: ArticleType;
   articleId: string;
   articleId: string;
   selectedChannelKeys?: string[];
   selectedChannelKeys?: string[];
   onChannelSelect?: Function;
   onChannelSelect?: Function;
-  channelReload?: boolean;
+  onClose?: Function;
 }
 }
 const RightPanelWidget = ({
 const RightPanelWidget = ({
   curr = "close",
   curr = "close",
@@ -21,62 +22,82 @@ const RightPanelWidget = ({
   articleId,
   articleId,
   onChannelSelect,
   onChannelSelect,
   selectedChannelKeys,
   selectedChannelKeys,
-  channelReload = false,
+  onClose,
 }: IWidget) => {
 }: IWidget) => {
-  const [dict, setDict] = useState("none");
-  const [channel, setChannel] = useState("none");
+  const [open, setOpen] = useState(false);
 
 
   useEffect(() => {
   useEffect(() => {
     switch (curr) {
     switch (curr) {
+      case "open":
+        setOpen(true);
+        break;
       case "dict":
       case "dict":
-        setDict("block");
-        setChannel("none");
+        setOpen(true);
         break;
         break;
       case "channel":
       case "channel":
-        setDict("none");
-        setChannel("block");
+        setOpen(true);
+        break;
+      case "close":
+        setOpen(false);
         break;
         break;
       default:
       default:
-        setDict("none");
-        setChannel("none");
+        setOpen(false);
         break;
         break;
     }
     }
   }, [curr]);
   }, [curr]);
   return (
   return (
     <Affix offsetTop={44}>
     <Affix offsetTop={44}>
-      <div key="panel">
-        <div
-          key="DictComponent"
-          style={{
-            width: 350,
-            height: `calc(100vh - 44px)`,
-            overflowY: "scroll",
-            display: dict,
-          }}
-        >
-          <DictComponent />
-        </div>
-        <div
-          key="ChannelPickerTable"
-          style={{
-            width: 350,
-            height: `calc(100vh - 44px)`,
-            overflowY: "scroll",
-            display: channel,
+      <div
+        key="panel"
+        style={{
+          width: 350,
+          height: `calc(100vh - 44px)`,
+          overflowY: "scroll",
+          display: open ? "block" : "none",
+        }}
+      >
+        <Tabs
+          size="small"
+          defaultActiveKey={curr}
+          tabBarExtraContent={{
+            right: (
+              <Button
+                type="text"
+                size="small"
+                icon={<CloseOutlined />}
+                onClick={() => {
+                  if (typeof onClose !== "undefined") {
+                    onClose();
+                  }
+                }}
+              />
+            ),
           }}
           }}
-        >
-          <ChannelPickerTable
-            type={type}
-            articleId={articleId}
-            selectedKeys={selectedChannelKeys}
-            onSelect={(e: IChannel[]) => {
-              console.log(e);
-              if (typeof onChannelSelect !== "undefined") {
-                onChannelSelect(e);
-              }
-            }}
-          />
-        </div>
+          items={[
+            {
+              label: `字典`,
+              key: "dict",
+              children: <DictComponent />,
+            },
+            {
+              label: `channel`,
+              key: "channel",
+              children: (
+                <ChannelPickerTable
+                  type={type}
+                  articleId={articleId}
+                  selectedKeys={selectedChannelKeys}
+                  onSelect={(e: IChannel[]) => {
+                    console.log(e);
+                    if (typeof onChannelSelect !== "undefined") {
+                      onChannelSelect(e);
+                    }
+                  }}
+                />
+              ),
+            },
+          ]}
+        />
       </div>
       </div>
     </Affix>
     </Affix>
   );
   );

+ 14 - 10
dashboard/src/pages/library/article/show.tsx

@@ -1,8 +1,9 @@
-import { Affix, Divider, Space } from "antd";
+import { Affix, Button, Divider, Space } from "antd";
 import { Header } from "antd/lib/layout/layout";
 import { Header } from "antd/lib/layout/layout";
 import { Key } from "antd/lib/table/interface";
 import { Key } from "antd/lib/table/interface";
 import { useEffect, useState } from "react";
 import { useEffect, useState } from "react";
 import { useNavigate, useParams, useSearchParams } from "react-router-dom";
 import { useNavigate, useParams, useSearchParams } from "react-router-dom";
+import { ColumnOutlinedIcon } from "../../../assets/icon";
 import { IApiResponseDictList } from "../../../components/api/Dict";
 import { IApiResponseDictList } from "../../../components/api/Dict";
 
 
 import Article, {
 import Article, {
@@ -112,6 +113,8 @@ const Widget = () => {
           <MainMenu />
           <MainMenu />
           <div></div>
           <div></div>
           <div key="right" style={{ display: "flex" }}>
           <div key="right" style={{ display: "flex" }}>
+            <Avatar placement="bottom" />
+            <Divider type="vertical" />
             <ModeSwitch
             <ModeSwitch
               channel={searchParams.get("channel")}
               channel={searchParams.get("channel")}
               currMode={currMode}
               currMode={currMode}
@@ -140,10 +143,13 @@ const Widget = () => {
               }}
               }}
             />
             />
             <Divider type="vertical" />
             <Divider type="vertical" />
-            <RightToolsSwitch
-              onModeChange={(open: TPanelName) => {
-                setRightPanel(open);
-              }}
+            <Button
+              style={{ display: "block", color: "white" }}
+              icon={<ColumnOutlinedIcon />}
+              type="text"
+              onClick={() =>
+                setRightPanel((value) => (value === "close" ? "dict" : "close"))
+              }
             />
             />
           </div>
           </div>
         </Header>
         </Header>
@@ -182,11 +188,6 @@ const Widget = () => {
                 <ToolButtonSetting type={type} articleId={id} />
                 <ToolButtonSetting type={type} articleId={id} />
               </Space>
               </Space>
             </div>
             </div>
-            <div>
-              <Space direction="vertical">
-                <Avatar placement="rightBottom" />
-              </Space>
-            </div>
           </div>
           </div>
         </Affix>
         </Affix>
         <div
         <div
@@ -224,6 +225,9 @@ const Widget = () => {
               type={type as ArticleType}
               type={type as ArticleType}
               articleId={id ? id : ""}
               articleId={id ? id : ""}
               selectedChannelKeys={channelId}
               selectedChannelKeys={channelId}
+              onClose={() => {
+                setRightPanel("close");
+              }}
               onChannelSelect={(e: IChannel[]) => {
               onChannelSelect={(e: IChannel[]) => {
                 //channel 改变
                 //channel 改变
                 console.log("onChannelSelect", e);
                 console.log("onChannelSelect", e);