123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <template>
- <div class="navbar">
- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
- <breadcrumb class="breadcrumb-container" v-if="showBreadcrumb" />
- <!-- <NavMenu class="navmenu" /> -->
- <div class="right-menu">
- <div class="right-menu-item hover-effect">
- <el-tooltip effect="dark" content="工程机登录" placement="bottom">
- <a class="el-icon-s-platform" style="font-size: 24px; line-height: 50px;" href="https://mpkf.weixin.qq.com/" target="_blank"></a>
- </el-tooltip>
- </div>
- <el-badge :value="noticeCount" :max="10" :hidden="!noticeVisible" class="right-menu-item hover-effect">
- <el-tooltip effect="dark" content="系统消息" placement="bottom">
- <i class="el-icon-message-solid" @click="goNotice" style="font-size: 24px; line-height: 50px;"></i>
- </el-tooltip>
- <!-- <el-button icon="el-icon-message-solid" type="text" class="notice-icon" @click="goNotice"></el-button> -->
- </el-badge>
- <template v-if="device!=='mobile'">
- <screenfull id="screenfull" class="right-menu-item hover-effect" />
- </template>
- <el-dropdown class="user-container" trigger="click">
- <div class="user right-menu-item hover-effect">
- <i class="el-icon-user-solid"></i>
- <span>{{name}}</span>
- </div>
- <el-dropdown-menu slot="dropdown" class="user-dropdown">
- <router-link to="/setting/personal">
- <el-dropdown-item>个人信息</el-dropdown-item>
- </router-link>
- <el-dropdown-item divided @click.native="logout">
- <span style="display:block;">退出登录</span>
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </div>
- </div>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- import Breadcrumb from '@/components/Breadcrumb'
- import Hamburger from '@/components/Hamburger'
- import Screenfull from '@/components/Screenfull'
- import NavMenu from '@/components/NavMenu'
- import {getNoticeListCount} from "@/api/notice";
- export default {
- data() {
- return {
- timer: '',
- noticeCount: 0
- }
- },
- mounted() {
- const that = this
- // 开定时器轮询未读消息接口(写在全局vuex里比较好)
- that.initNotice()
- this.timer = setInterval(function () {
- that.initNotice()
- }, 3000)
- },
- beforeDestroy() {
- window.clearInterval(this.timer)
- console.log('退出清理定时器' + this.timer)
- },
- components: {
- Breadcrumb,
- Hamburger,
- Screenfull,
- NavMenu
- },
- computed: {
- showBreadcrumb() {
- return this.$store.state.settings.breadcrumb
- },
- noticeVisible() {
- return this.noticeCount > 0
- },
- ...mapGetters([
- 'sidebar',
- 'avatar',
- 'device',
- 'name'
- ])
- },
- methods: {
- toggleSideBar() {
- this.$store.dispatch('app/toggleSideBar')
- },
- async logout() {
- await this.$store.dispatch('user/logout')
- // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
- this.$router.push(`/login`)
- },
- initNotice() {
- getNoticeListCount().then(res => {
- if (res.data > 0 && this.noticeCount !== res.data) {
- this.noticeCount = res.data
- } else if (res.data === 0 && this.noticeCount !== res.data) {
- this.noticeCount = 0
- }
- })
- },
- goNotice() {
- this.$router.push('/notice/index')
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "~@/styles/variables.scss";
- .navbar {
- width: 100%;
- height: 50px;
- overflow: hidden;
- background: #{$navbarBg};
- box-shadow: 0 1px 4px rgba(0,21,41,.08);
- .hamburger-container {
- line-height: 46px;
- height: 100%;
- color: #{$navbarText};
- float: left;
- cursor: pointer;
- transition: background .3s;
- -webkit-tap-highlight-color:transparent;
- border-right: 1px solid #eaeaea;
- &:hover {
- background: rgba(0, 0, 0, .025)
- }
- }
- .navmenu {
- float: left;
- }
- .breadcrumb-container {
- float: left;
- }
- .right-menu {
- float: right;
- height: 100%;
- line-height: 50px;
- &>div {
- float: left;
- }
- &:focus {
- outline: none;
- }
- .user-container {
- height: 50px;
- .user {
- i {
- font-size: 18px;
- margin-right: 5px;
- }
- span {
- font-size: 16px;
- }
- }
- }
- .right-menu-item {
- display: inline-block;
- padding: 0 15px;
- height: 100%;
- font-size: 18px;
- color: #{$navbarText};
- vertical-align: text-bottom;
- border-left: 1px solid #eaeaea;
- &.hover-effect {
- cursor: pointer;
- transition: background .3s;
- &:hover {
- background: rgba(0, 0, 0, .025)
- }
- }
- .notice-icon {
- padding-top: 0;
- padding-bottom: 0;
- }
- }
- }
- }
- </style>
- <style lang="scss">
- .navbar {
- .right-menu {
- .right-menu-item {
- .notice-icon>i {
- font-size: 18px;
- }
- sup {
- top: 12px;
- right: 25px;
- }
- }
- }
- }
- </style>
|