100 lines
2.6 KiB
JavaScript
100 lines
2.6 KiB
JavaScript
class Popups {
|
|
config = {
|
|
Name: $(".bj"),
|
|
contter: "标题",
|
|
iconfont: "警告",
|
|
neirong: "消息",
|
|
guanbi1: false,
|
|
weizhi: "RightTop",
|
|
iconfontEvent: () => { }
|
|
|
|
}
|
|
|
|
constructor(option) {
|
|
this.config.contter = option.contter || this.config.contter;
|
|
this.config.iconfont = option.iconfont || this.config.iconfont;
|
|
this.config.neirong = option.neirong || this.config.neirong;
|
|
this.config.weizhi = option.weizhi || this.config.weizhi;
|
|
this.config.guanbi1 = option.guanbi1 || this.config.guanbi1;
|
|
this.config.iconfontEvent = option.iconfontEvent || this.config.iconfontEvent;
|
|
console.log(option)
|
|
this.createPopups()
|
|
}
|
|
|
|
createPopups() {
|
|
|
|
this.config.Name.insertAdjacentHTML("beforeend",
|
|
`
|
|
<div class="back ${this.xuanzhe()}">
|
|
<div class="top">
|
|
<div class="top_left">
|
|
<i class="iconfont ${this.ibiaoq()}"></i>
|
|
<h4 class="contter">${this.config.contter}</h4>
|
|
</div>
|
|
<i class="iconfont icon-guanbi"></i>
|
|
</div>
|
|
<div class="neirong">${this.config.neirong}</div>
|
|
</div>`)
|
|
|
|
this.iconfontclous()
|
|
this.dingshi()
|
|
|
|
}
|
|
|
|
|
|
dingshi() {
|
|
if (this.config.guanbi1) {
|
|
setTimeout(() => this.clous(),3000)
|
|
}
|
|
}
|
|
|
|
/*关闭*/
|
|
clous() {
|
|
this.config.Name.removeChild($(".back"))
|
|
}
|
|
|
|
/*关闭按钮被点击时*/
|
|
iconfontclous() {
|
|
$(".icon-guanbi").onclick = () => {
|
|
this.clous();
|
|
this.config.iconfontEvent()
|
|
}
|
|
}
|
|
xuanzhe(shuju) {
|
|
switch (this.config.weizhi) {
|
|
case "LeftTop":
|
|
return shuju = "LeftTop";
|
|
break;
|
|
case "RightTop":
|
|
return shuju = "RightTop";
|
|
break;
|
|
case "LeftBottom":
|
|
return shuju = "LeftBottom";
|
|
break;
|
|
case "RightBottom":
|
|
return shuju = "RightBottom";
|
|
break;
|
|
}
|
|
|
|
}
|
|
ibiaoq(shu) {
|
|
switch (this.config.iconfont) {
|
|
case "警告":
|
|
return shu = "icon-icon-test";
|
|
break;
|
|
case "成功":
|
|
return shu = "icon-chenggong";
|
|
break;
|
|
case "错误":
|
|
return shu = "icon-icon-test1";
|
|
break;
|
|
case "消息":
|
|
return shu = "icon-xiaoxi";
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window.Popups = Popups |