forked from zhoou/vue-cli-multipage-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vAlert.vue
111 lines (109 loc) · 2.13 KB
/
vAlert.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
64
65
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
<transition name="fade">
<div
v-show="showDail"
v-bind:class="{
'alert': true,
'alert-success':(type == 'success'),
'alert-warning':(type == 'warning'),
'alert-info': (type == 'info'),
'alert-danger': (type == 'danger'),
'top': (placement === 'top'),
'top-right': (placement === 'top-right')
}"
v-bind:style="{width:width}"
role="alert"
>
<button v-show="dismissable" type="button" class="close" @click="close">
<span>×</span>
</button>
<slot></slot>
</div>
</transition>
</template>
<script>
import {coerce} from 'jspath/common/utils.js'
export default {
props: {
name: {
type: String,
default: 'vAlert_' + Math.floor(Math.random() * 1000 + 1)
},
type: {
type: String
},
dismissable: {
type: Boolean,
coerce: coerce.boolean,
default: false
},
show: {
type: Boolean,
coerce: coerce.boolean,
default: false
},
duration: {
type: Number,
coerce: coerce.number,
default: 0
},
width: {
type: String
},
placement: {
type: String
}
},
data () {
return {
showDail: this.show
}
},
watch: {
show (val) {
this.showDail = val
this.isShow(val)
}
},
methods: {
isShow (val) {
if (this._timeout) clearTimeout(this._timeout)
if (val && Boolean(this.duration)) {
this._timeout = setTimeout(() => {
this.$emit('changeState', {state: false, name: this.name})
this.showDail = false
}, this.duration)
}
},
close () {
this.$emit('changeState', {state: false, name: this.name})
this.showDail = false
}
}
}
</script>
<style>
.fade-enter-active {
transition: opacity .3s ease;
}
.fade-enter,
.fade-leave-active {
-webkit-transform: scale(1.1);
transform: scale(1.1);
opacity: 0;
}
.alert.top {
position: fixed;
top: 30px;
margin: 0 auto;
left: 0;
right: 0;
z-index: 1050;
}
.alert.top-right {
position: fixed;
top: 30px;
right: 50px;
z-index: 1050;
}
</style>