Files
YschcmsFront/src/components/WorkbenchHeader.vue
T

104 lines
2.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed } from "vue";
import { useRouter } from "vue-router";
import { useCmsStore } from "@/store";
import config from "@/assets/config/host.config";
/**
* 工作台同款深色顶栏(超管平台级页面共用):
* 标题 + 可选「返回」图标 + 头像/姓名(用户中心)+ 退出登录。
* 使用方:SchoolWorkbench(无返回)、ThemeManage(backTo=/workbench)。
*/
const props = defineProps<{
title: string;
/** 传入则渲染返回图标按钮(如返回工作台) */
backTo?: string;
}>();
const router = useRouter();
const store = useCmsStore();
const userInfo = computed(() => ({
name: store.session.baseUserName || "管理员",
avatar: store.session.baseUserAvatar,
}));
function goBack() {
if (props.backTo) {
router.push(props.backTo);
}
}
const linkUserInfo = () => {
window.location.href = config.baseHost + "/v/userinfo";
};
const logout = () => {
const url = "/logout?service=" + window.location.href;
window.location.href = config.ssoHost + url;
};
</script>
<template>
<header class="wb-header">
<h4>{{ title }}</h4>
<div class="wb-header-aside">
<a v-if="backTo" href="javascript:void(0);" class="back" title="返回工作台" @click="goBack">
<Icon type="ios-arrow-back" :size="20" />
</a>
<img :src="userInfo.avatar" v-if="userInfo.avatar" class="wb-avatar" @click="linkUserInfo" />
<a class="name" href="javascript:void(0);" @click="linkUserInfo">{{ userInfo.name }}</a>
<span class="delimiter"></span>
<a href="javascript:;" class="logout" @click="logout" title="退出登陆">
<i class="iconfont icon-logout"></i>
</a>
</div>
</header>
</template>
<style scoped lang="scss">
.wb-header {
height: 56px;
flex-shrink: 0;
background: #1f2a3a;
color: #fff;
display: flex;
align-items: center;
padding: 0 24px;
h4 {
color: #fff;
font-size: 16px;
margin: 0;
}
.wb-header-aside {
margin-left: auto;
display: flex;
align-items: center;
gap: 10px;
.name {
color: #fff;
}
.back {
color: #fff;
display: inline-flex;
align-items: center;
}
.delimiter {
width: 1px;
height: 16px;
background: rgba(255, 255, 255, 0.3);
display: inline-block;
}
.wb-avatar {
width: 28px;
height: 28px;
border-radius: 50%;
cursor: pointer;
}
.logout {
color: #fff;
display: inline-flex;
align-items: center;
}
}
}
</style>