user.ts 917 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { UserTableListType } from "@/types";
  2. // 初始化状态
  3. const initState = {
  4. // 列表数据
  5. tableInfo: {
  6. list: [] as UserTableListType[],
  7. total: 0,
  8. },
  9. // 角色列表数据
  10. roleList: [] as {
  11. label: string;
  12. value: number;
  13. }[],
  14. };
  15. // 定义 action 类型
  16. type UserActionType =
  17. | {
  18. type: "user/getList";
  19. payload: { list: UserTableListType[]; total: number };
  20. }
  21. | {
  22. type: "user/getRoleList";
  23. payload: {
  24. label: string;
  25. value: number;
  26. }[];
  27. };
  28. // 频道 reducer
  29. export default function userReducer(state = initState, action: UserActionType) {
  30. switch (action.type) {
  31. // 获取列表数据
  32. case "user/getList":
  33. return { ...state, tableInfo: action.payload };
  34. // 获取角色列表数据
  35. case "user/getRoleList":
  36. return { ...state, roleList: action.payload };
  37. default:
  38. return state;
  39. }
  40. }