visuddhinanda 3 лет назад
Родитель
Сommit
1ab260fd49
3 измененных файлов с 55 добавлено и 2 удалено
  1. 19 2
      dashboard/src/load.ts
  2. 34 0
      dashboard/src/reducers/term-vocabulary.ts
  3. 2 0
      dashboard/src/store.ts

+ 19 - 2
dashboard/src/load.ts

@@ -7,8 +7,10 @@ import { ISite, refresh as refreshLayout } from "./reducers/layout";
 import { ISettingItem, refresh as refreshSetting } from "./reducers/setting";
 import { ISettingItem, refresh as refreshSetting } from "./reducers/setting";
 import { refresh as refreshTheme } from "./reducers/theme";
 import { refresh as refreshTheme } from "./reducers/theme";
 import { get, IErrorResponse } from "./request";
 import { get, IErrorResponse } from "./request";
-//import { GRPC_HOST,  grpc_metadata } from "./request";
+import { get as getLang } from "./locales";
+
 import store from "./store";
 import store from "./store";
+import { ITerm, push } from "./reducers/term-vocabulary";
 
 
 export interface ISiteInfoResponse {
 export interface ISiteInfoResponse {
   title: string;
   title: string;
@@ -27,6 +29,14 @@ export interface ITokenRefreshResponse {
   data: IUserData;
   data: IUserData;
 }
 }
 
 
+interface ITermResponse {
+  ok: boolean;
+  message: string;
+  data: {
+    rows: ITerm[];
+    count: number;
+  };
+}
 const init = () => {
 const init = () => {
   get<ISiteInfoResponse | IErrorResponse>("/v2/siteinfo/en").then(
   get<ISiteInfoResponse | IErrorResponse>("/v2/siteinfo/en").then(
     (response) => {
     (response) => {
@@ -71,7 +81,14 @@ const init = () => {
     const json: ISettingItem[] = JSON.parse(setting);
     const json: ISettingItem[] = JSON.parse(setting);
     store.dispatch(refreshSetting(json));
     store.dispatch(refreshSetting(json));
   }
   }
-
+  //获取术语表
+  get<ITermResponse>(`/v2/term-vocabulary?view=grammar&lang=` + getLang()).then(
+    (json) => {
+      if (json.ok) {
+        store.dispatch(push(json.data.rows));
+      }
+    }
+  );
   //获取用户选择的主题
   //获取用户选择的主题
   const theme = localStorage.getItem("theme");
   const theme = localStorage.getItem("theme");
   if (theme === "dark") {
   if (theme === "dark") {

+ 34 - 0
dashboard/src/reducers/term-vocabulary.ts

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

+ 2 - 0
dashboard/src/store.ts

@@ -13,6 +13,7 @@ import currentCourseReducer from "./reducers/current-course";
 import sentenceReducer from "./reducers/sentence";
 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";
 
 
 const store = configureStore({
 const store = configureStore({
   reducer: {
   reducer: {
@@ -29,6 +30,7 @@ const store = configureStore({
     sentence: sentenceReducer,
     sentence: sentenceReducer,
     theme: themeReducer,
     theme: themeReducer,
     acceptPr: acceptPrReducer,
     acceptPr: acceptPrReducer,
+    termVocabulary: termVocabularyReducer,
   },
   },
 });
 });