visuddhinanda 3 лет назад
Родитель
Сommit
4a1e680edc
1 измененных файлов с 24 добавлено и 0 удалено
  1. 24 0
      dashboard/src/components/template/Wbw/WbwFactors.tsx

+ 24 - 0
dashboard/src/components/template/Wbw/WbwFactors.tsx

@@ -8,9 +8,33 @@ import { IWbw, TWbwDisplayMode } from "./WbwWord";
 import { PaliReal } from "../../../utils";
 import { useAppSelector } from "../../../hooks";
 import { inlineDict as _inlineDict } from "../../../reducers/inline-dict";
+import { IApiResponseDictData } from "../../api/Dict";
 
 const { Text } = Typography;
 
+export const getFactorsInDict = (
+  wordIn: string,
+  wordIndex: string[],
+  wordList: IApiResponseDictData[]
+): string[] => {
+  if (wordIndex.includes(wordIn)) {
+    const result = wordList.filter((word) => word.word === wordIn);
+    //查重
+    //TODO 加入信心指数并排序
+    let myMap = new Map<string, number>();
+    let factors: string[] = [];
+    for (const iterator of result) {
+      myMap.set(iterator.factors, 1);
+    }
+    myMap.forEach((value, key, map) => {
+      factors.push(key);
+    });
+    return factors;
+  } else {
+    return [];
+  }
+};
+
 interface IWidget {
   data: IWbw;
   display?: TWbwDisplayMode;