ab8aaf95
梁灏
add Dropdown comp...
|
1
2
3
|
<template>
<div
:class="[prefixCls]"
|
407eabd5
梁灏
update Dropdown
|
4
|
v-clickoutside="handleClose"
|
ab8aaf95
梁灏
add Dropdown comp...
|
5
|
@mouseenter="handleMouseenter"
|
407eabd5
梁灏
update Dropdown
|
6
|
@mouseleave="handleMouseleave">
|
b1c118d8
梁灏
support Dropdown
|
7
8
|
<div :class="[prefixCls + '-rel']" ref="reference" @click="handleClick"><slot></slot></div>
<transition :name="transition">
|
3e4bab96
梁灏
Dropdown add tran...
|
9
|
<Drop
|
f1800986
梁灏
update Dropdown cls
|
10
|
:class="dropdownCls"
|
3e4bab96
梁灏
Dropdown add tran...
|
11
12
13
14
15
|
v-show="currentVisible"
:placement="placement"
ref="drop"
@mouseenter.native="handleMouseenter"
@mouseleave.native="handleMouseleave"
|
548eac43
梁灏
fixed #1387 and u...
|
16
17
|
:data-transfer="transfer"
v-transfer-dom><slot name="list"></slot></Drop>
|
b1c118d8
梁灏
support Dropdown
|
18
|
</transition>
|
ab8aaf95
梁灏
add Dropdown comp...
|
19
20
21
22
23
|
</div>
</template>
<script>
import Drop from '../select/dropdown.vue';
import clickoutside from '../../directives/clickoutside';
|
3e4bab96
梁灏
Dropdown add tran...
|
24
|
import TransferDom from '../../directives/transfer-dom';
|
cb6418ac
梁灏
fixed #721
|
25
|
import { oneOf, findComponentUpward } from '../../utils/assist';
|
ab8aaf95
梁灏
add Dropdown comp...
|
26
27
28
29
|
const prefixCls = 'ivu-dropdown';
export default {
|
745bcbc2
梁灏
update Dropdown
|
30
|
name: 'Dropdown',
|
3e4bab96
梁灏
Dropdown add tran...
|
31
|
directives: { clickoutside, TransferDom },
|
ab8aaf95
梁灏
add Dropdown comp...
|
32
33
34
35
|
components: { Drop },
props: {
trigger: {
validator (value) {
|
51f9f894
梁灏
Dropdown add cust...
|
36
|
return oneOf(value, ['click', 'hover', 'custom']);
|
ab8aaf95
梁灏
add Dropdown comp...
|
37
38
39
|
},
default: 'hover'
},
|
745bcbc2
梁灏
update Dropdown
|
40
|
placement: {
|
ab8aaf95
梁灏
add Dropdown comp...
|
41
|
validator (value) {
|
745bcbc2
梁灏
update Dropdown
|
42
|
return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
|
ab8aaf95
梁灏
add Dropdown comp...
|
43
|
},
|
745bcbc2
梁灏
update Dropdown
|
44
|
default: 'bottom'
|
51f9f894
梁灏
Dropdown add cust...
|
45
46
47
48
|
},
visible: {
type: Boolean,
default: false
|
3e4bab96
梁灏
Dropdown add tran...
|
49
50
51
52
|
},
transfer: {
type: Boolean,
default: false
|
ab8aaf95
梁灏
add Dropdown comp...
|
53
54
|
}
},
|
407eabd5
梁灏
update Dropdown
|
55
56
57
|
computed: {
transition () {
return ['bottom-start', 'bottom', 'bottom-end'].indexOf(this.placement) > -1 ? 'slide-up' : 'fade';
|
f1800986
梁灏
update Dropdown cls
|
58
59
60
61
62
|
},
dropdownCls () {
return {
[prefixCls + '-transfer']: this.transfer
};
|
407eabd5
梁灏
update Dropdown
|
63
64
|
}
},
|
ab8aaf95
梁灏
add Dropdown comp...
|
65
66
|
data () {
return {
|
b1c118d8
梁灏
support Dropdown
|
67
68
|
prefixCls: prefixCls,
currentVisible: this.visible
|
b0893113
jingsam
add eslint
|
69
|
};
|
ab8aaf95
梁灏
add Dropdown comp...
|
70
|
},
|
b1c118d8
梁灏
support Dropdown
|
71
72
73
74
75
76
77
78
79
80
81
82
83
|
watch: {
visible (val) {
this.currentVisible = val;
},
currentVisible (val) {
if (val) {
this.$refs.drop.update();
} else {
this.$refs.drop.destroy();
}
this.$emit('on-visible-change', val);
}
},
|
ab8aaf95
梁灏
add Dropdown comp...
|
84
85
|
methods: {
handleClick () {
|
51f9f894
梁灏
Dropdown add cust...
|
86
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
87
88
89
|
if (this.trigger !== 'click') {
return false;
}
|
b1c118d8
梁灏
support Dropdown
|
90
|
this.currentVisible = !this.currentVisible;
|
ab8aaf95
梁灏
add Dropdown comp...
|
91
92
|
},
handleMouseenter () {
|
51f9f894
梁灏
Dropdown add cust...
|
93
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
94
95
96
|
if (this.trigger !== 'hover') {
return false;
}
|
3e4bab96
梁灏
Dropdown add tran...
|
97
|
if (this.timeout) clearTimeout(this.timeout);
|
ab8aaf95
梁灏
add Dropdown comp...
|
98
|
this.timeout = setTimeout(() => {
|
b1c118d8
梁灏
support Dropdown
|
99
|
this.currentVisible = true;
|
ab8aaf95
梁灏
add Dropdown comp...
|
100
101
102
|
}, 250);
},
handleMouseleave () {
|
51f9f894
梁灏
Dropdown add cust...
|
103
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
104
105
106
|
if (this.trigger !== 'hover') {
return false;
}
|
3e4bab96
梁灏
Dropdown add tran...
|
107
108
109
110
111
112
|
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.currentVisible = false;
}, 150);
}
|
ab8aaf95
梁灏
add Dropdown comp...
|
113
114
|
},
handleClose () {
|
51f9f894
梁灏
Dropdown add cust...
|
115
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
116
117
118
|
if (this.trigger !== 'click') {
return false;
}
|
b1c118d8
梁灏
support Dropdown
|
119
|
this.currentVisible = false;
|
6b71ba94
梁灏
update Dropdown
|
120
121
|
},
hasParent () {
|
cb6418ac
梁灏
fixed #721
|
122
123
124
|
// const $parent = this.$parent.$parent.$parent;
const $parent = findComponentUpward(this, 'Dropdown');
if ($parent) {
|
6b71ba94
梁灏
update Dropdown
|
125
126
127
128
|
return $parent;
} else {
return false;
}
|
ab8aaf95
梁灏
add Dropdown comp...
|
129
130
|
}
},
|
b1c118d8
梁灏
support Dropdown
|
131
132
|
mounted () {
this.$on('on-click', (key) => {
|
6b71ba94
梁灏
update Dropdown
|
133
|
const $parent = this.hasParent();
|
b1c118d8
梁灏
support Dropdown
|
134
135
136
|
if ($parent) $parent.$emit('on-click', key);
});
this.$on('on-hover-click', () => {
|
6b71ba94
梁灏
update Dropdown
|
137
|
const $parent = this.hasParent();
|
407eabd5
梁灏
update Dropdown
|
138
139
|
if ($parent) {
this.$nextTick(() => {
|
51f9f894
梁灏
Dropdown add cust...
|
140
|
if (this.trigger === 'custom') return false;
|
b1c118d8
梁灏
support Dropdown
|
141
|
this.currentVisible = false;
|
407eabd5
梁灏
update Dropdown
|
142
143
144
145
|
});
$parent.$emit('on-hover-click');
} else {
this.$nextTick(() => {
|
51f9f894
梁灏
Dropdown add cust...
|
146
|
if (this.trigger === 'custom') return false;
|
b1c118d8
梁灏
support Dropdown
|
147
|
this.currentVisible = false;
|
407eabd5
梁灏
update Dropdown
|
148
149
|
});
}
|
b1c118d8
梁灏
support Dropdown
|
150
151
|
});
this.$on('on-haschild-click', () => {
|
6b71ba94
梁灏
update Dropdown
|
152
|
this.$nextTick(() => {
|
51f9f894
梁灏
Dropdown add cust...
|
153
|
if (this.trigger === 'custom') return false;
|
b1c118d8
梁灏
support Dropdown
|
154
|
this.currentVisible = true;
|
6b71ba94
梁灏
update Dropdown
|
155
156
157
|
});
const $parent = this.hasParent();
if ($parent) $parent.$emit('on-haschild-click');
|
b1c118d8
梁灏
support Dropdown
|
158
|
});
|
2d74744d
梁灏
update Dropdown
|
159
|
}
|
b0893113
jingsam
add eslint
|
160
161
|
};
</script>
|