Parcourir la source

提取 factor 生成 为 factorChange 函数

visuddhinanda il y a 2 ans
Parent
commit
5e98dd3cc6
1 fichiers modifiés avec 22 ajouts et 15 suppressions
  1. 22 15
      dashboard/src/components/dict/SearchVocabulary.tsx

+ 22 - 15
dashboard/src/components/dict/SearchVocabulary.tsx

@@ -31,8 +31,9 @@ const SearchVocabularyWidget = ({
   const intervalRef = useRef<number | null>(null); //防抖计时器句柄
   const intervalRef = useRef<number | null>(null); //防抖计时器句柄
 
 
   useEffect(() => {
   useEffect(() => {
-    setInput(value);
     console.log("dict input", value);
     console.log("dict input", value);
+    setInput(value);
+    factorChange(value);
   }, [value]);
   }, [value]);
 
 
   const renderItem = (title: string, count: number, meaning?: string) => ({
   const renderItem = (title: string, count: number, meaning?: string) => ({
@@ -70,6 +71,24 @@ const SearchVocabularyWidget = ({
     }
     }
   };
   };
 
 
+  const factorChange = (word?: string) => {
+    if (typeof word === "undefined") {
+      setFactors([]);
+      return;
+    }
+    const strFactors = word.replaceAll("+", "-");
+    if (strFactors.indexOf("-") >= 0) {
+      setFactors(strFactors.split("-"));
+      if (typeof onSplit !== "undefined") {
+        onSplit(strFactors.replaceAll("-", "+"));
+      }
+    } else {
+      setFactors([]);
+      if (typeof onSplit !== "undefined") {
+        onSplit();
+      }
+    }
+  };
   const search = (value: string) => {
   const search = (value: string) => {
     console.log("search", value);
     console.log("search", value);
     stopLookup();
     stopLookup();
@@ -103,22 +122,10 @@ const SearchVocabularyWidget = ({
         popupClassName="certain-category-search-dropdown"
         popupClassName="certain-category-search-dropdown"
         dropdownMatchSelectWidth={400}
         dropdownMatchSelectWidth={400}
         options={options}
         options={options}
-        onChange={(value: string, option: ValueType | ValueType[]) => {
+        onChange={(value: string) => {
           console.log("input", value);
           console.log("input", value);
           setInput(value);
           setInput(value);
-
-          const strFactors = value.replaceAll("+", "-");
-          if (strFactors.indexOf("-") >= 0) {
-            setFactors(strFactors.split("-"));
-            if (typeof onSplit !== "undefined") {
-              onSplit(strFactors.replaceAll("-", "+"));
-            }
-          } else {
-            setFactors([]);
-            if (typeof onSplit !== "undefined") {
-              onSplit();
-            }
-          }
+          factorChange(value);
         }}
         }}
         onSearch={(value: string) => {
         onSearch={(value: string) => {
           console.log("auto complete on search", value);
           console.log("auto complete on search", value);