visuddhinanda 7 mesi fa
parent
commit
b2ff812bb5
1 ha cambiato i file con 84 aggiunte e 4 eliminazioni
  1. 84 4
      dashboard-v4/dashboard/src/components/template/WbwSent.tsx

+ 84 - 4
dashboard-v4/dashboard/src/components/template/WbwSent.tsx

@@ -1,4 +1,4 @@
-import { Button, Dropdown, message, Progress, Space, Tree } from "antd";
+import { Alert, Button, Dropdown, message, Progress, Space, Tree } from "antd";
 import { useEffect, useState } from "react";
 import { MoreOutlined, ExclamationCircleOutlined } from "@ant-design/icons";
 
@@ -31,6 +31,7 @@ import moment from "moment";
 import { courseInfo } from "../../reducers/current-course";
 import { ISentenceWbwListResponse } from "../api/Corpus";
 import { IDeleteResponse } from "../api/Article";
+import { useWbwStreamProcessor } from "./AIWbw";
 
 export const getWbwProgress = (data: IWbw[], answer?: IWbw[]) => {
   //计算完成度
@@ -277,6 +278,8 @@ export const WbwSentCtl = ({
   const [showProgress, setShowProgress] = useState(false);
   const [check, setCheck] = useState(answer ? true : false);
   const [courseAnswer, setCourseAnswer] = useState<IWbw[]>();
+  const { processStream, isProcessing, wbwData, error } =
+    useWbwStreamProcessor();
 
   const user = useAppSelector(currentUser);
   const course = useAppSelector(courseInfo);
@@ -312,6 +315,34 @@ export const WbwSentCtl = ({
     }
   };
 
+  useEffect(() => {
+    setWordData((origin) => {
+      origin.forEach((value, index, array) => {
+        const newOne = wbwData.find(
+          (v) =>
+            v.sn.join() === value.sn.join() || v.real.value === value.real.value
+        );
+        if (newOne) {
+          if (array[index].meaning !== undefined && newOne.meaning) {
+            array[index].meaning.value = newOne.meaning.value;
+          }
+          if (array[index].factors !== undefined && newOne.factors) {
+            array[index].factors.value = newOne.factors.value;
+          }
+          if (
+            array[index].factorMeaning !== undefined &&
+            newOne.factorMeaning
+          ) {
+            array[index].factorMeaning.value = newOne.factorMeaning.value;
+          }
+          if (array[index].type !== undefined && newOne.type) {
+            array[index].type.value = newOne.type.value;
+          }
+        }
+      });
+      return origin;
+    });
+  }, [wbwData]);
   useEffect(() => setShowProgress(wbwProgress), [wbwProgress]);
 
   const settings = useAppSelector(settingInfo);
@@ -324,9 +355,25 @@ export const WbwSentCtl = ({
 
   const newMode = useAppSelector(_mode);
 
-  const update = (data: IWbw[]) => {
-    console.debug("wbw update");
-    setWordData(paraMark(data));
+  const update = (data: IWbw[], replace: boolean = true) => {
+    if (replace) {
+      setWordData(paraMark(data));
+    } else {
+      setWordData((origin) => {
+        origin.forEach((value, index, array) => {
+          const newOne = data.find(
+            (v) =>
+              v.sn.join() === value.sn.join() ||
+              v.real.value === value.real.value
+          );
+          if (newOne) {
+            array[index] = newOne;
+          }
+        });
+        return origin;
+      });
+    }
+
     if (typeof onChange !== "undefined") {
       onChange(data);
     }
@@ -808,11 +855,23 @@ export const WbwSentCtl = ({
         <div className="progress" style={{ width: 400 }}>
           <Progress percent={progress} size="small" />
         </div>
+
         <Space>
           <Studio data={studio} hideAvatar />
           {<TimeShow updatedAt={updatedAt.toString()} />}
         </Space>
       </div>
+      {error ? <Alert message={error} /> : <></>}
+      {isProcessing ? (
+        <div>
+          <Progress
+            percent={Math.round((wbwData.length * 100) / wordData.length)}
+            size="small"
+          />
+        </div>
+      ) : (
+        <></>
+      )}
       <div className={`layout-${layoutDirection}`}>
         <Dropdown
           menu={{
@@ -823,6 +882,10 @@ export const WbwSentCtl = ({
                   id: "buttons.magic-dict",
                 }),
               },
+              {
+                key: "ai-magic-dict-current",
+                label: "ai-magic-dict",
+              },
               {
                 key: "progress",
                 label: "显示/隐藏进度条",
@@ -870,6 +933,16 @@ export const WbwSentCtl = ({
                   setLoading(true);
                   magicDictLookup();
                   break;
+                case "ai-magic-dict-current":
+                  const json = JSON.stringify(wordData, null, 2);
+                  const aiData = `
+\`\`\`json
+${json}
+\`\`\`
+                    `;
+                  console.log("ai", aiData);
+                  processStream("32226fe6-503f-43a2-bc95-5660ea7a29c4", aiData);
+                  break;
                 case "wbw-dict-publish-all":
                   wbwPublish(
                     wordData,
@@ -932,6 +1005,13 @@ export const WbwSentCtl = ({
         </Dropdown>
         {layoutDirection === "h" ? (
           wordData
+            .map((item) => {
+              const newData = wbwData.find(
+                (value) => value.sn.join() === item.sn.join()
+              );
+
+              return newData ?? item;
+            })
             .map((item, index) => {
               let newItem = item;
               const spell = item.real.value;