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>
|
fa0241a5
梁灏
fixed #212
|
8
9
10
11
12
13
14
|
<Drop
v-else
v-show="opened"
placement="bottom"
transition="slide-up"
v-ref:drop
:style="dropStyle"><slot></slot></Drop>
|
e05d7289
梁灏
update Menu
|
15
|
</li>
|
8778b343
梁灏
init Menu components
|
16
17
|
</template>
<script>
|
e05d7289
梁灏
update Menu
|
18
19
|
import Drop from '../select/dropdown.vue';
import Icon from '../icon/icon.vue';
|
fa0241a5
梁灏
fixed #212
|
20
21
|
import { getStyle } from '../../utils/assist';
|
e05d7289
梁灏
update Menu
|
22
23
|
const prefixCls = 'ivu-menu';
|
8778b343
梁灏
init Menu components
|
24
|
export default {
|
e05d7289
梁灏
update Menu
|
25
26
27
28
29
30
|
name: 'Submenu',
components: { Icon, Drop },
props: {
key: {
type: [String, Number],
required: true
|
0acdae19
梁灏
update Menu
|
31
32
33
34
|
},
disabled: {
type: Boolean,
default: false
|
e05d7289
梁灏
update Menu
|
35
36
|
}
},
|
8778b343
梁灏
init Menu components
|
37
|
data () {
|
e05d7289
梁灏
update Menu
|
38
39
40
|
return {
prefixCls: prefixCls,
active: false,
|
fa0241a5
梁灏
fixed #212
|
41
42
|
opened: false,
dropWidth: parseFloat(getStyle(this.$el, 'width'))
|
b0893113
jingsam
add eslint
|
43
|
};
|
e05d7289
梁灏
update Menu
|
44
45
46
47
48
49
50
|
},
computed: {
classes () {
return [
`${prefixCls}-submenu`,
{
[`${prefixCls}-item-active`]: this.active,
|
0acdae19
梁灏
update Menu
|
51
52
|
[`${prefixCls}-opened`]: this.opened,
[`${prefixCls}-submenu-disabled`]: this.disabled
|
e05d7289
梁灏
update Menu
|
53
|
}
|
b0893113
jingsam
add eslint
|
54
|
];
|
e05d7289
梁灏
update Menu
|
55
56
57
|
},
mode () {
return this.$parent.mode;
|
0acdae19
梁灏
update Menu
|
58
59
60
|
},
accordion () {
return this.$parent.accordion;
|
fa0241a5
梁灏
fixed #212
|
61
62
63
64
65
66
|
},
dropStyle () {
let style = {};
if (this.dropWidth) style.minWidth = `${this.dropWidth}px`;
return style;
|
e05d7289
梁灏
update Menu
|
67
68
69
70
|
}
},
methods: {
handleMouseenter () {
|
0acdae19
梁灏
update Menu
|
71
|
if (this.disabled) return;
|
e05d7289
梁灏
update Menu
|
72
|
if (this.mode === 'vertical') return;
|
0acdae19
梁灏
update Menu
|
73
|
|
e05d7289
梁灏
update Menu
|
74
75
|
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
|
ab673ebc
梁灏
update Menu
|
76
|
this.$parent.updateOpenKeys(this.key);
|
e05d7289
梁灏
update Menu
|
77
78
79
80
|
this.opened = true;
}, 250);
},
handleMouseleave () {
|
0acdae19
梁灏
update Menu
|
81
|
if (this.disabled) return;
|
e05d7289
梁灏
update Menu
|
82
|
if (this.mode === 'vertical') return;
|
0acdae19
梁灏
update Menu
|
83
|
|
e05d7289
梁灏
update Menu
|
84
85
|
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
|
ab673ebc
梁灏
update Menu
|
86
|
this.$parent.updateOpenKeys(this.key);
|
e05d7289
梁灏
update Menu
|
87
88
|
this.opened = false;
}, 150);
|
0acdae19
梁灏
update Menu
|
89
90
91
92
93
94
95
96
97
98
99
|
},
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
|
100
|
this.$parent.updateOpenKeys(this.key);
|
e05d7289
梁灏
update Menu
|
101
102
103
104
105
106
107
108
109
110
111
|
}
},
watch: {
mode (val) {
if (val === 'horizontal') {
this.$refs.drop.update();
}
},
opened (val) {
if (this.mode === 'vertical') return;
if (val) {
|
fa0241a5
梁灏
fixed #212
|
112
113
|
// set drop a width to fixed when menu has fixed position
this.dropWidth = parseFloat(getStyle(this.$el, 'width'));
|
e05d7289
梁灏
update Menu
|
114
115
116
117
118
|
this.$refs.drop.update();
} else {
this.$refs.drop.destroy();
}
}
|
8778b343
梁灏
init Menu components
|
119
|
},
|
e05d7289
梁灏
update Menu
|
120
121
|
events: {
'on-menu-item-select' () {
|
fd5cd823
梁灏
publish 0.9.10-rc-1
|
122
|
if (this.mode === 'horizontal') this.opened = false;
|
e05d7289
梁灏
update Menu
|
123
124
125
|
return true;
}
}
|
b0893113
jingsam
add eslint
|
126
127
|
};
</script>
|