2016-07-27 06:15:02 +00:00
|
|
|
<script>
|
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',
|
|
|
|
|
2016-08-22 04:02:09 +00:00
|
|
|
directives: { Clickoutside },
|
|
|
|
|
2016-07-27 06:15:02 +00:00
|
|
|
props: {
|
|
|
|
trigger: {
|
|
|
|
type: String,
|
|
|
|
default: 'hover'
|
|
|
|
},
|
|
|
|
menuAlign: {
|
|
|
|
type: String,
|
|
|
|
default: 'end'
|
2016-10-05 03:03:44 +00:00
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
splitButton: Boolean
|
2016-07-27 06:15:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
timeout: null,
|
|
|
|
visible: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-10-05 03:03:44 +00:00
|
|
|
mounted() {
|
|
|
|
this.initEvent();
|
|
|
|
},
|
|
|
|
|
2016-07-27 06:15:02 +00:00
|
|
|
methods: {
|
|
|
|
show() {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
this.timeout = setTimeout(() => {
|
|
|
|
this.visible = true;
|
|
|
|
}, 250);
|
|
|
|
},
|
|
|
|
hide() {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
this.timeout = setTimeout(() => {
|
|
|
|
this.visible = false;
|
|
|
|
}, 150);
|
|
|
|
},
|
|
|
|
handleClick() {
|
2016-10-05 03:03:44 +00:00
|
|
|
this.visible = !this.visible;
|
|
|
|
},
|
|
|
|
initEvent() {
|
|
|
|
let { trigger, show, hide, handleClick, splitButton } = this;
|
|
|
|
let triggerElm = splitButton
|
2016-10-09 03:25:44 +00:00
|
|
|
? this.$refs.trigger
|
2016-10-05 03:03:44 +00:00
|
|
|
: this.$slots.default[0].elm;
|
|
|
|
|
|
|
|
if (trigger === 'hover') {
|
|
|
|
triggerElm.addEventListener('mouseenter', show);
|
|
|
|
triggerElm.addEventListener('mouseleave', hide);
|
|
|
|
|
|
|
|
let dropdown = this.$slots.dropdown[0];
|
|
|
|
let insertHook = dropdown.data.hook.insert;
|
|
|
|
dropdown.data.hook.insert = (vnode) => {
|
|
|
|
insertHook(vnode);
|
|
|
|
this.$nextTick(_ => {
|
|
|
|
vnode.elm.addEventListener('mouseenter', show);
|
|
|
|
vnode.elm.addEventListener('mouseleave', hide);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
} else if (trigger === 'click') {
|
|
|
|
triggerElm.addEventListener('click', handleClick);
|
2016-07-27 06:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-05 03:03:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render(h) {
|
|
|
|
let { hide, splitButton, visible, type } = this;
|
|
|
|
let dropdownElm = visible ? this.$slots.dropdown : null;
|
|
|
|
|
|
|
|
var handleClick = _ => {
|
|
|
|
this.$emit('click');
|
|
|
|
};
|
|
|
|
|
|
|
|
let triggerElm = !splitButton
|
|
|
|
? this.$slots.default
|
|
|
|
: (<el-button-group>
|
|
|
|
<el-button type={type} nativeOn-click={handleClick}>
|
|
|
|
{this.$slots.default}
|
|
|
|
</el-button>
|
|
|
|
<el-button ref="trigger" type={type} class="el-dropdown__icon-button">
|
|
|
|
<i class="el-dropdown__icon el-icon-caret-bottom"></i>
|
|
|
|
</el-button>
|
|
|
|
</el-button-group>);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div class="el-dropdown" v-clickoutside={hide}>
|
|
|
|
{triggerElm}
|
|
|
|
<transition name="md-fade-bottom">
|
|
|
|
{dropdownElm}
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
);
|
2016-07-27 06:15:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|