浏览代码

feat[Menu]: menu icon support el-icon

花裤衩 5 年之前
父节点
当前提交
e2fd7c7528
共有 3 个文件被更改,包括 32 次插入3 次删除
  1. 13 1
      src/layout/components/Sidebar/Item.vue
  2. 2 2
      src/router/index.js
  3. 17 0
      src/styles/sidebar.scss

+ 13 - 1
src/layout/components/Sidebar/Item.vue

@@ -17,7 +17,11 @@ export default {
17
     const vnodes = []
17
     const vnodes = []
18
 
18
 
19
     if (icon) {
19
     if (icon) {
20
-      vnodes.push(<svg-icon icon-class={icon}/>)
20
+      if (icon.includes('el-icon')) {
21
+        vnodes.push(<i class={[icon, 'sub-el-icon']} />)
22
+      } else {
23
+        vnodes.push(<svg-icon icon-class={icon}/>)
24
+      }
21
     }
25
     }
22
 
26
 
23
     if (title) {
27
     if (title) {
@@ -27,3 +31,11 @@ export default {
27
   }
31
   }
28
 }
32
 }
29
 </script>
33
 </script>
34
+
35
+<style scoped>
36
+.sub-el-icon {
37
+  color: currentColor;
38
+  width: 1em;
39
+  height: 1em;
40
+}
41
+</style>

+ 2 - 2
src/router/index.js

@@ -19,7 +19,7 @@ import Layout from '@/layout'
19
  * meta : {
19
  * meta : {
20
     roles: ['admin','editor']    control the page roles (you can set multiple roles)
20
     roles: ['admin','editor']    control the page roles (you can set multiple roles)
21
     title: 'title'               the name show in sidebar and breadcrumb (recommend set)
21
     title: 'title'               the name show in sidebar and breadcrumb (recommend set)
22
-    icon: 'svg-name'             the icon show in the sidebar
22
+    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
23
     breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
23
     breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
24
     activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
24
     activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
25
   }
25
   }
@@ -60,7 +60,7 @@ export const constantRoutes = [
60
     component: Layout,
60
     component: Layout,
61
     redirect: '/example/table',
61
     redirect: '/example/table',
62
     name: 'Example',
62
     name: 'Example',
63
-    meta: { title: 'Example', icon: 'example' },
63
+    meta: { title: 'Example', icon: 'el-icon-s-help' },
64
     children: [
64
     children: [
65
       {
65
       {
66
         path: 'table',
66
         path: 'table',

+ 17 - 0
src/styles/sidebar.scss

@@ -57,6 +57,11 @@
57
       margin-right: 16px;
57
       margin-right: 16px;
58
     }
58
     }
59
 
59
 
60
+    .sub-el-icon {
61
+      margin-right: 12px;
62
+      margin-left: -2px;
63
+    }
64
+
60
     .el-menu {
65
     .el-menu {
61
       border: none;
66
       border: none;
62
       height: 100%;
67
       height: 100%;
@@ -105,6 +110,10 @@
105
         .svg-icon {
110
         .svg-icon {
106
           margin-left: 20px;
111
           margin-left: 20px;
107
         }
112
         }
113
+
114
+        .sub-el-icon {
115
+          margin-left: 19px;
116
+        }
108
       }
117
       }
109
     }
118
     }
110
 
119
 
@@ -118,6 +127,10 @@
118
           margin-left: 20px;
127
           margin-left: 20px;
119
         }
128
         }
120
 
129
 
130
+        .sub-el-icon {
131
+          margin-left: 19px;
132
+        }
133
+
121
         .el-submenu__icon-arrow {
134
         .el-submenu__icon-arrow {
122
           display: none;
135
           display: none;
123
         }
136
         }
@@ -178,6 +191,10 @@
178
     .svg-icon {
191
     .svg-icon {
179
       margin-right: 16px;
192
       margin-right: 16px;
180
     }
193
     }
194
+    .sub-el-icon {
195
+      margin-right: 12px;
196
+      margin-left: -2px;
197
+    }
181
   }
198
   }
182
 
199
 
183
   .nest-menu .el-submenu>.el-submenu__title,
200
   .nest-menu .el-submenu>.el-submenu__title,