c4d780c0
梁灏
init Drawer compo...
|
1
|
<template>
|
f59e6e89
梁灏
update Drawer
|
2
3
|
<div v-transfer-dom :data-transfer="transfer">
<transition name="fade">
|
8a3c7282
梁灏
add inner prop
|
4
|
<div :class="maskClasses" :style="maskStyle" v-show="visible" v-if="mask" @click="handleMask"></div>
|
f59e6e89
梁灏
update Drawer
|
5
6
|
</transition>
<div :class="wrapClasses" @click="handleWrapClick">
|
ab58648e
梁灏
update Drawer
|
7
8
|
<transition :name="'move-' + placement">
<div :class="classes" :style="mainStyles" v-show="visible">
|
1416321b
梁灏
update Drawer
|
9
|
<div :class="contentClasses" ref="content">
|
f59e6e89
梁灏
update Drawer
|
10
11
12
13
14
|
<a class="ivu-drawer-close" v-if="closable" @click="close">
<slot name="close">
<Icon type="ios-close"></Icon>
</slot>
</a>
|
1416321b
梁灏
update Drawer
|
15
|
<div :class="[prefixCls + '-header']" v-if="showHead"><slot name="header"><div :class="[prefixCls + '-header-inner']">{{ title }}</div></slot></div>
|
f59e6e89
梁灏
update Drawer
|
16
17
18
19
20
21
|
<div :class="[prefixCls + '-body']" :style="styles"><slot></slot></div>
</div>
</div>
</transition>
</div>
</div>
|
c4d780c0
梁灏
init Drawer compo...
|
22
23
|
</template>
<script>
|
749665ee
梁灏
add props
|
24
25
26
|
import Icon from '../icon';
import { oneOf } from '../../utils/assist';
import TransferDom from '../../directives/transfer-dom';
|
ab58648e
梁灏
update Drawer
|
27
|
import Emitter from '../../mixins/emitter';
|
749665ee
梁灏
add props
|
28
29
|
import ScrollbarMixins from '../modal/mixins-scrollbar';
|
c4d780c0
梁灏
init Drawer compo...
|
30
31
32
33
|
const prefixCls = 'ivu-drawer';
export default {
name: 'Drawer',
|
ab58648e
梁灏
update Drawer
|
34
|
mixins: [ Emitter, ScrollbarMixins ],
|
749665ee
梁灏
add props
|
35
36
|
components: { Icon },
directives: { TransferDom },
|
c4d780c0
梁灏
init Drawer compo...
|
37
|
props: {
|
749665ee
梁灏
add props
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
value: {
type: Boolean,
default: false
},
title: {
type: String
},
width: {
type: [Number, String],
default: 256
},
closable: {
type: Boolean,
default: true
},
maskClosable: {
type: Boolean,
default: true
},
mask: {
type: Boolean,
default: true
},
maskStyle: {
type: Object
},
|
ab58648e
梁灏
update Drawer
|
64
65
66
|
styles: {
type: Object
},
|
749665ee
梁灏
add props
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
scrollable: {
type: Boolean,
default: false
},
placement: {
validator (value) {
return oneOf(value, ['left', 'right']);
},
default: 'right'
},
zIndex: {
type: Number,
default: 1000
},
transfer: {
type: Boolean,
default () {
return !this.$IVIEW || this.$IVIEW.transfer === '' ? true : this.$IVIEW.transfer;
}
},
|
f59e6e89
梁灏
update Drawer
|
87
88
|
className: {
type: String
|
8a3c7282
梁灏
add inner prop
|
89
90
91
92
|
},
inner: {
type: Boolean,
default: false
|
f59e6e89
梁灏
update Drawer
|
93
|
}
|
749665ee
梁灏
add props
|
94
95
96
97
98
|
},
data () {
return {
prefixCls: prefixCls,
visible: this.value,
|
f59e6e89
梁灏
update Drawer
|
99
100
|
wrapShow: false,
showHead: true,
|
749665ee
梁灏
add props
|
101
102
|
};
},
|
f59e6e89
梁灏
update Drawer
|
103
104
105
106
107
108
109
|
computed: {
wrapClasses () {
return [
`${prefixCls}-wrap`,
{
[`${prefixCls}-hidden`]: !this.wrapShow,
[`${this.className}`]: !!this.className,
|
8a3c7282
梁灏
add inner prop
|
110
111
|
[`${prefixCls}-no-mask`]: !this.mask,
[`${prefixCls}-wrap-inner`]: this.inner
|
f59e6e89
梁灏
update Drawer
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
}
];
},
mainStyles () {
let style = {};
const width = parseInt(this.width);
const styleWidth = {
width: width <= 100 ? `${width}%` : `${width}px`
};
Object.assign(style, styleWidth);
return style;
},
contentClasses () {
return [
`${prefixCls}-content`,
{
[`${prefixCls}-content-no-mask`]: !this.mask
}
];
},
|
ab58648e
梁灏
update Drawer
|
136
137
138
139
140
141
|
classes () {
return [
`${prefixCls}`,
`${prefixCls}-${this.placement}`,
{
[`${prefixCls}-no-header`]: !this.showHead,
|
8a3c7282
梁灏
add inner prop
|
142
143
144
145
146
147
148
149
150
|
[`${prefixCls}-inner`]: this.inner
}
];
},
maskClasses () {
return [
`${prefixCls}-mask`,
{
[`${prefixCls}-mask-inner`]: this.inner
|
ab58648e
梁灏
update Drawer
|
151
152
153
|
}
];
}
|
f59e6e89
梁灏
update Drawer
|
154
|
},
|
749665ee
梁灏
add props
|
155
|
methods: {
|
f59e6e89
梁灏
update Drawer
|
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
close () {
this.visible = false;
this.$emit('input', false);
this.$emit('on-close');
},
handleMask () {
if (this.maskClosable && this.mask) {
this.close();
}
},
handleWrapClick (event) {
// use indexOf,do not use === ,because ivu-modal-wrap can have other custom className
const className = event.target.getAttribute('class');
if (className && className.indexOf(`${prefixCls}-wrap`) > -1) this.handleMask();
},
},
mounted () {
if (this.visible) {
this.wrapShow = true;
}
let showHead = true;
|
c4d780c0
梁灏
init Drawer compo...
|
178
|
|
f59e6e89
梁灏
update Drawer
|
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
if (this.$slots.header === undefined && !this.title) {
showHead = false;
}
this.showHead = showHead;
},
beforeDestroy () {
this.removeScrollEffect();
},
watch: {
value (val) {
this.visible = val;
},
visible (val) {
if (val === false) {
this.timer = setTimeout(() => {
this.wrapShow = false;
this.removeScrollEffect();
}, 300);
} else {
if (this.timer) clearTimeout(this.timer);
this.wrapShow = true;
if (!this.scrollable) {
this.addScrollEffect();
}
}
this.broadcast('Table', 'on-visible-change', val);
this.broadcast('Slider', 'on-visible-change', val); // #2852
this.$emit('on-visible-change', val);
},
scrollable (val) {
if (!val) {
this.addScrollEffect();
} else {
this.removeScrollEffect();
}
},
title (val) {
if (this.$slots.header === undefined) {
this.showHead = !!val;
}
}
|
c4d780c0
梁灏
init Drawer compo...
|
221
222
223
|
}
};
</script>
|