Navbar.vue 6.91 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2
<template>
  <div class="navbar">
yaqizhang's avatar
yaqizhang committed
3
    
耿迪迪's avatar
耿迪迪 committed
4

yaqizhang's avatar
yaqizhang committed
5
    <el-row :gutter="20">
yaqizhang's avatar
yaqizhang committed
6
      <el-col :span="22">
yaqizhang's avatar
yaqizhang committed
7 8 9 10 11
        <div style="float: left;padding: 5px;">
          <img src="@/assets/logo/top-left-logo.png" alt="" style="margin-top: 15px;">
        </div>
    
          <!-- 点击左侧二级菜单滑开 -->
yaqizhang's avatar
yaqizhang committed
12
        <!-- <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
yaqizhang's avatar
yaqizhang committed
13 14 15 16 17 18 19
    
        <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav"/>
    
    
        <!-- 顶部导航 -->
        <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav"/>
      </el-col>
yaqizhang's avatar
yaqizhang committed
20
      <el-col :span="2" style="float: right;">
耿迪迪's avatar
耿迪迪 committed
21
    <div class="right-menu">
yaqizhang's avatar
yaqizhang committed
22
      <!-- <template v-if="device!=='mobile'">
耿迪迪's avatar
耿迪迪 committed
23 24
        <search id="header-search" class="right-menu-item" />

yaqizhang's avatar
yaqizhang committed
25
        <el-tooltip content="源码地址" effect="dark" placement="bottom">
耿迪迪's avatar
耿迪迪 committed
26 27 28 29 30
          <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" />
yaqizhang's avatar
yaqizhang committed
31
        </el-tooltip>
耿迪迪's avatar
耿迪迪 committed
32 33 34 35 36 37 38

        <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>

yaqizhang's avatar
yaqizhang committed
39 40
      </template> -->
      
yaqizhang's avatar
yaqizhang committed
41 42 43
          <div class="formatDate">
            <span>{{ nowDate }}</span>
          </div>
yaqizhang's avatar
yaqizhang committed
44
          <!-- <div class="yhm">{{showUserName}}</div> -->
yaqizhang's avatar
yaqizhang committed
45 46
        
      
耿迪迪's avatar
耿迪迪 committed
47 48
      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
        <div class="avatar-wrapper">
yaqizhang's avatar
yaqizhang committed
49 50 51
          <!-- <img :src="avatar" class="user-avatar">
          <i class="el-icon-caret-bottom" /> -->
          <div class="yhm">{{showUserName}}</div>
耿迪迪's avatar
耿迪迪 committed
52 53 54 55 56 57 58 59 60 61 62 63 64
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/user/profile">
            <el-dropdown-item>个人中心</el-dropdown-item>
          </router-link>
          <el-dropdown-item @click.native="setting = true">
            <span>布局设置</span>
          </el-dropdown-item>
          <el-dropdown-item divided @click.native="logout">
            <span>退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
yaqizhang's avatar
yaqizhang committed
65
  
耿迪迪's avatar
耿迪迪 committed
66
    </div>
yaqizhang's avatar
yaqizhang committed
67 68
  </el-col>
</el-row>
耿迪迪's avatar
耿迪迪 committed
69 70 71 72 73 74 75 76 77 78 79
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
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 Search from '@/components/HeaderSearch'
yaqizhang's avatar
yaqizhang committed
80
import Cookie from 'js-cookie'
耿迪迪's avatar
耿迪迪 committed
81 82 83 84 85 86 87 88 89
export default {
  components: {
    Breadcrumb,
    TopNav,
    Hamburger,
    Screenfull,
    SizeSelect,
    Search
  },
yaqizhang's avatar
yaqizhang committed
90 91 92 93 94
  data() {
    return {
      nowDate: "", // 当前日期
    };
  },
耿迪迪's avatar
耿迪迪 committed
95
  computed: {
yaqizhang's avatar
yaqizhang committed
96 97 98
    showUserName(){
      return Cookie.get('username')
    },
耿迪迪's avatar
耿迪迪 committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    ...mapGetters([
      'sidebar',
      'avatar',
      'device'
    ]),
    setting: {
      get() {
        return this.$store.state.settings.showSettings
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'showSettings',
          value: val
        })
      }
    },
    topNav: {
      get() {
        return this.$store.state.settings.topNav
      }
    }
yaqizhang's avatar
yaqizhang committed
120
    
耿迪迪's avatar
耿迪迪 committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      this.$confirm('确定注销并退出系统吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.href = '/index';
        })
      }).catch(() => {});
yaqizhang's avatar
yaqizhang committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    },
    currentTime() {
      setInterval(this.formatDate, 500);
    },
    formatDate() {
      let date = new Date();
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月
      let day = date.getDate(); // 日
      let week = date.getDay(); // 星期
      let weekArr = [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" ];
      let hour = date.getHours(); // 时
      hour = hour < 10 ? "0" + hour : hour; // 如果只有一位,则前面补零
      let minute = date.getMinutes(); // 分
      minute = minute < 10 ? "0" + minute : minute; // 如果只有一位,则前面补零
      let second = date.getSeconds(); // 秒
      second = second < 10 ? "0" + second : second; // 如果只有一位,则前面补零
      this.nowDate = `${year}/${month}/${day}`;
    }
  },
  mounted() {
    this.currentTime();
  },
  beforeDestroy() {
    if (this.formatDate) {
      clearInterval(this.formatDate); // 在Vue实例销毁前,清除时间定时器
耿迪迪's avatar
耿迪迪 committed
162 163 164 165 166 167 168
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
yaqizhang's avatar
yaqizhang committed
169 170 171
  height: 80px;
  width: 100%;
  left: 0;
yaqizhang's avatar
yaqizhang committed
172
  /* line-height: 80px; */
耿迪迪's avatar
耿迪迪 committed
173
  overflow: hidden;
yaqizhang's avatar
yaqizhang committed
174 175
  position: fixed;
  background: #053B6A;
耿迪迪's avatar
耿迪迪 committed
176 177 178
  box-shadow: 0 1px 4px rgba(0,21,41,.08);

  .hamburger-container {
yaqizhang's avatar
yaqizhang committed
179
    /* line-height: 80px; */
耿迪迪's avatar
耿迪迪 committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color:transparent;

    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .topmenu-container {
yaqizhang's avatar
yaqizhang committed
196
    background-color: red;
耿迪迪's avatar
耿迪迪 committed
197
    position: absolute;
yaqizhang's avatar
yaqizhang committed
198 199
    left: 350px;
    background-color: #053B6A;
耿迪迪's avatar
耿迪迪 committed
200 201 202 203 204 205 206 207
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }
  .right-menu {
    float: right;
yaqizhang's avatar
yaqizhang committed
208
    width: 100%;
耿迪迪's avatar
耿迪迪 committed
209
    height: 100%;
yaqizhang's avatar
yaqizhang committed
210
    /* line-height: 80px; */
yaqizhang's avatar
yaqizhang committed
211 212
      
    
耿迪迪's avatar
耿迪迪 committed
213 214 215 216

    &:focus {
      outline: none;
    }
yaqizhang's avatar
yaqizhang committed
217
    .formatDate{
yaqizhang's avatar
yaqizhang committed
218 219 220 221 222
      width: 100%;
      height: 40px;
      line-height: 50px;
      text-align: center;
      font-size: 18px;
yaqizhang's avatar
yaqizhang committed
223 224 225
      color: #fff;
    }
    .yhm{
yaqizhang's avatar
yaqizhang committed
226
      font-size: 20px;
yaqizhang's avatar
yaqizhang committed
227
      color: #fff;
yaqizhang's avatar
yaqizhang committed
228
      width: 100%;
yaqizhang's avatar
yaqizhang committed
229 230 231
      text-overflow:ellipsis; 
      white-space: nowrap;
      overflow: hidden;
yaqizhang's avatar
yaqizhang committed
232
    }
耿迪迪's avatar
耿迪迪 committed
233 234
    .right-menu-item {
      display: inline-block;
yaqizhang's avatar
yaqizhang committed
235 236 237 238
      width: 100%;
      line-height: 30px;
      height: 40px;
      text-align: center;
耿迪迪's avatar
耿迪迪 committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
yaqizhang's avatar
yaqizhang committed
254 255
      width: 70%;
      margin-left: 15%;
耿迪迪's avatar
耿迪迪 committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278

      .avatar-wrapper {
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>