Commit b2d676bd83d2df9d9c0d8003c6afd245d6db450c

Authored by zhigang.li
1 parent 6b4e7383

fixed the bug about styles when mode is 'horizontal' of menu

examples/routers/menu.vue
1 <template> 1 <template>
2 <div> 2 <div>
3 - <Menu :theme="theme1" active-name="1" accordion @on-select="handleSelect" @on-open-change="handleOpen" :open-names="openArr"> 3 + <Menu :theme="theme1" mode="horizontal" active-name="1" accordion @on-select="handleSelect" @on-open-change="handleOpen" :open-names="openArr">
4 <Menu-item name="1"> 4 <Menu-item name="1">
5 <Icon type="ios-paper"></Icon> 5 <Icon type="ios-paper"></Icon>
6 一级1 6 一级1
@@ -16,7 +16,17 @@ @@ -16,7 +16,17 @@
16 </template> 16 </template>
17 <Menu-item name="3-1">二级1</Menu-item> 17 <Menu-item name="3-1">二级1</Menu-item>
18 <Menu-item name="3-2">二级2</Menu-item> 18 <Menu-item name="3-2">二级2</Menu-item>
19 - <Submenu name="3-3"> 19 + <MenuGroup title="Menu-Group">
  20 + <MenuItem name="3-3-3-3-1">
  21 + <Icon type="document-text"></Icon>
  22 + Group-item1
  23 + </MenuItem>
  24 + <MenuItem name="3-3-3-3-2">
  25 + <Icon type="chatbubbles"></Icon>
  26 + Group-item2
  27 + </MenuItem>
  28 + </MenuGroup>
  29 + <!-- <Submenu name="3-3">
20 <template slot="title"> 30 <template slot="title">
21 <Icon type="stats-bars"></Icon> 31 <Icon type="stats-bars"></Icon>
22 二级3 32 二级3
@@ -57,7 +67,7 @@ @@ -57,7 +67,7 @@
57 </template> 67 </template>
58 <Menu-item name="3-4-1">三级1</Menu-item> 68 <Menu-item name="3-4-1">三级1</Menu-item>
59 <Menu-item name="3-4-2">三级2</Menu-item> 69 <Menu-item name="3-4-2">三级2</Menu-item>
60 - </Submenu> 70 + </Submenu> -->
61 </Submenu> 71 </Submenu>
62 <Menu-item name="4"> 72 <Menu-item name="4">
63 <Icon type="settings"></Icon> 73 <Icon type="settings"></Icon>
src/components/menu/menu-group.vue
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 }, 25 },
26 computed: { 26 computed: {
27 groupStyle () { 27 groupStyle () {
28 - return this.hasParentSubmenu ? { 28 + return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
29 paddingLeft: 43 + (this.parentSubmenuNum - 1) * 28 + 'px' 29 paddingLeft: 43 + (this.parentSubmenuNum - 1) * 28 + 'px'
30 } : {}; 30 } : {};
31 } 31 }
src/components/menu/menu-item.vue
@@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
37 ]; 37 ];
38 }, 38 },
39 itemStyle () { 39 itemStyle () {
40 - return this.hasParentSubmenu ? { 40 + return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
41 paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' 41 paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
42 } : {}; 42 } : {};
43 } 43 }
src/components/menu/mixin.js
1 import { findComponentUpward, findComponentsUpward } from '../../utils/assist'; 1 import { findComponentUpward, findComponentsUpward } from '../../utils/assist';
2 export default { 2 export default {
  3 + data () {
  4 + return {
  5 + menu: findComponentUpward(this, 'Menu')
  6 + };
  7 + },
3 computed: { 8 computed: {
4 hasParentSubmenu () { 9 hasParentSubmenu () {
5 return findComponentUpward(this, 'Submenu'); 10 return findComponentUpward(this, 'Submenu');
6 }, 11 },
7 parentSubmenuNum () { 12 parentSubmenuNum () {
8 return findComponentsUpward(this, 'Submenu').length; 13 return findComponentsUpward(this, 'Submenu').length;
  14 + },
  15 + mode () {
  16 + return this.menu.mode;
9 } 17 }
10 } 18 }
11 }; 19 };
12 \ No newline at end of file 20 \ No newline at end of file
src/components/menu/submenu.vue
@@ -46,8 +46,7 @@ @@ -46,8 +46,7 @@
46 prefixCls: prefixCls, 46 prefixCls: prefixCls,
47 active: false, 47 active: false,
48 opened: false, 48 opened: false,
49 - dropWidth: parseFloat(getStyle(this.$el, 'width')),  
50 - parent: findComponentUpward(this, 'Menu') 49 + dropWidth: parseFloat(getStyle(this.$el, 'width'))
51 }; 50 };
52 }, 51 },
53 computed: { 52 computed: {
@@ -63,11 +62,8 @@ @@ -63,11 +62,8 @@
63 } 62 }
64 ]; 63 ];
65 }, 64 },
66 - mode () {  
67 - return this.parent.mode;  
68 - },  
69 accordion () { 65 accordion () {
70 - return this.parent.accordion; 66 + return this.menu.accordion;
71 }, 67 },
72 dropStyle () { 68 dropStyle () {
73 let style = {}; 69 let style = {};
@@ -88,7 +84,7 @@ @@ -88,7 +84,7 @@
88 84
89 clearTimeout(this.timeout); 85 clearTimeout(this.timeout);
90 this.timeout = setTimeout(() => { 86 this.timeout = setTimeout(() => {
91 - this.parent.updateOpenKeys(this.name); 87 + this.menu.updateOpenKeys(this.name);
92 this.opened = true; 88 this.opened = true;
93 }, 250); 89 }, 250);
94 }, 90 },
@@ -98,7 +94,7 @@ @@ -98,7 +94,7 @@
98 94
99 clearTimeout(this.timeout); 95 clearTimeout(this.timeout);
100 this.timeout = setTimeout(() => { 96 this.timeout = setTimeout(() => {
101 - this.parent.updateOpenKeys(this.name); 97 + this.menu.updateOpenKeys(this.name);
102 this.opened = false; 98 this.opened = false;
103 }, 150); 99 }, 150);
104 }, 100 },
@@ -112,7 +108,7 @@ @@ -112,7 +108,7 @@
112 }); 108 });
113 } 109 }
114 this.opened = !opened; 110 this.opened = !opened;
115 - this.parent.updateOpenKeys(this.name); 111 + this.menu.updateOpenKeys(this.name);
116 } 112 }
117 }, 113 },
118 watch: { 114 watch: {