🍒 feat(Http): 优化 Http接口与Http日志集成管理
This commit is contained in:
parent
1439739e6c
commit
fbd7d59dcb
@ -9,17 +9,53 @@ namespace Admin.NET.Core;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 远程请求接口特性
|
/// 远程请求接口特性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[SuppressSniffer]
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class HttpRemoteApiAttribute : Attribute
|
public class HttpRemoteApiAttribute : Attribute
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编码
|
/// 方法名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required]
|
[Required]
|
||||||
public string Code { get; set; }
|
public string Action { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 描述
|
/// 描述
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Required]
|
||||||
public string Desc { get; set; }
|
public string Desc { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求方式
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public HttpMethodEnum HttpMethod { get; set; } = HttpMethodEnum.Post;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 参数类型
|
||||||
|
/// </summary>
|
||||||
|
public HttpParameterTypeEnum? Type { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 远程请求接口参数类型枚举
|
||||||
|
/// </summary>
|
||||||
|
[SuppressSniffer]
|
||||||
|
[Description("远程请求接口参数类型枚举")]
|
||||||
|
public enum HttpParameterTypeEnum
|
||||||
|
{
|
||||||
|
[Description("查询")]
|
||||||
|
Query = 1,
|
||||||
|
|
||||||
|
[Description("表单")]
|
||||||
|
FormData = 2,
|
||||||
|
|
||||||
|
[Description("JSON")]
|
||||||
|
Json = 3,
|
||||||
|
|
||||||
|
[Description("XML")]
|
||||||
|
Xml = 4,
|
||||||
|
|
||||||
|
[Description("自定义")]
|
||||||
|
Custom = 5
|
||||||
}
|
}
|
||||||
@ -34,4 +34,14 @@ public static class HttpRemotesExtension {
|
|||||||
}
|
}
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置Http远程服务选项
|
||||||
|
/// </summary>
|
||||||
|
public static HttpRequestBuilder SetHttpOptions(this HttpRequestBuilder builder, HttpRemoteItem option, string apiDesc = "")
|
||||||
|
{
|
||||||
|
builder.SetHttpClientName(option.HttpName);
|
||||||
|
builder.WithHeader(CommonConst.HttpRemoteApiDescHeaderName, apiDesc, replace:true);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -55,7 +55,28 @@ public static partial class ObjectExtension
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string ToQueryString(this Dictionary<string, string> dict, bool urlEncode = true)
|
public static string ToQueryString(this Dictionary<string, string> dict, bool urlEncode = true)
|
||||||
{
|
{
|
||||||
return string.Join("&", dict.Select(p => $"{(urlEncode ? p.Key?.UrlEncode() : "")}={(urlEncode ? p.Value?.UrlEncode() : "")}"));
|
return string.Join("&", dict.Select(p => $"{(urlEncode ? p.Key?.UrlEncode() : p.Key)}={(urlEncode ? p.Value?.UrlEncode() : p.Value)}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据[CustomJsonProperty]特性转换属性为Query参数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <param name="urlEncode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ToCustomJsonPropertyQueryString(this object obj, bool urlEncode = true)
|
||||||
|
{
|
||||||
|
var properties = obj.GetType().GetProperties();
|
||||||
|
return string.Join("&", properties.Select(p =>
|
||||||
|
{
|
||||||
|
var name = p.GetCustomAttribute<CustomJsonPropertyAttribute>()?.Name ?? p.Name.ToFirstLetterLowerCase();
|
||||||
|
var val = p.GetValue(obj)?.ToString();
|
||||||
|
if (!urlEncode) return $"{name}={val}";
|
||||||
|
|
||||||
|
val = val?.UrlEncode();
|
||||||
|
name = name?.UrlEncode();
|
||||||
|
return $"{name}={val}";
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -16,6 +16,16 @@ public class PageLogHttpOutput
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long? Id { get; set; }
|
public long? Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 客户端名称
|
||||||
|
/// </summary>
|
||||||
|
public string HttpClientName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求接口描述
|
||||||
|
/// </summary>
|
||||||
|
public string HttpApiDesc { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求方式
|
/// 请求方式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -21,13 +21,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Query参数" v-if="data.requestUrl?.indexOf('?') != -1">
|
<el-form-item label="Query参数" v-if="data.requestUrl?.indexOf('?') != -1">
|
||||||
<el-row v-for="(value, key, index) in queryObject">
|
<el-row v-for="(value, key, index) in queryObject">
|
||||||
<el-col :span="4">
|
<span class="query-key">{{ key }}</span> = <span class="query-value">{{ value }}</span>&
|
||||||
<el-input :value="key" readonly>
|
|
||||||
</el-input>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="20">
|
|
||||||
<vue-json-pretty :data="tryJsonParse(value)" showLength showIcon showSelectController />
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="请求头">
|
<el-form-item label="请求头">
|
||||||
@ -90,3 +84,11 @@ defineExpose({
|
|||||||
openDialog,
|
openDialog,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.query-value {
|
||||||
|
color: #13ce66;
|
||||||
|
}
|
||||||
|
.query-key {
|
||||||
|
color: #d55fde;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Reference in New Issue
Block a user