| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { UserTableListType } from "@/types";
- // 初始化状态
- const initState = {
- // 列表数据
- tableInfo: {
- list: [] as UserTableListType[],
- total: 0,
- },
- // 角色列表数据
- roleList: [] as {
- label: string;
- value: number;
- }[],
- };
- // 定义 action 类型
- type UserActionType =
- | {
- type: "user/getList";
- payload: { list: UserTableListType[]; total: number };
- }
- | {
- type: "user/getRoleList";
- payload: {
- label: string;
- value: number;
- }[];
- };
- // 频道 reducer
- export default function userReducer(state = initState, action: UserActionType) {
- switch (action.type) {
- // 获取列表数据
- case "user/getList":
- return { ...state, tableInfo: action.payload };
- // 获取角色列表数据
- case "user/getRoleList":
- return { ...state, roleList: action.payload };
- default:
- return state;
- }
- }
|