A4Role.ts 835 B

123456789101112131415161718192021222324252627282930313233
  1. import { RoleTableType } from "@/types";
  2. // 初始化状态
  3. const initState = {
  4. // 列表数据
  5. tableInfo: {
  6. list: [] as RoleTableType[],
  7. total: 0,
  8. },
  9. // 用户的所有 权限信息(扁平化,且过滤掉没有权限的数据)
  10. A4RoleAll: [] as string[],
  11. };
  12. // 定义 action 类型
  13. type Props =
  14. | { type: "Role/getList"; payload: { list: RoleTableType[]; total: number } }
  15. | { type: "A4RoleAll/getInfo"; payload: string[] };
  16. // 频道 reducer
  17. export default function RoleReducer(state = initState, action: Props) {
  18. switch (action.type) {
  19. // 获取列表数据
  20. case "Role/getList":
  21. return { ...state, tableInfo: action.payload };
  22. // 用户的所有 权限信息
  23. case "A4RoleAll/getInfo":
  24. return { ...state, A4RoleAll: action.payload };
  25. default:
  26. return state;
  27. }
  28. }