MeiRiYiCheng_1_old/YBDevice.NWeb/Handler/CustomModel.cs

66 lines
1.6 KiB
C#
Raw Normal View History

2025-07-16 17:14:38 +08:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Nirvana.Common.ApiBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace YBDevice.NWeb
{
/// <summary>
/// 重写json
/// </summary>
public class CustomModel : PageModel
{
protected virtual JsonResult ResultJson(int code, string message, object data)
{
return new JsonResult(new
{
code = code,
message = message,
data = data
});
}
protected virtual JsonResult ResultJson(ResultInfo data)
{
return new JsonResult(new
{
code = data.code,
message = data.message,
data = data.data
});
}
protected virtual JsonResult Success(object data)
{
return new JsonResult(new
{
code = ResultState.SUCCESS,
message = "success",
data = data
});
}
protected virtual JsonResult SuccessMessage(string message)
{
return new JsonResult(new
{
code = ResultState.SUCCESS,
message = message
});
}
public virtual JsonResult Fail(string message)
{
message = string.IsNullOrEmpty(message) ? "请求失败" : message;
return new JsonResult(new
{
code = ResultState.FAIL,
message = message
});
}
}
}