Преглед изворни кода

添加总在最顶端支持

visuddhinanda пре 1 година
родитељ
комит
becf98ba4f

+ 38 - 24
dashboard/src/components/template/SentEdit.tsx

@@ -1,4 +1,4 @@
-import { Card } from "antd";
+import { Affix, Card } from "antd";
 import { useEffect, useRef, useState } from "react";
 import { useEffect, useRef, useState } from "react";
 import { IStudio } from "../auth/Studio";
 import { IStudio } from "../auth/Studio";
 
 
@@ -127,6 +127,7 @@ export const SentEditInner = ({
   const [isFocus, setIsFocus] = useState(false);
   const [isFocus, setIsFocus] = useState(false);
   const focus = useAppSelector(currFocus);
   const focus = useAppSelector(currFocus);
   const divRef = useRef<HTMLDivElement>(null);
   const divRef = useRef<HTMLDivElement>(null);
+  const [affix, setAffix] = useState<boolean>(false);
 
 
   useEffect(() => {
   useEffect(() => {
     if (focus) {
     if (focus) {
@@ -177,6 +178,32 @@ export const SentEditInner = ({
 
 
   const channelsId = translation?.map((item) => item.channel.id);
   const channelsId = translation?.map((item) => item.channel.id);
 
 
+  const content = (
+    <SentContent
+      sid={id}
+      book={book}
+      para={para}
+      wordStart={wordStart}
+      wordEnd={wordEnd}
+      origin={origin}
+      translation={translation}
+      answer={answer}
+      layout={layout}
+      magicDict={magicDict}
+      compact={isCompact}
+      mode={articleMode}
+      wbwProgress={wbwProgress}
+      readonly={readonly}
+      onWbwChange={(data: IWbw[]) => {
+        setWbwData(data);
+      }}
+      onMagicDictDone={() => {
+        setMagicDictLoading(false);
+        setMagicDict(undefined);
+      }}
+    />
+  );
+
   return (
   return (
     <Card
     <Card
       ref={divRef}
       ref={divRef}
@@ -192,29 +219,15 @@ export const SentEditInner = ({
       }}
       }}
       size="small"
       size="small"
     >
     >
-      <SentContent
-        sid={id}
-        book={book}
-        para={para}
-        wordStart={wordStart}
-        wordEnd={wordEnd}
-        origin={origin}
-        translation={translation}
-        answer={answer}
-        layout={layout}
-        magicDict={magicDict}
-        compact={isCompact}
-        mode={articleMode}
-        wbwProgress={wbwProgress}
-        readonly={readonly}
-        onWbwChange={(data: IWbw[]) => {
-          setWbwData(data);
-        }}
-        onMagicDictDone={() => {
-          setMagicDictLoading(false);
-          setMagicDict(undefined);
-        }}
-      />
+      {affix ? (
+        <Affix offsetTop={44}>
+          <div style={{ backgroundColor: affix ? "white" : "unset" }}>
+            {content}
+          </div>
+        </Affix>
+      ) : (
+        content
+      )}
       <SentTab
       <SentTab
         id={id}
         id={id}
         book={book}
         book={book}
@@ -239,6 +252,7 @@ export const SentEditInner = ({
         }}
         }}
         onCompact={(value: boolean) => setIsCompact(value)}
         onCompact={(value: boolean) => setIsCompact(value)}
         onModeChange={(value: ArticleMode | undefined) => setArticleMode(value)}
         onModeChange={(value: ArticleMode | undefined) => setArticleMode(value)}
+        onAffix={() => setAffix(!affix)}
       />
       />
     </Card>
     </Card>
   );
   );

+ 4 - 0
dashboard/src/components/template/SentEdit/SentMenu.tsx

@@ -43,6 +43,10 @@ const SentMenuWidget = ({
       key: "copy-link",
       key: "copy-link",
       label: intl.formatMessage({ id: "buttons.copy.link" }),
       label: intl.formatMessage({ id: "buttons.copy.link" }),
     },
     },
+    {
+      key: "affix",
+      label: "总在最顶端开/关",
+    },
     {
     {
       type: "divider",
       type: "divider",
     },
     },

+ 7 - 0
dashboard/src/components/template/SentEdit/SentTab.tsx

@@ -45,6 +45,7 @@ interface IWidget {
   onMagicDict?: Function;
   onMagicDict?: Function;
   onCompact?: Function;
   onCompact?: Function;
   onModeChange?: Function;
   onModeChange?: Function;
+  onAffix?: Function;
 }
 }
 const SentTabWidget = ({
 const SentTabWidget = ({
   id,
   id,
@@ -67,6 +68,7 @@ const SentTabWidget = ({
   onMagicDict,
   onMagicDict,
   onCompact,
   onCompact,
   onModeChange,
   onModeChange,
+  onAffix,
 }: IWidget) => {
 }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
   const [isCompact, setIsCompact] = useState(compact);
   const [isCompact, setIsCompact] = useState(compact);
@@ -184,6 +186,11 @@ const SentTabWidget = ({
                     message.success("链接地址已经拷贝到剪贴板");
                     message.success("链接地址已经拷贝到剪贴板");
                   });
                   });
                   break;
                   break;
+                case "affix":
+                  if (typeof onAffix !== "undefined") {
+                    onAffix();
+                  }
+                  break;
                 default:
                 default:
                   break;
                   break;
               }
               }