import { createSlice } from '@reduxjs/toolkit';

export const slice = createSlice({
    name: 'userInfo',
    initialState: {
        tokenInfo:null,
        user:{}
    },
    reducers: {
        add: (state,action) => {        //添加token
            state.tokenInfo=action.payload;
        },
        remove: (state) => {        //删除token
            state.tokenInfo=null;
        },
        setSys:(state,action) => {        //选中的系统和医院id
            const {sysId,sysName,hisId} = action.payload;
            state.sysId=sysId;
            state.sysName=sysName;
            state.hisId=hisId;
        },
        setUser:(state,action) => {        //删除token
            state.user=action.payload;
        },
        setUnReadNum(state,action){     //未读消息数量
            state.unReadNum=action.payload;
        }
    },
});

export const { remove, add, setSys, setUser,setUnReadNum } = slice.actions;

export default slice.reducer;
