Kaynağa Gözat

有未保存的脏数据不查词

visuddhinanda 2 yıl önce
ebeveyn
işleme
5861370382

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

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