更新组件
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||
<PackageReference Include="NewLife.Core" Version="8.1.2019.324" />
|
||||
<PackageReference Include="NewLife.Core" Version="8.1.2019.327" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
|
||||
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NewLife.XCode" Version="9.11.2019.324" />
|
||||
<PackageReference Include="NewLife.XCode" Version="9.11.2019.327" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
|
||||
<PackageReference Include="MimeKit" Version="2.1.3" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.15" />
|
||||
<PackageReference Include="NewLife.XCode" Version="9.11.2019.324" />
|
||||
<PackageReference Include="NewLife.XCode" Version="9.11.2019.327" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
<PackageReference Include="Senparc.Weixin" Version="6.3.10.1" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="16.6.14.2" />
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NewLife.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using XCode;
|
||||
|
||||
namespace COMCMS.Web.Common
|
||||
{
|
||||
public class JsonOptionsConfig
|
||||
{
|
||||
public static void ConfigJsonOptions(MvcJsonOptions options)
|
||||
{
|
||||
var settings = options.SerializerSettings;
|
||||
//日期类型默认格式化处理
|
||||
// //setting.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
|
||||
settings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
//// 空值处理
|
||||
//setting.NullValueHandling = NullValueHandling.Ignore;
|
||||
|
||||
// 最大序列化深度,包括请求传参的序列化深度,不可设置太小了
|
||||
settings.MaxDepth = 5;
|
||||
|
||||
// 忽略循环引用
|
||||
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
|
||||
// 全局设置要排除的字段
|
||||
settings.ContractResolver = new LimitPropsContractResolver(new[] { "password", "extends" }, false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 限制某些属性输出或排除,设置为保留时,只输出保留属性,其他属性全部忽略。
|
||||
/// 设置为排除,只排除设置的属性
|
||||
/// </summary>
|
||||
public class LimitPropsContractResolver : CamelCasePropertyNamesContractResolver
|
||||
{
|
||||
private readonly string[] _props = null;
|
||||
|
||||
private readonly bool _retain;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="props">传入的属性数组</param>
|
||||
/// <param name="retain">true:表示props是需要保留的字段 false:表示props是要排除的字段</param>
|
||||
public LimitPropsContractResolver(string[] props, bool retain = true)
|
||||
{
|
||||
//指定要序列化属性的清单
|
||||
this._props = props;
|
||||
|
||||
this._retain = retain;
|
||||
}
|
||||
|
||||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||
{
|
||||
var list = base.CreateProperties(type, memberSerialization);
|
||||
|
||||
// 非实体类型直接返回
|
||||
if (!typeof(EntityBase).IsAssignableFrom(type))
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
//只保留清单有列出的属性
|
||||
list = list.Where(p =>
|
||||
{
|
||||
var has = _props.Any(a => a.Equals(p.PropertyName, StringComparison.OrdinalIgnoreCase));
|
||||
if (_retain)
|
||||
{
|
||||
return has;
|
||||
}
|
||||
|
||||
return !has;
|
||||
}).ToList();
|
||||
NewLife.Log.XTrace.WriteLine(list.ToJson());
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace COMCMS.Web
|
||||
//部分系统配置
|
||||
services.Configure<SystemSetting>(Configuration.GetSection("SystemSetting"));
|
||||
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); ;
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonOptions(JsonOptionsConfig.ConfigJsonOptions);
|
||||
//防止汉字被自动编码
|
||||
services.Configure<WebEncoderOptions>(options =>
|
||||
{
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="NewLife.Core, Version=8.1.7022.38682, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NewLife.Core.8.1.2019.324\lib\net45\NewLife.Core.dll</HintPath>
|
||||
<Reference Include="NewLife.Core, Version=8.1.7025.14014, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NewLife.Core.8.1.2019.327\lib\net45\NewLife.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -46,8 +46,8 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="XCode, Version=9.11.7022.38685, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NewLife.XCode.9.11.2019.324\lib\net45\XCode.dll</HintPath>
|
||||
<Reference Include="XCode, Version=9.11.7025.14018, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NewLife.XCode.9.11.2019.327\lib\net45\XCode.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NewLife.Core" version="8.1.2019.324" targetFramework="net461" />
|
||||
<package id="NewLife.XCode" version="9.11.2019.324" targetFramework="net461" />
|
||||
<package id="NewLife.Core" version="8.1.2019.327" targetFramework="net461" />
|
||||
<package id="NewLife.XCode" version="9.11.2019.327" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user