be966e9f
梁灏
add Modal component
|
1
|
<template>
|
548eac43
梁灏
fixed #1387 and u...
|
2
|
<div v-transfer-dom :data-transfer="transfer">
|
672a2805
梁灏
fixed #505
|
3
|
<transition :name="transitionNames[1]">
|
1c7289e9
梁灏
Modal add mask & ...
|
4
|
<div :class="maskClasses" v-show="visible" v-if="showMask" @click="handleMask"></div>
|
6259471f
梁灏
support Modal
|
5
6
|
</transition>
<div :class="wrapClasses" @click="handleWrapClick">
|
f3454b37
marvinwilliam
add modal hidden ...
|
7
|
<transition :name="transitionNames[0]" @after-leave="animationFinish">
|
6259471f
梁灏
support Modal
|
8
|
<div :class="classes" :style="mainStyles" v-show="visible">
|
1c7289e9
梁灏
Modal add mask & ...
|
9
|
<div :class="contentClasses">
|
6259471f
梁灏
support Modal
|
10
11
|
<a :class="[prefixCls + '-close']" v-if="closable" @click="close">
<slot name="close">
|
06a4433d
梁灏
update Modal Icons
|
12
|
<Icon type="ios-close"></Icon>
|
6259471f
梁灏
support Modal
|
13
14
15
16
17
18
|
</slot>
</a>
<div :class="[prefixCls + '-header']" v-if="showHead"><slot name="header"><div :class="[prefixCls + '-header-inner']">{{ title }}</div></slot></div>
<div :class="[prefixCls + '-body']"><slot></slot></div>
<div :class="[prefixCls + '-footer']" v-if="!footerHide">
<slot name="footer">
|
e5337c81
梁灏
fixed some compon...
|
19
20
|
<i-button type="text" size="large" @click.native="cancel">{{ localeCancelText }}</i-button>
<i-button type="primary" size="large" :loading="buttonLoading" @click.native="ok">{{ localeOkText }}</i-button>
|
6259471f
梁灏
support Modal
|
21
22
23
|
</slot>
</div>
</div>
|
be966e9f
梁灏
add Modal component
|
24
|
</div>
|
6259471f
梁灏
support Modal
|
25
|
</transition>
|
be966e9f
梁灏
add Modal component
|
26
|
</div>
|
713bd3d7
梁灏
fixed #583
|
27
|
</div>
|
be966e9f
梁灏
add Modal component
|
28
29
30
|
</template>
<script>
import Icon from '../icon';
|
4b7138b9
梁灏
fixed some bugs
|
31
|
import iButton from '../button/button.vue';
|
713bd3d7
梁灏
fixed #583
|
32
|
import TransferDom from '../../directives/transfer-dom';
|
e5337c81
梁灏
fixed some compon...
|
33
|
import Locale from '../../mixins/locale';
|
67c9b1c8
梁灏
fixed #591
|
34
|
import Emitter from '../../mixins/emitter';
|
297648f1
梁灏
fixed #1063
|
35
|
import ScrollbarMixins from './mixins-scrollbar';
|
be966e9f
梁灏
add Modal component
|
36
37
38
39
|
const prefixCls = 'ivu-modal';
export default {
|
e5337c81
梁灏
fixed some compon...
|
40
|
name: 'Modal',
|
297648f1
梁灏
fixed #1063
|
41
|
mixins: [ Locale, Emitter, ScrollbarMixins ],
|
4b7138b9
梁灏
fixed some bugs
|
42
|
components: { Icon, iButton },
|
713bd3d7
梁灏
fixed #583
|
43
|
directives: { TransferDom },
|
be966e9f
梁灏
add Modal component
|
44
|
props: {
|
6259471f
梁灏
support Modal
|
45
|
value: {
|
be966e9f
梁灏
add Modal component
|
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
type: Boolean,
default: false
},
closable: {
type: Boolean,
default: true
},
maskClosable: {
type: Boolean,
default: true
},
title: {
type: String
},
width: {
type: [Number, String],
default: 520
},
okText: {
|
e5337c81
梁灏
fixed some compon...
|
65
|
type: String
|
be966e9f
梁灏
add Modal component
|
66
67
|
},
cancelText: {
|
e5337c81
梁灏
fixed some compon...
|
68
|
type: String
|
be966e9f
梁灏
add Modal component
|
69
70
71
72
73
|
},
loading: {
type: Boolean,
default: false
},
|
6259471f
梁灏
support Modal
|
74
|
styles: {
|
be966e9f
梁灏
add Modal component
|
75
76
77
78
79
80
81
82
83
|
type: Object
},
className: {
type: String
},
// for instance
footerHide: {
type: Boolean,
default: false
|
f9a2e611
Rijn
added scrolling p...
|
84
|
},
|
5d0b89ce
Rijn
change scrolling ...
|
85
|
scrollable: {
|
f9a2e611
Rijn
added scrolling p...
|
86
87
|
type: Boolean,
default: false
|
672a2805
梁灏
fixed #505
|
88
89
90
91
92
93
|
},
transitionNames: {
type: Array,
default () {
return ['ease', 'fade'];
}
|
548eac43
梁灏
fixed #1387 and u...
|
94
95
96
97
|
},
transfer: {
type: Boolean,
default: true
|
d42d4def
梁灏
Modal add fullscr...
|
98
99
100
101
|
},
fullscreen: {
type: Boolean,
default: false
|
1c7289e9
梁灏
Modal add mask & ...
|
102
103
104
105
106
107
108
109
|
},
mask: {
type: Boolean,
default: true
},
dragable: {
type: Boolean,
default: false
|
be966e9f
梁灏
add Modal component
|
110
111
112
113
114
115
116
|
}
},
data () {
return {
prefixCls: prefixCls,
wrapShow: false,
showHead: true,
|
6259471f
梁灏
support Modal
|
117
118
|
buttonLoading: false,
visible: this.value
|
b0893113
jingsam
add eslint
|
119
|
};
|
be966e9f
梁灏
add Modal component
|
120
121
122
123
124
125
126
|
},
computed: {
wrapClasses () {
return [
`${prefixCls}-wrap`,
{
[`${prefixCls}-hidden`]: !this.wrapShow,
|
1c7289e9
梁灏
Modal add mask & ...
|
127
128
|
[`${this.className}`]: !!this.className,
[`${prefixCls}-no-mask`]: !this.showMask
|
be966e9f
梁灏
add Modal component
|
129
|
}
|
b0893113
jingsam
add eslint
|
130
|
];
|
be966e9f
梁灏
add Modal component
|
131
132
133
134
135
|
},
maskClasses () {
return `${prefixCls}-mask`;
},
classes () {
|
d42d4def
梁灏
Modal add fullscr...
|
136
137
138
139
140
141
|
return [
`${prefixCls}`,
{
[`${prefixCls}-fullscreen`]: this.fullscreen,
[`${prefixCls}-fullscreen-no-header`]: this.fullscreen && !this.showHead,
[`${prefixCls}-fullscreen-no-footer`]: this.fullscreen && this.footerHide
|
1c7289e9
梁灏
Modal add mask & ...
|
142
143
144
145
146
147
148
149
|
}
];
},
contentClasses () {
return [
`${prefixCls}-content`,
{
[`${prefixCls}-content-no-mask`]: !this.showMask
|
d42d4def
梁灏
Modal add fullscr...
|
150
151
|
}
];
|
be966e9f
梁灏
add Modal component
|
152
|
},
|
6259471f
梁灏
support Modal
|
153
|
mainStyles () {
|
be966e9f
梁灏
add Modal component
|
154
155
|
let style = {};
|
f03c4e64
梁灏
Modal update widt...
|
156
|
const width = parseInt(this.width);
|
be966e9f
梁灏
add Modal component
|
157
|
const styleWidth = {
|
f03c4e64
梁灏
Modal update widt...
|
158
|
width: width <= 100 ? `${width}%` : `${width}px`
|
be966e9f
梁灏
add Modal component
|
159
160
|
};
|
6259471f
梁灏
support Modal
|
161
|
const customStyle = this.styles ? this.styles : {};
|
be966e9f
梁灏
add Modal component
|
162
163
164
165
|
Object.assign(style, styleWidth, customStyle);
return style;
|
e5337c81
梁灏
fixed some compon...
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
},
localeOkText () {
if (this.okText === undefined) {
return this.t('i.modal.okText');
} else {
return this.okText;
}
},
localeCancelText () {
if (this.cancelText === undefined) {
return this.t('i.modal.cancelText');
} else {
return this.cancelText;
}
|
1c7289e9
梁灏
Modal add mask & ...
|
180
181
182
|
},
showMask () {
return this.dragable ? false : this.mask;
|
be966e9f
梁灏
add Modal component
|
183
184
185
186
187
|
}
},
methods: {
close () {
this.visible = false;
|
6259471f
梁灏
support Modal
|
188
|
this.$emit('input', false);
|
be966e9f
梁灏
add Modal component
|
189
190
|
this.$emit('on-cancel');
},
|
1c7289e9
梁灏
Modal add mask & ...
|
191
192
|
handleMask () {
if (this.maskClosable && this.showMask) {
|
be966e9f
梁灏
add Modal component
|
193
194
195
|
this.close();
}
},
|
09bce8de
梁灏
update Modal
|
196
197
|
handleWrapClick (event) {
// use indexOf,do not use === ,because ivu-modal-wrap can have other custom className
|
48dd8ebf
梁灏
update Modal
|
198
|
const className = event.target.getAttribute('class');
|
1c7289e9
梁灏
Modal add mask & ...
|
199
|
if (className && className.indexOf(`${prefixCls}-wrap`) > -1) this.handleMask();
|
09bce8de
梁灏
update Modal
|
200
|
},
|
be966e9f
梁灏
add Modal component
|
201
202
203
204
205
206
207
208
|
cancel () {
this.close();
},
ok () {
if (this.loading) {
this.buttonLoading = true;
} else {
this.visible = false;
|
6259471f
梁灏
support Modal
|
209
|
this.$emit('input', false);
|
be966e9f
梁灏
add Modal component
|
210
211
212
213
214
215
|
}
this.$emit('on-ok');
},
EscClose (e) {
if (this.visible && this.closable) {
if (e.keyCode === 27) {
|
b0893113
jingsam
add eslint
|
216
|
this.close();
|
be966e9f
梁灏
add Modal component
|
217
218
219
|
}
}
},
|
f3454b37
marvinwilliam
add modal hidden ...
|
220
221
|
animationFinish() {
this.$emit('on-hidden');
|
be966e9f
梁灏
add Modal component
|
222
223
|
}
},
|
6259471f
梁灏
support Modal
|
224
|
mounted () {
|
be966e9f
梁灏
add Modal component
|
225
226
227
228
229
230
|
if (this.visible) {
this.wrapShow = true;
}
let showHead = true;
|
2ac208b9
梁灏
fixed #407
|
231
|
if (this.$slots.header === undefined && !this.title) {
|
be966e9f
梁灏
add Modal component
|
232
233
234
235
236
237
238
239
240
241
|
showHead = false;
}
this.showHead = showHead;
// ESC close
document.addEventListener('keydown', this.EscClose);
},
beforeDestroy () {
document.removeEventListener('keydown', this.EscClose);
|
727b795c
梁灏
reset body scroll...
|
242
|
this.removeScrollEffect();
|
be966e9f
梁灏
add Modal component
|
243
244
|
},
watch: {
|
6259471f
梁灏
support Modal
|
245
246
|
value (val) {
this.visible = val;
|
6259471f
梁灏
support Modal
|
247
|
},
|
be966e9f
梁灏
add Modal component
|
248
249
250
|
visible (val) {
if (val === false) {
this.buttonLoading = false;
|
e011898c
梁灏
fixed #197
|
251
|
this.timer = setTimeout(() => {
|
be966e9f
梁灏
add Modal component
|
252
|
this.wrapShow = false;
|
9084eb18
梁灏
fixed #92
|
253
|
this.removeScrollEffect();
|
be966e9f
梁灏
add Modal component
|
254
|
}, 300);
|
be966e9f
梁灏
add Modal component
|
255
|
} else {
|
e011898c
梁灏
fixed #197
|
256
|
if (this.timer) clearTimeout(this.timer);
|
be966e9f
梁灏
add Modal component
|
257
|
this.wrapShow = true;
|
5d0b89ce
Rijn
change scrolling ...
|
258
|
if (!this.scrollable) {
|
f9a2e611
Rijn
added scrolling p...
|
259
260
|
this.addScrollEffect();
}
|
be966e9f
梁灏
add Modal component
|
261
|
}
|
67c9b1c8
梁灏
fixed #591
|
262
|
this.broadcast('Table', 'on-visible-change', val);
|
2eccfc99
梁灏
fixed #2852
|
263
|
this.broadcast('Slider', 'on-visible-change', val); // #2852
|
d1f698ca
yangdan8
Modal弹窗请添加on-visi...
|
264
|
this.$emit('on-visible-change', val);
|
3c01d81a
梁灏
fixed Modal bug,w...
|
265
266
267
268
269
|
},
loading (val) {
if (!val) {
this.buttonLoading = false;
}
|
f9a2e611
Rijn
added scrolling p...
|
270
|
},
|
5d0b89ce
Rijn
change scrolling ...
|
271
|
scrollable (val) {
|
f346ce4b
Rijn
lint fix
|
272
|
if (!val) {
|
f9a2e611
Rijn
added scrolling p...
|
273
274
275
276
|
this.addScrollEffect();
} else {
this.removeScrollEffect();
}
|
f024ab82
H
修复modal标题属性首次如果没有...
|
277
278
279
|
},
title (val) {
if (this.$slots.header === undefined) {
|
c5625bfd
梁灏
update Modal
|
280
|
this.showHead = !!val;
|
f024ab82
H
修复modal标题属性首次如果没有...
|
281
|
}
|
be966e9f
梁灏
add Modal component
|
282
283
|
}
}
|
b0893113
jingsam
add eslint
|
284
|
};
|
d6342fe1
jingsam
fixed ie bug
|
285
|
</script>
|