审查视图

src/vuex/store.js 1.9 KB
朱兆平 authored
1 2 3 4 5 6 7 8 9
import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'

Vue.use(Vuex)

// 应用初始状态
const state = {
10
    count: 10,
11 12 13 14 15 16 17 18 19 20 21 22
    //所有打开的路由
    openTab:[],
    //激活状态,
    activeIndex: '/main',
    //用户菜单
    userMenu:[],
    userInfo:{
        userId: 0,
        username: '',
        companyId: 0,
        companyName: '',
        realname: '',
23 24
        userface: '',
        companyInfo:{}
25 26
    }
朱兆平 authored
27 28 29 30
}

// 定义所需的 mutations
const mutations = {
31 32
    // 添加tabs
    add_tabs (state, data) {
朱兆平 authored
33 34 35 36 37 38 39 40 41 42 43 44 45 46
        const _this = this;
        let flag = false;
        if (this.state.openTab.length>0){
            this.state.openTab.forEach(function (v) {
                if (data && v.route === data.route) {
                    flag = true;
                }
            });
            if (!flag) {
                _this.state.openTab.push(data);
            }
        }else{
            _this.state.openTab.push(data);
        }
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    },
    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;
    },
朱兆平 authored
66 67 68 69
    //设置用户菜单
    set_user_menu(state, menu){
        this.state.userMenu = menu;
    },
70 71 72 73
    //设置用户信息
    set_user_info(state,info){
       state.userInfo = info;
    },
朱兆平 authored
74 75 76 77 78 79 80 81 82 83 84 85 86 87
    INCREMENT(state) {
        state.count++
    },
    DECREMENT(state) {
        state.count--
    }
}

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