import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'

Vue.use(Vuex)

// 应用初始状态
const state = {
    count: 10,
    openTab:[],//所有打开的路由
    activeIndex: '/main' //激活状态
}

// 定义所需的 mutations
const mutations = {
    // 添加tabs
    add_tabs (state, data) {
        this.state.openTab.push(data);
    },
    set_tabs(state,value){
        this.state.openTab= value;
    },
    // 删除tabs
    delete_tabs (state, route) {
        let index = 0;
        for (let option of state.openTab) {
            if (option.route === route) {
                break;
            }
            index++;
        }
        this.state.openTab.splice(index, 1);
    },
    // 设置当前激活的tab
    set_active_index (state, index) {
        this.state.activeIndex = index;
    },
    INCREMENT(state) {
        state.count++
    },
    DECREMENT(state) {
        state.count--
    }
}

// 创建 store 实例
export default new Vuex.Store({
    actions,
    getters,
    state,
    mutations
})