command.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * 查字典,添加术语命令
  3. */
  4. import { createSlice, PayloadAction } from "@reduxjs/toolkit";
  5. import { IWidgetDict } from "../components/dict/DictComponent";
  6. import { ITerm } from "../components/term/TermEdit";
  7. import type { RootState } from "../store";
  8. export interface ITermCommand {}
  9. export interface ICommand {
  10. prop?: ITerm | IWidgetDict;
  11. type?: "term" | "dict";
  12. }
  13. interface IState {
  14. message?: ICommand;
  15. command?: "term" | "dict";
  16. lookup?: string;
  17. }
  18. const initialState: IState = {};
  19. export const slice = createSlice({
  20. name: "command",
  21. initialState,
  22. reducers: {
  23. //TODO 去掉command
  24. command: (state, action: PayloadAction<ICommand>) => {
  25. state.message = action.payload;
  26. },
  27. lookup: (state, action: PayloadAction<string | undefined>) => {
  28. state.lookup = action.payload;
  29. },
  30. },
  31. });
  32. export const { command } = slice.actions;
  33. export const { lookup } = slice.actions;
  34. export const commandParam = (state: RootState): IState => state.command;
  35. export const message = (state: RootState): ICommand | undefined =>
  36. state.command.message;
  37. export const lookupWord = (state: RootState): string | undefined =>
  38. state.command.lookup;
  39. export default slice.reducer;