import { Vue } from 'vue-property-decorator' ; import { MutationTree } from 'vuex' ; import createMenu from '@/config/menu' ; import { RootState , localStoreType } from './types' ; import defaultHomeKey from '@/config/default.homeKey' ; import enableRouterLocalStore from '@/utils/enableRouterLocalStore' ; import localStore from '@/localStore' ; const mutations = { TOGGLE_LANGUAGE ( state , lan ) { state . language . current = Vue . prototype . $currentLanguage = lan ; } , TOGGLE_THEME ( state , theme ) { state . theme = theme ; } , TOGGLE_THEME_COLOR ( state , themeColor ) { state . themeColor = themeColor ; } , TOGGLE_NAVLAYOUT ( state , navLayout ) { state . navLayout = navLayout ; } , TOGGLE_TABTOOL ( state ) { state . tabTool = ! state . tabTool ; } , TOGGLE_TABMODE ( state , tabMode ) { state . tabMode = tabMode ; } , TOGGLE_SIDERMENU ( state , deviceType ) { state . siderMenu . collapsed = ! state . siderMenu . collapsed ; if ( deviceType !== 'mobile' ) state . siderMenu . open = [ ] ; } , OPEN_SIDERSUBMENU ( state , open ) { state . siderMenu . open = open ; } , TOGGLE_DEVICETYPE ( state , deviceType ) { state . deviceType = deviceType ; } , TOGGLE_FIXED_LEFTMENU ( state ) { state . fixedLeftMenu = ! state . fixedLeftMenu ; } , TOGGLE_FIXED_HEADER ( state ) { state . fixedHeader = ! state . fixedHeader ; } , TOGGLE_GLOBAL_SCROLL ( state ) { state . globalScroll = ! state . globalScroll ; } , HANDLE_TAB ( state , tabInfo ) { const tabList = state . tabList , tabHistory = state . tabHistory ; const tab = tabList . find ( item => item . id === tabInfo . id ) ; if ( ! tab ) { tabList . push ( tabInfo ) ; tabHistory . push ( tabInfo . keyPath ) ; } state . tabActive = tabInfo . id ; } , REMOVE_TAB ( state , { tabInfo , vm } ) { state . tabHistory = state . tabHistory . filter ( keyPath => keyPath !== tabInfo . keyPath ) ; state . tabList = state . tabList . filter ( item => item . id !== tabInfo . id ) ; vm . $router . push ( state . tabHistory [ state . tabHistory . length - 1 ] ) ; if ( vm . autoOffset && typeof vm . autoOffset === 'function' ) vm . autoOffset ( ) ; } , CLEAR_TAB ( state , vm ) { const newTabList = state . tabList . filter ( item => item . id === defaultHomeKey ) ; state . tabList = newTabList ; state . tabHistory = [ newTabList [ 0 ] . keyPath ] ; vm . $router . push ( newTabList [ 0 ] . keyPath ) ; } , TOGGLE_LOCAL_STORE ( state , type ) { state [ type ] = ! state [ type ] ; if ( type === 'routerLocalStore' ) { if ( state [ type ] ) { window . _enableRouterLocalStore = enableRouterLocalStore ( ( this as any ) ) ; } else if ( window . _enableRouterLocalStore && typeof window . _enableRouterLocalStore === 'function' ) { window . _enableRouterLocalStore ( ) ; window . _enableRouterLocalStore = null ; localStore . clear ( ) ; } } } , TOGGLE_REMREBER_ME ( state , checked ) { state . rememberMe = checked ; if ( ! state . rememberMe ) { state . rememberLoginInfo = null ; } } , REMEMBER_LOGIN_PARAMS ( state , info ) { state . rememberLoginInfo = info ; } , SET_LOGIN_INFO ( state , info ) { const authMap = ( info . auth as { [ x ] : any ; } ) [ info . username ] ; const menuTree = createMenu ( authMap ) ; state . menuTree = menuTree ; state . loginInfo = { ... info , auth : authMap } ; } , LOGOUT ( state ) { state . loginInfo = { } ; state . siderMenu . open = [ ] ; state . siderMenu . collapsed = false ; } } ; export default mutations ;