9699c270
梁灏
add Poptip component
|
1
2
3
4
5
|
<template>
<div
:class="classes"
@mouseenter="handleMouseenter"
@mouseleave="handleMouseleave"
|
69c2de7a
Роман Ковжогин
iOS click-outside...
|
6
7
|
v-click-outside="handleClose"
v-click-outside:touchstart="handleClose">
|
9699c270
梁灏
add Poptip component
|
8
|
<div
|
d6342fe1
jingsam
fixed ie bug
|
9
|
:class="[prefixCls + '-rel']"
|
79288d43
梁灏
support Poptip & ...
|
10
|
ref="reference"
|
9699c270
梁灏
add Poptip component
|
11
|
@click="handleClick"
|
071506fc
梁灏
optimize Poptip f...
|
12
13
|
@mousedown="handleFocus(false)"
@mouseup="handleBlur(false)">
|
9699c270
梁灏
add Poptip component
|
14
15
|
<slot></slot>
</div>
|
79288d43
梁灏
support Poptip & ...
|
16
|
<transition name="fade">
|
fcf3cace
梁灏
Poptip & Tooltip ...
|
17
|
<div
|
1d83a8aa
梁灏
fixed #1612
|
18
|
:class="popperClasses"
|
fcf3cace
梁灏
Poptip & Tooltip ...
|
19
20
21
|
:style="styles"
ref="popper"
v-show="visible"
|
b75ad4a1
梁灏
fixed #1700
|
22
|
@click="handleTransferClick"
|
fcf3cace
梁灏
Poptip & Tooltip ...
|
23
24
|
@mouseenter="handleMouseenter"
@mouseleave="handleMouseleave"
|
548eac43
梁灏
fixed #1387 and u...
|
25
26
|
:data-transfer="transfer"
v-transfer-dom>
|
79288d43
梁灏
support Poptip & ...
|
27
28
29
30
|
<div :class="[prefixCls + '-content']">
<div :class="[prefixCls + '-arrow']"></div>
<div :class="[prefixCls + '-inner']" v-if="confirm">
<div :class="[prefixCls + '-body']">
|
e64ee85c
梁灏
update Poptip Icons
|
31
|
<i class="ivu-icon ivu-icon-ios-help-circle"></i>
|
79288d43
梁灏
support Poptip & ...
|
32
33
34
|
<div :class="[prefixCls + '-body-message']"><slot name="title">{{ title }}</slot></div>
</div>
<div :class="[prefixCls + '-footer']">
|
e5337c81
梁灏
fixed some compon...
|
35
36
|
<i-button type="text" size="small" @click.native="cancel">{{ localeCancelText }}</i-button>
<i-button type="primary" size="small" @click.native="ok">{{ localeOkText }}</i-button>
|
79288d43
梁灏
support Poptip & ...
|
37
|
</div>
|
9699c270
梁灏
add Poptip component
|
38
|
</div>
|
79288d43
梁灏
support Poptip & ...
|
39
|
<div :class="[prefixCls + '-inner']" v-if="!confirm">
|
a980832f
梁灏
Poptip add paddin...
|
40
41
|
<div :class="[prefixCls + '-title']" :style="contentPaddingStyle" v-if="showTitle" ref="title"><slot name="title"><div :class="[prefixCls + '-title-inner']">{{ title }}</div></slot></div>
<div :class="[prefixCls + '-body']" :style="contentPaddingStyle">
|
130ed889
梁灏
Poptip add prop w...
|
42
|
<div :class="contentClasses"><slot name="content"><div :class="[prefixCls + '-body-content-inner']">{{ content }}</div></slot></div>
|
79288d43
梁灏
support Poptip & ...
|
43
|
</div>
|
613f5243
梁灏
update Poptip
|
44
|
</div>
|
9699c270
梁灏
add Poptip component
|
45
46
|
</div>
</div>
|
79288d43
梁灏
support Poptip & ...
|
47
|
</transition>
|
9699c270
梁灏
add Poptip component
|
48
49
50
51
|
</div>
</template>
<script>
import Popper from '../base/popper';
|
4b7138b9
梁灏
fixed some bugs
|
52
|
import iButton from '../button/button.vue';
|
26369639
Graham Fairweather
Update v-click-ou...
|
53
|
import {directive as clickOutside} from 'v-click-outside-x';
|
fcf3cace
梁灏
Poptip & Tooltip ...
|
54
|
import TransferDom from '../../directives/transfer-dom';
|
9699c270
梁灏
add Poptip component
|
55
|
import { oneOf } from '../../utils/assist';
|
7bafe9d9
梁灏
fixes #4453 #4480...
|
56
|
import { transferIndex, transferIncrease } from '../../utils/transfer-queue';
|
e5337c81
梁灏
fixed some compon...
|
57
|
import Locale from '../../mixins/locale';
|
9699c270
梁灏
add Poptip component
|
58
59
60
61
|
const prefixCls = 'ivu-poptip';
export default {
|
79288d43
梁灏
support Poptip & ...
|
62
|
name: 'Poptip',
|
e5337c81
梁灏
fixed some compon...
|
63
|
mixins: [ Popper, Locale ],
|
26369639
Graham Fairweather
Update v-click-ou...
|
64
|
directives: { clickOutside, TransferDom },
|
4b7138b9
梁灏
fixed some bugs
|
65
|
components: { iButton },
|
9699c270
梁灏
add Poptip component
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
props: {
trigger: {
validator (value) {
return oneOf(value, ['click', 'focus', 'hover']);
},
default: 'click'
},
placement: {
validator (value) {
return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
},
default: 'top'
},
title: {
type: [String, Number]
},
content: {
type: [String, Number],
default: ''
},
width: {
type: [String, Number]
},
confirm: {
type: Boolean,
default: false
},
okText: {
|
e5337c81
梁灏
fixed some compon...
|
94
|
type: String
|
9699c270
梁灏
add Poptip component
|
95
96
|
},
cancelText: {
|
e5337c81
梁灏
fixed some compon...
|
97
|
type: String
|
fcf3cace
梁灏
Poptip & Tooltip ...
|
98
99
100
|
},
transfer: {
type: Boolean,
|
d54c9795
梁灏
Poptip support gl...
|
101
|
default () {
|
fe5ffd7f
梁灏
fixed #4196 #4165
|
102
|
return !this.$IVIEW || this.$IVIEW.transfer === '' ? false : this.$IVIEW.transfer;
|
d54c9795
梁灏
Poptip support gl...
|
103
|
}
|
19c208d3
梁灏
Poptip add prop `...
|
104
105
106
|
},
popperClass: {
type: String
|
130ed889
梁灏
Poptip add prop w...
|
107
108
109
110
|
},
wordWrap: {
type: Boolean,
default: false
|
a980832f
梁灏
Poptip add paddin...
|
111
112
113
114
|
},
// default by css: 8px 16px
padding: {
type: String
|
9699c270
梁灏
add Poptip component
|
115
116
117
118
|
}
},
data () {
return {
|
88bb7c92
梁灏
fix bug of Poptip
|
119
|
prefixCls: prefixCls,
|
071506fc
梁灏
optimize Poptip f...
|
120
|
showTitle: true,
|
b75ad4a1
梁灏
fixed #1700
|
121
122
|
isInput: false,
disableCloseUnderTransfer: false, // transfer 模式下,点击 slot 也会触发关闭
|
7bafe9d9
梁灏
fixes #4453 #4480...
|
123
|
tIndex: this.handleGetIndex()
|
b0893113
jingsam
add eslint
|
124
|
};
|
9699c270
梁灏
add Poptip component
|
125
126
127
128
|
},
computed: {
classes () {
return [
|
4b7138b9
梁灏
fixed some bugs
|
129
|
`${prefixCls}`,
|
9699c270
梁灏
add Poptip component
|
130
|
{
|
4b7138b9
梁灏
fixed some bugs
|
131
|
[`${prefixCls}-confirm`]: this.confirm
|
9699c270
梁灏
add Poptip component
|
132
|
}
|
b0893113
jingsam
add eslint
|
133
|
];
|
9699c270
梁灏
add Poptip component
|
134
|
},
|
1d83a8aa
梁灏
fixed #1612
|
135
136
137
138
|
popperClasses () {
return [
`${prefixCls}-popper`,
{
|
19c208d3
梁灏
Poptip add prop `...
|
139
140
|
[`${prefixCls}-confirm`]: this.transfer && this.confirm,
[`${this.popperClass}`]: !!this.popperClass
|
1d83a8aa
梁灏
fixed #1612
|
141
142
143
|
}
];
},
|
9699c270
梁灏
add Poptip component
|
144
145
146
|
styles () {
let style = {};
|
b0893113
jingsam
add eslint
|
147
|
if (this.width) {
|
4b7138b9
梁灏
fixed some bugs
|
148
|
style.width = `${this.width}px`;
|
9699c270
梁灏
add Poptip component
|
149
|
}
|
7bafe9d9
梁灏
fixes #4453 #4480...
|
150
151
152
|
if (this.transfer) style['z-index'] = 1060 + this.tIndex;
|
9699c270
梁灏
add Poptip component
|
153
|
return style;
|
e5337c81
梁灏
fixed some compon...
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
},
localeOkText () {
if (this.okText === undefined) {
return this.t('i.poptip.okText');
} else {
return this.okText;
}
},
localeCancelText () {
if (this.cancelText === undefined) {
return this.t('i.poptip.cancelText');
} else {
return this.cancelText;
}
|
130ed889
梁灏
Poptip add prop w...
|
168
169
170
171
172
173
174
175
|
},
contentClasses () {
return [
`${prefixCls}-body-content`,
{
[`${prefixCls}-body-content-word-wrap`]: this.wordWrap
}
];
|
a980832f
梁灏
Poptip add paddin...
|
176
177
178
|
},
contentPaddingStyle () {
const styles = {};
|
855d4940
梁灏
Tag add more colo...
|
179
|
if (this.padding !== '') styles['padding'] = this.padding;
|
a980832f
梁灏
Poptip add paddin...
|
180
|
return styles;
|
7bafe9d9
梁灏
fixes #4453 #4480...
|
181
|
},
|
9699c270
梁灏
add Poptip component
|
182
183
184
185
186
187
188
189
190
191
192
193
|
},
methods: {
handleClick () {
if (this.confirm) {
this.visible = !this.visible;
return true;
}
if (this.trigger !== 'click') {
return false;
}
this.visible = !this.visible;
},
|
b75ad4a1
梁灏
fixed #1700
|
194
195
196
|
handleTransferClick () {
if (this.transfer) this.disableCloseUnderTransfer = true;
},
|
9699c270
梁灏
add Poptip component
|
197
|
handleClose () {
|
b75ad4a1
梁灏
fixed #1700
|
198
199
200
201
|
if (this.disableCloseUnderTransfer) {
this.disableCloseUnderTransfer = false;
return false;
}
|
9699c270
梁灏
add Poptip component
|
202
203
204
205
206
207
208
209
210
|
if (this.confirm) {
this.visible = false;
return true;
}
if (this.trigger !== 'click') {
return false;
}
this.visible = false;
},
|
071506fc
梁灏
optimize Poptip f...
|
211
212
|
handleFocus (fromInput = true) {
if (this.trigger !== 'focus' || this.confirm || (this.isInput && !fromInput)) {
|
9699c270
梁灏
add Poptip component
|
213
214
215
216
|
return false;
}
this.visible = true;
},
|
071506fc
梁灏
optimize Poptip f...
|
217
218
|
handleBlur (fromInput = true) {
if (this.trigger !== 'focus' || this.confirm || (this.isInput && !fromInput)) {
|
9699c270
梁灏
add Poptip component
|
219
220
221
222
223
224
225
226
|
return false;
}
this.visible = false;
},
handleMouseenter () {
if (this.trigger !== 'hover' || this.confirm) {
return false;
}
|
fcf3cace
梁灏
Poptip & Tooltip ...
|
227
228
229
230
|
if (this.enterTimer) clearTimeout(this.enterTimer);
this.enterTimer = setTimeout(() => {
this.visible = true;
}, 100);
|
9699c270
梁灏
add Poptip component
|
231
232
233
234
235
|
},
handleMouseleave () {
if (this.trigger !== 'hover' || this.confirm) {
return false;
}
|
fcf3cace
梁灏
Poptip & Tooltip ...
|
236
237
238
239
240
241
|
if (this.enterTimer) {
clearTimeout(this.enterTimer);
this.enterTimer = setTimeout(() => {
this.visible = false;
}, 100);
}
|
9699c270
梁灏
add Poptip component
|
242
243
244
245
246
247
248
249
|
},
cancel () {
this.visible = false;
this.$emit('on-cancel');
},
ok () {
this.visible = false;
this.$emit('on-ok');
|
071506fc
梁灏
optimize Poptip f...
|
250
251
|
},
getInputChildren () {
|
79288d43
梁灏
support Poptip & ...
|
252
253
|
const $input = this.$refs.reference.querySelectorAll('input');
const $textarea = this.$refs.reference.querySelectorAll('textarea');
|
071506fc
梁灏
optimize Poptip f...
|
254
255
256
257
258
259
260
261
262
|
let $children = null;
if ($input.length) {
$children = $input[0];
} else if ($textarea.length) {
$children = $textarea[0];
}
return $children;
|
7bafe9d9
梁灏
fixes #4453 #4480...
|
263
264
265
266
267
268
269
|
},
handleGetIndex () {
transferIncrease();
return transferIndex;
},
handleIndexIncrease () {
this.tIndex = this.handleGetIndex();
|
9699c270
梁灏
add Poptip component
|
270
|
}
|
88bb7c92
梁灏
fix bug of Poptip
|
271
|
},
|
79288d43
梁灏
support Poptip & ...
|
272
|
mounted () {
|
88bb7c92
梁灏
fix bug of Poptip
|
273
|
if (!this.confirm) {
|
79288d43
梁灏
support Poptip & ...
|
274
|
// this.showTitle = this.$refs.title.innerHTML != `<div class="${prefixCls}-title-inner"></div>`;
|
8e7ac210
Aresn
fixed #1222
|
275
|
this.showTitle = (this.$slots.title !== undefined) || this.title;
|
88bb7c92
梁灏
fix bug of Poptip
|
276
|
}
|
071506fc
梁灏
optimize Poptip f...
|
277
278
|
// if trigger and children is input or textarea,listen focus & blur event
if (this.trigger === 'focus') {
|
b8adf5cf
Aresn
fixed #1101
|
279
280
281
|
this.$nextTick(() => {
const $children = this.getInputChildren();
if ($children) {
|
8e7ac210
Aresn
fixed #1222
|
282
|
this.isInput = true;
|
b8adf5cf
Aresn
fixed #1101
|
283
284
285
286
|
$children.addEventListener('focus', this.handleFocus, false);
$children.addEventListener('blur', this.handleBlur, false);
}
});
|
071506fc
梁灏
optimize Poptip f...
|
287
288
289
290
291
292
293
294
|
}
},
beforeDestroy () {
const $children = this.getInputChildren();
if ($children) {
$children.removeEventListener('focus', this.handleFocus, false);
$children.removeEventListener('blur', this.handleBlur, false);
}
|
9699c270
梁灏
add Poptip component
|
295
|
}
|
b0893113
jingsam
add eslint
|
296
|
};
|
d6342fe1
jingsam
fixed ie bug
|
297
|
</script>
|