import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";
import SecureLS from "secure-ls";
var ls = new SecureLS({ isCompression: false });
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    menus: [], // 菜单
    siteId: "", // 站点id
    deptList: [], // 部门列表
  },
  getters: {
    siteId(state) {
      return state.siteId;
    },
    deptList(state) {
      return state.deptList;
    },
  },
  mutations: {
    SET_MENUS(state, menus) {
      state.menus = menus;
    },
    SET_SITEID(state, siteId) {
      state.siteId = siteId;
    },
    SET_deptList(state, deptList) {
      state.deptList = deptList;
    },
  },
  actions: {},
  modules: {},
  // 持久化插件
  plugins: [
    // createPersistedState({
    //   storage: window.sessionStorage,
    // }),
    createPersistedState({
      key: "info",
      storage: {
        getItem: (key) => ls.get(key),
        setItem: (key, value) => ls.set(key, value),
        removeItem: (key) => ls.remove(key),
      },
    }),
  ],
});
