update Message

Message add closable func, and update params
This commit is contained in:
Aresn 2017-05-31 15:49:41 +08:00
parent e993204310
commit e0bd31a64c
6 changed files with 97 additions and 17 deletions

View file

@ -1,5 +1,6 @@
<template> <template>
<div> <div>
<i-button @click.native="info">显示普通提示</i-button>
<i-button @click.native="success">显示成功提示</i-button> <i-button @click.native="success">显示成功提示</i-button>
<i-button @click.native="warning">显示警告提示</i-button> <i-button @click.native="warning">显示警告提示</i-button>
<i-button @click.native="error">显示错误提示</i-button> <i-button @click.native="error">显示错误提示</i-button>
@ -9,6 +10,17 @@
<script> <script>
export default { export default {
methods: { methods: {
info () {
// this.$Message.info('');
this.$Message.success({
content: '这是一条普通提示2',
duration: 500,
onClose () {
console.log(123)
},
closable: true
})
},
success () { success () {
this.$Message.success('这是一条成功的提示'); this.$Message.success('这是一条成功的提示');
}, },

View file

@ -1,10 +1,20 @@
<template> <template>
<transition :name="transitionName"> <transition :name="transitionName">
<div :class="classes" :style="styles"> <div :class="classes" :style="styles">
<div :class="[baseClass + '-content']" ref="content" v-html="content"></div> <template v-if="type === 'notice'">
<a :class="[baseClass + '-close']" @click="close" v-if="closable"> <div :class="[baseClass + '-content']" ref="content" v-html="content"></div>
<i class="ivu-icon ivu-icon-ios-close-empty"></i> <a :class="[baseClass + '-close']" @click="close" v-if="closable">
</a> <i class="ivu-icon ivu-icon-ios-close-empty"></i>
</a>
</template>
<template v-if="type === 'message'">
<div :class="[baseClass + '-content']" ref="content">
<div :class="[baseClass + '-content-text']" v-html="content"></div>
<a :class="[baseClass + '-close']" @click="close" v-if="closable">
<i class="ivu-icon ivu-icon-ios-close-empty"></i>
</a>
</div>
</template>
</div> </div>
</transition> </transition>
</template> </template>
@ -19,6 +29,9 @@
type: Number, type: Number,
default: 1.5 default: 1.5
}, },
type: {
type: String
},
content: { content: {
type: String, type: String,
default: '' default: ''

View file

@ -5,6 +5,7 @@
:key="notice.name" :key="notice.name"
:prefix-cls="prefixCls" :prefix-cls="prefixCls"
:styles="notice.styles" :styles="notice.styles"
:type="notice.type"
:content="notice.content" :content="notice.content"
:duration="notice.duration" :duration="notice.duration"
:closable="notice.closable" :closable="notice.closable"

View file

@ -28,7 +28,7 @@ function getMessageInstance () {
return messageInstance; return messageInstance;
} }
function notice (content, duration = defaultDuration, type, onClose) { function notice (content = '', duration = defaultDuration, type, onClose = function () {}, closable = false) {
if (!onClose) { if (!onClose) {
onClose = function () { onClose = function () {
@ -52,7 +52,9 @@ function notice (content, duration = defaultDuration, type, onClose) {
<span>${content}</span> <span>${content}</span>
</div> </div>
`, `,
onClose: onClose onClose: onClose,
closable: closable,
type: 'message'
}); });
// 用于手动消除 // 用于手动消除
@ -66,20 +68,50 @@ function notice (content, duration = defaultDuration, type, onClose) {
} }
export default { export default {
info (content, duration, onClose) { info (options) {
return notice(content, duration, 'info', onClose); const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'info', options.onClose, options.closable);
}, },
success (content, duration, onClose) { success (options) {
return notice(content, duration, 'success', onClose); const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'success', options.onClose, options.closable);
}, },
warning (content, duration, onClose) { warning (options) {
return notice(content, duration, 'warning', onClose); const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'warning', options.onClose, options.closable);
}, },
error (content, duration, onClose) { error (options) {
return notice(content, duration, 'error', onClose); const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'error', options.onClose, options.closable);
}, },
loading (content, duration, onClose) { loading (options) {
return notice(content, duration, 'loading', onClose); const type = typeof options;
if (type === 'string') {
options = {
content: options
};
}
return notice(options.content, options.duration, 'loading', options.onClose, options.closable);
}, },
config (options) { config (options) {
if (options.top) { if (options.top) {

View file

@ -71,7 +71,8 @@ function notice (type, options) {
transitionName: 'move-notice', transitionName: 'move-notice',
content: content, content: content,
onClose: onClose, onClose: onClose,
closable: true closable: true,
type: 'notice'
}); });
} }

View file

@ -14,6 +14,18 @@
vertical-align: middle; vertical-align: middle;
position: absolute; position: absolute;
left: 50%; left: 50%;
&-close {
position: absolute;
right: 4px;
top: 9px;
color: #999;
outline: none;
i.@{icon-prefix-cls}{
.close-base(-3px);
}
}
} }
&-notice-content { &-notice-content {
@ -25,6 +37,15 @@
box-shadow: @shadow-base; box-shadow: @shadow-base;
background: #fff; background: #fff;
display: block; display: block;
&-text{
display: inline-block;
}
}
&-notice-closable{
.@{message-prefix-cls}-notice-content-text{
padding-right: 32px;
}
} }
&-success .@{icon-prefix-cls} { &-success .@{icon-prefix-cls} {