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: {
    devicenum: "", // 设备编号
    homeInfo: {}, // 首页数据
    datumList: [], // 首页材料
    matterList: [], // 首页事项
    deviceCode: "", // 设备编码
  },
  getters: {
    deviceCode(state) {
      return state.deviceCode;
    },
  },
  mutations: {
    SET_devicenum(state, devicenum) {
      state.devicenum = devicenum;
    },
    SET_homeInfo(state, homeInfo) {
      state.homeInfo = homeInfo;
    },
    SET_datumList(state, datumList) {
      state.datumList = datumList;
    },
    SET_matterList(state, matterList) {
      state.matterList = matterList;
    },
    SET_deviceCode(state, deviceCode) {
      state.deviceCode = deviceCode;
    },
  },
  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),
      },
    }),
  ],
});
