import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 告警等级配置
    alarmLevelConfig: null,
    // 系统模式
    systemMode: null,
    openTab: [], // 所有打开的路由
    activeIndex: '/main', // 激活状态
    keepAliveRouter: [],
    deviceList: [], // 设备列表
    alarmNoticeList: [], // 警告通知列表（该告警通知列表会当告警出现的）
    alarmList: [], // 告警集合
    unConfirmAlarmList: [], // 告警未确认集合
    confirmAlarmList: [], // 告警确认集合
    clearAlarmList: [], // 告警清除集合
    configDifferencesList: [], // 配置差异信息
    subnetList:[],  //子网
    selectObject:[],  //侧边栏或拓扑图选中的设备
    linkList:[], // 链路集合

    ElineList:[], // Eline 业务集合
    CDPList:[], // CDP 业务集合
    // 服务器List
    serverList:[],
    SDNCServerList:[], topologyNodeList:[], // 拓扑节点集合
    othersList:[],
    // 权限List
    authorityList : {},
    passDev: {},
	  token : null,
    // 请求协议、IP、端口号、项目路径
    protocal: '',
    ip:'',
    port:'',
    project:'',
    // 传统模式 / SDN模式
    traditionPattern:'',
    // 存储点击设备
    clickDevice:'',

  },
  mutations: {
    // 设置告警等级配置
    setAlarmLevelConfig:function (state, data) {
      this.state.alarmLevelConfig = data;
    },
    // 设置系统模式
    setSystemMode: function (state, data) {
      this.state.systemMode = data;
    },
    // 添加tabs
    add_tabs (state, data) {
      this.state.openTab.push(data)
    },
    // 删除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)
    },
    // 设置tabs
    set_tabs (state,data) {
      this.state.openTab = data
    },
    // 添加tabs
    add_keepAliveRouter (state, data) {
      this.state.keepAliveRouter.push(data)
    },
    // 删除tabs
    delete_keepAliveRouter (state, route) {
      let index = 0;
      for (let option of state.keepAliveRouter) {
        if (option === route) {
          break
        }
        index++
      }
      this.state.keepAliveRouter.splice(index, 1)
    },
    // 设置tabs
    set_keepAliveRouter (state,data) {
      this.state.keepAliveRouter = data
    },
    // 设置当前激活的tab
    set_active_index (state, index) {
      this.state.activeIndex = index
    },
    // 设置设备列表的值
    setDeviceList (state, data) {
      this.state.deviceList = data
    },
    // 设置告警列表的值
    setAlarmNoticeList (state) {
      this.state.alarmNoticeList.splice(0,this.state.alarmNoticeList.length)
    },
    // 获取设备列表的值
    getDeviceList (state, data) {
      this.state.deviceList.push(data)
    },
    // 获取告警列表的值
    getAlarmNoticeList (state, data) {
      this.state.alarmNoticeList.push(data)
    },
    // 获取告警列表的值
    setAlarmList (state, data) {
      this.state.alarmList = data
    },
    // 获取告警列表的值
    setUnConfirmAlarmList (state, data) {
      this.state.unConfirmAlarmList = data
    },
    setPassDev (state, data) {
      this.state.passDev = data
    },
    getPassDev (state, data) {
      this.state.passDev.push(data)
    },
    // 获取告警列表的值
    setConfirmAlarmList (state, data) {
      this.state.confirmAlarmList = data
    },
    // 获取告警列表的值
    setClearAlarmList (state, data) {
      this.state.clearAlarmList = data
    },
    // 获取配置差异表的值
    setConfigDifferencesList (state, data) {
      this.state.configDifferencesList = data
    },
    // 获取链路集合的值
    setLinkList (state, data) {
      this.state.linkList = data
    },
    // 设置设备列表的值
    setSubnetList (state, data) {
      this.state.subnetList = data
    },
    // 设置选中设备的图
    setSelectObject (state, data) {
      this.state.selectObject = data
    },
    // 设置拓扑集合中的值
    setTopologyNodeList (state, data) {
      this.state.topologyNodeList = data
    },
    // 设置ElineList
    setElineList(state,data){
      this.state.ElineList = data
    },
    // 设置 CDPList
    setCDPList(state,data){
      this.state.CDPList = data
    },
    // 设置 serverList
    setServerList(state,data){
      this.state.serverList = data
    },
    // 设置 SDNCServerList
    setSDNCServerList(state,data){
      this.state.SDNCServerList = data
    },
    // 设置 OthersServerList
    setOthersServerList(state,data){
      this.state.othersServerList = data
    },
    // 设置 AuthorityList
    setAuthorityList(state,data){
      this.state.authorityList = data
    },
    // 设置 token
    setToken(state,data){
      this.state.token = data
    },
    // 设置 traditionPattern
    setTraditionPattern(state,data){
      this.state.traditionPattern = data
    },
    // 设置 clickDevice
    setClickDevice(state,data){
      this.state.clickDevice = data
    },
  },
  actions: {

  }
})
