退出登录
This commit is contained in:
@@ -120,3 +120,17 @@ export const AccountBindEmail = (data) => {
|
||||
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结尾
|
||||
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,9 +28,10 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
||||
setLocal(data, 'token')
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
const logout = async (reload: boolean = false) => {
|
||||
// 处理退出登录的一些逻辑
|
||||
return new Promise((resolve) => {
|
||||
const userId = state.value.userInfo.userId
|
||||
if (userId) await AccountLogout({ userId })
|
||||
state.value.userInfo = {
|
||||
userId: "",
|
||||
email: "",
|
||||
@@ -38,8 +41,8 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
||||
}
|
||||
state.value.token = ''
|
||||
removeLocal('token')
|
||||
resolve('')
|
||||
})
|
||||
if (reload) router.go(0)
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
:key="v.path"
|
||||
class="nav-item"
|
||||
: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)"
|
||||
>
|
||||
@@ -141,8 +144,7 @@
|
||||
hideProfilePopover()
|
||||
ElMessageBox.confirm('Are you sure to log off?')
|
||||
.then(() => {
|
||||
userInfoStore.logout()
|
||||
router.go(0)
|
||||
userInfoStore.logout(true)
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user