2016-12-07 12:10:47 +08:00
|
|
|
<template>
|
2018-06-21 10:22:11 +08:00
|
|
|
<a v-if="to" :href="linkUrl" :target="target" :class="classes" @click="handleClickItem" :style="itemStyle"><slot></slot></a>
|
|
|
|
<li v-else :class="classes" @click.stop="handleClickItem" :style="itemStyle"><slot></slot></li>
|
2016-12-07 12:10:47 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
2017-03-06 13:31:48 +08:00
|
|
|
import Emitter from '../../mixins/emitter';
|
2018-06-21 10:36:53 +08:00
|
|
|
import { findComponentUpward } from '../../utils/assist';
|
2018-01-19 15:56:57 +08:00
|
|
|
import mixin from './mixin';
|
2018-06-21 10:22:11 +08:00
|
|
|
import mixinsLink from '../../mixins/link';
|
2016-12-07 20:45:21 +08:00
|
|
|
|
2018-06-25 14:27:36 +08:00
|
|
|
const prefixCls = 'ivu-menu';
|
|
|
|
|
2016-12-07 12:10:47 +08:00
|
|
|
export default {
|
2016-12-07 20:45:21 +08:00
|
|
|
name: 'MenuItem',
|
2018-06-21 10:22:11 +08:00
|
|
|
mixins: [ Emitter, mixin, mixinsLink ],
|
2016-12-07 20:45:21 +08:00
|
|
|
props: {
|
2017-03-06 13:31:48 +08:00
|
|
|
name: {
|
2016-12-07 20:45:21 +08:00
|
|
|
type: [String, Number],
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2018-06-21 10:22:11 +08:00
|
|
|
},
|
2016-12-07 20:45:21 +08:00
|
|
|
},
|
2016-12-07 12:10:47 +08:00
|
|
|
data () {
|
2016-12-07 20:45:21 +08:00
|
|
|
return {
|
|
|
|
active: false
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
2016-12-07 20:45:21 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
classes () {
|
|
|
|
return [
|
|
|
|
`${prefixCls}-item`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-item-active`]: this.active,
|
|
|
|
[`${prefixCls}-item-selected`]: this.active,
|
|
|
|
[`${prefixCls}-item-disabled`]: this.disabled
|
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
];
|
2018-01-15 13:17:58 +08:00
|
|
|
},
|
|
|
|
itemStyle () {
|
2018-01-22 13:12:15 +08:00
|
|
|
return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
|
2018-01-15 13:17:58 +08:00
|
|
|
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
|
|
|
|
} : {};
|
2016-12-07 20:45:21 +08:00
|
|
|
}
|
2016-12-07 12:10:47 +08:00
|
|
|
},
|
2016-12-07 20:45:21 +08:00
|
|
|
methods: {
|
2018-06-21 10:22:11 +08:00
|
|
|
handleClickItem (event) {
|
2016-12-08 11:55:38 +08:00
|
|
|
if (this.disabled) return;
|
2017-03-06 13:31:48 +08:00
|
|
|
|
2018-01-15 13:17:58 +08:00
|
|
|
let parent = findComponentUpward(this, 'Submenu');
|
2017-03-06 13:31:48 +08:00
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
this.dispatch('Submenu', 'on-menu-item-select', this.name);
|
|
|
|
} else {
|
|
|
|
this.dispatch('Menu', 'on-menu-item-select', this.name);
|
|
|
|
}
|
2018-06-21 10:22:11 +08:00
|
|
|
|
|
|
|
this.handleCheckClick(event);
|
2016-12-07 20:45:21 +08:00
|
|
|
}
|
2017-03-06 13:31:48 +08:00
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
this.$on('on-update-active-name', (name) => {
|
|
|
|
if (this.name === name) {
|
|
|
|
this.active = true;
|
2018-01-15 13:17:58 +08:00
|
|
|
this.dispatch('Submenu', 'on-update-active-name', name);
|
2017-03-06 13:31:48 +08:00
|
|
|
} else {
|
|
|
|
this.active = false;
|
|
|
|
}
|
|
|
|
});
|
2016-12-07 20:45:21 +08:00
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
|
|
|
</script>
|