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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!--导航组件-->
<template>
  <div class="app-sidebar">
    <div class="box">
      <el-menu
        router
        unique-opened
        :default-active="$route.path"
        class="el-menu-vertical-demo"
        @select="handleOpen"
        @close="handleClose"
        background-color="#314255"
        text-color="#bfcbd9"
        active-text-color="#fff"
      >
        <el-submenu v-for="item in menus" :key="item.id" :index="item.id.toString()" >
          <template slot="title">
            <i class="el-icon-money icon"></i>
            <span>{{ item.title }}</span>
          </template>
          <el-menu-item v-for="itm in item.children" :key="itm.id" :index="itm.path">{{ itm.title }}</el-menu-item>
          
          <!-- <el-menu-item index="/client/salesLead">销售线索</el-menu-item>
          <el-menu-item index="/client/clientManage">客户管理</el-menu-item>
          <el-menu-item index="/client/contacts">联系人</el-menu-item>
          <el-menu-item index="/client/followupRecords">跟进记录</el-menu-item> -->
        </el-submenu>
        
 
        <!-- <el-submenu index="4">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>后台配置</span>
          </template>
          <el-menu-item index="/backgroundConfig/memberManage">成员管理</el-menu-item>
          <el-menu-item index="/backgroundConfig/rolePermssion">角色权限</el-menu-item>
        </el-submenu> -->
      </el-menu>
      <el-empty v-if="this.menus===null||this.menus===undefined||this.menus.length===0" :image-size="130" description="没有侧栏菜单"></el-empty>
    </div>
  </div>
</template>
 
<script>
export default {
  name: "AppSidebar",
  props: {},
  data() {
    return {
      menus:[]
    }
  },
  watch: {
    // $route: {
    //   handler: "initNavMenu",
    //   immediate: true
    // }
  },
  created() {
    this.initNavMenu()
    this.getMenuTreeByRole()
  },
  methods: {
    getMenuTreeByRole(){
      let newList=this.$store.state.menus
      console.log(newList,"newList")
      // 隐藏了 生成计划 和 服务收费管理模块
      if(newList[1]){
        const found = newList[1].children.find(obj => obj.title === "生成计划")
        if(found){
          newList[1].children=[...newList[1].children.slice(0, -1)];  
        }
      }
      if(newList[2]){
        const found1 = newList[2].children.find(obj => obj.title === "服务收费管理")
        if(found1){
          newList[2].children=[...newList[2].children.slice(0, -1)];  
        }
      }
      this.menus=newList
    },
    // 监听路由
    initNavMenu() {
      // console.log(this.$route.name)
    },
    handleOpen(index) {
      console.log(index)
    },
    handleClose() {}
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import "./index.scss";
::v-deep .el-empty{
  .el-empty__description{
    p{
      color: #dddd;
    }
  }
}
</style>