diff --git a/JY-Salon-Front/src/views/ProfileView.vue b/JY-Salon-Front/src/views/ProfileView.vue index 5dfec5fc..8c4f30af 100644 --- a/JY-Salon-Front/src/views/ProfileView.vue +++ b/JY-Salon-Front/src/views/ProfileView.vue @@ -18,6 +18,12 @@ +
+ +
+
头像 @@ -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(session.userInfo) const profileForm = reactive({ nickname: '', @@ -169,6 +177,24 @@ const go = async (item: ProfileMenu): Promise => { } } +const logout = async (): Promise => { + 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 => { 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;