/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-03-04 09:21:53
 * @LastEditors: 无尘
 * @LastEditTime: 2020-03-05 18:15:50
 */
import Vuex from 'vuex';
import Vue from 'vue';
import * as types from './types';

Vue.use(Vuex);
export default new Vuex.Store({
  state: {
    user: {},
    token: null,
    title: '',
    show: false,
    bgHeight: window.screen.availHeight - 440 - 24 + 'px',
    addDepartment: [], // 添加
    editDepartment: [], // 编辑配置
    delDepartment: [] // 删除配置
  },
  mutations: {
    [types.LOGIN]: (state, data) => {
      sessionStorage.token = data;
      state.token = data;
    },
    [types.LOGOUT]: state => {
      sessionStorage.removeItem('token');
      state.token = null;
    },
    [types.TITLE]: (state, data) => {
      state.title = data;
    },
    [types.SHOW]: (state, data) => {
      state.show = data;
    },
    saveAdd: (state, data) => {
      state.addDepartment.push(data);
    },
    saveEdit: (state, data) => {
      state.editDepartment.push(data);
    },
    saveDel: (state, data) => {
      state.delDepartment.push(data);
    },
    clearAdd: state => {
      state.addDepartment = [];
    },
    clearEdit: state => {
      state.editDepartment = [];
    },
    clearData: state => {
      state.addDepartment = [];
      state.editDepartment = [];
      state.delDepartment = [];
    }
  },
  actions: {
    saveAddInfo(context, data) {
      context.commit('saveAdd', data);
    },
    saveEditInfo(context, data) {
      context.commit('saveEdit', data);
    },
    saveDelInfo(context, data) {
      context.commit('saveDel', data);
    },
    clearAddData(context, data) {
      context.commit('clearAdd');
    },
    clearEditData(context, data) {
      context.commit('clearEdit');
    },
    clearTreeData(context, data) {
      context.commit('clearData');
    }
  }
});
