2016-07-27 06:15:02 +00:00
|
|
|
<template>
|
|
|
|
<div class="el-dropdown"
|
|
|
|
:class="{'el-dropdown--text': type === 'text'}"
|
2016-08-12 04:19:06 +00:00
|
|
|
v-clickoutside="hide"
|
2016-07-27 06:15:02 +00:00
|
|
|
>
|
2016-08-12 04:19:06 +00:00
|
|
|
<!-- 分割的下拉按钮 -->
|
2016-07-27 06:15:02 +00:00
|
|
|
<el-button-group v-if="iconSeparate">
|
2016-08-12 04:19:06 +00:00
|
|
|
<el-button :size="size" :type="type" @click.native="$emit('mainclick')">{{text}}</el-button>
|
2016-07-27 06:15:02 +00:00
|
|
|
<el-button
|
|
|
|
:size="size"
|
|
|
|
:type="type"
|
|
|
|
class="el-dropdown__icon-button"
|
2016-08-12 04:19:06 +00:00
|
|
|
@mouseenter.native="handleMouseEnter"
|
|
|
|
@mouseleave.native="handleMouseLeave"
|
|
|
|
@click.native="handleClick">
|
2016-07-27 06:15:02 +00:00
|
|
|
<i class="el-dropdown__icon el-icon-caret-bottom"></i>
|
|
|
|
</el-button>
|
|
|
|
</el-button-group>
|
2016-08-12 04:19:06 +00:00
|
|
|
<!-- 不分割的下拉按钮 -->
|
|
|
|
<el-button :size="size" :type="type" @mouseenter.native="handleMouseEnter" @mouseleave.native="handleMouseLeave" @click.native="handleClick" v-else>
|
2016-07-27 06:15:02 +00:00
|
|
|
{{text}}<i class="el-dropdown__icon el-icon-caret-bottom"></i>
|
|
|
|
</el-button>
|
|
|
|
<!-- 下拉菜单 -->
|
2016-08-12 04:19:06 +00:00
|
|
|
<transition name="md-fade-bottom">
|
|
|
|
<el-dropdown-menu
|
|
|
|
v-if="visible"
|
|
|
|
@mouseenter.native="handleMouseEnter"
|
2016-08-17 05:53:56 +00:00
|
|
|
@mouseleave.native="handleMouseLeave">
|
2016-08-12 04:19:06 +00:00
|
|
|
<slot></slot>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</transition>
|
2016-07-27 06:15:02 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
/**
|
|
|
|
* dropdown
|
|
|
|
* @module packages/dropdown
|
|
|
|
* @desc 下拉菜单组件
|
|
|
|
* @param {string} label - 名称
|
|
|
|
*/
|
|
|
|
import ElButton from 'packages/button/index.js';
|
|
|
|
import ElButtonGroup from 'packages/button-group/index.js';
|
|
|
|
import ElDropdownMenu from './dropdown-menu.vue';
|
2016-08-22 04:02:09 +00:00
|
|
|
import Clickoutside from 'main/utils/clickoutside';
|
2016-07-27 06:15:02 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ElDropdown',
|
|
|
|
|
|
|
|
components: {
|
|
|
|
ElButton,
|
|
|
|
ElButtonGroup,
|
|
|
|
ElDropdownMenu
|
|
|
|
},
|
|
|
|
|
2016-08-22 04:02:09 +00:00
|
|
|
directives: { Clickoutside },
|
|
|
|
|
2016-07-27 06:15:02 +00:00
|
|
|
props: {
|
|
|
|
text: String,
|
|
|
|
type: String,
|
|
|
|
iconSeparate: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
trigger: {
|
|
|
|
type: String,
|
|
|
|
default: 'hover'
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
menuAlign: {
|
|
|
|
type: String,
|
|
|
|
default: 'end'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
timeout: null,
|
|
|
|
visible: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
show() {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
this.timeout = setTimeout(() => {
|
|
|
|
this.visible = true;
|
|
|
|
}, 250);
|
|
|
|
},
|
|
|
|
hide() {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
this.timeout = setTimeout(() => {
|
|
|
|
this.visible = false;
|
|
|
|
}, 150);
|
|
|
|
},
|
|
|
|
handleMouseEnter() {
|
|
|
|
if (this.trigger === 'hover') {
|
|
|
|
this.show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleMouseLeave() {
|
|
|
|
if (this.trigger === 'hover') {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleClick() {
|
|
|
|
if (this.trigger === 'click') {
|
|
|
|
this.visible = !this.visible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|