登录
This commit is contained in:
@@ -4,6 +4,7 @@ import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { removeLocal, setLocal } from '@/utils/local'
|
||||
import MyEvent from '@/utils/myEvent'
|
||||
import { Logout, GetUserInfo } from '@/api/login'
|
||||
export const useUserInfoStore = defineStore('userInfo', () => {
|
||||
const state = ref({
|
||||
userInfo: {},
|
||||
@@ -11,8 +12,14 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
||||
|
||||
})
|
||||
|
||||
// getters
|
||||
const getUserInfo = computed(() => state.value.userInfo)
|
||||
const getUserInfo = async () => {
|
||||
const res = await GetUserInfo()
|
||||
if (res) {
|
||||
state.value.userInfo = { ...res }
|
||||
} else {
|
||||
state.value.userInfo = {}
|
||||
}
|
||||
}
|
||||
|
||||
// actions
|
||||
const setUserInfo = (data: any) => {
|
||||
@@ -24,8 +31,9 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
||||
// setLocal(data, 'token')
|
||||
}
|
||||
|
||||
const logOut = async () => {
|
||||
const logOut = async (isApi: boolean = true) => {
|
||||
// 处理退出登录的一些逻辑
|
||||
if (isApi) await Logout()
|
||||
state.value.token = ''
|
||||
state.value.userInfo = {}
|
||||
// removeLocal('token')
|
||||
|
||||
Reference in New Issue
Block a user