import { defineStore } from "pinia";

import { constantRoute, errorRoute } from "@/router/routes";
import { SystemMenu } from "@/types/config/index";

export interface UserStore {
  userInfo: tokenInfo | undefined;
  menuRoutes: SystemMenu[];
  token:string
}

export const useUserStore = defineStore({
  id: "user-stores",
  state: (): UserStore => {
    return {
      userInfo: undefined,
      menuRoutes: constantRoute,
      token:''
    };
  },
  actions: {
    tokenList(token:string){
      this.token = token
    },
    setTokenInfo(user: tokenInfo) {
      // 保存userinfo
      this.userInfo = user;
    },
    // 清空用户信息（退出登录）
    deleteToken() {
      this.token = undefined
      this.userInfo = undefined;
    },
  },
  persist: {
    key: "user-stores",
    storage: window.localStorage,
    paths:["token"]
    // paths: ["userInfo"],
  },
});
