import Vue from 'vue' ; import { ActionTree } from 'vuex' ; import crypto from '@/utils/crypto' ; import authList from '@/config/auth.config' ; import themeColor from '@/config/themeColor' ; import defaultThemeColor from '@/style/defaultThemeColor' ; import { loginApi } from '@/api' ; import { theme , tabMode , tabItem , navLayout , RootState , deviceType , languageType , routesInfoMap , localStoreType } from './types' ; const actions = { toggleLanguage ( { commit } , lan ) { commit ( 'TOGGLE_LANGUAGE' , lan ) ; } , toggleGlobalTheme ( { commit } , theme ) { commit ( 'TOGGLE_THEME' , theme ) ; } , toggleThemeColor ( { commit } , themeColor ) { commit ( 'TOGGLE_THEME_COLOR' , themeColor . key ) ; } , toggleNavLayout ( { commit } , navLayout ) { commit ( 'TOGGLE_NAVLAYOUT' , navLayout ) ; } , toggleTabTool ( { commit } ) { commit ( 'TOGGLE_TABTOOL' ) ; } , toggleTabMode ( { commit } , tabMode ) { commit ( 'TOGGLE_TABMODE' , tabMode ) ; } , toggleSiderMenuCollapsed ( { commit } , deviceType ) { commit ( 'TOGGLE_SIDERMENU' , deviceType ) ; } , openSiderSubMenu ( { commit } , open ) { commit ( 'OPEN_SIDERSUBMENU' , open ) ; } , toggleDeviceType ( { commit } , deviceType ) { commit ( 'TOGGLE_DEVICETYPE' , deviceType ) ; } , toggleFixedLeftMenu ( { commit } ) { commit ( 'TOGGLE_FIXED_LEFTMENU' ) ; } , toggleFixedHeader ( { commit } ) { commit ( 'TOGGLE_FIXED_HEADER' ) ; } , toggleGlobalScroll ( { commit } ) { commit ( 'TOGGLE_GLOBAL_SCROLL' ) ; } , handleTab ( { commit } , tabInfo ) { commit ( 'HANDLE_TAB' , tabInfo ) ; } , removeTab ( { commit } , tabInfo ) { commit ( 'REMOVE_TAB' , tabInfo ) ; if ( tabInfo . module ) { tabInfo . module . forEach ( moduleName => commit ( `${ moduleName }/CLEAR_STORE` ) ) ; } } , clearTab ( { commit } , payload ) { commit ( 'CLEAR_TAB' , payload . vm ) ; if ( payload . tabList && payload . tabList . length > 1 ) { payload . tabList . forEach ( item => { const { module } = payload . routesInfoMap [ item . id ] || { module : false } ; if ( module ) module . forEach ( moduleName => commit ( `${ moduleName }/CLEAR_STORE` ) ) ; } ) ; } } , toogleLocalStore ( { commit } , type ) { commit ( 'TOGGLE_LOCAL_STORE' , type ) ; } , clearAllLocalStore ( { commit } , payload ) { commit ( 'RESET_LOCAL_STORE' ) ; const colorInfo = themeColor . find ( item => item . color === defaultThemeColor ) ; if ( payload . vm . setDefaultThemeColor ) payload . vm . setDefaultThemeColor ( colorInfo , false ) ; commit ( 'CLEAR_TAB' , payload . vm ) ; if ( payload . tabList && payload . tabList . length > 1 ) { payload . tabList . forEach ( item => { const { module } = payload . routesInfoMap [ item . id ] ; if ( module ) module . forEach ( moduleName => commit ( `${ moduleName }/CLEAR_STORE` ) ) ; } ) ; } } , toggleRmemberMe ( { commit } , checked ) { commit ( 'TOGGLE_REMREBER_ME' , checked ) ; } , async login ( store , params ) { const res = await loginApi . login ( params ) ; if ( typeof res === 'string' || ! res ) return res || '未查询到登录数据' ; store . commit ( 'SET_LOGIN_INFO' , { ... res , auth : authList } ) ; if ( params . username && store . state . rememberMe ) store . commit ( 'REMEMBER_LOGIN_PARAMS' , { account : params . username , password : crypto . encrypt ( params . password ) } ) ; return true ; } , async logout ( { commit } ) { await new Promise ( res => { setTimeout ( res , 500 ) ; } ) ; commit ( 'LOGOUT' ) ; return true ; } } ; export default actions ;