From 4950105fdda29a51d77f62a67dee3faaf7d16cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=83=E5=BD=A9=E6=9E=AB=E5=8F=B6?= <424235748@qq.com> Date: Wed, 16 Nov 2022 09:33:38 +0000 Subject: [PATCH] =?UTF-8?q?update=20component/pear/module/common.js.=20?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3submit=E4=B8=AD=E4=B8=80=E5=A4=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=8C=E5=8F=8A=E5=AE=8C=E5=96=84submit=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=9F=BA=E6=9C=AC=E4=B8=8A=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=9B=BF=E4=BB=A3=E9=A1=B5=E9=9D=A2=E4=B8=AD=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E6=8F=90=E4=BA=A4=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 七彩枫叶 <424235748@qq.com> --- component/pear/module/common.js | 39 ++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/component/pear/module/common.js b/component/pear/module/common.js index 6f1eac8..a8ae02d 100644 --- a/component/pear/module/common.js +++ b/component/pear/module/common.js @@ -41,29 +41,52 @@ layui.define(['jquery', 'element','table'], function(exports) { /** - * 提交 json 数据 + * 提交 json 数据 * @param data 提交数据 * @param href 提交接口 + * @param ajaxtype 提交方式 * @param table 刷新父级表 - * + * @param callback 自定义回调函数 * */ - this.submit = function(data,href,table,callback){ + this.submit = function(href,data,ajaxtype,table,callback){ + if(ajaxtype==''){ ajaxtype='post';} $.ajax({ url:href, data:JSON.stringify(data), dataType:'json', contentType:'application/json', - type:'post', - success:callback !=null?callback(result):function(result){ - if(result.success){ + type:ajaxtype, + success:callback !=null?callback:function(result){ + if(result.code==1){ layer.msg(result.msg,{icon:1,time:1000},function(){ parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页 - parent.layui.table.reload(table); + if(table!=null){parent.layui.table.reload(table);} }); }else{ layer.msg(result.msg,{icon:2,time:1000}); } - } + }, + //异步访问出错的时候会用到error,可以扩充 + error:function(XMLHttpRequest){ + if(XMLHttpRequest.status==419) + { + layer.msg('长时间未操作,自动刷新后重试!',{icon: 5}); + setTimeout(function () { window.location.reload();}, 2000); + } + if(XMLHttpRequest.status==429) + { + layer.msg('尝试次数太多,请一分钟后再试',{icon: 5}); + } + if(XMLHttpRequest.status==500) + { + layer.msg(XMLHttpRequest.responseJSON.message,{icon: 5}); + } + }, + //完成的时候会用到,例如更新token + complete:function (xhr,status){ + console.log(xhr); + console.log(status); + } }) } } -- Gitee