Browse Source

word interface 跟数据库返回数据匹配,有可能为null

visuddhinanda 2 years ago
parent
commit
dd0f904ca0

+ 10 - 10
dashboard/src/components/api/Dict.ts

@@ -5,11 +5,11 @@ import { ICaseListData } from "../dict/CaseList";
 export interface IDictRequest {
   id?: number;
   word: string;
-  type?: string;
-  grammar?: string;
+  type?: string | null;
+  grammar?: string | null;
   mean?: string | null;
   parent?: string | null;
-  note?: string;
+  note?: string | null;
   factors?: string | null;
   factormean?: string | null;
   confidence: number;
@@ -38,13 +38,13 @@ export interface IDictInfo {
 export interface IApiResponseDictData {
   id: string;
   word: string;
-  type: string;
-  grammar: string;
-  mean: string;
-  parent: string;
-  note: string;
-  factors: string;
-  factormean: string;
+  type?: string | null;
+  grammar?: string | null;
+  mean?: string | null;
+  parent?: string | null;
+  note?: string | null;
+  factors?: string | null;
+  factormean?: string | null;
   language: string;
   dict?: IDictInfo;
   dict_id: string;

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

@@ -57,18 +57,20 @@ const CommunityWidget = ({ word }: IWidget) => {
             const currScore = Math.floor(
               (it.exp / 3600) * (it.confidence / 100)
             );
-
-            score = meaning.get(it.mean);
-            meaning.set(it.mean, score ? score + currScore : currScore);
+            if (it.mean) {
+              score = meaning.get(it.mean);
+              meaning.set(it.mean, score ? score + currScore : currScore);
+            }
 
             if (it.type || it.grammar) {
               const strCase = it.type + "$" + it.grammar;
               score = grammar.get(strCase);
               grammar.set(strCase, score ? score + currScore : currScore);
             }
-
-            score = parent.get(it.parent);
-            parent.set(it.parent, score ? score + currScore : currScore);
+            if (it.parent) {
+              score = parent.get(it.parent);
+              parent.set(it.parent, score ? score + currScore : currScore);
+            }
 
             if (it.editor) {
               score = editorId.get(it.editor.id);

+ 9 - 3
dashboard/src/components/dict/Compound.tsx

@@ -61,9 +61,15 @@ const CompoundWidget = ({ word, add, split, onSearch }: IWidget) => {
     const url = `/v2/userdict?view=compound&word=${word}&order=confidence`;
     get<IApiResponseDictList>(url).then((json) => {
       if (json.ok) {
-        const data = json.data.rows.map((item) => {
-          return { value: item.factors, label: item.factors };
-        });
+        const data = json.data.rows
+          .filter((value) => typeof value.factors === "string")
+          .map((item) => {
+            if (item.factors) {
+              return { value: item.factors, label: item.factors };
+            } else {
+              return { value: "", label: "" };
+            }
+          });
         setCompound(data);
       }
     });

+ 7 - 7
dashboard/src/components/dict/DictCreate.tsx

@@ -7,13 +7,13 @@ import DictEditInner from "./DictEditInner";
 export interface IDictFormData {
   id: number;
   word: string;
-  type: string;
-  grammar: string;
-  parent: string;
-  meaning: string;
-  note: string;
-  factors: string;
-  factormeaning: string;
+  type?: string | null;
+  grammar?: string | null;
+  parent?: string | null;
+  meaning?: string | null;
+  note?: string | null;
+  factors?: string | null;
+  factormeaning?: string | null;
   lang: string;
   confidence: number;
 }

+ 6 - 6
dashboard/src/components/dict/UserDictList.tsx

@@ -35,12 +35,12 @@ export interface IWord {
   sn: number;
   wordId: string;
   word: string;
-  type: string;
-  grammar: string;
-  parent: string;
-  meaning: string;
-  note: string;
-  factors: string;
+  type?: string | null;
+  grammar?: string | null;
+  parent?: string | null;
+  meaning?: string | null;
+  note?: string | null;
+  factors?: string | null;
   dict?: IDictInfo;
   updated_at?: string;
   created_at?: string;

+ 1 - 1
dashboard/src/components/template/Wbw/CaseFormula.tsx

@@ -44,7 +44,7 @@ const CaseFormulaWidget = ({ data, onChange, onCaseChange }: IWidget) => {
       );
     }
     let strFormula: string;
-    if (result.length > 0) {
+    if (result.length > 0 && result[0].mean) {
       strFormula = result[0].mean;
     } else {
       strFormula = "{无}";

+ 3 - 1
dashboard/src/components/template/Wbw/WbwDetailBasic.tsx

@@ -42,7 +42,9 @@ export const getParentInDict = (
     let myMap = new Map<string, number>();
     let parent: string[] = [];
     for (const iterator of result) {
-      myMap.set(iterator.parent, 1);
+      if (iterator.parent) {
+        myMap.set(iterator.parent, 1);
+      }
     }
     myMap.forEach((value, key, map) => {
       parent.push(key);

+ 3 - 1
dashboard/src/components/template/Wbw/WbwDetailParent2.tsx

@@ -33,7 +33,9 @@ const WbwParent2Widget = ({ data, onChange }: IWidget) => {
       let myMap = new Map<string, number>();
       let parent: string[] = [];
       for (const iterator of result) {
-        myMap.set(iterator.parent, 1);
+        if (iterator.parent) {
+          myMap.set(iterator.parent, 1);
+        }
       }
       myMap.forEach((value, key, map) => {
         parent.push(key);

+ 3 - 1
dashboard/src/components/template/Wbw/WbwFactorMeaning.tsx

@@ -48,7 +48,9 @@ const WbwFactorMeaningWidget = ({
       let myMap = new Map<string, number>();
       let factors: string[] = [];
       for (const iterator of result) {
-        myMap.set(iterator.factormean, 1);
+        if (iterator.factormean) {
+          myMap.set(iterator.factormean, 1);
+        }
       }
       myMap.forEach((value, key, map) => {
         factors.push(key);

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

@@ -23,7 +23,9 @@ export const getFactorsInDict = (
     let myMap = new Map<string, number>();
     let factors: string[] = [];
     for (const iterator of result) {
-      myMap.set(iterator.factors, 1);
+      if (iterator.factors) {
+        myMap.set(iterator.factors, 1);
+      }
     }
     myMap.forEach((value, key, map) => {
       factors.push(key);
@@ -69,7 +71,9 @@ const WbwFactorsWidget = ({ data, display, onChange }: IWidget) => {
       let myMap = new Map<string, number>();
       let factors: string[] = [];
       for (const iterator of result) {
-        myMap.set(iterator.factors, 1);
+        if (iterator.factors) {
+          myMap.set(iterator.factors, 1);
+        }
       }
       myMap.forEach((value, key, map) => {
         factors.push(key);

+ 1 - 0
dashboard/src/components/template/Wbw/WbwMeaningSelect.tsx

@@ -75,6 +75,7 @@ const WbwMeaningSelectWidget = ({ data, onSelect }: IWidget) => {
         const indexParent = mParent.findIndex((item) => item.word === word1);
         result1.forEach((value, index, array) => {
           if (
+            value.parent &&
             value.parent !== "" &&
             !baseRemind.includes(value.parent) &&
             !baseDone.includes(value.parent)