be966e9f
梁灏
add Modal component
|
1
2
3
4
|
<template>
<div :class="wrapClasses">
<div :class="maskClasses" v-show="visible" @click="mask" transition="fade"></div>
<div :class="classes" :style="styles" v-show="visible" transition="ease">
|
3336334e
梁灏
Support IE9、10、11
|
5
|
<div :class="[prefixCls + '-content']">
|
d6342fe1
jingsam
fixed ie bug
|
6
|
<a :class="[prefixCls + '-close']" v-if="closable" @click="close">
|
be966e9f
梁灏
add Modal component
|
7
8
9
10
|
<slot name="close">
<Icon type="ios-close-empty"></Icon>
</slot>
</a>
|
09a04302
梁灏
optimize Modal style
|
11
|
<div :class="[prefixCls + '-header']" v-if="showHead" v-el:head><slot name="header"><div :class="[prefixCls + '-header-inner']">{{ title }}</div></slot></div>
|
d6342fe1
jingsam
fixed ie bug
|
12
13
|
<div :class="[prefixCls + '-body']"><slot></slot></div>
<div :class="[prefixCls + '-footer']" v-if="!footerHide">
|
be966e9f
梁灏
add Modal component
|
14
|
<slot name="footer">
|
66993732
梁灏
update Modal、Poptip
|
15
|
<i-button type="text" size="large" @click="cancel">{{ cancelText }}</i-button>
|
4b7138b9
梁灏
fixed some bugs
|
16
|
<i-button type="primary" size="large" :loading="buttonLoading" @click="ok">{{ okText }}</i-button>
|
be966e9f
梁灏
add Modal component
|
17
18
19
20
21
22
23
24
|
</slot>
</div>
</div>
</div>
</div>
</template>
<script>
import Icon from '../icon';
|
4b7138b9
梁灏
fixed some bugs
|
25
|
import iButton from '../button/button.vue';
|
be966e9f
梁灏
add Modal component
|
26
|
import { getScrollBarSize } from '../../utils/assist';
|
012cbf28
梁灏
update locale
|
27
|
import { t } from '../../locale';
|
be966e9f
梁灏
add Modal component
|
28
29
30
31
|
const prefixCls = 'ivu-modal';
export default {
|
4b7138b9
梁灏
fixed some bugs
|
32
|
components: { Icon, iButton },
|
be966e9f
梁灏
add Modal component
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
props: {
visible: {
type: Boolean,
default: false
},
closable: {
type: Boolean,
default: true
},
maskClosable: {
type: Boolean,
default: true
},
title: {
type: String
},
width: {
type: [Number, String],
default: 520
},
okText: {
type: String,
|
012cbf28
梁灏
update locale
|
55
56
57
|
default () {
return t('i.modal.okText');
}
|
be966e9f
梁灏
add Modal component
|
58
59
60
|
},
cancelText: {
type: String,
|
012cbf28
梁灏
update locale
|
61
62
63
|
default () {
return t('i.modal.cancelText');
}
|
be966e9f
梁灏
add Modal component
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
},
loading: {
type: Boolean,
default: false
},
style: {
type: Object
},
className: {
type: String
},
// for instance
footerHide: {
type: Boolean,
default: false
|
f9a2e611
Rijn
added scrolling p...
|
79
|
},
|
5d0b89ce
Rijn
change scrolling ...
|
80
|
scrollable: {
|
f9a2e611
Rijn
added scrolling p...
|
81
82
|
type: Boolean,
default: false
|
be966e9f
梁灏
add Modal component
|
83
84
85
86
87
88
89
90
|
}
},
data () {
return {
prefixCls: prefixCls,
wrapShow: false,
showHead: true,
buttonLoading: false
|
b0893113
jingsam
add eslint
|
91
|
};
|
be966e9f
梁灏
add Modal component
|
92
93
94
95
96
97
98
99
100
|
},
computed: {
wrapClasses () {
return [
`${prefixCls}-wrap`,
{
[`${prefixCls}-hidden`]: !this.wrapShow,
[`${this.className}`]: !!this.className
}
|
b0893113
jingsam
add eslint
|
101
|
];
|
be966e9f
梁灏
add Modal component
|
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
},
maskClasses () {
return `${prefixCls}-mask`;
},
classes () {
return `${prefixCls}`;
},
styles () {
let style = {};
const styleWidth = {
width: `${this.width}px`
};
|
b0893113
jingsam
add eslint
|
116
|
const customStyle = this.style ? this.style : {};
|
be966e9f
梁灏
add Modal component
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
Object.assign(style, styleWidth, customStyle);
return style;
}
},
methods: {
close () {
this.visible = false;
this.$emit('on-cancel');
},
mask () {
if (this.maskClosable) {
this.close();
}
},
cancel () {
this.close();
},
ok () {
if (this.loading) {
this.buttonLoading = true;
} else {
this.visible = false;
}
this.$emit('on-ok');
},
EscClose (e) {
if (this.visible && this.closable) {
if (e.keyCode === 27) {
|
b0893113
jingsam
add eslint
|
147
|
this.close();
|
be966e9f
梁灏
add Modal component
|
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
}
}
},
checkScrollBar () {
let fullWindowWidth = window.innerWidth;
if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
const documentElementRect = document.documentElement.getBoundingClientRect();
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
}
this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;
if (this.bodyIsOverflowing) {
this.scrollBarWidth = getScrollBarSize();
}
},
setScrollBar () {
if (this.bodyIsOverflowing && this.scrollBarWidth !== undefined) {
document.body.style.paddingRight = `${this.scrollBarWidth}px`;
}
},
resetScrollBar () {
document.body.style.paddingRight = '';
},
addScrollEffect () {
this.checkScrollBar();
this.setScrollBar();
document.body.style.overflow = 'hidden';
},
removeScrollEffect() {
document.body.style.overflow = '';
this.resetScrollBar();
}
},
ready () {
if (this.visible) {
this.wrapShow = true;
}
let showHead = true;
|
09a04302
梁灏
optimize Modal style
|
187
|
if (this.$els.head.innerHTML == `<div class="${prefixCls}-header-inner"></div>` && !this.title) {
|
be966e9f
梁灏
add Modal component
|
188
189
190
191
192
193
194
195
196
197
|
showHead = false;
}
this.showHead = showHead;
// ESC close
document.addEventListener('keydown', this.EscClose);
},
beforeDestroy () {
document.removeEventListener('keydown', this.EscClose);
|
727b795c
梁灏
reset body scroll...
|
198
|
this.removeScrollEffect();
|
be966e9f
梁灏
add Modal component
|
199
200
201
202
203
|
},
watch: {
visible (val) {
if (val === false) {
this.buttonLoading = false;
|
e011898c
梁灏
fixed #197
|
204
|
this.timer = setTimeout(() => {
|
be966e9f
梁灏
add Modal component
|
205
|
this.wrapShow = false;
|
9084eb18
梁灏
fixed #92
|
206
|
this.removeScrollEffect();
|
be966e9f
梁灏
add Modal component
|
207
|
}, 300);
|
be966e9f
梁灏
add Modal component
|
208
|
} else {
|
e011898c
梁灏
fixed #197
|
209
|
if (this.timer) clearTimeout(this.timer);
|
be966e9f
梁灏
add Modal component
|
210
|
this.wrapShow = true;
|
5d0b89ce
Rijn
change scrolling ...
|
211
|
if (!this.scrollable) {
|
f9a2e611
Rijn
added scrolling p...
|
212
213
|
this.addScrollEffect();
}
|
be966e9f
梁灏
add Modal component
|
214
|
}
|
3c01d81a
梁灏
fixed Modal bug,w...
|
215
216
217
218
219
|
},
loading (val) {
if (!val) {
this.buttonLoading = false;
}
|
f9a2e611
Rijn
added scrolling p...
|
220
|
},
|
5d0b89ce
Rijn
change scrolling ...
|
221
|
scrollable (val) {
|
f346ce4b
Rijn
lint fix
|
222
|
if (!val) {
|
f9a2e611
Rijn
added scrolling p...
|
223
224
225
226
|
this.addScrollEffect();
} else {
this.removeScrollEffect();
}
|
be966e9f
梁灏
add Modal component
|
227
228
|
}
}
|
b0893113
jingsam
add eslint
|
229
|
};
|
d6342fe1
jingsam
fixed ie bug
|
230
|
</script>
|