import {
  defineStore
} from 'pinia'
import {
  login
} from '@/api/user';
import {
  message
} from 'ant-design-vue';
import router from '@/router/index';
export const useStore = defineStore('user', () => {
  const userInfo = ref();
  const token = ref(null);


  const getUserInfo = async (param) => {
    // login(param).then(res => {
    //   if (res.code == '9000') {
    //     message.success('登录成功!');
    //     token.value = res.data;
    //     let strings = res.data.split("."); //截取token，获取载体
    //     userInfo.value = JSON.parse(decodeURIComponent(escape(window.atob(strings[1].replace(/-/g, "+").replace(/_/g, "/")))));
    //     router.push({
    //       name: 'homepage'
    //     });
    //   }
    // }).catch(err => {
    //   message.error(err.message);
    // })
  }
  const clearUserInfo = () => {
    userInfo.value = {};
    localStorage.removeItem('user');
  };


  return {
    userInfo,
    token
  }
}, {
  persist: true
})