import Vue from 'vue'
import Vuex from 'vuex'
import router from 'vue-router'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
	plugins: [
		createPersistedState({
			key: 'stort',
			paths: ['userInfo','tabList','includeTabs'] //, 'Tags'
		})
	],
	state: {
		userInfo: {
			username: '',
			password: '',
			token: '',
			value:''
		},
		tabList: [{
			title:'工作首页',
			path:'/home',
			name:'home'
		}],
		includeTabs:[]
	},
	mutations: {
		setuserInfo(state, data) {//登录存储
			state.userInfo = data
		},
		addTab: (state, tab) => {
			var tabVal = state.tabList.some(item => item.path === tab.path)
			if(tabVal===false){
				state.tabList.push(tab)
				state.includeTabs.push(tab.name)
			}
		},
		addinclude: (state, tab) => {//删除缓存
			var tb = tab.replace('/','');
			state.includeTabs.forEach(function(item,index) {
				if(item === tb){
					state.includeTabs.splice(index,1)
				}
			})
		},
		delTab: (state, tab) => {
			state.tabList.forEach(function(item,index) {
				if(item.path === tab){
					state.tabList.splice(index,1)
				}
			})
		}
	},
	getters: {
		// 获取tbsList
		getTabs: (state) => {
			return state.tabList.length
		}
	},
	actions: {},
	modules: {}
})
