111
jihongshun
8 天以前 0c741cdda7ef9935a20d3090dfea97e1ce8ae754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template>
  <el-container style="height: 100%;">
    <el-aside width="200px" style="background-color: #215398;min-height: 300px">
      <div style="padding-top: 20px;height: 200px;text-align: center;color: #eee">
        <div>
          <el-avatar :size="80" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"></el-avatar>
        </div>
        <el-dropdown style="margin-top: 20px;" trigger="click" @command="handleUserCommand">
          <span class="el-dropdown-link">
            {{currentUser.username}}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
 
      </div>
      <div style="margin-top: 20px;">
        <div class="menuItem" v-for="item in manageMenus" :key="item.name" @click="redirectMenu(item)"
             :class=" item.path=== key ? 'menuActive':''">{{item.meta.title}}</div>
      </div>
    </el-aside>
    <el-main>
      <router-view :key="key" />
    </el-main>
  </el-container>
</template>
 
<script>
import { manageMenus } from '@/router'
import {removeToken} from "@/utils/auth";
export default {
  name: "Layout",
  computed: {
    key() {
      return this.$route.path
    },
    manageMenus() {
      return manageMenus
    },
    currentUser(){
      return JSON.parse(localStorage.getItem("userinfo"))
    }
  },
  methods:{
    redirectMenu(item){
      this.$router.push(item.path)
    },
    handleUserCommand(command){
      if (command === 'logout'){
        removeToken();
        this.$router.push('/login');
      }
    }
  }
}
</script>
 
<style scoped>
.menuItem{line-height: 45px;padding-left: 40px;cursor: pointer;color: #eee;font-size: 14px;}
.menuItem:hover{background-color: #3F4B5F}
.menuActive{color: #409eff;background-color: #0a1e39
}
.el-dropdown-link {cursor: pointer; color: #eee;}
</style>