import Vue from 'vue' ; import Vuex from 'vuex' ; import createPersistedState from 'vuex-persistedstate' ; import routerInfo from '@/config/routesInfo' ; import { RootState , languageType , languageOption } from './types' ; import defaultThemeColor from '@/style/defaultThemeColor' ; import themeColor from '@/config/themeColor' ; import defaultLanguage from '@/locale/default' ; import defaultHomeKey from '@/config/default.homeKey' ; import systemLocalStoreKey from '@/config/systemLocalStoreKey' ; import getClientHW from '@/utils/getClientHW' ; import * as modules from './models' ; import mutations from './mutations' ; import locale from '@/locale' ; import actions from './actions' ; const colorInfo = themeColor . find ( item => item . color === defaultThemeColor ) ; Vue . use ( Vuex ) ; const createLanguagelist = ( locale ) : Array < languageOption > => { const languageList = [ ] ; for ( let key in locale ) { languageList [ languageList . length ] = { key , name : locale [ key ] . name } ; } return languageList ; } ; const clientHW = getClientHW ( ) ; const routesInfoMap = routerInfo ( ) ; const createState = ( lan ) : RootState => ( { version : '0.0.0' , theme : 'dark' , themeColor : colorInfo ? colorInfo . key : 'color0' , navLayout : 'left' , fixedLeftMenu : true , fixedHeader : true , tabTool : true , tabMode : 'scroll' , globalScroll : false , language : { current : lan , list : createLanguagelist ( locale ) } , menuTree : [ ] , siderMenu : { collapsed : false , open : [ ] } , tabList : [ { id : defaultHomeKey , keyPath : `/${ defaultHomeKey }` } ] , tabActive : defaultHomeKey , tabHistory : [ `/${ defaultHomeKey }` ] , deviceType : clientHW . width > 1199 ? 'desktop' : clientHW . width > 576 ? 'tablet' : 'mobile' , systemLocalStore : true , routerLocalStore : false , routesInfoMap : routesInfoMap , loginInfo : { } , rememberMe : false , rememberLoginInfo : null } ) ; export default new Vuex . Store ( { state : createState ( defaultLanguage ) , actions , mutations : { RESET_LOCAL_STORE ( state ) { const initState = createState ( defaultLanguage ) ; systemLocalStoreKey . forEach ( ( key ) => { if ( key === 'loginInfo' ) return ; state [ key ] = initState [ key ] ; } ) ; } , ... mutations } , modules : modules , plugins : [ createPersistedState ( { key : 'vue-tsx-admin' , reducer ( root ) { if ( ! root . systemLocalStore ) { return { systemLocalStore : false } ; } const localStore = { } ; systemLocalStoreKey . forEach ( key => { localStore [ key ] = root [ key ] ; } ) ; return localStore ; } } ) ] } ) ;