jiangchengfeiyi-Web/src/layout/components/Header.vue

81 lines
2.4 KiB
Vue
Raw Normal View History

2024-10-23 09:55:22 +00:00
<template>
2024-10-29 02:51:27 +00:00
<div style=" height: 70px; width: 1248px; display: flex;
2024-10-23 09:55:22 +00:00
justify-content: space-between; align-items: center;">
2024-10-29 02:51:27 +00:00
<div style=" display: flex; justify-content: center;
2024-10-23 09:55:22 +00:00
align-items: center; margin-left: 10px">
2024-10-29 02:51:27 +00:00
<el-icon @click="changeState" v-show="showLog" size="20px" style="margin-right: 10px">
<Expand />
</el-icon>
<el-icon @click="changeState" v-show="!showLog" size="20px" style="margin-right: 10px">
<Fold />
</el-icon>
<el-breadcrumb separator="/">
<a-breadcrumb-item>{{ route.name }}</a-breadcrumb-item>
</el-breadcrumb>
</div>
<div :style="{ display: 'flex', justifyContent: 'center', alignItems: 'center', marginRight: offset + 'px' }">
<el-avatar style="margin-right: 10px">
2024-10-29 09:59:16 +00:00
<img :src="userInfo.userAvatar" alt="">
2024-10-29 02:51:27 +00:00
</el-avatar>
<el-dropdown style="cursor: pointer;" size="default">
<span class="el-dropdown-link" style="font-size: 16px; font-weight: bold;">
2024-10-29 09:59:16 +00:00
<span>{{ userInfo.userName }}</span><el-icon class="el-icon--right"><arrow-down /></el-icon>
2024-10-29 02:51:27 +00:00
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="$router.push('/PersonalCenter')">个人信息</el-dropdown-item>
<el-dropdown-item @click="logout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
2024-10-23 09:55:22 +00:00
</template>
<script setup lang="ts">
2024-10-29 09:59:16 +00:00
import { onMounted, ref } from 'vue'
2024-10-29 02:51:27 +00:00
import emitter from '@/utils/emitter'
import { useRoute, useRouter } from "vue-router";
import myAxios from '@/api/myAxios';
import { userStore } from '@/store/userStore';
import { ElMessage } from 'element-plus';
const router = useRouter();
const route = useRoute();
const offset = ref(20)
const showLog = ref(false)
const store = userStore()
2024-10-29 09:59:16 +00:00
const userInfo = store.loginUser
2024-10-29 02:51:27 +00:00
const logout = async () => {
const res: any = await myAxios.post("/user/logout", {})
if (res.data.code == 1 && res.data) {
store.$reset()
await router.replace('/')
ElMessage({
type: 'info',
message: '登出成功',
})
2024-10-23 09:55:22 +00:00
}
2024-10-29 02:51:27 +00:00
}
const changeState = () => {
showLog.value = !showLog.value
emitter.emit('Aside', showLog.value)
if (showLog.value) {
offset.value = -116
} else {
offset.value = 20
2024-10-23 09:55:22 +00:00
}
2024-10-29 02:51:27 +00:00
}
2024-10-23 09:55:22 +00:00
</script>
<style scoped>
2024-10-29 02:51:27 +00:00
:deep(.el-tooltip__trigger:focus-visible) {
outline: unset;
}
2024-10-23 09:55:22 +00:00
</style>