ab8aaf95
梁灏
add Dropdown comp...
|
1
2
3
|
<template>
<div
:class="[prefixCls]"
|
26369639
Graham Fairweather
Update v-click-ou...
|
4
|
v-click-outside="onClickoutside"
|
ab8aaf95
梁灏
add Dropdown comp...
|
5
|
@mouseenter="handleMouseenter"
|
407eabd5
梁灏
update Dropdown
|
6
|
@mouseleave="handleMouseleave">
|
eccaa940
梁灏
Dropdown add new ...
|
7
|
<div :class="relClasses" ref="reference" @click="handleClick" @contextmenu.prevent="handleRightClick"><slot></slot></div>
|
e09b07b7
huanghong
解决drop弹出动画异常
|
8
|
<transition name="transition-drop">
|
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
|
:data-transfer="transfer"
|
7bafe9d9
梁灏
fixes #4453 #4480...
|
17
|
:transfer="transfer"
|
548eac43
梁灏
fixed #1387 and u...
|
18
|
v-transfer-dom><slot name="list"></slot></Drop>
|
b1c118d8
梁灏
support Dropdown
|
19
|
</transition>
|
ab8aaf95
梁灏
add Dropdown comp...
|
20
21
22
23
|
</div>
</template>
<script>
import Drop from '../select/dropdown.vue';
|
26369639
Graham Fairweather
Update v-click-ou...
|
24
|
import {directive as clickOutside} from 'v-click-outside-x';
|
3e4bab96
梁灏
Dropdown add tran...
|
25
|
import TransferDom from '../../directives/transfer-dom';
|
cb6418ac
梁灏
fixed #721
|
26
|
import { oneOf, findComponentUpward } from '../../utils/assist';
|
ab8aaf95
梁灏
add Dropdown comp...
|
27
28
29
30
|
const prefixCls = 'ivu-dropdown';
export default {
|
745bcbc2
梁灏
update Dropdown
|
31
|
name: 'Dropdown',
|
26369639
Graham Fairweather
Update v-click-ou...
|
32
|
directives: { clickOutside, TransferDom },
|
ab8aaf95
梁灏
add Dropdown comp...
|
33
34
35
36
|
components: { Drop },
props: {
trigger: {
validator (value) {
|
eccaa940
梁灏
Dropdown add new ...
|
37
|
return oneOf(value, ['click', 'hover', 'custom', 'contextMenu']);
|
ab8aaf95
梁灏
add Dropdown comp...
|
38
39
40
|
},
default: 'hover'
},
|
745bcbc2
梁灏
update Dropdown
|
41
|
placement: {
|
ab8aaf95
梁灏
add Dropdown comp...
|
42
|
validator (value) {
|
745bcbc2
梁灏
update Dropdown
|
43
|
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...
|
44
|
},
|
745bcbc2
梁灏
update Dropdown
|
45
|
default: 'bottom'
|
51f9f894
梁灏
Dropdown add cust...
|
46
47
48
49
|
},
visible: {
type: Boolean,
default: false
|
3e4bab96
梁灏
Dropdown add tran...
|
50
51
52
|
},
transfer: {
type: Boolean,
|
262c8524
梁灏
Dropdown support ...
|
53
|
default () {
|
fe5ffd7f
梁灏
fixed #4196 #4165
|
54
|
return !this.$IVIEW || this.$IVIEW.transfer === '' ? false : this.$IVIEW.transfer;
|
262c8524
梁灏
Dropdown support ...
|
55
|
}
|
da0f6770
梁灏
Dropdown add prop...
|
56
57
58
59
|
},
transferClassName: {
type: String
},
|
ab8aaf95
梁灏
add Dropdown comp...
|
60
|
},
|
407eabd5
梁灏
update Dropdown
|
61
62
63
|
computed: {
transition () {
return ['bottom-start', 'bottom', 'bottom-end'].indexOf(this.placement) > -1 ? 'slide-up' : 'fade';
|
f1800986
梁灏
update Dropdown cls
|
64
65
66
|
},
dropdownCls () {
return {
|
da0f6770
梁灏
Dropdown add prop...
|
67
68
|
[prefixCls + '-transfer']: this.transfer,
[this.transferClassName]: this.transferClassName
|
f1800986
梁灏
update Dropdown cls
|
69
|
};
|
eccaa940
梁灏
Dropdown add new ...
|
70
71
72
73
74
75
76
77
|
},
relClasses () {
return [
`${prefixCls}-rel`,
{
[`${prefixCls}-rel-user-select-none`]: this.trigger === 'contextMenu'
}
];
|
407eabd5
梁灏
update Dropdown
|
78
79
|
}
},
|
ab8aaf95
梁灏
add Dropdown comp...
|
80
81
|
data () {
return {
|
b1c118d8
梁灏
support Dropdown
|
82
83
|
prefixCls: prefixCls,
currentVisible: this.visible
|
b0893113
jingsam
add eslint
|
84
|
};
|
ab8aaf95
梁灏
add Dropdown comp...
|
85
|
},
|
b1c118d8
梁灏
support Dropdown
|
86
87
88
89
90
91
92
93
94
95
96
97
98
|
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...
|
99
100
|
methods: {
handleClick () {
|
51f9f894
梁灏
Dropdown add cust...
|
101
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
102
103
104
|
if (this.trigger !== 'click') {
return false;
}
|
b1c118d8
梁灏
support Dropdown
|
105
|
this.currentVisible = !this.currentVisible;
|
ab8aaf95
梁灏
add Dropdown comp...
|
106
|
},
|
eccaa940
梁灏
Dropdown add new ...
|
107
108
109
110
111
112
113
|
handleRightClick () {
if (this.trigger === 'custom') return false;
if (this.trigger !== 'contextMenu') {
return false;
}
this.currentVisible = !this.currentVisible;
},
|
ab8aaf95
梁灏
add Dropdown comp...
|
114
|
handleMouseenter () {
|
51f9f894
梁灏
Dropdown add cust...
|
115
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
116
117
118
|
if (this.trigger !== 'hover') {
return false;
}
|
3e4bab96
梁灏
Dropdown add tran...
|
119
|
if (this.timeout) clearTimeout(this.timeout);
|
ab8aaf95
梁灏
add Dropdown comp...
|
120
|
this.timeout = setTimeout(() => {
|
b1c118d8
梁灏
support Dropdown
|
121
|
this.currentVisible = true;
|
ab8aaf95
梁灏
add Dropdown comp...
|
122
123
124
|
}, 250);
},
handleMouseleave () {
|
51f9f894
梁灏
Dropdown add cust...
|
125
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
126
127
128
|
if (this.trigger !== 'hover') {
return false;
}
|
3e4bab96
梁灏
Dropdown add tran...
|
129
130
131
132
133
134
|
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.currentVisible = false;
}, 150);
}
|
ab8aaf95
梁灏
add Dropdown comp...
|
135
|
},
|
526a142c
Sergio Crisostomo
add click outside...
|
136
137
|
onClickoutside (e) {
this.handleClose();
|
eccaa940
梁灏
Dropdown add new ...
|
138
|
this.handleRightClose();
|
526a142c
Sergio Crisostomo
add click outside...
|
139
140
|
if (this.currentVisible) this.$emit('on-clickoutside', e);
},
|
ab8aaf95
梁灏
add Dropdown comp...
|
141
|
handleClose () {
|
51f9f894
梁灏
Dropdown add cust...
|
142
|
if (this.trigger === 'custom') return false;
|
ab8aaf95
梁灏
add Dropdown comp...
|
143
144
145
|
if (this.trigger !== 'click') {
return false;
}
|
b1c118d8
梁灏
support Dropdown
|
146
|
this.currentVisible = false;
|
6b71ba94
梁灏
update Dropdown
|
147
|
},
|
eccaa940
梁灏
Dropdown add new ...
|
148
149
150
151
152
153
154
|
handleRightClose () {
if (this.trigger === 'custom') return false;
if (this.trigger !== 'contextMenu') {
return false;
}
this.currentVisible = false;
},
|
6b71ba94
梁灏
update Dropdown
|
155
|
hasParent () {
|
cb6418ac
梁灏
fixed #721
|
156
157
158
|
// const $parent = this.$parent.$parent.$parent;
const $parent = findComponentUpward(this, 'Dropdown');
if ($parent) {
|
6b71ba94
梁灏
update Dropdown
|
159
160
161
162
|
return $parent;
} else {
return false;
}
|
ab8aaf95
梁灏
add Dropdown comp...
|
163
164
|
}
},
|
b1c118d8
梁灏
support Dropdown
|
165
166
|
mounted () {
this.$on('on-click', (key) => {
|
6b71ba94
梁灏
update Dropdown
|
167
|
const $parent = this.hasParent();
|
b1c118d8
梁灏
support Dropdown
|
168
169
170
|
if ($parent) $parent.$emit('on-click', key);
});
this.$on('on-hover-click', () => {
|
6b71ba94
梁灏
update Dropdown
|
171
|
const $parent = this.hasParent();
|
407eabd5
梁灏
update Dropdown
|
172
173
|
if ($parent) {
this.$nextTick(() => {
|
51f9f894
梁灏
Dropdown add cust...
|
174
|
if (this.trigger === 'custom') return false;
|
b1c118d8
梁灏
support Dropdown
|
175
|
this.currentVisible = false;
|
407eabd5
梁灏
update Dropdown
|
176
177
178
179
|
});
$parent.$emit('on-hover-click');
} else {
this.$nextTick(() => {
|
51f9f894
梁灏
Dropdown add cust...
|
180
|
if (this.trigger === 'custom') return false;
|
b1c118d8
梁灏
support Dropdown
|
181
|
this.currentVisible = false;
|
407eabd5
梁灏
update Dropdown
|
182
183
|
});
}
|
b1c118d8
梁灏
support Dropdown
|
184
185
|
});
this.$on('on-haschild-click', () => {
|
6b71ba94
梁灏
update Dropdown
|
186
|
this.$nextTick(() => {
|
51f9f894
梁灏
Dropdown add cust...
|
187
|
if (this.trigger === 'custom') return false;
|
b1c118d8
梁灏
support Dropdown
|
188
|
this.currentVisible = true;
|
6b71ba94
梁灏
update Dropdown
|
189
190
191
|
});
const $parent = this.hasParent();
if ($parent) $parent.$emit('on-haschild-click');
|
b1c118d8
梁灏
support Dropdown
|
192
|
});
|
2d74744d
梁灏
update Dropdown
|
193
|
}
|
b0893113
jingsam
add eslint
|
194
195
|
};
</script>
|