8778b343
梁灏
init Menu components
|
1
|
<template>
|
e05d7289
梁灏
update Menu
|
2
|
<li :class="classes" @mouseenter="handleMouseenter" @mouseleave="handleMouseleave">
|
0acdae19
梁灏
update Menu
|
3
4
5
|
<div :class="[prefixCls + '-submenu-title']" v-el:reference @click="handleClick">
<slot name="title"></slot>
<Icon type="ios-arrow-down" :class="[prefixCls + '-submenu-title-icon']"></Icon>
|
e05d7289
梁灏
update Menu
|
6
|
</div>
|
0acdae19
梁灏
update Menu
|
7
|
<ul :class="[prefixCls]" v-if="mode === 'vertical'" v-show="opened"><slot></slot></ul>
|
e05d7289
梁灏
update Menu
|
8
9
|
<Drop v-else v-show="opened" placement="bottom" transition="slide-up" v-ref:drop><slot></slot></Drop>
</li>
|
8778b343
梁灏
init Menu components
|
10
11
|
</template>
<script>
|
e05d7289
梁灏
update Menu
|
12
13
14
15
|
import Drop from '../select/dropdown.vue';
import Icon from '../icon/icon.vue';
const prefixCls = 'ivu-menu';
|
8778b343
梁灏
init Menu components
|
16
|
export default {
|
e05d7289
梁灏
update Menu
|
17
18
19
20
21
22
|
name: 'Submenu',
components: { Icon, Drop },
props: {
key: {
type: [String, Number],
required: true
|
0acdae19
梁灏
update Menu
|
23
24
25
26
|
},
disabled: {
type: Boolean,
default: false
|
e05d7289
梁灏
update Menu
|
27
28
|
}
},
|
8778b343
梁灏
init Menu components
|
29
|
data () {
|
e05d7289
梁灏
update Menu
|
30
31
32
33
34
35
36
37
38
39
40
41
|
return {
prefixCls: prefixCls,
active: false,
opened: false
}
},
computed: {
classes () {
return [
`${prefixCls}-submenu`,
{
[`${prefixCls}-item-active`]: this.active,
|
0acdae19
梁灏
update Menu
|
42
43
|
[`${prefixCls}-opened`]: this.opened,
[`${prefixCls}-submenu-disabled`]: this.disabled
|
e05d7289
梁灏
update Menu
|
44
45
46
47
48
|
}
]
},
mode () {
return this.$parent.mode;
|
0acdae19
梁灏
update Menu
|
49
50
51
|
},
accordion () {
return this.$parent.accordion;
|
e05d7289
梁灏
update Menu
|
52
53
54
55
|
}
},
methods: {
handleMouseenter () {
|
0acdae19
梁灏
update Menu
|
56
|
if (this.disabled) return;
|
e05d7289
梁灏
update Menu
|
57
|
if (this.mode === 'vertical') return;
|
0acdae19
梁灏
update Menu
|
58
|
|
e05d7289
梁灏
update Menu
|
59
60
|
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
|
ab673ebc
梁灏
update Menu
|
61
|
this.$parent.updateOpenKeys(this.key);
|
e05d7289
梁灏
update Menu
|
62
63
64
65
|
this.opened = true;
}, 250);
},
handleMouseleave () {
|
0acdae19
梁灏
update Menu
|
66
|
if (this.disabled) return;
|
e05d7289
梁灏
update Menu
|
67
|
if (this.mode === 'vertical') return;
|
0acdae19
梁灏
update Menu
|
68
|
|
e05d7289
梁灏
update Menu
|
69
70
|
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
|
ab673ebc
梁灏
update Menu
|
71
|
this.$parent.updateOpenKeys(this.key);
|
e05d7289
梁灏
update Menu
|
72
73
|
this.opened = false;
}, 150);
|
0acdae19
梁灏
update Menu
|
74
75
76
77
78
79
80
81
82
83
84
|
},
handleClick () {
if (this.disabled) return;
if (this.mode === 'horizontal') return;
const opened = this.opened;
if (this.accordion) {
this.$parent.$children.forEach(item => {
if (item.$options.name === 'Submenu') item.opened = false;
});
}
this.opened = !opened;
|
ab673ebc
梁灏
update Menu
|
85
|
this.$parent.updateOpenKeys(this.key);
|
e05d7289
梁灏
update Menu
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
}
},
watch: {
mode (val) {
if (val === 'horizontal') {
this.$refs.drop.update();
}
},
opened (val) {
if (this.mode === 'vertical') return;
if (val) {
this.$refs.drop.update();
} else {
this.$refs.drop.destroy();
}
}
|
8778b343
梁灏
init Menu components
|
102
|
},
|
e05d7289
梁灏
update Menu
|
103
104
|
events: {
'on-menu-item-select' () {
|
fd5cd823
梁灏
publish 0.9.10-rc-1
|
105
|
if (this.mode === 'horizontal') this.opened = false;
|
e05d7289
梁灏
update Menu
|
106
107
108
|
return true;
}
}
|
8778b343
梁灏
init Menu components
|
109
110
|
}
</script>
|