Skip to content

Commit 0fa51fa

Browse files
committed
Message: display in stack mode
1 parent 8933a05 commit 0fa51fa

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/message/src/main.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ const Message = function(options) {
3232
}
3333
instance.vm = instance.$mount();
3434
document.body.appendChild(instance.vm.$el);
35+
let verticalOffset = options.offset || 20;
36+
instances.forEach(item => {
37+
verticalOffset += item.$el.offsetHeight + 16;
38+
});
39+
instance.verticalOffset = verticalOffset;
3540
instance.vm.visible = true;
3641
instance.dom = instance.vm.$el;
3742
instance.dom.style.zIndex = PopupManager.nextZIndex();
@@ -52,15 +57,25 @@ const Message = function(options) {
5257
});
5358

5459
Message.close = function(id, userOnClose) {
55-
for (let i = 0, len = instances.length; i < len; i++) {
60+
let len = instances.length;
61+
let index = -1;
62+
for (let i = 0; i < len; i++) {
5663
if (id === instances[i].id) {
64+
index = i;
5765
if (typeof userOnClose === 'function') {
5866
userOnClose(instances[i]);
5967
}
6068
instances.splice(i, 1);
6169
break;
6270
}
6371
}
72+
if (len <= 1 || index === -1) return;
73+
const removedHeight = instances[index].dom.offsetHeight;
74+
for (let i = index; i < len - 1 ; i++) {
75+
let dom = instances[i].dom;
76+
dom.style['top'] =
77+
parseInt(dom.style['top'], 10) - removedHeight - 16 + 'px';
78+
}
6479
};
6580

6681
Message.closeAll = function() {

packages/message/src/main.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
showClose ? 'is-closable' : '',
99
customClass
1010
]"
11+
:style="positionStyle"
1112
v-show="visible"
1213
@mouseenter="clearTimer"
1314
@mouseleave="startTimer"
@@ -43,6 +44,7 @@
4344
onClose: null,
4445
showClose: false,
4546
closed: false,
47+
verticalOffset: 20,
4648
timer: null,
4749
dangerouslyUseHTMLString: false,
4850
center: false
@@ -54,6 +56,11 @@
5456
return this.type && !this.iconClass
5557
? `el-message__icon el-icon-${ typeMap[this.type] }`
5658
: '';
59+
},
60+
positionStyle() {
61+
return {
62+
'top': `${ this.verticalOffset }px`
63+
};
5764
}
5865
},
5966

packages/theme-chalk/src/message.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
top: 20px;
1414
transform: translateX(-50%);
1515
background-color: $--message-background-color;
16-
transition: opacity 0.3s, transform .4s;
16+
transition: opacity 0.3s, transform .4s, top 0.4s;
1717
overflow: hidden;
1818
padding: $--message-padding;
1919
display: flex;

0 commit comments

Comments
 (0)