import { removeToken } from '@/lin/utils/token' ; import { getStageInfo , handleAvatar , handlePermissions , } from '../getters/app.getters' ; import * as types from './mutation-types' ; import { IRouterItem } from '@/types/project' ; import { IUserType , IOriginalPermissions , IHistoryItem , IMessage , IAppState , } from '@/types/store' ; import { Mutation } from 'dream-redux/types' ; const target = 'app' ; export const updateRoute = ( pathname ) : Mutation => ( { type : types . UPDATE_ROUTE , target , operation : ( state ) => { const stageInfo = getStageInfo ( state ) ( pathname ) ; state . currentRoute = { config : stageInfo [ stageInfo . length - 1 ] , treePath : stageInfo } ; } } ) ; export const clearRoute = ( ) : Mutation => ( { type : types . CLEAR_ROUTE , target , operation : ( state ) => { state . currentRoute = { config : { } as IRouterItem , treePath : [ ] } ; } } ) ; export const setUserAndState = ( user ) : Mutation => ( { type : types . SET_USER_AND_STATE , target , operation : ( state ) => { user . avatar = handleAvatar ( user . avatar ) ; state . logined = true ; state . user = user ; } } ) ; export const setUserPermissions = ( permissions ) : Mutation => ( { type : types . SET_USER_PERMISSIONS , target , operation : ( state ) => { state . permissions = handlePermissions ( permissions ) ; } } ) ; export const loginOut = ( ) : Mutation => ( { type : types . REMOVE_LOGINED , target , operation : ( state ) => { removeToken ( ) ; state . logined = false ; } } ) ; export const changeReuseTab = ( histories ) : Mutation => ( { type : types . CHANGE_REUSE_TAB , target , operation : ( state ) => { state . histories = histories ; } } ) ; export const addReadedMessage = ( message ) : Mutation => ( { type : types . ADD_READED_MESSAGE , target , operation : ( state ) => { state . readedMessages . push ( message ) ; } } ) ; export const addUnreadMessage = ( message ) : Mutation => ( { type : types . ADD_UNREAD_MESSAGE , target , operation : ( state ) => { state . unreadMessages . push ( message ) ; } } ) ; export const removeUnreadMessage = ( messageId ) : Mutation => ( { type : types . ADD_UNREAD_MESSAGE , target , operation : ( state ) => { const index = state . unreadMessages . findIndex ( item => item . id === messageId ) ; state . unreadMessages . splice ( index , 1 ) ; } } ) ;