Просмотр исходного кода

Merge pull request #1824 from visuddhinanda/agile

chapter 句子编号用api获取
visuddhinanda 2 лет назад
Родитель
Сommit
06e9c82ea0

+ 18 - 0
dashboard/src/components/api/Channel.ts

@@ -52,3 +52,21 @@ export interface IApiResponseChannelList {
     count: number;
   };
 }
+
+export interface ISentInChapterListResponse {
+  ok: boolean;
+  data: ISentInChapterListData;
+  message: string;
+}
+
+export interface ISentInChapterListData {
+  rows: ISentInChapterListDataRow[];
+  count: number;
+}
+
+export interface ISentInChapterListDataRow {
+  book: number;
+  paragraph: number;
+  word_begin: number;
+  word_end: number;
+}

+ 6 - 14
dashboard/src/components/channel/ChannelInfo.tsx

@@ -4,12 +4,14 @@ import { useEffect, useState } from "react";
 import { IItem } from "./ChannelPickerTable";
 
 interface IChannelInfoModal {
+  sentenceCount: number;
   open?: boolean;
   channel?: IItem;
   onClose?: Function;
 }
 
 export const ChannelInfoModal = ({
+  sentenceCount,
   open,
   channel,
   onClose,
@@ -30,25 +32,15 @@ export const ChannelInfoModal = ({
       }}
       footer={<></>}
     >
-      <ChannelInfoWidget channel={channel} />
+      <ChannelInfoWidget sentenceCount={sentenceCount} channel={channel} />
     </Modal>
   );
 };
 interface IWidget {
+  sentenceCount: number;
   channel?: IItem;
 }
-const ChannelInfoWidget = ({ channel }: IWidget) => {
-  const [count, setCount] = useState<number>();
-  useEffect(() => {
-    const sentElement = document.querySelectorAll(".pcd_sent");
-    let sentList: string[] = [];
-    for (let index = 0; index < sentElement.length; index++) {
-      const element = sentElement[index];
-      const id = element.id.split("_")[1];
-      sentList.push(id);
-    }
-    setCount(sentList.length);
-  }, []);
+const ChannelInfoWidget = ({ sentenceCount, channel }: IWidget) => {
   let totalStrLen = 0;
   let finalStrLen = 0;
   let finalSent = 0;
@@ -65,7 +57,7 @@ const ChannelInfoWidget = ({ channel }: IWidget) => {
       <StatisticCard
         title={"版本:" + channel?.title}
         statistic={{
-          value: count,
+          value: sentenceCount,
           suffix: "句",
           description: (
             <Statistic title="完成度" value={Math.round(final) + "%"} />

+ 50 - 11
dashboard/src/components/channel/ChannelMy.tsx

@@ -20,8 +20,11 @@ import {
   InfoCircleOutlined,
 } from "@ant-design/icons";
 
-import { post } from "../../request";
-import { IApiResponseChannelList } from "../api/Channel";
+import { get, post } from "../../request";
+import {
+  IApiResponseChannelList,
+  ISentInChapterListResponse,
+} from "../api/Channel";
 import { IItem, IProgressRequest } from "./ChannelPickerTable";
 import { LockIcon } from "../../assets/icon";
 import StudioName from "../auth/StudioName";
@@ -66,10 +69,15 @@ const ChannelMy = ({
   const [copyOpen, setCopyOpen] = useState<boolean>(false);
   const [infoOpen, setInfoOpen] = useState<boolean>(false);
   const [statistic, setStatistic] = useState<IItem>();
-  useEffect(() => load(), []);
+  const [sentenceCount, setSentenceCount] = useState<number>(0);
+  useEffect(() => {
+    load();
+  }, []);
 
   useEffect(() => {
-    setSelectedRowKeys(selectedKeys);
+    if (selectedRowKeys.join() !== selectedKeys.join()) {
+      setSelectedRowKeys(selectedKeys);
+    }
   }, [selectedKeys]);
 
   useEffect(() => {
@@ -117,19 +125,49 @@ const ChannelMy = ({
     }
   };
   const load = () => {
-    const sentElement = document.querySelectorAll(".pcd_sent");
     let sentList: string[] = [];
-    for (let index = 0; index < sentElement.length; index++) {
-      const element = sentElement[index];
-      const id = element.id.split("_")[1];
-      sentList.push(id);
+    if (type === "chapter") {
+      const id = articleId?.split("-");
+      if (id?.length === 2) {
+        const url = `/v2/sentences-in-chapter?book=${id[0]}&para=${id[1]}`;
+        console.info("url", url);
+        get<ISentInChapterListResponse>(url)
+          .then((res) => {
+            console.debug("ISentInChapterListResponse", res);
+            if (res && res.ok) {
+              sentList = res.data.rows.map((item) => {
+                return `${item.book}-${item.paragraph}-${item.word_begin}-${item.word_end}`;
+              });
+
+              loadChannel(sentList);
+            } else {
+              console.error("res", res);
+            }
+          })
+          .catch((reason: any) => {
+            console.error(reason);
+          });
+      }
+    } else {
+      const sentElement = document.querySelectorAll(".pcd_sent");
+      for (let index = 0; index < sentElement.length; index++) {
+        const element = sentElement[index];
+        const id = element.id.split("_")[1];
+        sentList.push(id);
+      }
+      loadChannel(sentList);
     }
+  };
+
+  function loadChannel(sentences: string[]) {
+    setSentenceCount(sentences.length);
+    console.debug("sentences", sentences);
     const currOwner = "all";
 
     console.log("owner", currOwner);
     setLoading(true);
     post<IProgressRequest, IApiResponseChannelList>(`/v2/channel-progress`, {
-      sentence: sentList,
+      sentence: sentences,
       owner: currOwner,
     })
       .then((res) => {
@@ -168,7 +206,7 @@ const ChannelMy = ({
       .finally(() => {
         setLoading(false);
       });
-  };
+  }
   return (
     <div style={style}>
       <Card
@@ -404,6 +442,7 @@ const ChannelMy = ({
         onClose={() => setCopyOpen(false)}
       />
       <ChannelInfoModal
+        sentenceCount={sentenceCount}
         channel={statistic}
         open={infoOpen}
         onClose={() => setInfoOpen(false)}