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