2016-08-15 03:51:25 +00:00
|
|
|
<template>
|
2016-08-15 08:10:12 +00:00
|
|
|
<transition name="el-message-fade">
|
2016-12-14 05:43:14 +00:00
|
|
|
<div
|
2017-09-06 04:41:06 +00:00
|
|
|
:class="[
|
|
|
|
'el-message',
|
|
|
|
type && !iconClass ? `el-message--${ type }` : '',
|
|
|
|
center ? 'is-center' : '',
|
|
|
|
customClass]"
|
2016-12-14 05:43:14 +00:00
|
|
|
v-show="visible"
|
|
|
|
@mouseenter="clearTimer"
|
|
|
|
@mouseleave="startTimer">
|
2017-09-06 04:41:06 +00:00
|
|
|
<i :class="iconClass" v-if="iconClass"></i>
|
|
|
|
<i :class="typeClass" v-else></i>
|
|
|
|
<slot>
|
|
|
|
<p v-if="!dangerouslyUseHTMLString" class="el-message__content">{{ message }}</p>
|
|
|
|
<p v-else v-html="message" class="el-message__content"></p>
|
|
|
|
</slot>
|
|
|
|
<i v-if="showClose" class="el-message__closeBtn el-icon-close" @click="close"></i>
|
2016-08-15 03:51:25 +00:00
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script type="text/babel">
|
2017-08-01 12:32:20 +00:00
|
|
|
const typeMap = {
|
2017-09-06 04:41:06 +00:00
|
|
|
success: 'success',
|
|
|
|
info: 'info',
|
2017-08-01 12:32:20 +00:00
|
|
|
warning: 'warning',
|
2017-09-06 04:41:06 +00:00
|
|
|
error: 'error'
|
2017-08-01 12:32:20 +00:00
|
|
|
};
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
visible: false,
|
|
|
|
message: '',
|
2016-08-15 08:10:12 +00:00
|
|
|
duration: 3000,
|
|
|
|
type: 'info',
|
2016-12-14 05:43:14 +00:00
|
|
|
iconClass: '',
|
|
|
|
customClass: '',
|
2016-08-15 03:51:25 +00:00
|
|
|
onClose: null,
|
2016-08-15 08:10:12 +00:00
|
|
|
showClose: false,
|
2016-08-15 03:51:25 +00:00
|
|
|
closed: false,
|
2017-08-02 09:34:37 +00:00
|
|
|
timer: null,
|
2017-09-06 04:41:06 +00:00
|
|
|
dangerouslyUseHTMLString: false,
|
|
|
|
center: false
|
2016-08-15 03:51:25 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2017-08-01 12:32:20 +00:00
|
|
|
iconWrapClass() {
|
|
|
|
const classes = ['el-message__icon'];
|
|
|
|
if (this.type && !this.iconClass) {
|
|
|
|
classes.push(`el-message__icon--${ this.type }`);
|
|
|
|
}
|
|
|
|
return classes;
|
|
|
|
},
|
|
|
|
|
|
|
|
typeClass() {
|
|
|
|
return this.type && !this.iconClass
|
2017-09-06 04:41:06 +00:00
|
|
|
? `el-message__icon el-icon-${ typeMap[this.type] }`
|
2017-08-01 12:32:20 +00:00
|
|
|
: '';
|
2016-08-15 03:51:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
closed(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.visible = false;
|
2016-11-03 07:36:57 +00:00
|
|
|
this.$el.addEventListener('transitionend', this.destroyElement);
|
2016-08-15 03:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2016-11-03 07:36:57 +00:00
|
|
|
destroyElement() {
|
|
|
|
this.$el.removeEventListener('transitionend', this.destroyElement);
|
|
|
|
this.$destroy(true);
|
|
|
|
this.$el.parentNode.removeChild(this.$el);
|
|
|
|
},
|
|
|
|
|
2016-11-13 12:03:17 +00:00
|
|
|
close() {
|
2016-08-15 03:51:25 +00:00
|
|
|
this.closed = true;
|
|
|
|
if (typeof this.onClose === 'function') {
|
2016-10-21 03:22:35 +00:00
|
|
|
this.onClose(this);
|
2016-08-15 03:51:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clearTimer() {
|
|
|
|
clearTimeout(this.timer);
|
|
|
|
},
|
|
|
|
|
|
|
|
startTimer() {
|
|
|
|
if (this.duration > 0) {
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
if (!this.closed) {
|
2016-11-13 12:03:17 +00:00
|
|
|
this.close();
|
2016-08-15 03:51:25 +00:00
|
|
|
}
|
|
|
|
}, this.duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2016-08-15 08:10:12 +00:00
|
|
|
this.startTimer();
|
2016-08-15 03:51:25 +00:00
|
|
|
}
|
|
|
|
};
|
2016-11-03 07:36:57 +00:00
|
|
|
</script>
|