-
Notifications
You must be signed in to change notification settings - Fork 21
/
notice.vue
172 lines (166 loc) · 3.32 KB
/
notice.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
112
113
114
115
116
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
147
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
<template>
<vc-transition-slide mode="right" @after-leave="handleRemove">
<div
v-show="visible"
ref="target"
class="vc-notice__wrapper"
>
<vc-icon v-if="mode" :type="`o-${mode}`" :class="`is-${mode}`" class="vc-notice__icon" />
<div>
<!-- title -->
<div v-if="title" :style="{marginBottom: content ? '8px' : ''}" class="vc-notice__title">
<p
v-if="typeof title === 'string'"
v-html="title"
/>
<vc-customer
v-else-if="typeof title === 'function'"
:render="title"
/>
</div>
<!-- content -->
<div v-if="content" class="vc-notice__content">
<p
v-if="typeof content === 'string'"
v-html="content"
/>
<vc-customer
v-else-if="typeof content === 'function'"
:render="content"
/>
</div>
</div>
<!-- close -->
<vc-icon
v-if="closable"
type="close"
style="font-size: 12px"
class="vc-notice__close"
@click="handleClose"
/>
</div>
</vc-transition-slide>
</template>
<script>
import Icon from "../icon";
import Transition from '../transition';
import Customer from "../customer/index";
export default {
name: 'vc-nontice',
components: {
'vc-icon': Icon,
'vc-customer': Customer,
'vc-transition-slide': Transition.Slide,
},
props: {
title: [String, Function],
content: [String, Function],
duration: {
type: Number,
default: 4.5
},
closable: {
type: Boolean,
default: true,
},
mode: {
type: String,
validator: v => /(info|loading|success|error|warning)/.test(v)
},
beforeClose: Function
},
data() {
return {
// 先要隐藏在显示,才有transition
visible: false,
};
},
mounted() {
this.visible = true;
if (this.duration !== 0) {
this.timer = setTimeout(() => {
// 主线程
this.visible = false;
}, this.duration * 1000 - 300); // 动画时间
}
},
destroyed() {
this.timer && clearTimeout(this.timer);
},
methods: {
handleRemove() {
this.$emit('close');
},
async handleClose(e) {
let visible = false;
if (this.beforeClose) {
visible = await this.beforeClose();
}
this.visible = visible;
}
}
};
</script>
<style lang="scss">
@import '../style/vars.scss';
@include block(vc-notice) {
position: fixed;
right: 0px;
top: 24px;
bottom: auto;
z-index: 4000;
width: 384px;
margin-right: 24px;
box-sizing: border-box;
@include element(wrapper) {
position: relative;
margin-bottom: 16px;
padding: 16px;
overflow: hidden;
display: flex;
align-items: center;
background: $white;
box-shadow: $border-shadow;
border-radius: 4px;
font-size: 14px;
@include element(title) {
color: rgba(0, 0, 0, 0.85);
padding-right: 24px;
font-size: 16px;
display: inline-block;
}
@include element(content) {
line-height: 1.5;
color: rgba(0, 0, 0, 0.65);
}
@include element(icon) {
padding-right: 8px;
font-size: 22px;
line-height: 24px;
align-self: flex-start;
@include when(success) {
color: $success;
}
@include when(error) {
color: $error;
}
@include when(warning) {
color: $warning;
}
@include when(info) {
color: $info;
}
}
}
@include element(close) {
position: absolute;
top: 16px;
right: 22px;
font-size: 12px;
cursor: pointer;
height: 24px;
display: inline-flex;
align-items: center;
}
}
</style>