<template>
|
<div class="navbar">
|
<div class="sys-name-wrapper">
|
<div class="logo"><img :src="logUrl" alt=""></div>
|
<div class="sys-name">{{ title }}</div>
|
</div>
|
<div class="right-menu">
|
<el-dropdown
|
class="avatar-container right-menu-item hover-effect"
|
trigger="click"
|
>
|
<div class="avatar-wrapper">
|
<svg-icon icon-class="peoples"></svg-icon>
|
<span class="user-name">{{ uname }}</span>
|
<el-icon class="el-icon-caret-bottom" size="small">
|
<CaretBottom />
|
</el-icon>
|
</div>
|
<template #dropdown>
|
<el-dropdown-menu>
|
<router-link to="/">
|
<el-dropdown-item @click="pwdVisible = true">修改密码</el-dropdown-item>
|
</router-link>
|
<el-dropdown-item @click="logout">
|
<span style="display: block">退出登录</span>
|
</el-dropdown-item>
|
</el-dropdown-menu>
|
</template>
|
</el-dropdown>
|
</div>
|
<!-- 密码修改 -->
|
<el-dialog
|
title="密码修改"
|
width="400px"
|
v-model="pwdVisible"
|
:close-on-click-modal="false"
|
top="0"
|
class="dialog-center"
|
:modal-append-to-body="false"
|
>
|
<pwd-change v-if="pwdVisible" @success="pwdVisible = false"></pwd-change>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup name="Navbar">
|
import { computed, ref, reactive, watchEffect, onMounted } from "vue";
|
import { useRoute, useRouter } from "vue-router";
|
import { CaretBottom } from "@element-plus/icons-vue";
|
import SvgIcon from "@/components/SvgIcon/index.vue";
|
import useWebSocket from "@/hooks/useWebSocket";
|
import useElement from "@/hooks/useElement.js";
|
import { changeControlMode } from '@/api/system.js';
|
import { useUserStore } from '@/store/user';
|
import { useAppStore } from '@/store/app';
|
import { storeToRefs } from 'pinia';
|
import { updatePassword } from '@/api/user.js';
|
import PwdChange from '@/components/PwdChange.vue';
|
import defaultSettings from '@/settings.js';
|
import gjdw from '@/assets/images/gjdw-log.png';
|
const userStore = useUserStore();
|
const appStore = useAppStore();
|
const { sidebar, device } = storeToRefs(appStore);
|
const { avatar, uname } = storeToRefs(userStore);
|
|
const { updateSessionId, logout: _logout, getInfo } = userStore;
|
const { toggleSidebar: _toggleSidebar } = appStore;
|
|
|
const { message } = useWebSocket("loginCheck");
|
|
const { $alert, $loading, $message, $confirm } = useElement();
|
|
const logUrl = ref(gjdw);
|
|
const pwdVisible = ref(false);
|
|
const router = useRouter();
|
const route = useRoute();
|
const ctrlModel = ref(0);
|
|
const title = ref(defaultSettings.title);
|
|
|
watchEffect(() => {
|
if (message.value) {
|
const {
|
code,
|
data: {
|
checkLogin: {
|
data,
|
msg
|
},
|
},
|
} = JSON.parse(message.value);
|
if (!data) {
|
$message(msg);
|
logout();
|
// updateSessionId('');
|
// localStorage.removeItem("uname");
|
// localStorage.removeItem("uid");
|
// setTimeout(() => {
|
// $router.push("/login");
|
// location.reload();
|
// }, 2000);
|
}
|
}
|
|
});
|
|
|
function changeModel() {
|
let value = !ctrlModel.value * 1;
|
let loading = $loading();
|
changeControlMode(value).then((res) => {
|
let { code, data } = res;
|
loading.close();
|
if (code && data) {
|
$message.success("操作成功");
|
} else {
|
$message.error("操作失败");
|
}
|
})
|
.catch((err) => {
|
loading.close();
|
$message.error("操作失败");
|
console.log(err);
|
});
|
|
}
|
|
function toggleSidebar() {
|
_toggleSidebar();
|
}
|
async function logout() {
|
await _logout();
|
// console.log('logout', '=============');
|
|
router.push(`/login?redirect=${route.fullPath}`);
|
}
|
|
onMounted(() => {
|
});
|
</script>
|
|
<style lang="less" scoped>
|
.navbar {
|
position: relative;
|
height: 128px;
|
overflow: hidden;
|
position: relative;
|
background: #fff;
|
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
|
margin-bottom: -18px;
|
background:
|
url("@/assets/images/bg-title.png") center center e('/') 100% 100% no-repeat;
|
// border-image: url("@/assets/images/site-title-bg2.png") 64 0 780 0 / 64px 0 788px 0;
|
.sys-name-wrapper {
|
display: inline-flex;
|
align-items: center;
|
position: absolute;
|
left: 50%;
|
top: 0;
|
transform: translate(-50%, 0%);
|
line-height: 64px;
|
color: var(--light-color);
|
font-size: 1.5rem;
|
.logo {
|
position: relative;
|
width: 5.5rem;
|
height: 2.5rem;
|
margin-right: 14px;
|
img {
|
width: 100%;
|
height: 100%;
|
object-fit: contain;
|
}
|
&::after {
|
position: absolute;
|
content: '';
|
top: 50%;
|
right: -8px;
|
width: 2px;
|
height: 80%;
|
transform: translateY(-50%);
|
background: #0ff;
|
}
|
}
|
|
.sys-icon {
|
display: inline-block;
|
font-weight: 700;
|
margin-left: 16px;
|
margin-right: 8px;
|
}
|
|
.sys-name {
|
font-weight: 700;
|
display: inline-block;
|
}
|
}
|
|
.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;
|
}
|
|
.errLog-container {
|
display: inline-block;
|
vertical-align: top;
|
}
|
|
.right-menu {
|
float: right;
|
height: 100%;
|
line-height: 64px;
|
padding-left: 40px;
|
background: linear-gradient(to right, transparent 0, rgba(7,20,38, .6) 20px, #071426 40px, #071426);
|
|
.user-name {
|
margin-left: 0.6em;
|
}
|
|
&:focus {
|
outline: none;
|
}
|
|
.right-menu-item {
|
display: inline-block;
|
padding: 0 8px;
|
height: 100%;
|
line-height: 64px;
|
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: 30px;
|
|
.avatar-wrapper {
|
margin-top: 10px;
|
position: relative;
|
height: 45px;
|
display: flex;
|
align-items: center;
|
color: #fff;
|
|
.user-avatar {
|
cursor: pointer;
|
width: 40px;
|
height: 40px;
|
border-radius: 10px;
|
margin-right: 10px;
|
}
|
|
.el-icon-caret-bottom {
|
cursor: pointer;
|
position: absolute;
|
right: -20px;
|
// top: 25px;
|
font-size: 12px;
|
}
|
}
|
}
|
}
|
|
.flex-inline {
|
display: inline-flex;
|
line-height: normal;
|
align-items: center;
|
height: 100%;
|
margin-right: 2em;
|
float: left;
|
|
.label {
|
&::after {
|
content: ':';
|
}
|
|
}
|
|
.value {
|
margin-left: 0.4em;
|
}
|
|
.btn {
|
margin-left: 2em;
|
background: #0ff;
|
padding: 6px;
|
border-radius: 6px;
|
color: #000;
|
cursor: pointer;
|
font-size: 14px;
|
}
|
}
|
}
|
</style>
|