import { createStore } from 'vuex'

export default createStore({
  state: {
    stateTagsList: [{
      id: '21',
      labelName: '库存',
      path: '/stock'
    }],
    user: {},
    menuList: [],
    token: '',
    verifier: ''
  },
  getters: {
    getUserName(state) {
      return state.user.userName
    },
    getMenuList(state) {
      return state.menuList
    },
    getToken(state) {
      return state.token
    },
    getVerify(state) {
      return state.verifier
    },
  },
  mutations: {
    /**
   * 选择tag标签
   */
    mutationSelectTags(state, data) {
      let result = false
      for (let i = 0; i < state.stateTagsList.length; i++) {
        if (state.stateTagsList[i].path == data.path) {
          return result = true
        }
      }
      result === false ? state.stateTagsList.push(data) : ''
    },

    /**
     * 关闭tag标签
     */
    mutationCloseTag(state, data) {
      let result = state.stateTagsList.findIndex(item => item.path === data.path)
      state.stateTagsList.splice(result, 1)
    },

    /**
     * 存储用户信息
     */
    mutationUser(state, data) {
      state.user = data
      sessionStorage.setItem("user", state.user)
    },

    /**
     * 存储菜单信息
     */
    mutationMenu(state, data) {
      state.menuList = data
      sessionStorage.setItem("menuList", state.menuList)
    },

    /**
     * 存储认证
     */
    mutationAddVerify(state, data) {
      state.verifier = data
    },

    mutationClearVerify(state) {
      state.verifier = ''
    },
  },
  actions: {
  },
  modules: {
  }
})
