Przeglądaj źródła

add parentChannels

visuddhinanda 1 rok temu
rodzic
commit
4409612546

+ 5 - 14
dashboard/src/components/article/Article.tsx

@@ -50,6 +50,7 @@ interface IWidget {
   articleId?: string;
   mode?: ArticleMode | null;
   channelId?: string | null;
+  parentChannels?: string[];
   book?: string | null;
   para?: string | null;
   anthologyId?: string | null;
@@ -70,6 +71,7 @@ const ArticleWidget = ({
   book,
   para,
   channelId,
+  parentChannels,
   articleId,
   anthologyId,
   courseId,
@@ -97,6 +99,7 @@ const ArticleWidget = ({
           type={type}
           articleId={onArticleChange ? articleId : currId}
           channelId={channelId}
+          parentChannels={parentChannels}
           mode={mode}
           anthologyId={anthologyId}
           active={active}
@@ -107,11 +110,7 @@ const ArticleWidget = ({
               onArticleEdit(value);
             }
           }}
-          onArticleChange={(type: ArticleType, id: string, target: string) => {
-            if (typeof onArticleChange !== "undefined") {
-              onArticleChange(type, id, target);
-            }
-          }}
+          onArticleChange={onArticleChange}
           onLoad={(data: IArticleDataResponse) => {
             if (typeof onLoad !== "undefined") {
               onLoad(data);
@@ -239,15 +238,7 @@ const ArticleWidget = ({
           channelId={channelId}
           courseId={courseId}
           mode={mode}
-          onArticleChange={(
-            newType: ArticleType,
-            id: string,
-            target: string
-          ) => {
-            if (typeof onArticleChange !== "undefined") {
-              onArticleChange(type, id, target);
-            }
-          }}
+          onArticleChange={onArticleChange}
         />
       ) : (
         <></>

+ 4 - 5
dashboard/src/components/article/TypeArticle.tsx

@@ -11,6 +11,7 @@ interface IWidget {
   articleId?: string;
   mode?: ArticleMode | null;
   channelId?: string | null;
+  parentChannels?: string[];
   anthologyId?: string | null;
   active?: boolean;
   hideInteractive?: boolean;
@@ -24,6 +25,7 @@ interface IWidget {
 const TypeArticleWidget = ({
   type,
   channelId,
+  parentChannels,
   articleId,
   anthologyId,
   mode = "read",
@@ -66,17 +68,14 @@ const TypeArticleWidget = ({
           isSubWindow={isSubWindow}
           type={type}
           channelId={channelId}
+          parentChannels={parentChannels}
           articleId={articleId}
           anthologyId={anthologyId}
           mode={mode}
           active={active}
           hideInteractive={hideInteractive}
           hideTitle={hideTitle}
-          onArticleChange={(type: string, id: string, target: string) => {
-            if (typeof onArticleChange !== "undefined") {
-              onArticleChange(type, id, target);
-            }
-          }}
+          onArticleChange={onArticleChange}
           onLoad={(data: IArticleDataResponse) => {
             if (typeof onLoad !== "undefined") {
               onLoad(data);

+ 46 - 3
dashboard/src/components/article/TypeArticleReader.tsx

@@ -3,6 +3,7 @@ import { Divider, message, Space, Tag } from "antd";
 
 import { get } from "../../request";
 import {
+  IAnthologyResponse,
   IArticleDataResponse,
   IArticleNavData,
   IArticleNavResponse,
@@ -19,12 +20,14 @@ import ErrorResult from "../general/ErrorResult";
 import NavigateButton from "./NavigateButton";
 import InteractiveArea from "../discussion/InteractiveArea";
 import TypeArticleReaderToolbar from "./TypeArticleReaderToolbar";
+import { IChannel } from "../channel/Channel";
 
 interface IWidget {
   type?: ArticleType;
   articleId?: string;
   mode?: ArticleMode | null;
   channelId?: string | null;
+  parentChannels?: string[];
   anthologyId?: string | null;
   active?: boolean;
   hideInteractive?: boolean;
@@ -38,6 +41,7 @@ interface IWidget {
 const TypeArticleReaderWidget = ({
   type,
   channelId,
+  parentChannels,
   articleId,
   anthologyId,
   mode = "read",
@@ -57,10 +61,40 @@ const TypeArticleReaderWidget = ({
   const [errorCode, setErrorCode] = useState<number>();
   const [currPath, setCurrPath] = useState<ITocPathNode[]>();
   const [nav, setNav] = useState<IArticleNavData>();
+  const [defaultChannel, setDefaultChannel] = useState<IChannel | null>();
 
   const channels = channelId?.split("_");
 
   const srcDataMode = mode === "edit" || mode === "wbw" ? "edit" : "read";
+
+  //创建时获取文集channel
+  useEffect(() => {
+    if (!anthologyId) {
+      return;
+    }
+    if (channelId) {
+      return;
+    }
+    const url = `/v2/anthology/${anthologyId}`;
+    console.info("api request", url);
+
+    get<IAnthologyResponse>(url).then((json) => {
+      if (json.ok) {
+        if (json.data.default_channel) {
+          if (typeof onArticleChange === "undefined") {
+            //自控
+            setDefaultChannel(json.data.default_channel);
+          } else {
+            //外控
+            onArticleChange("article", articleId, null);
+          }
+        } else {
+          setDefaultChannel(null);
+        }
+      }
+    });
+  }, []);
+
   useEffect(() => {
     console.log("srcDataMode", srcDataMode);
     if (!active) {
@@ -71,14 +105,23 @@ const TypeArticleReaderWidget = ({
       return;
     }
 
+    let mChannels: string[] = [];
+    if (channelId) {
+      mChannels.push(channelId);
+    }
+    if (parentChannels) {
+      mChannels = [...parentChannels, ...mChannels];
+    }
     let url = `/v2/article/${articleId}?mode=${srcDataMode}`;
-    url += channelId ? `&channel=${channelId}` : "";
+    if (mChannels.length > 0) {
+      url += `&channel=${mChannels.join("_")}`;
+    }
     url += anthologyId ? `&anthology=${anthologyId}` : "";
-    console.info("article url", url);
+    console.info("article api request", url);
     setLoading(true);
     get<IArticleResponse>(url)
       .then((json) => {
-        console.log("article", json);
+        console.info("article api response", json);
         if (json.ok) {
           setArticleData(json.data);
           setCurrPath(json.data.path);

+ 8 - 1
dashboard/src/components/template/Article.tsx

@@ -18,9 +18,11 @@ export type TDisplayStyle =
 interface IWidgetChapterCtl {
   type?: ArticleType;
   id?: string;
+  anthology?: string;
   book?: string;
   paragraphs?: string;
   channel?: string;
+  parentChannels?: string[];
   title?: React.ReactNode;
   focus?: string | null;
   style?: TDisplayStyle;
@@ -30,7 +32,9 @@ interface IWidgetChapterCtl {
 export const ArticleCtl = ({
   type,
   id,
+  anthology,
   channel,
+  parentChannels,
   title,
   focus,
   book,
@@ -52,14 +56,17 @@ export const ArticleCtl = ({
     setIsModalOpen(false);
   };
   const aTitle = title ? title : "chapter" + id;
+  console.log("anthology", anthology, channel);
   const article = (
     <Article
       active={true}
       type={type}
       articleId={id}
+      anthologyId={anthology}
       book={book}
       para={paragraphs}
       channelId={channel}
+      parentChannels={parentChannels}
       focus={focus}
       mode="read"
       hideInteractive={true}
@@ -126,7 +133,7 @@ export const ArticleCtl = ({
     case "toggle":
       output = (
         <Collapse bordered={false}>
-          <Collapse.Panel header={aTitle} key="parent2">
+          <Collapse.Panel header={`${aTitle} ${anthology}`} key="parent2">
             {article}
           </Collapse.Panel>
         </Collapse>