/**
 * 用户基本信息
 */
import { setCache, getCache } from '@/utils/cache';
import { getUserInfo } from '../../api/user';

export default {
  state: () => ({
    user_info: getCache('user_info') || {},
  }),
  mutations: {
    SET_USER_INFO(state, data) {
      state.user_info = data;
      setCache('user_info', state.user_info);
    },
  },
  actions: {
    GetUserInfo({ commit }) {
      return new Promise((resolve, reject) => {
        getUserInfo()
          .then(res => {
            commit('SET_USER_INFO', res.data);
            resolve(res);
          })
          .catch(err => {
            reject(err);
          });
      });
    },
  },
};
