Commit e0bd31a64c8ea0452dba1c3e6b4f9a40594f587a

Authored by Aresn
1 parent e9932043

update Message

Message add closable func, and update params
examples/routers/message.vue
1 <template> 1 <template>
2 <div> 2 <div>
  3 + <i-button @click.native="info">显示普通提示</i-button>
3 <i-button @click.native="success">显示成功提示</i-button> 4 <i-button @click.native="success">显示成功提示</i-button>
4 <i-button @click.native="warning">显示警告提示</i-button> 5 <i-button @click.native="warning">显示警告提示</i-button>
5 <i-button @click.native="error">显示错误提示</i-button> 6 <i-button @click.native="error">显示错误提示</i-button>
@@ -9,6 +10,17 @@ @@ -9,6 +10,17 @@
9 <script> 10 <script>
10 export default { 11 export default {
11 methods: { 12 methods: {
  13 + info () {
  14 +// this.$Message.info('这是一条普通提示');
  15 + this.$Message.success({
  16 + content: '这是一条普通提示2',
  17 + duration: 500,
  18 + onClose () {
  19 + console.log(123)
  20 + },
  21 + closable: true
  22 + })
  23 + },
12 success () { 24 success () {
13 this.$Message.success('这是一条成功的提示'); 25 this.$Message.success('这是一条成功的提示');
14 }, 26 },
src/components/base/notification/notice.vue
1 <template> 1 <template>
2 <transition :name="transitionName"> 2 <transition :name="transitionName">
3 <div :class="classes" :style="styles"> 3 <div :class="classes" :style="styles">
4 - <div :class="[baseClass + '-content']" ref="content" v-html="content"></div>  
5 - <a :class="[baseClass + '-close']" @click="close" v-if="closable">  
6 - <i class="ivu-icon ivu-icon-ios-close-empty"></i>  
7 - </a> 4 + <template v-if="type === 'notice'">
  5 + <div :class="[baseClass + '-content']" ref="content" v-html="content"></div>
  6 + <a :class="[baseClass + '-close']" @click="close" v-if="closable">
  7 + <i class="ivu-icon ivu-icon-ios-close-empty"></i>
  8 + </a>
  9 + </template>
  10 + <template v-if="type === 'message'">
  11 + <div :class="[baseClass + '-content']" ref="content">
  12 + <div :class="[baseClass + '-content-text']" v-html="content"></div>
  13 + <a :class="[baseClass + '-close']" @click="close" v-if="closable">
  14 + <i class="ivu-icon ivu-icon-ios-close-empty"></i>
  15 + </a>
  16 + </div>
  17 + </template>
8 </div> 18 </div>
9 </transition> 19 </transition>
10 </template> 20 </template>
@@ -19,6 +29,9 @@ @@ -19,6 +29,9 @@
19 type: Number, 29 type: Number,
20 default: 1.5 30 default: 1.5
21 }, 31 },
  32 + type: {
  33 + type: String
  34 + },
22 content: { 35 content: {
23 type: String, 36 type: String,
24 default: '' 37 default: ''
src/components/base/notification/notification.vue
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 :key="notice.name" 5 :key="notice.name"
6 :prefix-cls="prefixCls" 6 :prefix-cls="prefixCls"
7 :styles="notice.styles" 7 :styles="notice.styles"
  8 + :type="notice.type"
8 :content="notice.content" 9 :content="notice.content"
9 :duration="notice.duration" 10 :duration="notice.duration"
10 :closable="notice.closable" 11 :closable="notice.closable"
src/components/message/index.js
@@ -28,7 +28,7 @@ function getMessageInstance () { @@ -28,7 +28,7 @@ function getMessageInstance () {
28 return messageInstance; 28 return messageInstance;
29 } 29 }
30 30
31 -function notice (content, duration = defaultDuration, type, onClose) { 31 +function notice (content = '', duration = defaultDuration, type, onClose = function () {}, closable = false) {
32 if (!onClose) { 32 if (!onClose) {
33 onClose = function () { 33 onClose = function () {
34 34
@@ -52,7 +52,9 @@ function notice (content, duration = defaultDuration, type, onClose) { @@ -52,7 +52,9 @@ function notice (content, duration = defaultDuration, type, onClose) {
52 <span>${content}</span> 52 <span>${content}</span>
53 </div> 53 </div>
54 `, 54 `,
55 - onClose: onClose 55 + onClose: onClose,
  56 + closable: closable,
  57 + type: 'message'
56 }); 58 });
57 59
58 // 用于手动消除 60 // 用于手动消除
@@ -66,20 +68,50 @@ function notice (content, duration = defaultDuration, type, onClose) { @@ -66,20 +68,50 @@ function notice (content, duration = defaultDuration, type, onClose) {
66 } 68 }
67 69
68 export default { 70 export default {
69 - info (content, duration, onClose) {  
70 - return notice(content, duration, 'info', onClose); 71 + info (options) {
  72 + const type = typeof options;
  73 + if (type === 'string') {
  74 + options = {
  75 + content: options
  76 + };
  77 + }
  78 + return notice(options.content, options.duration, 'info', options.onClose, options.closable);
71 }, 79 },
72 - success (content, duration, onClose) {  
73 - return notice(content, duration, 'success', onClose); 80 + success (options) {
  81 + const type = typeof options;
  82 + if (type === 'string') {
  83 + options = {
  84 + content: options
  85 + };
  86 + }
  87 + return notice(options.content, options.duration, 'success', options.onClose, options.closable);
74 }, 88 },
75 - warning (content, duration, onClose) {  
76 - return notice(content, duration, 'warning', onClose); 89 + warning (options) {
  90 + const type = typeof options;
  91 + if (type === 'string') {
  92 + options = {
  93 + content: options
  94 + };
  95 + }
  96 + return notice(options.content, options.duration, 'warning', options.onClose, options.closable);
77 }, 97 },
78 - error (content, duration, onClose) {  
79 - return notice(content, duration, 'error', onClose); 98 + error (options) {
  99 + const type = typeof options;
  100 + if (type === 'string') {
  101 + options = {
  102 + content: options
  103 + };
  104 + }
  105 + return notice(options.content, options.duration, 'error', options.onClose, options.closable);
80 }, 106 },
81 - loading (content, duration, onClose) {  
82 - return notice(content, duration, 'loading', onClose); 107 + loading (options) {
  108 + const type = typeof options;
  109 + if (type === 'string') {
  110 + options = {
  111 + content: options
  112 + };
  113 + }
  114 + return notice(options.content, options.duration, 'loading', options.onClose, options.closable);
83 }, 115 },
84 config (options) { 116 config (options) {
85 if (options.top) { 117 if (options.top) {
src/components/notice/index.js
@@ -71,7 +71,8 @@ function notice (type, options) { @@ -71,7 +71,8 @@ function notice (type, options) {
71 transitionName: 'move-notice', 71 transitionName: 'move-notice',
72 content: content, 72 content: content,
73 onClose: onClose, 73 onClose: onClose,
74 - closable: true 74 + closable: true,
  75 + type: 'notice'
75 }); 76 });
76 } 77 }
77 78
src/styles/components/message.less
@@ -14,6 +14,18 @@ @@ -14,6 +14,18 @@
14 vertical-align: middle; 14 vertical-align: middle;
15 position: absolute; 15 position: absolute;
16 left: 50%; 16 left: 50%;
  17 +
  18 + &-close {
  19 + position: absolute;
  20 + right: 4px;
  21 + top: 9px;
  22 + color: #999;
  23 + outline: none;
  24 +
  25 + i.@{icon-prefix-cls}{
  26 + .close-base(-3px);
  27 + }
  28 + }
17 } 29 }
18 30
19 &-notice-content { 31 &-notice-content {
@@ -25,6 +37,15 @@ @@ -25,6 +37,15 @@
25 box-shadow: @shadow-base; 37 box-shadow: @shadow-base;
26 background: #fff; 38 background: #fff;
27 display: block; 39 display: block;
  40 + &-text{
  41 + display: inline-block;
  42 + }
  43 + }
  44 +
  45 + &-notice-closable{
  46 + .@{message-prefix-cls}-notice-content-text{
  47 + padding-right: 32px;
  48 + }
28 } 49 }
29 50
30 &-success .@{icon-prefix-cls} { 51 &-success .@{icon-prefix-cls} {