:zap:数据返回格式改为可灵活扩展,跟ruoyi保存一致

This commit is contained in:
不做码农
2023-09-08 15:18:14 +08:00
parent 803d862513
commit 70371e92b3
5 changed files with 36 additions and 48 deletions
@@ -82,12 +82,7 @@ namespace ZR.ServiceCore.Middleware
if (!HasPermi && !Permission.Equals("common"))
{
logger.Info($"用户{info.UserName}没有权限访问{url},当前权限[{Permission}]");
JsonResult result = new(new ApiResult()
{
Code = (int)ResultCode.FORBIDDEN,
Msg = $"你当前没有权限[{Permission}]访问,请联系管理员",
Data = url
})
JsonResult result = new(new ApiResult((int)ResultCode.FORBIDDEN, $"你当前没有权限[{Permission}]访问,请联系管理员", url))
{
ContentType = "application/json",
};
@@ -46,11 +46,8 @@ namespace ZR.ServiceCore.Middleware
if (!string.IsNullOrEmpty(msg))
{
logger.Info($"请求参数错误,{msg}");
ApiResult response = new()
{
Code = (int)ResultCode.PARAM_ERROR,
Msg = msg
};
ApiResult response = new((int)ResultCode.PARAM_ERROR, msg);
context.Result = new JsonResult(response);
}
return base.OnActionExecutionAsync(context, next);
+3 -2
View File
@@ -63,8 +63,9 @@ namespace ZR.Admin.WebApi.Filters
{
string msg = $"请求访问[{url}]失败,无法访问系统资源";
//logger.Info(msg);
context.Result = new JsonResult(new ApiResult((int)ResultCode.DENY, msg));
var r = new ApiResult((int)ResultCode.DENY, msg);
context.Result = new JsonResult(r);
}
}
}