8778b343
梁灏
init Menu components
|
1
|
<template>
|
e05d7289
梁灏
update Menu
|
2
|
<li :class="classes" @mouseenter="handleMouseenter" @mouseleave="handleMouseleave">
|
a163daa0
zhigang.li
Add logical treat...
|
3
|
<div :class="[prefixCls + '-submenu-title']" ref="reference" @click.stop="handleClick" :style="titleStyle">
|
0acdae19
梁灏
update Menu
|
4
|
<slot name="title"></slot>
|
d082f8cc
梁灏
menu add global s...
|
5
|
<Icon :type="arrowType" :custom="customArrowType" :size="arrowSize" :class="[prefixCls + '-submenu-title-icon']" />
|
e05d7289
梁灏
update Menu
|
6
|
</div>
|
841cb1fe
Aresn
Menu support tran...
|
7
8
9
|
<collapse-transition v-if="mode === 'vertical'">
<ul :class="[prefixCls]" v-show="opened"><slot></slot></ul>
</collapse-transition>
|
fd1582c5
梁灏
support Menu & La...
|
10
11
12
13
14
|
<transition name="slide-up" v-else>
<Drop
v-show="opened"
placement="bottom"
ref="drop"
|
e510a3e7
梁灏
update Menu
|
15
|
:style="dropStyle"><ul :class="[prefixCls + '-drop-list']"><slot></slot></ul>
|
c708835c
梁灏
update Menu to su...
|
16
|
</Drop>
|
fd1582c5
梁灏
support Menu & La...
|
17
|
</transition>
|
e05d7289
梁灏
update Menu
|
18
|
</li>
|
8778b343
梁灏
init Menu components
|
19
20
|
</template>
<script>
|
e05d7289
梁灏
update Menu
|
21
22
|
import Drop from '../select/dropdown.vue';
import Icon from '../icon/icon.vue';
|
841cb1fe
Aresn
Menu support tran...
|
23
|
import CollapseTransition from '../base/collapse-transition';
|
acba45fe
zhigang.li
move computed val...
|
24
|
import { getStyle, findComponentUpward, findComponentsDownward } from '../../utils/assist';
|
fd1582c5
梁灏
support Menu & La...
|
25
|
import Emitter from '../../mixins/emitter';
|
acba45fe
zhigang.li
move computed val...
|
26
|
import mixin from './mixin';
|
fa0241a5
梁灏
fixed #212
|
27
|
|
e05d7289
梁灏
update Menu
|
28
29
|
const prefixCls = 'ivu-menu';
|
8778b343
梁灏
init Menu components
|
30
|
export default {
|
e05d7289
梁灏
update Menu
|
31
|
name: 'Submenu',
|
acba45fe
zhigang.li
move computed val...
|
32
|
mixins: [ Emitter, mixin ],
|
841cb1fe
Aresn
Menu support tran...
|
33
|
components: { Icon, Drop, CollapseTransition },
|
e05d7289
梁灏
update Menu
|
34
|
props: {
|
fd1582c5
梁灏
support Menu & La...
|
35
|
name: {
|
e05d7289
梁灏
update Menu
|
36
37
|
type: [String, Number],
required: true
|
0acdae19
梁灏
update Menu
|
38
39
40
41
|
},
disabled: {
type: Boolean,
default: false
|
e05d7289
梁灏
update Menu
|
42
43
|
}
},
|
8778b343
梁灏
init Menu components
|
44
|
data () {
|
e05d7289
梁灏
update Menu
|
45
46
47
|
return {
prefixCls: prefixCls,
active: false,
|
fa0241a5
梁灏
fixed #212
|
48
|
opened: false,
|
b2d676bd
zhigang.li
fixed the bug abo...
|
49
|
dropWidth: parseFloat(getStyle(this.$el, 'width'))
|
b0893113
jingsam
add eslint
|
50
|
};
|
e05d7289
梁灏
update Menu
|
51
52
53
54
55
56
|
},
computed: {
classes () {
return [
`${prefixCls}-submenu`,
{
|
4bce7645
zhigang.li
make menu support...
|
57
|
[`${prefixCls}-item-active`]: this.active && !this.hasParentSubmenu,
|
0acdae19
梁灏
update Menu
|
58
|
[`${prefixCls}-opened`]: this.opened,
|
4bce7645
zhigang.li
make menu support...
|
59
60
61
|
[`${prefixCls}-submenu-disabled`]: this.disabled,
[`${prefixCls}-submenu-has-parent-submenu`]: this.hasParentSubmenu,
[`${prefixCls}-child-item-active`]: this.active
|
e05d7289
梁灏
update Menu
|
62
|
}
|
b0893113
jingsam
add eslint
|
63
|
];
|
e05d7289
梁灏
update Menu
|
64
|
},
|
0acdae19
梁灏
update Menu
|
65
|
accordion () {
|
b2d676bd
zhigang.li
fixed the bug abo...
|
66
|
return this.menu.accordion;
|
fa0241a5
梁灏
fixed #212
|
67
68
69
70
71
72
|
},
dropStyle () {
let style = {};
if (this.dropWidth) style.minWidth = `${this.dropWidth}px`;
return style;
|
4bce7645
zhigang.li
make menu support...
|
73
|
},
|
4bce7645
zhigang.li
make menu support...
|
74
|
titleStyle () {
|
5a2efc4a
zhigang.li
update
|
75
|
return this.hasParentSubmenu && this.mode !== 'horizontal' ? {
|
4bce7645
zhigang.li
make menu support...
|
76
77
|
paddingLeft: 43 + (this.parentSubmenuNum - 1) * 24 + 'px'
} : {};
|
d082f8cc
梁灏
menu add global s...
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
},
// 3.4.0, global setting customArrow 有值时,arrow 赋值空
arrowType () {
let type = 'ios-arrow-down';
if (this.$IVIEW) {
if (this.$IVIEW.menu.customArrow) {
type = '';
} else if (this.$IVIEW.menu.arrow) {
type = this.$IVIEW.menu.arrow;
}
}
return type;
},
// 3.4.0, global setting
customArrowType () {
let type = '';
if (this.$IVIEW) {
if (this.$IVIEW.menu.customArrow) {
type = this.$IVIEW.menu.customArrow;
}
}
return type;
},
// 3.4.0, global setting
arrowSize () {
let size = '';
if (this.$IVIEW) {
if (this.$IVIEW.menu.arrowSize) {
size = this.$IVIEW.menu.arrowSize;
}
}
return size;
|
e05d7289
梁灏
update Menu
|
113
114
115
116
|
}
},
methods: {
handleMouseenter () {
|
0acdae19
梁灏
update Menu
|
117
|
if (this.disabled) return;
|
e05d7289
梁灏
update Menu
|
118
|
if (this.mode === 'vertical') return;
|
0acdae19
梁灏
update Menu
|
119
|
|
e05d7289
梁灏
update Menu
|
120
121
|
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
|
b2d676bd
zhigang.li
fixed the bug abo...
|
122
|
this.menu.updateOpenKeys(this.name);
|
e05d7289
梁灏
update Menu
|
123
124
125
126
|
this.opened = true;
}, 250);
},
handleMouseleave () {
|
0acdae19
梁灏
update Menu
|
127
|
if (this.disabled) return;
|
e05d7289
梁灏
update Menu
|
128
|
if (this.mode === 'vertical') return;
|
0acdae19
梁灏
update Menu
|
129
|
|
e05d7289
梁灏
update Menu
|
130
131
|
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
|
b2d676bd
zhigang.li
fixed the bug abo...
|
132
|
this.menu.updateOpenKeys(this.name);
|
e05d7289
梁灏
update Menu
|
133
134
|
this.opened = false;
}, 150);
|
0acdae19
梁灏
update Menu
|
135
136
137
138
139
140
|
},
handleClick () {
if (this.disabled) return;
if (this.mode === 'horizontal') return;
const opened = this.opened;
if (this.accordion) {
|
a163daa0
zhigang.li
Add logical treat...
|
141
|
this.$parent.$children.forEach(item => {
|
0acdae19
梁灏
update Menu
|
142
143
144
145
|
if (item.$options.name === 'Submenu') item.opened = false;
});
}
this.opened = !opened;
|
b2d676bd
zhigang.li
fixed the bug abo...
|
146
|
this.menu.updateOpenKeys(this.name);
|
e05d7289
梁灏
update Menu
|
147
148
149
150
151
152
153
154
155
156
157
|
}
},
watch: {
mode (val) {
if (val === 'horizontal') {
this.$refs.drop.update();
}
},
opened (val) {
if (this.mode === 'vertical') return;
if (val) {
|
fa0241a5
梁灏
fixed #212
|
158
159
|
// set drop a width to fixed when menu has fixed position
this.dropWidth = parseFloat(getStyle(this.$el, 'width'));
|
e05d7289
梁灏
update Menu
|
160
161
162
163
164
|
this.$refs.drop.update();
} else {
this.$refs.drop.destroy();
}
}
|
8778b343
梁灏
init Menu components
|
165
|
},
|
fd1582c5
梁灏
support Menu & La...
|
166
167
|
mounted () {
this.$on('on-menu-item-select', (name) => {
|
fd5cd823
梁灏
publish 0.9.10-rc-1
|
168
|
if (this.mode === 'horizontal') this.opened = false;
|
fd1582c5
梁灏
support Menu & La...
|
169
|
this.dispatch('Menu', 'on-menu-item-select', name);
|
e05d7289
梁灏
update Menu
|
170
|
return true;
|
fd1582c5
梁灏
support Menu & La...
|
171
172
|
});
this.$on('on-update-active-name', (status) => {
|
4bce7645
zhigang.li
make menu support...
|
173
174
175
176
|
if (findComponentUpward(this, 'Submenu')) this.dispatch('Submenu', 'on-update-active-name', status);
if (findComponentsDownward(this, 'Submenu')) findComponentsDownward(this, 'Submenu').forEach(item => {
item.active = false;
});
|
fd1582c5
梁灏
support Menu & La...
|
177
178
|
this.active = status;
});
|
e05d7289
梁灏
update Menu
|
179
|
}
|
b0893113
jingsam
add eslint
|
180
181
|
};
</script>
|