优化 Header 组件
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
<header class="header-container" :class="{ 'hide-shadow': hideShadow }"
|
<header class="header-container" :class="{ 'hide-shadow': hideShadow }"
|
||||||
:style="{ height, zIndex, lineHeight: height }">
|
:style="{ height, zIndex, lineHeight: height }">
|
||||||
<div class="opts left-opts" v-if="$slots['left-opts'] || title || $slots.title">
|
<div class="opts left-opts" v-if="$slots['left-opts'] || title || $slots.title">
|
||||||
<a-button v-if="showHome" class="header-btn" @click="backToHome">首页</a-button>
|
<a-button v-if="showBack" @click="back">返回</a-button>
|
||||||
<a-button v-if="showBack" class="header-btn" @click="back">返回</a-button>
|
<a-button v-if="showHome" @click="backToHome">首页</a-button>
|
||||||
<slot name="left-opts" />
|
<slot name="left-opts" />
|
||||||
</div>
|
</div>
|
||||||
<div class="title" v-if="title || $slots.title">
|
<div class="title" v-if="title || $slots.title">
|
||||||
@@ -13,6 +13,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="opts right-opts" v-if="$slots['right-opts'] || title || $slots.title">
|
<div class="opts right-opts" v-if="$slots['right-opts'] || title || $slots.title">
|
||||||
<slot name="right-opts" />
|
<slot name="right-opts" />
|
||||||
|
<a-button @click="handleLogout" type="primary" danger
|
||||||
|
v-if="showLogout && username">退出:{{ username }}</a-button>
|
||||||
</div>
|
</div>
|
||||||
<slot />
|
<slot />
|
||||||
</header>
|
</header>
|
||||||
@@ -20,6 +22,9 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import { Modal } from 'ant-design-vue';
|
||||||
|
import { useAuthStore, useUserStore } from '@/store';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
showHome: {
|
showHome: {
|
||||||
@@ -30,6 +35,10 @@ defineProps({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
showLogout: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
@@ -51,6 +60,22 @@ defineProps({
|
|||||||
const emit = defineEmits(['back']);
|
const emit = defineEmits(['back']);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const { username } = storeToRefs(userStore);
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
const handleLogout = () => {
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示',
|
||||||
|
content: `是否确认退出登录:${ username.value }`,
|
||||||
|
okText: '确定',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk: () => {
|
||||||
|
authStore.logout();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const back = () => {
|
const back = () => {
|
||||||
emit('back');
|
emit('back');
|
||||||
defaultBack();
|
defaultBack();
|
||||||
@@ -61,7 +86,7 @@ const defaultBack = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const backToHome = () => {
|
const backToHome = () => {
|
||||||
router.push({ name: 'ipc' });
|
router.push({ name: 'Index' });
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -72,7 +97,8 @@ const backToHome = () => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
background-color: #fff;
|
background-color: #1f2e54;
|
||||||
|
color: #fff;
|
||||||
box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px -1px, rgba(0, 0, 0, 0.06) 0px 2px 4px -1px;
|
box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px -1px, rgba(0, 0, 0, 0.06) 0px 2px 4px -1px;
|
||||||
|
|
||||||
&.hide-shadow {
|
&.hide-shadow {
|
||||||
@@ -81,6 +107,7 @@ const backToHome = () => {
|
|||||||
|
|
||||||
.title {
|
.title {
|
||||||
flex: 14;
|
flex: 14;
|
||||||
|
color: #fff;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -105,12 +132,5 @@ const backToHome = () => {
|
|||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.header-btn.ant-btn) {
|
|
||||||
height: 80%;
|
|
||||||
text-align: center;
|
|
||||||
font-size: clamp(14px, 1vw, 18px);
|
|
||||||
padding: 0 0.75rem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user