Vue点击子菜单,父菜单高亮显示,图标切换


 

 完整版

  1 <template>
  2     <div class="sidebar">
  3         <el-menu class="sidebar-el-menu" :default-active="activeMenu" text-color="#36BFF3" active-text-color="#fff"
  4             unique-opened router @select="selectmenu">
  5             <!-- 一级菜单 -->
  6             <template v-for="(item,index) in menus">
  7                 <el-menu-item v-if="!item.children" :key="index" :index="item.path" :id="item.path">
  8                     <img :src="item.path === $route.path ? item.Aicon : item.icon">
  9                     <span class="span4" slot="title">{{item.name}}</span>
 10                 </el-menu-item>
 11                 <!-- 多级菜单 -->
 12                 <el-submenu v-else :key="index" :index="item.icon" :id="item.path">
 13                     <template slot="title">
 14                         <img :src="chooseIcon(item, $route.path)">
 15                         <span class="span4" slot="title">{{item.name}} </span>
 16                     </template>
 17                     <template v-for="(etem, index) in item.children">
 18                         <el-menu-item :index="etem.path" :key="index">
 19                             {{etem.name}}
 20                         </el-menu-item>
 21                     </template>
 22                 </el-submenu>
 23             </template>
 24         </el-menu>
 25     </div>
 26 </template>
 27 
 28 <script>
 29     // import bus from '../common/bus';
 30     export default {
 31         data() {
 32             return {
 33                 activeMenu: '/archivesInfor',
 34                 menus: [{
 35                         name: '档案管理',
 36                         icon: require('../../assets/imgs/dagl.png'), // 未高亮图标
 37                         Aicon: require('../../assets/imgs/icon_dagl.png'), // 高亮图标
 38 
 39                         children: [{
 40                                 name: '档案信息',
 41                                 path: '/archivesInfor'
 42                             },
 43                             {
 44                                 name: '档案借阅',
 45                                 path: '/ArchivesBorrowing'
 46                             },
 47                             {
 48                                 name: '在借档案',
 49                                 path: '/BorrowedArchives'
 50                             },
 51                             {
 52                                 name: '丢失档案',
 53                                 path: '/LossArchives'
 54                             },
 55                             {
 56                                 name: '档案回收站',
 57                                 path: '/ArchivesRecovery'
 58                             },
 59                         ]
 60                     },
 61                     {
 62                         name: '档案盘点',
 63                         icon: require('../../assets/imgs/dapd.png'), // 未高亮图标
 64                         Aicon: require('../../assets/imgs/icon_dapd.png'), // 高亮图标
 65                         children: [{
 66                                 name: '盘点计划',
 67                                 path: '/InventoryPlan'
 68                             },
 69                             {
 70                                 name: '盘点任务',
 71                                 path: '/InventoryTask'
 72                             },
 73                             {
 74                                 name: '外借人员管理',
 75                                 path: '/ManagementLoanPer'
 76                             },
 77 
 78                         ]
 79                     },
 80                     {
 81                         name: '基础配置',
 82                         icon: require('../../assets/imgs/jcpz.png'), // 未高亮图标
 83                         Aicon: require('../../assets/imgs/icon_jcpz.png'), // 高亮图标
 84                         children: [{
 85                                 name: '介质类型',
 86                                 path: '/MediaType'
 87                             },
 88                             {
 89                                 name: '保密级别',
 90                                 path: '/SecurityLevel'
 91                             },
 92                             {
 93                                 name: '档案分类',
 94                                 path: '/ArchivesType'
 95                             },
 96 
 97                         ]
 98                     },
 99                     {
100                         name: '档案盒管理',
101                         icon: require('../../assets/imgs/dahg.png'), // 未高亮图标
102                         Aicon: require('../../assets/imgs/icon_dahg.png'), // 高亮图标
103                         children: [{
104                                 name: '档案盒新增',
105                                 path: '/ArchivesBoxAdd'
106                             },
107                             {
108                                 name: '档案盒信息',
109                                 path: '/ArchivesBoxEdit'
110                             },
111                         ]
112                     },
113                     {
114                         name: '历史信息查询',
115                         icon: require('../../assets/imgs/icon_ls.png'), // 未高亮图标
116                         Aicon: require('../../assets/imgs/lixx.png'), // 高亮图标
117                         children: [{
118                                 name: '档案操作记录',
119                                 path: '/ArchivesOperRecord'
120                             },
121                             {
122                                 name: '历史盘点任务',
123                                 path: '/HistoryInventory'
124                             },
125                             {
126                                 name: '门口机消息记录',
127                                 path: '/DoorNewsRecord'
128                             },
129                         ]
130                     },
131                     {
132                         name: '统计分析',
133                         icon: require('../../assets/imgs/tjfx.png'), // 未高亮图标
134                         Aicon: require('../../assets/imgs/icon_tjfx.png'), // 高亮图标
135                         children: [{
136                                 name: '档案数量统计',
137                                 path: '/archNumberStatistics'
138                             },
139                             {
140                                 name: '档案借阅统计',
141                                 path: '/archBorrowingStatistics'
142                             },
143                             {
144                                 name: '档案操作统计',
145                                 path: '/archOperationStatistics'
146                             },
147 
148                         ]
149                     },
150                 ]
151             };
152         },
153 
154         methods: {
155             selectmenu(index, indexPath) {
156                 this.activeMenu = index
157             },
158             chooseIcon(item, route) {
159                 let n = 0 // 用于判断当前一级菜单下的二级菜单是否被点击
160                 for (let i = 0; i < item.children.length; i++) {
161                     if (item.children[i].path == route) {
162                         n = 1
163                     }
164                 }
165                 if (n == 1) { // 被点击了,返回高亮图标
166                     return item.Aicon
167                 } else { // 未被点击,返回未高亮图标
168                     return item.icon
169 
170                 }
171             },
172         }
173     };
174 </script>
175 
176 <style scoped>
177     .sidebar {
178         display: block;
179     }
180 
181     .sidebar::-webkit-scrollbar {
182         width: 0;
183     }
184 
185     .sidebar-el-menu:not(.el-menu--collapse) {
186         width: 220px;
187         height: 912px;
188         margin: 0 0 30px 30px;
189         background: url(../../assets/imgs/tabk.png) no-repeat;
190         background-size: 100% 100%;
191     }
192 
193     .sidebar>ul {
194         height: 100%;
195     }
196 
197     >>>.el-submenu__title {
198         height: 80px;
199     }
200 
201     >>>.el-submenu__title>span {
202         line-height: 80px;
203         margin: 0 10px;
204         font-size: 18px;
205         font-family: Source Han Sans CN;
206         font-weight: 500;
207     }
208 
209     >>>.el-submenu__title>span::before {
210         position: absolute;
211         left: 20px;
212         top: 80px;
213         content: "";
214         width: 180px;
215         height: 1px;
216         background: #36BEF2;
217         opacity: 0.3;
218     }
219 
220     >>>.el-submenu__icon-arrow {
221         background: url(../../assets/imgs/tb-l-1.png);
222     }
223 
224     >>>.el-submenu.is-active .el-submenu__title .el-submenu__icon-arrow {
225         background: url(../../assets/imgs/tb-l-2.png);
226     }
227 
228     >>>.el-menu-item {
229         padding-left: 60px !important;
230         line-height: 80px;
231         height: 80px;
232         font-size: 18px;
233     }
234 
235     >>>.el-submenu.is-active .el-submenu__title .span4 {
236         color: #fff;
237     }
238 
239     >>>.sidebar-el-menu {
240         padding-top: 18px
241     }
242 </style>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM