增加店务前端退出登录入口
This commit is contained in:
@@ -18,6 +18,12 @@
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="card logout-section section">
|
||||
<button class="logout-btn" type="button" :disabled="logoutLoading" @click="logout">
|
||||
{{ logoutLoading ? '退出中...' : '退出登录' }}
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<BaseModal v-model="editModalVisible" title="个人信息" :close-disabled="profileSaving || avatarUploading">
|
||||
<div class="profile-avatar-row">
|
||||
<img v-if="profileForm.avatar" class="profile-avatar profile-avatar--image" :src="profileForm.avatar" alt="头像" />
|
||||
@@ -75,6 +81,7 @@ import { useRouter } from 'vue-router'
|
||||
import { ChevronRight } from 'lucide-vue-next'
|
||||
import BaseModal from '@/components/BaseModal.vue'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { fileApi } from '@/api/file'
|
||||
import { userApi } from '@/api/user'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
@@ -93,6 +100,7 @@ const toast = useToastStore()
|
||||
const editModalVisible = ref(false)
|
||||
const profileSaving = ref(false)
|
||||
const avatarUploading = ref(false)
|
||||
const logoutLoading = ref(false)
|
||||
const userInfo = ref<UserInfo | null>(session.userInfo)
|
||||
const profileForm = reactive({
|
||||
nickname: '',
|
||||
@@ -169,6 +177,24 @@ const go = async (item: ProfileMenu): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
const logout = async (): Promise<void> => {
|
||||
if (logoutLoading.value) {
|
||||
return
|
||||
}
|
||||
logoutLoading.value = true
|
||||
try {
|
||||
await authApi.logout()
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : '服务端退出失败,已清除本地登录状态'
|
||||
if (!toast.visible || toast.message !== message) {
|
||||
toast.error(message)
|
||||
}
|
||||
} finally {
|
||||
session.clear()
|
||||
await router.replace('/login')
|
||||
}
|
||||
}
|
||||
|
||||
const uploadAvatar = async (event: Event): Promise<void> => {
|
||||
const target = event.target as HTMLInputElement
|
||||
const file = target.files?.[0]
|
||||
@@ -292,6 +318,22 @@ onMounted(loadProfile)
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.logout-section {
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
width: 100%;
|
||||
min-height: 54px;
|
||||
color: #c4483c;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.logout-btn:disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.profile-avatar-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user