layui2.6.0下的table.render无error的参数拦截统一提示鉴权信息

63 阅读1分钟

情景

异常情况

响应数据结构

{"code":401,"success":false,"data":null,"msg":"请求未授权"}

layui.all.js中修改

  • 全局搜索数据接口请求异常
  • 具体参考的代码部分
//增加表格网络请求的401提示
if(Object.prototype.hasOwnProperty.call(e,"status") && e['status']=='401'){ //状态码为401统一拦截
    if(Object.prototype.hasOwnProperty.call(e,"responseJSON")){
        var responseJSON=e['responseJSON']
        if(Object.prototype.hasOwnProperty.call(responseJSON,'code') && responseJSON['code']=='401'){
            layui.layer.msg(responseJSON['msg'] || "无操作权限")
        }
    }
}
  • 参考截图的位置

image.png