import { defineStore } from "pinia"
import { login } from '@/api/user'
import useStorage from '@/utils/useStorage'

export const useUser = defineStore({
  id: "user",
  state: () => ({
    userInfo: useStorage.get('userInfo'),
    token: useStorage.get('token'),
  }),
  actions: {
    // 登录
    userlogin(param) {
      return login(param).then(res => {
        this.userInfo = res
        this.token = res.token
        useStorage.set("token", this.token);
        useStorage.set("userInfo", this.userInfo);
        return this.userInfo;
      })
    }
  }
})
