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

export default new Vuex.Store({
  state: {
    menus: [], // 菜单
    token: "",
    siteId: "", // 站点id
    deptList: [], // 部门列表
    sysName: "", // 系统名称
    sysLogo: "", // 系统logo
    path: "", // 门户跳转过来的路由
  },
  getters: {
    SET_path(state, path) {
      state.path = path;
    },
    token(state) {
      return state.token;
    },
    siteId(state) {
      return state.siteId;
    },
    deptList(state) {
      return state.deptList;
    },
    path(state) {
      return state.path;
    },
  },
  mutations: {
    SET_MENUS(state, menus) {
      state.menus = menus;
    },
    SET_SITEID(state, siteId) {
      state.siteId = siteId;
    },
    SET_deptList(state, deptList) {
      state.deptList = deptList;
    },
    SET_sysName(state, sysName) {
      state.sysName = sysName;
    },
    SET_sysLogo(state, sysLogo) {
      state.sysLogo = sysLogo;
    },
    SET_token(state, token) {
      state.token = token;
    },
  },
  actions: {},
  modules: {},
  // 持久化插件
  plugins: [
    // createPersistedState({
    //   storage: window.sessionStorage,
    // }),
    createPersistedState({
      key: "sample",
      storage: {
        getItem: (key) => SessionCrypto.getItem(key),
        setItem: (key, value) => SessionCrypto.setItem(key, value),
        removeItem: (key) => SessionCrypto.remove(key),
      },
    }),
  ],
});
