封装bootstrap-dialog.js中的3个提示框
这里主要对项目中常用的3个提示框进行了封装,成功提示框,错误提示框和选择提示框:
//弹出错误提示的登录框
$.showErr = function (str, func) {
// 调用show方法
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DANGER,
title: "错误 ",
message: str,
size: BootstrapDialog.SIZE_SMALL, //size为小,默认的对话框比较宽
buttons: [{
// 设置关闭按钮
label: "关闭",
action: function (dialogItself) {
dialogItself.close();
}
}],
// 指定时间内可自动关闭
onshown: function (dialogRef) {
setTimeout(function () {
dialogRef.close();
}, 3000);
},
// 对话框关闭时带入callback方法
onhide: func
});
};
//弹出确认框
$.showSuccessTimeout = function (str, func) {
BootstrapDialog.show({
type: BootstrapDialog.TYPE_SUCCESS,
title: "成功 ",
message: str,
size: BootstrapDialog.SIZE_SMALL,
buttons: [{
label: "确定",
action: function (dialogItself) {
dialogItself.close();
}
}],
// 指定时间内可自动关闭
onshown: function (dialogRef) {
setTimeout(function () {
dialogRef.close();
}, 3000);
},
onhide: func
});
};
//弹出提示框
$.showPromptTimeout = function (str, cb) {
BootstrapDialog.confirm({
title: '提示',
message: str,
type: BootstrapDialog.TYPE_SUCCESS,
size: BootstrapDialog.SIZE_SMALL,
btnCancelLabel: '取消',
btnOKLabel: '确定',
closeByBackdrop: false,
closable: true,
draggable: true,
callback: cb
});
return true;
};