dialog统一标准调用方法(内部记录)

时间:2023-03-08 16:01:51

更新base-config.js

对话框统一为三种形式(如后期需要再添加其他方式)

//对话框--确定取消
//dialogOkFun:确定函数 dialogCancelFun:取消函数
function dialogOkCancel(dialog_ok_fun,dialog_cancel_fun){ art.dialog(
{
content:'确定要删除吗?',
width: 250,   
lock:true,
zIndex:9999,
title: '提示',
style:'succeed noClose',
close:function(){$.fancybox.close();}
},
function()
{
var jscode = new Function(dialog_ok_fun)();
},
function()
{
var jscode = new Function(dialog_cancel_fun)();
} );
} //对话框--直接关闭
//dialog_msg:对话框内容 dialog_time:对话框存在时间 dialog_width:对话框宽度,默认样式传入0即可,如果需要自定义宽度传入非0数字 dialog_close_fun:关闭时执行函数
function dialogClose(dialog_msg,dialog_time,dialog_width,dialog_close_fun) {
if(dialog_width == 0 || dialog_width == '') {
dialog_width = 200;
}
art.dialog({
height: 70,
  width: dialog_width,          
  fixed: true,
time: dialog_time,
title: '提示',
content: '<label>' + dialog_msg + '</label>',
zIndex:9999,
top:'50%',
close:function(){
var jscode = new Function(dialog_close_fun)();
}
/*lock: true*/
}).show;
} //对话框--点击确定后关闭
//dialog_msg:对话框内容 dialog_width:对话框宽度,默认样式传入0即可,如果需要自定义宽度传入非0数字 dialog_ok_fun:关闭时执行函数
function dialogOk(dialog_msg,dialog_width,dialog_ok_fun) {
if(dialog_width == 0 || dialog_width == '') {
dialog_width = 200;
}
art.dialog({
height: 70,
  width: dialog_width,          
  fixed: true,
  zIndex:9999,
/* time: 3,*/
title: '提示',
content: '<label>' + dialog_msg + '</label>',
top:'50%',
ok: function () {
var jscode = new Function(dialog_ok_fun)();
}, }).show;
}

页面代码调用示例

<script type="text/javascript" src="../../../js/base-config.js"></script>

//在template模板中调用
<a href="javascript:dialogOkCancel('cancelCollect(<%= list[i].iid %>,<%= list[i].table_pk %>)','cancelColle()');">删除</a> //在函数中调用
function cancelCollect(id,table_pk){
$.ajax({
type:"POST",
async: true,
data:{"id": id,"table_pk":table_pk,"random_num":creatRandomNum()},
url: url_path_action + "/resource/cancelResCollect",
success: function(data){
if(data.success){
dialogClose("操作成功。",2,0,'goPage(1)');
// collect1("操作成功。",2,1);
}else{
if(data.info == "notlogin"){
top.location = "/";
}else{
alert(data.info);
}
}
}
});
}

注:今后页面不允许出现alert()和自定义的对话框,之前完成的页面自己修改一下,辛苦啦~~