import { defineStore } from "pinia";
import { store } from "@/store";
import {
  getUserInfoApi,
} from "../../apis/myAccount";
export const userInfoModules = defineStore("userInfoState", () => {
  // state
  // const userInfo = ref(null)
  const userInfo = ref({})

  // 登录获取用户信息
  async function getUserInfo() {
    const res = await getUserInfoApi()
    userInfo.value = res.data
    localStorage.setItem("AccountInfo", JSON.stringify(res.data));
  }
  // 退出清除用户信息
  function loginOut(params) {
    userInfo.value = {
      avatarUrl: null
    }
    localStorage.removeItem("AccountInfo");
  }
  return { userInfo, getUserInfo, loginOut };
},
  {
    persist: true
  });