visuddhinanda 3 лет назад
Родитель
Сommit
1b8c7ea5cc

+ 42 - 17
dashboard/src/components/template/Wbw/WbwFactorMeaning.tsx

@@ -1,26 +1,15 @@
 import { useIntl } from "react-intl";
+import { useState, useEffect } from "react";
 import type { MenuProps } from "antd";
-import { Dropdown } from "antd";
-import { Typography } from "antd";
+import { Dropdown, Space, Typography } from "antd";
+import { LoadingOutlined } from "@ant-design/icons";
 
 import { IWbw, TWbwDisplayMode } from "./WbwWord";
 import { PaliReal } from "../../../utils";
-const { Text } = Typography;
+import { useAppSelector } from "../../../hooks";
+import { inlineDict as _inlineDict } from "../../../reducers/inline-dict";
 
-const items: MenuProps["items"] = [
-  {
-    key: "factor1+意思",
-    label: "factor1+意思",
-  },
-  {
-    key: "factor2+意思",
-    label: "factor2+意思",
-  },
-  {
-    key: "factor3+意思",
-    label: "factor3+意思",
-  },
-];
+const { Text } = Typography;
 
 interface IWidget {
   data: IWbw;
@@ -29,6 +18,42 @@ interface IWidget {
 }
 const Widget = ({ data, display, onChange }: IWidget) => {
   const intl = useIntl();
+  const defaultMenu: MenuProps["items"] = [
+    {
+      key: "loading",
+      label: (
+        <Space>
+          <LoadingOutlined />
+          {"Loading"}
+        </Space>
+      ),
+    },
+  ];
+  const [items, setItems] = useState<MenuProps["items"]>(defaultMenu);
+
+  const inlineDict = useAppSelector(_inlineDict);
+  useEffect(() => {
+    if (inlineDict.wordIndex.includes(data.word.value)) {
+      const result = inlineDict.wordList.filter(
+        (word) => word.word === data.word.value
+      );
+      //查重
+      //TODO 加入信心指数并排序
+      let myMap = new Map<string, number>();
+      let factors: string[] = [];
+      for (const iterator of result) {
+        myMap.set(iterator.factormean, 1);
+      }
+      myMap.forEach((value, key, map) => {
+        factors.push(key);
+      });
+
+      const menu = factors.map((item) => {
+        return { key: item, label: item };
+      });
+      setItems(menu);
+    }
+  }, [inlineDict]);
 
   const onClick: MenuProps["onClick"] = (e) => {
     console.log("click ", e);

+ 42 - 16
dashboard/src/components/template/Wbw/WbwFactors.tsx

@@ -1,26 +1,16 @@
+import { useState, useEffect } from "react";
 import { useIntl } from "react-intl";
 import type { MenuProps } from "antd";
-import { Dropdown } from "antd";
-import { Typography } from "antd";
+import { Dropdown, Space, Typography } from "antd";
+import { LoadingOutlined } from "@ant-design/icons";
 
 import { IWbw, TWbwDisplayMode } from "./WbwWord";
 import { PaliReal } from "../../../utils";
+import { useAppSelector } from "../../../hooks";
+import { inlineDict as _inlineDict } from "../../../reducers/inline-dict";
+
 const { Text } = Typography;
 
-const items: MenuProps["items"] = [
-  {
-    key: "factor1+word",
-    label: "factor1+word",
-  },
-  {
-    key: "factor2+word",
-    label: "factor2+word",
-  },
-  {
-    key: "factor3+word",
-    label: "factor3+word",
-  },
-];
 interface IWidget {
   data: IWbw;
   display?: TWbwDisplayMode;
@@ -29,6 +19,42 @@ interface IWidget {
 
 const Widget = ({ data, display, onChange }: IWidget) => {
   const intl = useIntl();
+  const defaultMenu: MenuProps["items"] = [
+    {
+      key: "loading",
+      label: (
+        <Space>
+          <LoadingOutlined />
+          {"Loading"}
+        </Space>
+      ),
+    },
+  ];
+  const [items, setItems] = useState<MenuProps["items"]>(defaultMenu);
+
+  const inlineDict = useAppSelector(_inlineDict);
+  useEffect(() => {
+    if (inlineDict.wordIndex.includes(data.word.value)) {
+      const result = inlineDict.wordList.filter(
+        (word) => word.word === data.word.value
+      );
+      //查重
+      //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);
+      });
+
+      const menu = factors.map((item) => {
+        return { key: item, label: item };
+      });
+      setItems(menu);
+    }
+  }, [inlineDict]);
 
   const onClick: MenuProps["onClick"] = (e) => {
     console.log("click ", e);

+ 5 - 19
dashboard/src/components/template/Wbw/WbwWord.tsx

@@ -9,7 +9,7 @@ import "./wbw.css";
 import WbwPara from "./WbwPara";
 import WbwPage from "./WbwPage";
 import { useAppSelector } from "../../../hooks";
-import { add, wordList } from "../../../reducers/inline-dict";
+import { add, wordList, wordIndex } from "../../../reducers/inline-dict";
 import { get } from "../../../request";
 import { IApiResponseDictList, IDictDataRequest } from "../../api/Dict";
 import store from "../../../store";
@@ -95,7 +95,8 @@ const Widget = ({
   const [wordData, setWordData] = useState(data);
   const [fieldDisplay, setFieldDisplay] = useState(fields);
   const intervalRef = useRef<number | null>(null); //防抖计时器句柄
-  const inlineWords = useAppSelector(wordList);
+  const inlineWordList = useAppSelector(wordList);
+  const inlineWordIndex = useAppSelector(wordIndex);
 
   useEffect(() => {
     setWordData(data);
@@ -131,29 +132,14 @@ const Widget = ({
   const lookup = (word: string) => {
     stopLookup();
     //查询这个词在内存字典里是否有
-    if (inlineWords.has(word)) {
+    if (inlineWordIndex.includes(word)) {
       //已经有了,退出
       return;
     }
     get<IApiResponseDictList>(`/v2/wbwlookup?word=${word}`).then((json) => {
       console.log("lookup ok", json.data.count);
       //扫描结果将结果按照词头分开
-      /*
-      let wordList = new Map<string, IDictDataRequest[]>();
-      for (const word of json.data.rows) {
-        if (!wordList.has(word.word)) {
-          wordList.set(word.word, [word]);
-        } else {
-          const oldValue = wordList.get(word.word);
-          if (typeof oldValue === "undefined") {
-            wordList.set(word.word, [word]);
-          } else {
-            wordList.set(word.word, [...oldValue, word]);
-          }
-        }
-      }
-      store.dispatch(add(wordList));
-	  */
+      store.dispatch(add(json.data.rows));
     });
 
     console.log("lookup", word);