Merge pull request #2872 from lison16/menu

update Menu
This commit is contained in:
Aresn 2018-01-22 13:35:40 +08:00 committed by GitHub
commit 105af4ee57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 20 deletions

View file

@ -5,11 +5,12 @@
</li> </li>
</template> </template>
<script> <script>
import { findComponentUpward, findComponentsUpward } from '../../utils/assist'; import mixin from './mixin';
const prefixCls = 'ivu-menu'; const prefixCls = 'ivu-menu';
export default { export default {
name: 'MenuGroup', name: 'MenuGroup',
mixins: [ mixin ],
props: { props: {
title: { title: {
type: String, type: String,
@ -22,14 +23,8 @@
}; };
}, },
computed: { computed: {
parentSubmenuNum () {
return findComponentsUpward(this, 'Submenu').length;
},
hasParentSubmenu () {
return findComponentUpward(this, 'Submenu');
},
groupStyle () { groupStyle () {
return this.hasParentSubmenu ? { return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 28 + 'px' paddingLeft: 43 + (this.parentSubmenuNum - 1) * 28 + 'px'
} : {}; } : {};
} }

View file

@ -37,7 +37,7 @@
]; ];
}, },
itemStyle () { itemStyle () {
return this.hasParentSubmenu ? { return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
} : {}; } : {};
} }

View file

@ -1,11 +1,19 @@
import { findComponentUpward, findComponentsUpward } from '../../utils/assist'; import { findComponentUpward, findComponentsUpward } from '../../utils/assist';
export default { export default {
data () {
return {
menu: findComponentUpward(this, 'Menu')
};
},
computed: { computed: {
hasParentSubmenu () { hasParentSubmenu () {
return findComponentUpward(this, 'Submenu'); return findComponentUpward(this, 'Submenu');
}, },
parentSubmenuNum () { parentSubmenuNum () {
return findComponentsUpward(this, 'Submenu').length; return findComponentsUpward(this, 'Submenu').length;
},
mode () {
return this.menu.mode;
} }
} }
}; };

View file

@ -46,8 +46,7 @@
prefixCls: prefixCls, prefixCls: prefixCls,
active: false, active: false,
opened: false, opened: false,
dropWidth: parseFloat(getStyle(this.$el, 'width')), dropWidth: parseFloat(getStyle(this.$el, 'width'))
parent: findComponentUpward(this, 'Menu')
}; };
}, },
computed: { computed: {
@ -63,11 +62,8 @@
} }
]; ];
}, },
mode () {
return this.parent.mode;
},
accordion () { accordion () {
return this.parent.accordion; return this.menu.accordion;
}, },
dropStyle () { dropStyle () {
let style = {}; let style = {};
@ -76,7 +72,7 @@
return style; return style;
}, },
titleStyle () { titleStyle () {
return this.hasParentSubmenu ? { return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px' paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
} : {}; } : {};
} }
@ -88,7 +84,7 @@
clearTimeout(this.timeout); clearTimeout(this.timeout);
this.timeout = setTimeout(() => { this.timeout = setTimeout(() => {
this.parent.updateOpenKeys(this.name); this.menu.updateOpenKeys(this.name);
this.opened = true; this.opened = true;
}, 250); }, 250);
}, },
@ -98,7 +94,7 @@
clearTimeout(this.timeout); clearTimeout(this.timeout);
this.timeout = setTimeout(() => { this.timeout = setTimeout(() => {
this.parent.updateOpenKeys(this.name); this.menu.updateOpenKeys(this.name);
this.opened = false; this.opened = false;
}, 150); }, 150);
}, },
@ -112,7 +108,7 @@
}); });
} }
this.opened = !opened; this.opened = !opened;
this.parent.updateOpenKeys(this.name); this.menu.updateOpenKeys(this.name);
} }
}, },
watch: { watch: {