Parcourir la source

Merge pull request #2134 from visuddhinanda/agile

添加 标准答案获取按钮
visuddhinanda il y a 1 an
Parent
commit
89f8941d47

+ 14 - 15
dashboard/src/components/template/Wbw/WbwCase.tsx

@@ -181,24 +181,23 @@ const WbwCaseWidget = ({
     data.real.value.trim().length > 0
   ) {
     //非标点符号
+    const checkClass = answer
+      ? errorClass("case", data.case?.value, answer?.case?.value)
+      : "";
     return (
-      <div
-        className={
-          "wbw_word_item" +
-          errorClass("case", data.case?.value, answer?.case?.value)
-        }
-        style={{ display: "flex" }}
-      >
+      <div className={"wbw_word_item"} style={{ display: "flex" }}>
         <Text type="secondary">
           <div>
-            <Dropdown
-              key="dropdown"
-              menu={{ items, onClick }}
-              placement="bottomLeft"
-            >
-              <span>{caseElement}</span>
-            </Dropdown>
-            <WbwParentIcon data={data} />
+            <span className={checkClass}>
+              <Dropdown
+                key="dropdown"
+                menu={{ items, onClick }}
+                placement="bottomLeft"
+              >
+                <span>{caseElement}</span>
+              </Dropdown>
+            </span>
+            <WbwParentIcon data={data} answer={answer} />
             <WbwParent2 data={data} />
             {showSplit ? (
               <Button

+ 8 - 10
dashboard/src/components/template/Wbw/WbwFactorMeaning.tsx

@@ -97,17 +97,15 @@ const WbwFactorMeaningWidget = ({
   }
 
   if (typeof data.real !== "undefined" && PaliReal(data.real.value) !== "") {
+    const checkClass = answer
+      ? errorClass(
+          "factorMeaning",
+          data.factorMeaning?.value,
+          answer?.factorMeaning?.value
+        )
+      : "";
     return (
-      <div
-        className={
-          "wbw_word_item" +
-          errorClass(
-            "factorMeaning",
-            data.factorMeaning?.value,
-            answer?.factorMeaning?.value
-          )
-        }
-      >
+      <div className={"wbw_word_item" + checkClass}>
         <Text type="secondary">
           <Dropdown
             menu={{

+ 4 - 6
dashboard/src/components/template/Wbw/WbwFactors.tsx

@@ -125,13 +125,11 @@ const WbwFactorsWidget = ({ data, answer, display, onChange }: IWidget) => {
         );
       }
     }
+    const checkClass = answer
+      ? errorClass("factors", data.factors?.value, answer?.factors?.value)
+      : "";
     return (
-      <div
-        className={
-          "wbw_word_item" +
-          errorClass("factors", data.factors?.value, answer?.factors?.value)
-        }
-      >
+      <div className={"wbw_word_item" + checkClass}>
         <Text type="secondary">
           <Dropdown menu={{ items, onClick }} placement="bottomLeft">
             {factors}

+ 24 - 24
dashboard/src/components/template/Wbw/WbwMeaning.tsx

@@ -16,25 +16,28 @@ export const errorClass = (
   answer?: string | null
 ): string => {
   let classError = "";
-  if (data && answer) {
-    if (answer !== data) {
-      classError = " wbw_check";
-      switch (field) {
-        case "case":
-          classError += " wbw_error";
-          break;
-        case "factors":
-          classError += " wbw_warning";
-          break;
-        case "factorMeaning":
-          classError += " wbw_info";
-          break;
-        case "meaning":
-          classError += " wbw_info";
-          break;
-      }
+
+  if (answer !== data) {
+    classError = " wbw_check";
+    switch (field) {
+      case "parent":
+        classError += " wbw_error";
+        break;
+      case "case":
+        classError += " wbw_error";
+        break;
+      case "factors":
+        classError += " wbw_warning";
+        break;
+      case "factorMeaning":
+        classError += " wbw_info";
+        break;
+      case "meaning":
+        classError += " wbw_info";
+        break;
     }
   }
+
   return classError;
 };
 
@@ -175,14 +178,11 @@ const WbwMeaningWidget = ({
     data.real.value.trim().length > 0
   ) {
     //非标点符号
-
+    const checkClass = answer
+      ? errorClass("meaning", data.meaning?.value, answer?.meaning?.value)
+      : "";
     return (
-      <div
-        className={
-          "wbw_word_item" +
-          errorClass("meaning", data.meaning?.value, answer?.meaning?.value)
-        }
-      >
+      <div className={"wbw_word_item" + checkClass}>
         {editable || display === "list" ? (
           meaningInner
         ) : (

+ 21 - 5
dashboard/src/components/template/Wbw/WbwParentIcon.tsx

@@ -1,21 +1,37 @@
 import { Tooltip } from "antd";
 import { IWbw } from "./WbwWord";
 import { Dict2SvgIcon } from "../../../assets/icon";
+import { errorClass } from "./WbwMeaning";
 
 interface IWidget {
   data: IWbw;
+  answer?: IWbw;
 }
-const WbwParentIcon = ({ data }: IWidget) => {
-  return data.parent?.value ? (
+const WbwParentIcon = ({ data, answer }: IWidget) => {
+  const iconEmpty = answer?.parent ? <Dict2SvgIcon /> : <></>;
+  let title: string | null | undefined = "空";
+  if (typeof data.parent?.value === "string" && data.parent?.value.length > 0) {
+    title = data.parent?.value;
+  }
+  const icon = data.parent?.value ? (
     data.parent.value.trim() !== "" ? (
-      <Tooltip title={data.parent?.value}>
+      <Tooltip title={title}>
         <Dict2SvgIcon />
       </Tooltip>
     ) : (
-      <></>
+      iconEmpty
     )
   ) : (
-    <></>
+    iconEmpty
+  );
+
+  const errClass = answer
+    ? errorClass("parent", data.parent?.value, answer?.parent?.value)
+    : "";
+  return (
+    <span className={"wbw_word_item" + errClass}>
+      <span className="icon">{icon}</span>
+    </span>
   );
 };
 

+ 3 - 1
dashboard/src/components/template/Wbw/wbw.css

@@ -89,7 +89,9 @@
 .wbw_error {
   text-decoration-color: red;
 }
-
+.wbw_error .icon {
+  color: red;
+}
 .wbw_warning {
   text-decoration-color: orange;
 }

+ 53 - 5
dashboard/src/components/template/WbwSent.tsx

@@ -4,7 +4,7 @@ import { MoreOutlined, ExclamationCircleOutlined } from "@ant-design/icons";
 
 import { useAppSelector } from "../../hooks";
 import { mode as _mode } from "../../reducers/article-mode";
-import { post } from "../../request";
+import { get, post } from "../../request";
 import { ArticleMode } from "../article/Article";
 import WbwWord, {
   IWbw,
@@ -28,6 +28,8 @@ import Studio, { IStudio } from "../auth/Studio";
 import { IChannel } from "../channel/Channel";
 import TimeShow from "../general/TimeShow";
 import moment from "moment";
+import { courseInfo } from "../../reducers/current-course";
+import { ISentenceWbwListResponse } from "../api/Corpus";
 
 export const getWbwProgress = (data: IWbw[], answer?: IWbw[]) => {
   //计算完成度
@@ -271,12 +273,44 @@ export const WbwSentCtl = ({
   const [fieldDisplay, setFieldDisplay] = useState(fields);
   const [displayMode, setDisplayMode] = useState<ArticleMode>();
   const [loading, setLoading] = useState(false);
-
   const [showProgress, setShowProgress] = useState(false);
+  const [check, setCheck] = useState(answer ? true : false);
+  const [courseAnswer, setCourseAnswer] = useState<IWbw[]>();
+
   const user = useAppSelector(currentUser);
+  const course = useAppSelector(courseInfo);
 
   console.debug("wbw sent lang", channelLang);
 
+  const loadAnswer = () => {
+    if (courseAnswer) {
+      return;
+    }
+    let url = `/v2/wbw-sentence?view=course-answer`;
+    url += `&book=${book}&para=${para}&wordStart=${wordStart}&wordEnd=${wordEnd}`;
+    if (course) {
+      url += `&course=${course.courseId}`;
+      setLoading(true);
+      console.info("wbw sentence api request", url);
+      get<ISentenceWbwListResponse>(url)
+        .then((json) => {
+          console.info("wbw sentence api response", json);
+          if (json.ok) {
+            console.debug("wbw sentence course", course);
+            if (json.data.rows.length > 0 && json.data.rows[0].origin) {
+              let response = json.data.rows[0].origin[0];
+              setCourseAnswer(
+                response ? JSON.parse(response.content ?? "") : undefined
+              );
+            }
+          }
+        })
+        .finally(() => setLoading(false));
+    } else {
+      console.debug("并非课程");
+    }
+  };
+
   useEffect(() => setShowProgress(wbwProgress), [wbwProgress]);
 
   const settings = useAppSelector(settingInfo);
@@ -742,7 +776,12 @@ export const WbwSentCtl = ({
 
   return (
     <div style={{ width: "100%" }}>
-      <div style={{ display: showProgress ? "flex" : "none" }}>
+      <div
+        style={{
+          display: showProgress ? "flex" : "none",
+          justifyContent: "space-between",
+        }}
+      >
         <div className="progress" style={{ width: 400 }}>
           <Progress percent={progress} size="small" />
         </div>
@@ -765,6 +804,10 @@ export const WbwSentCtl = ({
                 key: "progress",
                 label: "显示/隐藏进度条",
               },
+              {
+                key: "check",
+                label: "显示/隐藏错误提示",
+              },
               {
                 key: "wbw-dict-publish-all",
                 label: "发布全部单词",
@@ -811,6 +854,10 @@ export const WbwSentCtl = ({
                 case "progress":
                   setShowProgress((origin) => !origin);
                   break;
+                case "check":
+                  loadAnswer();
+                  setCheck(!check);
+                  break;
                 case "reset":
                   modal.confirm({
                     title: "清除逐词解析数据",
@@ -854,12 +901,13 @@ export const WbwSentCtl = ({
               return newItem;
             })
             .map((item, id) => {
-              const currAnswer = answer?.find(
+              const aa = courseAnswer ?? answer;
+              const currAnswer = aa?.find(
                 (value) => value.sn.join() === item.sn.join()
               );
               return wbwRender(item, id, {
                 studio: studio,
-                answer: currAnswer,
+                answer: check ? currAnswer : undefined,
               });
             })
         ) : (