退出登录

This commit is contained in:
李志鹏
2026-05-22 13:53:07 +08:00
parent ecf53c8353
commit 49cec0ee28
3 changed files with 35 additions and 16 deletions

View File

@@ -1,8 +1,10 @@
// 每一个存储的模块命名规则use开头store结尾
import { AccountLogout } from '@/api/account'
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { removeLocal, setLocal } from '@/utils/local'
import MyEvent from '@/utils/myEvent'
import router from '@/router'
export const useUserInfoStore = defineStore('userInfo', () => {
const state = ref({
userInfo: {
@@ -26,20 +28,21 @@ export const useUserInfoStore = defineStore('userInfo', () => {
setLocal(data, 'token')
}
const logout = () => {
const logout = async (reload: boolean = false) => {
// 处理退出登录的一些逻辑
return new Promise((resolve) => {
state.value.userInfo = {
userId: "",
email: "",
username: "",
accessToken: "",
expiresIn: "",
}
state.value.token = ''
removeLocal('token')
resolve('')
})
const userId = state.value.userInfo.userId
if (userId) await AccountLogout({ userId })
state.value.userInfo = {
userId: "",
email: "",
username: "",
accessToken: "",
expiresIn: "",
}
state.value.token = ''
removeLocal('token')
if (reload) router.go(0)
}
return {