|
@@ -1,12 +1,33 @@
|
|
|
|
+<template>
|
|
|
|
+ <li
|
|
|
|
+ :class="{ 'el-submenu': true, 'is-active': active, 'is-opened': opened}"
|
|
|
|
+ @mouseenter="handleMouseenter"
|
|
|
|
+ @mouseleave="handleMouseleave"
|
|
|
|
+ >
|
|
|
|
+ <div class="el-submenu__title" @click="handleClick">
|
|
|
|
+
|
|
|
|
+ <slot name="title"></slot>
|
|
|
|
+ <i :class="{
|
|
|
|
+ 'el-submenu__icon-arrow': true,
|
|
|
|
+ 'el-icon-arrow-down': rootMenu.mode === 'vertical',
|
|
|
|
+ 'el-icon-caret-bottom': rootMenu.mode === 'horizontal'
|
|
|
|
+ }">
|
|
|
|
+ </i>
|
|
|
|
+ </div>
|
|
|
|
+ <transition :name="rootMenu.mode === 'horizontal' ? 'md-fade-bottom' : ''">
|
|
|
|
+ <ul class="el-menu" v-show="opened"><slot></slot></ul>
|
|
|
|
+ </transition>
|
|
|
|
+ </li>
|
|
|
|
+</template>
|
|
<script>
|
|
<script>
|
|
- import emitter from 'main/mixins/emitter';
|
|
|
|
|
|
+ import menuMixin from './menu-mixin';
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
name: 'el-submenu',
|
|
name: 'el-submenu',
|
|
|
|
|
|
componentName: 'submenu',
|
|
componentName: 'submenu',
|
|
|
|
|
|
- mixins: [emitter],
|
|
|
|
|
|
+ mixins: [menuMixin],
|
|
|
|
|
|
props: {
|
|
props: {
|
|
index: {
|
|
index: {
|
|
@@ -16,117 +37,43 @@
|
|
},
|
|
},
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- opened: false,
|
|
|
|
timeout: null,
|
|
timeout: null,
|
|
active: false
|
|
active: false
|
|
};
|
|
};
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
- indexPath() {
|
|
|
|
- var path = [this.index];
|
|
|
|
- var parent = this.$parent;
|
|
|
|
- while (parent.$options._componentTag !== 'el-menu') {
|
|
|
|
- if (parent.index) {
|
|
|
|
- path.unshift(parent.index);
|
|
|
|
- }
|
|
|
|
- parent = parent.$parent;
|
|
|
|
- }
|
|
|
|
- return path;
|
|
|
|
- },
|
|
|
|
- rootMenu() {
|
|
|
|
- var parent = this.$parent;
|
|
|
|
- while (parent.$options._componentTag !== 'el-menu') {
|
|
|
|
- parent = parent.$parent;
|
|
|
|
- }
|
|
|
|
- return parent;
|
|
|
|
- },
|
|
|
|
- mode() {
|
|
|
|
- return this.rootMenu.mode;
|
|
|
|
|
|
+ opened() {
|
|
|
|
+ return this.rootMenu.openedMenus.indexOf(this.index) !== -1;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
handleClick() {
|
|
handleClick() {
|
|
- if (this.mode === 'vertical') {
|
|
|
|
- if (!this.opened) {
|
|
|
|
- this.dispatch('menu', 'expand-menu', [this.index, this.indexPath]);
|
|
|
|
- this.opened = true;
|
|
|
|
- } else {
|
|
|
|
- this.dispatch('menu', 'collapse-menu', [this.index, this.indexPath]);
|
|
|
|
- this.opened = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ this.rootMenu.handleSubmenuClick(this.index, this.indexPath);
|
|
},
|
|
},
|
|
handleMouseenter() {
|
|
handleMouseenter() {
|
|
- if (this.mode === 'horizontal') {
|
|
|
|
|
|
+ if (this.rootMenu.mode === 'horizontal') {
|
|
clearTimeout(this.timeout);
|
|
clearTimeout(this.timeout);
|
|
this.timeout = setTimeout(() => {
|
|
this.timeout = setTimeout(() => {
|
|
- this.dispatch('menu', 'expand-menu', [this.index, this.indexPath]);
|
|
|
|
- this.opened = true;
|
|
|
|
|
|
+ this.rootMenu.openMenu(this.index, this.indexPath);
|
|
}, 300);
|
|
}, 300);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
handleMouseleave() {
|
|
handleMouseleave() {
|
|
- if (this.mode === 'horizontal') {
|
|
|
|
|
|
+ if (this.rootMenu.mode === 'horizontal') {
|
|
clearTimeout(this.timeout);
|
|
clearTimeout(this.timeout);
|
|
this.timeout = setTimeout(() => {
|
|
this.timeout = setTimeout(() => {
|
|
- this.dispatch('menu', 'collapse-menu', [this.index, this.indexPath]);
|
|
|
|
- this.opened = false;
|
|
|
|
|
|
+ this.rootMenu.closeMenu(this.index, this.indexPath);
|
|
}, 300);
|
|
}, 300);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ created() {
|
|
|
|
+ this.rootMenu.submenus[this.index] = this;
|
|
|
|
+ },
|
|
mounted() {
|
|
mounted() {
|
|
- this.$on('close-menu', (openedIndexs) => {
|
|
|
|
- if (openedIndexs && openedIndexs.indexOf(this.index) === -1) {
|
|
|
|
- this.opened = false;
|
|
|
|
- }
|
|
|
|
|
|
+ this.$on('item-select', (index, indexPath) => {
|
|
|
|
+ this.active = indexPath.indexOf(this.index) !== -1;
|
|
});
|
|
});
|
|
- this.$on('open-menu', (IndexsArray) => {
|
|
|
|
- if (IndexsArray && IndexsArray.indexOf(this.index) !== -1) {
|
|
|
|
- this.opened = true;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.$on('select', (index, indexPath) => {
|
|
|
|
- if (this.mode === 'horizontal') {
|
|
|
|
- this.active = indexPath.indexOf(this.index) !== -1;
|
|
|
|
- this.opened = false;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- render(h) {
|
|
|
|
- var submenu;
|
|
|
|
-
|
|
|
|
- if (this.mode === 'horizontal') {
|
|
|
|
- submenu = (
|
|
|
|
- <transition name="md-fade-bottom">
|
|
|
|
- {this.opened ? <ul class="el-menu">{this.$slots.default}</ul> : null }
|
|
|
|
- </transition>
|
|
|
|
- );
|
|
|
|
- } else {
|
|
|
|
- submenu = (
|
|
|
|
- this.opened ? <ul class="el-menu">{this.$slots.default}</ul> : null
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <li
|
|
|
|
- class={{ 'el-submenu': true, 'is-active': this.active, 'is-opened': this.opened}}
|
|
|
|
- on-mouseenter={this.handleMouseenter}
|
|
|
|
- on-mouseleave={this.handleMouseleave}
|
|
|
|
- >
|
|
|
|
- <div class="el-submenu__title" on-click={this.handleClick}>
|
|
|
|
-
|
|
|
|
- {this.$slots.title}
|
|
|
|
- <i class={{
|
|
|
|
- 'el-submenu__icon-arrow': true,
|
|
|
|
- 'el-icon-arrow-down': this.mode === 'vertical',
|
|
|
|
- 'el-icon-caret-bottom': this.mode === 'horizontal'
|
|
|
|
- }}>
|
|
|
|
- </i>
|
|
|
|
- </div>
|
|
|
|
- {submenu}
|
|
|
|
- </li>
|
|
|
|
- );
|
|
|
|
}
|
|
}
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|