Sfoglia il codice sorgente

点文集,加入文集参数

visuddhinanda 2 anni fa
parent
commit
b0fb9c7cff

+ 19 - 2
dashboard/src/components/article/Article.tsx

@@ -4,7 +4,7 @@ import { Divider, message, Result, Space, Tag } from "antd";
 import { get, post } from "../../request";
 import store from "../../store";
 import { IArticleDataResponse, IArticleResponse } from "../api/Article";
-import ArticleView from "./ArticleView";
+import ArticleView, { IFirstAnthology } from "./ArticleView";
 import { ICourseCurrUserResponse } from "../api/Course";
 import { ICourseUser, signIn } from "../../reducers/course-user";
 import { ITextbook, refresh } from "../../reducers/current-course";
@@ -68,6 +68,7 @@ interface IWidget {
   onArticleChange?: Function;
   onFinal?: Function;
   onLoad?: Function;
+  onAnthologySelect?: Function;
 }
 const ArticleWidget = ({
   type,
@@ -84,6 +85,7 @@ const ArticleWidget = ({
   onArticleChange,
   onFinal,
   onLoad,
+  onAnthologySelect,
 }: IWidget) => {
   const [articleData, setArticleData] = useState<IArticleDataResponse>();
   const [articleHtml, setArticleHtml] = useState<string[]>(["<span />"]);
@@ -348,6 +350,15 @@ const ArticleWidget = ({
   };
 
   //const comment = <CommentListCard resId={articleData?.uid} resType="article" />
+  let anthology: IFirstAnthology | undefined;
+  if (articleData?.anthology_count && articleData.anthology_first) {
+    anthology = {
+      id: articleData.anthology_first.uid,
+      title: articleData.anthology_first.title,
+      count: articleData?.anthology_count,
+    };
+  }
+
   return (
     <div>
       {showSkeleton ? (
@@ -374,6 +385,7 @@ const ArticleWidget = ({
           type={type}
           articleId={articleId}
           remains={remains}
+          anthology={anthology}
           onEnd={() => {
             if (type === "chapter" && articleData) {
               getNextPara(articleData);
@@ -391,9 +403,14 @@ const ArticleWidget = ({
               onArticleChange(newArticle, target);
             }
           }}
+          onAnthologySelect={(id: string) => {
+            if (typeof onAnthologySelect !== "undefined") {
+              onAnthologySelect(id);
+            }
+          }}
         />
       )}
-
+      <Divider />
       {extra}
       <Divider />
     </div>

+ 29 - 4
dashboard/src/components/article/ArticleView.tsx

@@ -1,4 +1,4 @@
-import { Typography, Divider, Button, Skeleton } from "antd";
+import { Typography, Divider, Button, Skeleton, Space } from "antd";
 import { ReloadOutlined } from "@ant-design/icons";
 
 import MdView from "../template/MdView";
@@ -8,7 +8,11 @@ import { ArticleType } from "./Article";
 import VisibleObserver from "../general/VisibleObserver";
 
 const { Paragraph, Title, Text } = Typography;
-
+export interface IFirstAnthology {
+  id: string;
+  title: string;
+  count: number;
+}
 export interface IWidgetArticleData {
   id?: string;
   title?: string;
@@ -23,8 +27,10 @@ export interface IWidgetArticleData {
   type?: ArticleType;
   articleId?: string;
   remains?: boolean;
+  anthology?: IFirstAnthology;
   onEnd?: Function;
   onPathChange?: Function;
+  onAnthologySelect?: Function;
 }
 
 const ArticleViewWidget = ({
@@ -40,9 +46,11 @@ const ArticleViewWidget = ({
   channels,
   type,
   articleId,
+  anthology,
   onEnd,
   remains,
   onPathChange,
+  onAnthologySelect,
 }: IWidgetArticleData) => {
   let currChannelList = <></>;
   switch (type) {
@@ -77,7 +85,24 @@ const ArticleViewWidget = ({
         />
       </div>
 
-      <div>
+      <Space direction="vertical">
+        <Text>
+          {path.length === 0 && anthology ? (
+            <>
+              <Text>{"文集:"}</Text>
+              <Button
+                type="link"
+                onClick={() => {
+                  if (typeof onAnthologySelect !== "undefined") {
+                    onAnthologySelect(anthology.id);
+                  }
+                }}
+              >
+                {anthology.title}
+              </Button>
+            </>
+          ) : undefined}
+        </Text>
         <TocPath
           data={path}
           channel={channels}
@@ -104,7 +129,7 @@ const ArticleViewWidget = ({
           {summary}
         </Paragraph>
         <Divider />
-      </div>
+      </Space>
       {html
         ? html.map((item, id) => {
             return (

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

@@ -293,6 +293,16 @@ const Widget = () => {
               onLoad={(article: IArticleDataResponse) => {
                 setLoadedArticleData(article);
               }}
+              onAnthologySelect={(id: string) => {
+                let output: any = { anthology: id };
+                searchParams.forEach((value, key) => {
+                  console.log(value, key);
+                  if (key !== "anthology") {
+                    output[key] = value;
+                  }
+                });
+                setSearchParams(output);
+              }}
             />
             <Navigate
               type={type as ArticleType}
@@ -303,7 +313,6 @@ const Widget = () => {
               ) => {
                 let url = `/article/${type}/${newId}?mode=${currMode}`;
                 searchParams.forEach((value, key) => {
-                  console.log(value, key);
                   if (key !== "mode") {
                     url += `&${key}=${value}`;
                   }