Sfoglia il codice sorgente

Merge pull request #2010 from visuddhinanda/agile

#2006 有未保存的脏数据不查词
visuddhinanda 2 anni fa
parent
commit
78d9cc9de6

+ 9 - 2
dashboard/src/components/dict/DictComponent.tsx

@@ -1,9 +1,10 @@
 import { useState, useEffect } from "react";
 import { useState, useEffect } from "react";
 
 
 import { useAppSelector } from "../../hooks";
 import { useAppSelector } from "../../hooks";
-import { lookup, lookupWord } from "../../reducers/command";
+import { lookup, lookupWord, myDictIsDirty } from "../../reducers/command";
 import store from "../../store";
 import store from "../../store";
 import Dictionary from "./Dictionary";
 import Dictionary from "./Dictionary";
+import { notification } from "antd";
 
 
 export interface IWidgetDict {
 export interface IWidgetDict {
   word?: string;
   word?: string;
@@ -12,12 +13,18 @@ const DictComponentWidget = ({ word }: IWidgetDict) => {
   const [wordSearch, setWordSearch] = useState(word);
   const [wordSearch, setWordSearch] = useState(word);
   //接收查字典消息
   //接收查字典消息
   const searchWord = useAppSelector(lookupWord);
   const searchWord = useAppSelector(lookupWord);
+  const myDictDirty = useAppSelector(myDictIsDirty);
+
   useEffect(() => {
   useEffect(() => {
     console.log("get command", searchWord);
     console.log("get command", searchWord);
+    if (myDictDirty) {
+      notification.warning({ message: "用户词典有未保存内容,请保存后再查词" });
+      return;
+    }
     if (typeof searchWord === "string" && searchWord !== wordSearch) {
     if (typeof searchWord === "string" && searchWord !== wordSearch) {
       setWordSearch(searchWord);
       setWordSearch(searchWord);
     }
     }
-  }, [searchWord]);
+  }, [searchWord, myDictDirty, wordSearch]);
 
 
   return (
   return (
     <Dictionary
     <Dictionary

+ 50 - 47
dashboard/src/components/dict/DictContent.tsx

@@ -1,4 +1,4 @@
-import { Button, Col, Divider, Row, Tabs } from "antd";
+import { Col, Divider, Row, Tabs } from "antd";
 
 
 import type { IAnchorData } from "./DictList";
 import type { IAnchorData } from "./DictList";
 import type { IWidgetWordCardData } from "./WordCard";
 import type { IWidgetWordCardData } from "./WordCard";
@@ -33,6 +33,54 @@ export interface IApiDictContentData {
   data: IDictContentData;
   data: IDictContentData;
 }
 }
 
 
+interface IMyDict {
+  word?: string;
+}
+const MyDict = ({ word }: IMyDict) => {
+  const user = useAppSelector(currentUser);
+  const [myTab, setMyTab] = useState<string>("list");
+  const [myRefresh, setMyRefresh] = useState(false);
+  return (
+    <div>
+      <Tabs
+        size="small"
+        type="card"
+        style={{ backgroundColor: "white" }}
+        activeKey={myTab}
+        onChange={(activeKey: string) => setMyTab(activeKey)}
+        items={[
+          {
+            label: "列表",
+            key: "list",
+            children: (
+              <UserDictList
+                studioName={user?.realName}
+                word={word}
+                compact={true}
+                refresh={myRefresh}
+                onRefresh={(value: boolean) => setMyRefresh(value)}
+              />
+            ),
+          },
+          {
+            label: "新建",
+            key: "new",
+            children: (
+              <MyCreate
+                word={word}
+                onSave={() => {
+                  setMyRefresh(true);
+                  setMyTab("list");
+                }}
+              />
+            ),
+          },
+        ]}
+      />
+    </div>
+  );
+};
+
 interface IWidget {
 interface IWidget {
   word?: string;
   word?: string;
   data: IDictContentData;
   data: IDictContentData;
@@ -41,51 +89,6 @@ interface IWidget {
 
 
 const DictContentWidget = ({ word, data, compact }: IWidget) => {
 const DictContentWidget = ({ word, data, compact }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
-  const user = useAppSelector(currentUser);
-  const [myRefresh, setMyRefresh] = useState(false);
-
-  const MyDict = () => {
-    const [myTab, setMyTab] = useState<string>("list");
-    return (
-      <div>
-        <Tabs
-          size="small"
-          type="card"
-          style={{ backgroundColor: "white" }}
-          activeKey={myTab}
-          onChange={(activeKey: string) => setMyTab(activeKey)}
-          items={[
-            {
-              label: "列表",
-              key: "list",
-              children: (
-                <UserDictList
-                  studioName={user?.realName}
-                  word={word}
-                  compact={true}
-                  refresh={myRefresh}
-                  onRefresh={(value: boolean) => setMyRefresh(value)}
-                />
-              ),
-            },
-            {
-              label: "新建",
-              key: "new",
-              children: (
-                <MyCreate
-                  word={word}
-                  onSave={() => {
-                    setMyRefresh(true);
-                    setMyTab("list");
-                  }}
-                />
-              ),
-            },
-          ]}
-        />
-      </div>
-    );
-  };
 
 
   return (
   return (
     <>
     <>
@@ -151,7 +154,7 @@ const DictContentWidget = ({ word, data, compact }: IWidget) => {
               {
               {
                 label: `单词本`,
                 label: `单词本`,
                 key: "my",
                 key: "my",
-                children: <MyDict />,
+                children: <MyDict word={word} />,
               },
               },
             ]}
             ]}
           />
           />

+ 8 - 6
dashboard/src/components/dict/MyCreate.tsx

@@ -187,12 +187,14 @@ const MyCreateWidget = ({ word, onSave }: IWidget) => {
   }
   }
 
 
   const reset = () => {
   const reset = () => {
-    fieldChanged("meaning", "");
-    fieldChanged("note", "");
-    fieldChanged("type", "");
-    fieldChanged("grammar", "");
-    fieldChanged("factors", "");
-    fieldChanged("factorMeaning", "");
+    let mData: IWbw = JSON.parse(JSON.stringify(editWord));
+    mData.note = { value: "", status: 7 };
+    mData.meaning = { value: "", status: 7 };
+    mData.type = { value: "", status: 7 };
+    mData.grammar = { value: "", status: 7 };
+    mData.factors = { value: "", status: 7 };
+    mData.factorMeaning = { value: "", status: 7 };
+    setEditWord(mData);
   };
   };
   return (
   return (
     <div style={{ padding: "0 5px" }}>
     <div style={{ padding: "0 5px" }}>

+ 14 - 1
dashboard/src/components/dict/UserDictList.tsx

@@ -26,7 +26,7 @@ import {
   IUserDictDeleteRequest,
   IUserDictDeleteRequest,
 } from "../../components/api/Dict";
 } from "../../components/api/Dict";
 import { delete_2, get } from "../../request";
 import { delete_2, get } from "../../request";
-import { useRef, useState } from "react";
+import { useEffect, useRef, useState } from "react";
 import DictEdit from "../../components/dict/DictEdit";
 import DictEdit from "../../components/dict/DictEdit";
 import { IDeleteResponse } from "../../components/api/Article";
 import { IDeleteResponse } from "../../components/api/Article";
 import TimeShow from "../general/TimeShow";
 import TimeShow from "../general/TimeShow";
@@ -60,6 +60,8 @@ interface IWidget {
   dictName?: string;
   dictName?: string;
   word?: string;
   word?: string;
   compact?: boolean;
   compact?: boolean;
+  refresh?: boolean;
+  onRefresh?: Function;
 }
 }
 const UserDictListWidget = ({
 const UserDictListWidget = ({
   studioName,
   studioName,
@@ -67,6 +69,8 @@ const UserDictListWidget = ({
   dictName,
   dictName,
   word,
   word,
   compact = false,
   compact = false,
+  refresh = false,
+  onRefresh,
 }: IWidget) => {
 }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
   const [isEditOpen, setIsEditOpen] = useState(false);
   const [isEditOpen, setIsEditOpen] = useState(false);
@@ -114,6 +118,15 @@ const UserDictListWidget = ({
     });
     });
   };
   };
 
 
+  useEffect(() => {
+    if (refresh === true) {
+      ref.current?.reload();
+      if (typeof onRefresh !== "undefined") {
+        onRefresh(false);
+      }
+    }
+  }, [onRefresh, refresh]);
+
   const ref = useRef<ActionType>();
   const ref = useRef<ActionType>();
 
 
   return (
   return (