import Vue from "vue";
import Vuex from "vuex";
// import api from "@/common/api.js";
import method from "@/common/tool";
Vue.use(Vuex);
import { getInfo } from "@/utils/login";
const store = new Vuex.Store({
  state: {
    userInfo: null,
  },
  getters: {
    userInfo: (state) => {
      return state.userInfo;
    },
  },
  mutations: {
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo;
    },
    EXIT: (state) => {
      uni.removeStorageSync("user_account");
      uni.removeStorageSync("token");
      state.userInfo = null;
    },
    LOGIN_CB: (state, data) => {
      uni.setStorageSync("user_account", data.user_account);
      uni.setStorageSync("token", data.token);
    },
  },
  actions: {
    getUserInfo({ commit }, data) {
      return new Promise(async (resolve) => {
        const res = await getInfo(data);
        commit("SET_USERINFO", res);
        resolve();
      });
    },
  },
});
export default store;
