using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api.Common { public enum ReturnCode { ArgsError = -1001, LoginError = -1002, GeneralError = -1003, LoginPriv = -1004, TokenError = 401, ResultError = 402, PasswordLogin = 2, ProcedureSuccess = 1, Success = 0, DataError = -1, } public class ApiResult { private static readonly Dictionary codeMessageDict = new Dictionary() { { ReturnCode.Success, "操作成功。" }, { ReturnCode.ArgsError, "参数错误。" }, { ReturnCode.GeneralError, "操作错误。" }, { ReturnCode.LoginError, "用户名或密码错误。" }, { ReturnCode.PasswordLogin, "后台未绑定,手机密码登录。" }, { ReturnCode.DataError, "返回数据为空。" }, { ReturnCode.LoginPriv, "用户没有权限。" } }; public ApiResult(ReturnCode returnCode = ReturnCode.Success, string msg = null) { Code = returnCode; Message = msg ?? (codeMessageDict[returnCode] ?? "未知错误。"); } public ReturnCode Code { get; set; } public string Message { get; set; } } public class ApiResult : ApiResult { public ApiResult(T data, ReturnCode returnCode = ReturnCode.Success, string msg = null) : base(returnCode, msg) { Data = data; } public T Data { get; set; } } }