This commit is contained in:
2026-02-26 16:55:25 +08:00
parent e741d50761
commit dfdf2400c1
17 changed files with 287 additions and 55 deletions

View File

@@ -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')