const displayAlert = (type: 'succ' | 'error' |'info', data, time) =>{
var popUp = document.createElement("div");
let icon = null;
if (type == "succ") {
icon = '<i class="iconfont 图标类名 success"></i>'
} else if (type == "error") {
icon = '<i class="iconfont 图标类名 error"></i>'
} else if (type == "info") {
icon = '<i class="iconfont 图标类名 info"></i>'
} else {
console.log("入参type错误");
return;
}
popUp.id = "popUp";
popUp.className = styles.commonPopUp;
popUp.style.animationName = "popUp";
popUp.style.animationDuration = time / 1000 - 0.5 + 's';
popUp.style.animationFillMode = 'forwards';
if (document.getElementById("popUp") == null) {
document.body.appendChild(popUp);
popUp.innerHTML = icon + data;
setTimeout(function () {
document.body.removeChild(popUp);
}, time);
}
}
.commonPopUp {
position: fixed;
top: 10%;
left: 50%;
transform: translateX(-50%);
padding: 8px 12px;
background: #FFF;
font-size: 16px;
border-radius: 4px;
color: #333;
line-height: 16px;
text-align: center;
box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
z-index: 999;
:global{
.iconfont {
margin-right: 10px;
&.success {
color: #52c41a;
}
&.error {
color: #F5222D;
}
&.info {
color: #FAAD14;
}
}
}
}