用户模块:用户注销
This commit is contained in:
parent
09e8e444ca
commit
8d551ab0da
@ -20,7 +20,20 @@
|
||||
<a-col flex="120px">
|
||||
<div class="user-login-status">
|
||||
<div v-if="loginUserStore.loginUser.id">
|
||||
{{ loginUserStore.loginUser.userName ?? '无名' }}
|
||||
<a-dropdown>
|
||||
<ASpace>
|
||||
<a-avatar :src="loginUserStore.loginUser.userAvatar" />
|
||||
{{ loginUserStore.loginUser.userName ?? '无名' }}
|
||||
</ASpace>
|
||||
<template #overlay>
|
||||
<a-menu>
|
||||
<a-menu-item @click="doLogout">
|
||||
<LogoutOutlined />
|
||||
退出登录
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</template>
|
||||
</a-dropdown>
|
||||
</div>
|
||||
<div v-else>
|
||||
<a-button type="primary" href="/user/login">登录</a-button>
|
||||
@ -33,9 +46,11 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue'
|
||||
import { HomeOutlined } from '@ant-design/icons-vue'
|
||||
import { HomeOutlined, LogoutOutlined } from '@ant-design/icons-vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'
|
||||
import { userLogoutUsingPost } from '@/api/userController.ts'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const loginUserStore = useLoginUserStore()
|
||||
|
||||
@ -71,6 +86,21 @@ const doMenuClick = ({ key }: { key: string }) => {
|
||||
path: key,
|
||||
})
|
||||
}
|
||||
|
||||
// 用户注销
|
||||
const doLogout = async () => {
|
||||
const res = await userLogoutUsingPost()
|
||||
console.log(res)
|
||||
if (res.data.code === 200) {
|
||||
loginUserStore.setLoginUser({
|
||||
userName: '未登录',
|
||||
})
|
||||
message.success('退出登录成功')
|
||||
await router.push('/user/login')
|
||||
} else {
|
||||
message.error('退出登录失败,' + res.data.message)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
@ -48,7 +48,7 @@ const formState = reactive<API.UserLoginRequest>({
|
||||
const handleSubmit = async (values: any) => {
|
||||
const res = await userLoginUsingPost(values)
|
||||
// 登录成功,把登录态保存到全局状态中
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
if (res.data.code === 200 && res.data.data) {
|
||||
await loginUserStore.fetchLoginUser()
|
||||
message.success('登录成功')
|
||||
await router.push({
|
||||
|
@ -67,7 +67,7 @@ const handleSubmit = async (values: any) => {
|
||||
}
|
||||
const res = await userRegisterUsingPost(values)
|
||||
// 注册成功,跳转到登录页面
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
if (res.data.code === 200 && res.data.data) {
|
||||
message.success('注册成功')
|
||||
await router.push({
|
||||
path: '/user/login',
|
||||
|
@ -9,7 +9,7 @@ export const useLoginUserStore = defineStore('loginUser', () => {
|
||||
|
||||
async function fetchLoginUser() {
|
||||
const res = await getLoginUserUsingGet()
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
if (res.data.code === 200 && res.data.data) {
|
||||
loginUser.value = res.data.data
|
||||
}
|
||||
// // 测试用户登录,3 秒后自动登录
|
||||
|
Loading…
Reference in New Issue
Block a user