import { Session } from '@/utils/storage.js';
import SystemConfig from '@/utils/SystemConfig'


const userInfosModule = {
  namespaced: true,
  state: {
    userInfos: {},
    authoritys: null,
  },
  mutations: {
    // 设置用户信息
    getUserInfos(state, data) {
      state.userInfos = data;
    },
  },
  getters: {
    authoritys: state => {
      if (!state.authoritys) {
        try {
          state.authoritys = Session.get(SystemConfig.adminAccess);
        } catch (e) {
          console.error(e)
        }
      }
      return state.authoritys
    },
  },
  actions: {
    // 设置用户信息
    async setUserInfos({ commit }, data) {
      if (data) {
        commit('getUserInfos', data);
      } else {
        const users = Session.get(SystemConfig.adminUser);
        if (users) commit('getUserInfos', users);
      }
    },
  },
};

export default userInfosModule;