2016-12-07 12:10:47 +08:00
|
|
|
<template>
|
2016-12-07 20:45:21 +08:00
|
|
|
<ul :class="classes"><slot></slot></ul>
|
2016-12-07 12:10:47 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
2016-12-07 20:45:21 +08:00
|
|
|
import { oneOf } from '../../utils/assist';
|
|
|
|
|
|
|
|
const prefixCls = 'ivu-menu';
|
|
|
|
|
2016-12-07 12:10:47 +08:00
|
|
|
export default {
|
2016-12-07 20:45:21 +08:00
|
|
|
props: {
|
|
|
|
mode: {
|
|
|
|
validator (value) {
|
|
|
|
return oneOf(value, ['horizontal', 'vertical']);
|
|
|
|
},
|
|
|
|
default: 'vertical'
|
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
validator (value) {
|
|
|
|
return oneOf(value, ['light', 'dark', 'primary']);
|
|
|
|
},
|
|
|
|
default: 'light'
|
|
|
|
},
|
|
|
|
activeKey: {
|
|
|
|
type: [String, Number]
|
|
|
|
},
|
|
|
|
openKeys: {
|
|
|
|
type: Array
|
|
|
|
},
|
|
|
|
accordion: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
2016-12-07 12:10:47 +08:00
|
|
|
data () {
|
2016-12-07 20:45:21 +08:00
|
|
|
return {
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
classes () {
|
|
|
|
return [
|
|
|
|
`${prefixCls}`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-${this.mode}`]: this.mode,
|
|
|
|
[`${prefixCls}-${this.theme}`]: this.theme
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateActiveKey () {
|
|
|
|
this.$children.forEach((item, index) => {
|
|
|
|
if (!this.activeKey && index === 0) this.activeKey = item.key;
|
|
|
|
|
|
|
|
if (item.$options.name === 'Submenu') {
|
|
|
|
item.active = false;
|
|
|
|
item.$children.forEach(subitem => {
|
|
|
|
if (subitem.$options.name === 'MenuGroup') {
|
|
|
|
subitem.$children.forEach(groupItem => {
|
|
|
|
if (groupItem.key === this.activeKey) {
|
|
|
|
groupItem.active = true;
|
|
|
|
groupItem.$parent.$parent.active = true;
|
|
|
|
} else {
|
|
|
|
groupItem.active = false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if (subitem.key === this.activeKey) {
|
|
|
|
subitem.active = true;
|
|
|
|
subitem.$parent.active = true;
|
|
|
|
} else {
|
|
|
|
subitem.active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
item.active = item.key === this.activeKey;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
compiled () {
|
|
|
|
this.updateActiveKey();
|
2016-12-07 12:10:47 +08:00
|
|
|
},
|
2016-12-07 20:45:21 +08:00
|
|
|
events: {
|
|
|
|
'on-menu-item-select' (key) {
|
|
|
|
this.activeKey = key;
|
|
|
|
this.updateActiveKey();
|
|
|
|
this.$emit('on-select', key);
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 12:10:47 +08:00
|
|
|
}
|
|
|
|
</script>
|