262 lines
6.5 KiB
Vue
262 lines
6.5 KiB
Vue
![]() |
<template>
|
||
|
<div class="navbar">
|
||
|
<hamburger id="hamburger-container" :is-active="appStore.sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
|
||
|
<breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!settingsStore.topNav" />
|
||
|
<top-nav id="topmenu-container" class="topmenu-container" v-if="settingsStore.topNav" />
|
||
|
|
||
|
<div class="right-menu flex align-center">
|
||
|
<template v-if="appStore.device !== 'mobile'">
|
||
|
<el-select v-model="companyName"
|
||
|
clearable
|
||
|
filterable
|
||
|
reserve-keyword
|
||
|
placeholder="请选择租户"
|
||
|
v-if="userId === 1"
|
||
|
@change="dynamicTenantEvent"
|
||
|
@clear="dynamicClearEvent">
|
||
|
<el-option
|
||
|
v-for="item in tenantList"
|
||
|
:key="item.tenantId"
|
||
|
:label="item.companyName"
|
||
|
:value="item.tenantId">
|
||
|
</el-option>
|
||
|
<template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
|
||
|
</el-select>
|
||
|
|
||
|
<header-search id="header-search" class="right-menu-item" />
|
||
|
|
||
|
<el-tooltip content="源码地址" effect="dark" placement="bottom">
|
||
|
<ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
|
||
|
</el-tooltip>
|
||
|
|
||
|
<el-tooltip content="文档地址" effect="dark" placement="bottom">
|
||
|
<ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
|
||
|
</el-tooltip>
|
||
|
|
||
|
<screenfull id="screenfull" class="right-menu-item hover-effect" />
|
||
|
|
||
|
<el-tooltip content="布局大小" effect="dark" placement="bottom">
|
||
|
<size-select id="size-select" class="right-menu-item hover-effect" />
|
||
|
</el-tooltip>
|
||
|
</template>
|
||
|
<div class="avatar-container">
|
||
|
<el-dropdown @command="handleCommand" class="right-menu-item hover-effect" trigger="click">
|
||
|
<div class="avatar-wrapper">
|
||
|
<img :src="userStore.avatar" class="user-avatar" />
|
||
|
<el-icon><caret-bottom /></el-icon>
|
||
|
</div>
|
||
|
<template #dropdown>
|
||
|
<el-dropdown-menu>
|
||
|
<router-link to="/user/profile" v-if="!dynamic">
|
||
|
<el-dropdown-item>个人中心</el-dropdown-item>
|
||
|
</router-link>
|
||
|
<el-dropdown-item command="setLayout">
|
||
|
<span>布局设置</span>
|
||
|
</el-dropdown-item>
|
||
|
<el-dropdown-item divided command="logout">
|
||
|
<span>退出登录</span>
|
||
|
</el-dropdown-item>
|
||
|
</el-dropdown-menu>
|
||
|
</template>
|
||
|
</el-dropdown>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script setup>
|
||
|
import { ElMessageBox } from 'element-plus'
|
||
|
import Breadcrumb from '@/components/Breadcrumb'
|
||
|
import TopNav from '@/components/TopNav'
|
||
|
import Hamburger from '@/components/Hamburger'
|
||
|
import Screenfull from '@/components/Screenfull'
|
||
|
import SizeSelect from '@/components/SizeSelect'
|
||
|
import HeaderSearch from '@/components/HeaderSearch'
|
||
|
import RuoYiGit from '@/components/RuoYi/Git'
|
||
|
import RuoYiDoc from '@/components/RuoYi/Doc'
|
||
|
import useAppStore from '@/store/modules/app'
|
||
|
import useUserStore from '@/store/modules/user'
|
||
|
import useSettingsStore from '@/store/modules/settings'
|
||
|
import { getTenantList } from "@/api/login";
|
||
|
import { dynamicClear, dynamicTenant } from "@/api/system/tenant";
|
||
|
|
||
|
const appStore = useAppStore()
|
||
|
const userStore = useUserStore()
|
||
|
const settingsStore = useSettingsStore()
|
||
|
|
||
|
const { proxy } = getCurrentInstance();
|
||
|
|
||
|
const userId = ref(userStore.userId);
|
||
|
const companyName = ref(undefined);
|
||
|
const tenantList = ref([]);
|
||
|
// 是否切换了租户
|
||
|
const dynamic = ref(false);
|
||
|
|
||
|
// 动态切换
|
||
|
function dynamicTenantEvent(tenantId) {
|
||
|
if (companyName.value != null && companyName.value !== '') {
|
||
|
dynamicTenant(tenantId).then(res => {
|
||
|
dynamic.value = true;
|
||
|
proxy.$tab.closeAllPage()
|
||
|
proxy.$router.push('/')
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function dynamicClearEvent() {
|
||
|
dynamicClear().then(res => {
|
||
|
dynamic.value = false;
|
||
|
proxy.$tab.closeAllPage()
|
||
|
proxy.$router.push('/')
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 租户列表
|
||
|
function initTenantList() {
|
||
|
getTenantList().then(res => {
|
||
|
tenantList.value = res.data;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
defineExpose({
|
||
|
initTenantList,
|
||
|
})
|
||
|
|
||
|
function toggleSideBar() {
|
||
|
appStore.toggleSideBar()
|
||
|
}
|
||
|
|
||
|
function handleCommand(command) {
|
||
|
switch (command) {
|
||
|
case "setLayout":
|
||
|
setLayout();
|
||
|
break;
|
||
|
case "logout":
|
||
|
logout();
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function logout() {
|
||
|
ElMessageBox.confirm('确定注销并退出系统吗?', '提示', {
|
||
|
confirmButtonText: '确定',
|
||
|
cancelButtonText: '取消',
|
||
|
type: 'warning'
|
||
|
}).then(() => {
|
||
|
userStore.logOut().then(() => {
|
||
|
location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
|
||
|
})
|
||
|
}).catch(() => { });
|
||
|
}
|
||
|
|
||
|
const emits = defineEmits(['setLayout'])
|
||
|
function setLayout() {
|
||
|
emits('setLayout');
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style lang='scss' scoped>
|
||
|
|
||
|
:deep .el-select .el-input__wrapper {
|
||
|
height:30px;
|
||
|
}
|
||
|
|
||
|
.flex {
|
||
|
display: flex;
|
||
|
}
|
||
|
|
||
|
.align-center {
|
||
|
align-items: center;
|
||
|
}
|
||
|
|
||
|
.navbar {
|
||
|
height: 50px;
|
||
|
overflow: hidden;
|
||
|
position: relative;
|
||
|
background: #fff;
|
||
|
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
|
||
|
|
||
|
.hamburger-container {
|
||
|
line-height: 46px;
|
||
|
height: 100%;
|
||
|
float: left;
|
||
|
cursor: pointer;
|
||
|
transition: background 0.3s;
|
||
|
-webkit-tap-highlight-color: transparent;
|
||
|
|
||
|
&:hover {
|
||
|
background: rgba(0, 0, 0, 0.025);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
.breadcrumb-container {
|
||
|
float: left;
|
||
|
}
|
||
|
|
||
|
.topmenu-container {
|
||
|
position: absolute;
|
||
|
left: 50px;
|
||
|
}
|
||
|
|
||
|
.errLog-container {
|
||
|
display: inline-block;
|
||
|
vertical-align: top;
|
||
|
}
|
||
|
|
||
|
.right-menu {
|
||
|
float: right;
|
||
|
height: 100%;
|
||
|
line-height: 50px;
|
||
|
display: flex;
|
||
|
|
||
|
&:focus {
|
||
|
outline: none;
|
||
|
}
|
||
|
|
||
|
.right-menu-item {
|
||
|
display: inline-block;
|
||
|
padding: 0 8px;
|
||
|
height: 100%;
|
||
|
font-size: 18px;
|
||
|
color: #5a5e66;
|
||
|
vertical-align: text-bottom;
|
||
|
|
||
|
&.hover-effect {
|
||
|
cursor: pointer;
|
||
|
transition: background 0.3s;
|
||
|
|
||
|
&:hover {
|
||
|
background: rgba(0, 0, 0, 0.025);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
.avatar-container {
|
||
|
margin-right: 40px;
|
||
|
|
||
|
.avatar-wrapper {
|
||
|
margin-top: 5px;
|
||
|
position: relative;
|
||
|
|
||
|
.user-avatar {
|
||
|
cursor: pointer;
|
||
|
width: 40px;
|
||
|
height: 40px;
|
||
|
border-radius: 10px;
|
||
|
}
|
||
|
|
||
|
i {
|
||
|
cursor: pointer;
|
||
|
position: absolute;
|
||
|
right: -20px;
|
||
|
top: 25px;
|
||
|
font-size: 12px;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</style>
|