退出登录
This commit is contained in:
@@ -120,3 +120,17 @@ export const AccountBindEmail = (data) => {
|
|||||||
loading: true
|
loading: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出登录
|
||||||
|
* @param data - 参数
|
||||||
|
* @param data.userId - 用户ID
|
||||||
|
*/
|
||||||
|
export const AccountLogout = (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/buyer/account/logout',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
loading: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
// 每一个存储的模块,命名规则use开头,store结尾
|
// 每一个存储的模块,命名规则use开头,store结尾
|
||||||
|
import { AccountLogout } from '@/api/account'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { removeLocal, setLocal } from '@/utils/local'
|
import { removeLocal, setLocal } from '@/utils/local'
|
||||||
import MyEvent from '@/utils/myEvent'
|
import MyEvent from '@/utils/myEvent'
|
||||||
|
import router from '@/router'
|
||||||
export const useUserInfoStore = defineStore('userInfo', () => {
|
export const useUserInfoStore = defineStore('userInfo', () => {
|
||||||
const state = ref({
|
const state = ref({
|
||||||
userInfo: {
|
userInfo: {
|
||||||
@@ -26,20 +28,21 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
|||||||
setLocal(data, 'token')
|
setLocal(data, 'token')
|
||||||
}
|
}
|
||||||
|
|
||||||
const logout = () => {
|
const logout = async (reload: boolean = false) => {
|
||||||
// 处理退出登录的一些逻辑
|
// 处理退出登录的一些逻辑
|
||||||
return new Promise((resolve) => {
|
const userId = state.value.userInfo.userId
|
||||||
state.value.userInfo = {
|
if (userId) await AccountLogout({ userId })
|
||||||
userId: "",
|
state.value.userInfo = {
|
||||||
email: "",
|
userId: "",
|
||||||
username: "",
|
email: "",
|
||||||
accessToken: "",
|
username: "",
|
||||||
expiresIn: "",
|
accessToken: "",
|
||||||
}
|
expiresIn: "",
|
||||||
state.value.token = ''
|
}
|
||||||
removeLocal('token')
|
state.value.token = ''
|
||||||
resolve('')
|
removeLocal('token')
|
||||||
})
|
if (reload) router.go(0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -9,7 +9,10 @@
|
|||||||
:key="v.path"
|
:key="v.path"
|
||||||
class="nav-item"
|
class="nav-item"
|
||||||
:class="{
|
:class="{
|
||||||
active: v.path === '/' ? activePath === v.path : new RegExp(`^${v.path}`).test(activePath)
|
active:
|
||||||
|
v.path === '/'
|
||||||
|
? activePath === v.path
|
||||||
|
: new RegExp(`^${v.path}`).test(activePath)
|
||||||
}"
|
}"
|
||||||
@click="onNavItemClick(v.path)"
|
@click="onNavItemClick(v.path)"
|
||||||
>
|
>
|
||||||
@@ -141,8 +144,7 @@
|
|||||||
hideProfilePopover()
|
hideProfilePopover()
|
||||||
ElMessageBox.confirm('Are you sure to log off?')
|
ElMessageBox.confirm('Are you sure to log off?')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
userInfoStore.logout()
|
userInfoStore.logout(true)
|
||||||
router.go(0)
|
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user