import { defineStore } from 'pinia';
import { TLogin, TRoleList } from "@/api/index.d";
import { roleList } from '@/api';

export const useCommonStore = defineStore('common', {
  state: () => {
    return {
      time: new Date(),
      user: <TLogin.IRes>{},
      roleList: <TRoleList[]>[]
    };
  },
  getters: {},
  actions: {
    setTime() {
      this.time = new Date();
    },
    getRoleList() {
      roleList().then(res => {
        this.roleList = res
      })
    },
    setUser(data: TLogin.IRes) {
      this.user = data
    },
    clearStore() {
      this.$reset();
    }
  },
  persist: true
});
