Просмотр исходного кода

:sparkles: 从服务器获取nissaya ending 表

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

+ 17 - 179
dashboard/src/components/template/Nissaya/NissayaMeaning.tsx

@@ -1,199 +1,37 @@
-import GrammarPop from "../../dict/GrammarPop";
+import { useAppSelector } from "../../../hooks";
+import { getEnding } from "../../../reducers/nissaya-ending-vocabulary";
+import { NissayaCardPop } from "../../general/NissayaCard";
 
 
 interface IWidget {
 interface IWidget {
   text?: string;
   text?: string;
   code?: string;
   code?: string;
 }
 }
 
 
-interface IEnding {
-  text: string;
-  gid: string;
-}
-//缅文语尾高亮和提示气泡
-function myEndingTooltip(inStr?: string): JSX.Element {
-  if (typeof inStr === "undefined") {
+const Widget = ({ text, code = "my" }: IWidget) => {
+  const endings = useAppSelector(getEnding);
+  if (typeof text === "undefined") {
     return <></>;
     return <></>;
   }
   }
-  let myEnding = [
-    {
-      id: "my_nom1",
-      name: "သည်",
-      tooltip: "主语",
-    },
-    {
-      id: "my_nom2",
-      name: "ကား",
-      tooltip: "主格/主语",
-    },
-    {
-      id: "my_nom3",
-      name: "က",
-      tooltip: "主格/主语",
-    },
-    {
-      id: "my_acc1",
-      name: "ကို",
-      tooltip: "宾格/宾语",
-    },
-    {
-      id: "my_acc2",
-      name: "သို့",
-      tooltip: "宾格/趋向",
-    },
-    {
-      id: "my_inst1",
-      name: "ဖြင့်",
-      tooltip: "具格/用",
-    },
-    {
-      id: "my_inst2",
-      name: "နှင့်",
-      tooltip: "具格/与",
-    },
-    {
-      id: "my_inst2",
-      name: "နှင့်",
-      tooltip: "具格/与",
-    },
-    {
-      id: "my_inst3",
-      name: "ကြောင့်",
-      tooltip: "具格/凭借;从格/原因",
-    },
-    {
-      id: "my_inst3",
-      name: "ကြောင်း",
-      tooltip: "具格/凭借;从格/原因",
-    },
-    {
-      id: "my_dat1",
-      name: "အား",
-      tooltip: "目的格/对象(间接宾语),对……来说",
-    },
-    {
-      id: "my_dat2",
-      name: "ငှာ",
-      tooltip: "目的格/表示目的,为了……",
-    },
-    {
-      id: "my_dat2",
-      name: "အတွက်",
-      tooltip: "目的格/表示目的,为了……",
-    },
-    {
-      id: "my_abl1",
-      name: "မှ",
-      tooltip: "从格/表示来源,从……",
-    },
-    {
-      id: "my_abl2",
-      name: "အောက်",
-      tooltip: "从格/表达比较,比……多",
-    },
-    {
-      id: "my_abl3",
-      name: "ထက်",
-      tooltip: "从格/表达比较,比……少",
-    },
-    {
-      id: "my_gen1",
-      name: "၏",
-      tooltip: "属格/的",
-    },
-    {
-      id: "my_gen2",
-      name: "တွင်",
-      tooltip: "属格/表达范围,……中的",
-    },
-    {
-      id: "my_loc1",
-      name: "၌",
-      tooltip: "处格/处(范围)",
-    },
-    {
-      id: "my_loc2",
-      name: "ကြောင့်",
-      tooltip: "处格/表达动机,因……,旨在……",
-    },
-    {
-      id: "my_abs",
-      name: "၍",
-      tooltip: "连续体",
-    },
-    {
-      id: "my_pl",
-      name: "တို့",
-      tooltip: "复数",
-    },
-    {
-      id: "my_pl",
-      name: "များ",
-      tooltip: "复数",
-    },
-    {
-      id: "my_pl",
-      name: "ကုန်",
-      tooltip: "复数",
-    },
-    {
-      id: "my_pl",
-      name: "ကြ",
-      tooltip: "复数",
-    },
-    {
-      id: "my_time",
-      name: "ပတ်လုံး",
-      tooltip: "时间的整数",
-    },
-    {
-      id: "my_time",
-      name: "လုံလုံး",
-      tooltip: "时间的整数",
-    },
-    {
-      id: "my_length",
-      name: "တိုင်တိုင်",
-      tooltip: "距离,长度的整数",
-    },
-    {
-      id: "my_length",
-      name: "တိုင်အောင်",
-      tooltip: "距离,长度的整数",
-    },
-    {
-      id: "my_def",
-      name: "နေစဉ်",
-      tooltip: "同时发生的时间状语(当……的时候)",
-    },
-    {
-      id: "my_def",
-      name: "လျက်",
-      tooltip: "同时发生的时间状语(当……的时候)",
-    },
-  ];
-
-  let ending: IEnding[] = [];
-  let head: string = inStr;
-  for (const iterator of myEnding) {
-    if (inStr.indexOf(iterator.name) === inStr.length - iterator.name.length) {
-      head = inStr.substring(0, inStr.indexOf(iterator.name));
-      ending.push({ text: iterator.name, gid: iterator.id });
+  let head = text;
+  let end: string[] = [];
+  for (let loop = 0; loop < 3; loop++) {
+    for (let index = 0; index < head.length; index++) {
+      const ending = head.slice(index);
+      if (endings?.includes(ending)) {
+        end.unshift(head.slice(index));
+        head = head.slice(0, index);
+      }
     }
     }
   }
   }
-  const eEnding = ending.map((item, id) => {
-    return <GrammarPop text={item.text} key={id} gid={`grammar_${item.gid}`} />;
+  const eEnding = end.map((item, id) => {
+    return <NissayaCardPop text={item} key={id} trigger={item} />;
   });
   });
-
   return (
   return (
     <>
     <>
       <span>{head}</span>
       <span>{head}</span>
       {eEnding}
       {eEnding}
     </>
     </>
   );
   );
-}
-const Widget = ({ text, code = "my" }: IWidget) => {
-  console.log("nissaya-meaning", text);
-  return myEndingTooltip(text);
 };
 };
 
 
 export default Widget;
 export default Widget;

+ 21 - 0
dashboard/src/load.ts

@@ -11,6 +11,7 @@ import { get as getLang } from "./locales";
 
 
 import store from "./store";
 import store from "./store";
 import { ITerm, push } from "./reducers/term-vocabulary";
 import { ITerm, push } from "./reducers/term-vocabulary";
+import { push as nissayaEndingPush } from "./reducers/nissaya-ending-vocabulary";
 
 
 export interface ISiteInfoResponse {
 export interface ISiteInfoResponse {
   title: string;
   title: string;
@@ -37,6 +38,17 @@ interface ITermResponse {
     count: number;
     count: number;
   };
   };
 }
 }
+interface INissayaEnding {
+  ending: string;
+}
+interface INissayaEndingResponse {
+  ok: boolean;
+  message: string;
+  data: {
+    rows: INissayaEnding[];
+    count: number;
+  };
+}
 const init = () => {
 const init = () => {
   get<ISiteInfoResponse | IErrorResponse>("/v2/siteinfo/en").then(
   get<ISiteInfoResponse | IErrorResponse>("/v2/siteinfo/en").then(
     (response) => {
     (response) => {
@@ -89,6 +101,15 @@ const init = () => {
       }
       }
     }
     }
   );
   );
+  //获取nissaya ending 表
+  get<INissayaEndingResponse>(`/v2/nissaya-ending-vocabulary?lang=my`).then(
+    (json) => {
+      if (json.ok) {
+        const nissayaEnding = json.data.rows.map((item) => item.ending);
+        store.dispatch(nissayaEndingPush(nissayaEnding));
+      }
+    }
+  );
   //获取用户选择的主题
   //获取用户选择的主题
   const theme = localStorage.getItem("theme");
   const theme = localStorage.getItem("theme");
   if (theme === "dark") {
   if (theme === "dark") {

+ 29 - 0
dashboard/src/reducers/nissaya-ending-vocabulary.ts

@@ -0,0 +1,29 @@
+/**
+ * 从服务器获取的术语表
+ */
+import { createSlice, PayloadAction } from "@reduxjs/toolkit";
+
+import type { RootState } from "../store";
+
+interface IState {
+  ending?: string[];
+}
+
+const initialState: IState = {};
+
+export const slice = createSlice({
+  name: "nissaya-ending-vocabulary",
+  initialState,
+  reducers: {
+    push: (state, action: PayloadAction<string[]>) => {
+      state.ending = action.payload;
+    },
+  },
+});
+
+export const { push } = slice.actions;
+
+export const getEnding = (state: RootState): string[] | undefined =>
+  state.nissayaEndingVocabulary.ending;
+
+export default slice.reducer;

+ 2 - 0
dashboard/src/store.ts

@@ -14,6 +14,7 @@ import sentenceReducer from "./reducers/sentence";
 import themeReducer from "./reducers/theme";
 import themeReducer from "./reducers/theme";
 import acceptPrReducer from "./reducers/accept-pr";
 import acceptPrReducer from "./reducers/accept-pr";
 import termVocabularyReducer from "./reducers/term-vocabulary";
 import termVocabularyReducer from "./reducers/term-vocabulary";
+import nissayaEndingVocabularyReducer from "./reducers/nissaya-ending-vocabulary";
 
 
 const store = configureStore({
 const store = configureStore({
   reducer: {
   reducer: {
@@ -31,6 +32,7 @@ const store = configureStore({
     theme: themeReducer,
     theme: themeReducer,
     acceptPr: acceptPrReducer,
     acceptPr: acceptPrReducer,
     termVocabulary: termVocabularyReducer,
     termVocabulary: termVocabularyReducer,
+    nissayaEndingVocabulary: nissayaEndingVocabularyReducer,
   },
   },
 });
 });