/*
 * @Author: lmc 934268770@qq.com
 * @Date: 2022-11-25 09:06:41
 * @LastEditors: lmc 934268770@qq.com
 * @LastEditTime: 2022-11-25 09:33:59
 * @FilePath: \witcarbon-vue\src\store\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import Vuex from 'vuex'
import cloneDeep from 'lodash/cloneDeep'
import user from './modules/user'

Vue.use(Vuex)

export default new Vuex.Store({
  namespaced: true,
  state: {
    currentMenuId:'',//当前菜单id
    erjismenu:null,
    yijiInd:null,
    currentPayWorryRecord:'',
    // 侧边栏, 折叠状态
    sidebarFold: false,
    // 侧边栏, 菜单
    sidebarMenuList: [],
    sidebarMenuActiveName: '', 
    // 内容, 是否需要刷新
    contentIsNeedRefresh: false,
    currentMenuIndex:0,
    isFull:false,
    stateTagsList:[],
    // 内容, 标签页(默认添加首页)
    contentTabs: [
      {
        ...window.SITE_CONFIG['contentTabDefault'],
        'name': 'home',
        'title': 'home'
      }
    ],
    contentTabsActiveName: 'home'
  },
  modules: {
    user
  },
  mutations: {
  /**
     * 选择tag标签
     */
    mutationSelectTags(state, data){
      let result = false
      for(let i=0; i<state.stateTagsList.length;i++){
        if(state.stateTagsList[i].name == data.name){
          return result = true
        }
      }
      result === false ? state.stateTagsList.push(data) : '';
    },
  
    /**
     * 关闭tag标签
     */
    mutationCloseTag(state, data){
      let result = state.stateTagsList.findIndex(item => item.name === data.name)
      state.stateTagsList.splice(result, 1)
    },
    //关闭所有
    mutationCloseAll(state){
      let last = state.stateTagsList.filter(item =>item.meta.menuId === state.currentMenuId)
      state.stateTagsList=last;
    },
    // 重置vuex本地储存状态
    resetStore (state) {
      Object.keys(state).forEach((key) => {
        state[key] = cloneDeep(window.SITE_CONFIG['storeState'][key])
      })
    }
  }
})
