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