Skip to content

Commit 41a673e

Browse files
committed
1.查询表单展开收起按钮在查询条件数量较少无需展开时将自动隐藏.
2. NgZorro配置 Util.Ui.NgZorro.NgZorroOptions 新增属性 EnableTableRowCheckedClass ,用于勾选表格复选框时,为表格行添加 table-row-checked 样式类. 3. NgZorro配置 Util.Ui.NgZorro.NgZorroOptions 新增属性 RazorRootDirectory ,用于设置Razor文件根路径,并将默认值修改为: /ClientApp. 4. NgZorro配置 Util.Ui.NgZorro.NgZorroOptions 新增属性 GenerateHtmlVersion, 控制Razor页面生成html文件路径的方式,使用传统方式需要设置为 v1 . 5. 内置Razor生成Html控制器 Util.Ui.NgZorro.Controllers.GenerateHtmlController. 6. 修复文件监视操作类 Util.Helpers.FileWatcher 多次触发同一个监视事件的问题.
1 parent 139753d commit 41a673e

File tree

23 files changed

+304
-136
lines changed

23 files changed

+304
-136
lines changed

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>8</VersionMajor>
44
<VersionMinor>0</VersionMinor>
5-
<VersionPatch>9</VersionPatch>
5+
<VersionPatch>10</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
<VersionSuffix></VersionSuffix>
88
</PropertyGroup>

src/Util.Core/Helpers/FileWatcher.cs

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,34 @@ public class FileWatcher : IDisposable {
88
/// 文件系统监视器
99
/// </summary>
1010
private readonly FileSystemWatcher _watcher;
11+
/// <summary>
12+
/// 防抖间隔
13+
/// </summary>
14+
private int _debounceInterval;
15+
/// <summary>
16+
/// 文件监视事件过滤器
17+
/// </summary>
18+
private readonly FileWatcherEventFilter _fileWatcherEventFilter;
1119

1220
/// <summary>
1321
/// 初始化文件监视器
1422
/// </summary>
1523
public FileWatcher() {
1624
_watcher = new FileSystemWatcher();
17-
_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
25+
_watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite
26+
| NotifyFilters.CreationTime | NotifyFilters.LastAccess
27+
| NotifyFilters.Attributes | NotifyFilters.Size | NotifyFilters.Security;
28+
_debounceInterval = 200;
29+
_fileWatcherEventFilter = new FileWatcherEventFilter();
30+
}
31+
32+
/// <summary>
33+
/// 设置防抖间隔,默认值: 200 毫秒
34+
/// </summary>
35+
/// <param name="interval">防抖间隔, 单位: 毫秒</param>
36+
public FileWatcher Debounce( int interval ) {
37+
_debounceInterval = interval;
38+
return this;
1839
}
1940

2041
/// <summary>
@@ -52,7 +73,8 @@ public FileWatcher Filter( string filter ) {
5273
/// <param name="action">文件创建监听事件处理器</param>
5374
public FileWatcher OnCreated( Action<object, FileSystemEventArgs> action ) {
5475
_watcher.Created += ( source, e ) => {
55-
action( source, e );
76+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
77+
action( source, e );
5678
};
5779
return this;
5880
}
@@ -63,7 +85,8 @@ public FileWatcher OnCreated( Action<object, FileSystemEventArgs> action ) {
6385
/// <param name="action">文件创建监听事件处理器</param>
6486
public FileWatcher OnCreatedAsync( Func<object, FileSystemEventArgs, Task> action ) {
6587
_watcher.Created += async ( source, e ) => {
66-
await action( source, e );
88+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
89+
await action( source, e );
6790
};
6891
return this;
6992
}
@@ -74,7 +97,8 @@ public FileWatcher OnCreatedAsync( Func<object, FileSystemEventArgs, Task> actio
7497
/// <param name="action">文件变更监听事件处理器</param>
7598
public FileWatcher OnChanged( Action<object, FileSystemEventArgs> action ) {
7699
_watcher.Changed += ( source, e ) => {
77-
action( source, e );
100+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
101+
action( source, e );
78102
};
79103
return this;
80104
}
@@ -85,7 +109,8 @@ public FileWatcher OnChanged( Action<object, FileSystemEventArgs> action ) {
85109
/// <param name="action">文件变更监听事件处理器</param>
86110
public FileWatcher OnChangedAsync( Func<object, FileSystemEventArgs, Task> action ) {
87111
_watcher.Changed += async ( source, e ) => {
88-
await action( source, e );
112+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
113+
await action( source, e );
89114
};
90115
return this;
91116
}
@@ -96,7 +121,8 @@ public FileWatcher OnChangedAsync( Func<object, FileSystemEventArgs, Task> actio
96121
/// <param name="action">文件删除监听事件处理器</param>
97122
public FileWatcher OnDeleted( Action<object, FileSystemEventArgs> action ) {
98123
_watcher.Deleted += ( source, e ) => {
99-
action( source, e );
124+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
125+
action( source, e );
100126
};
101127
return this;
102128
}
@@ -107,7 +133,8 @@ public FileWatcher OnDeleted( Action<object, FileSystemEventArgs> action ) {
107133
/// <param name="action">文件删除监听事件处理器</param>
108134
public FileWatcher OnDeletedAsync( Func<object, FileSystemEventArgs, Task> action ) {
109135
_watcher.Deleted += async ( source, e ) => {
110-
await action( source, e );
136+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
137+
await action( source, e );
111138
};
112139
return this;
113140
}
@@ -118,7 +145,8 @@ public FileWatcher OnDeletedAsync( Func<object, FileSystemEventArgs, Task> actio
118145
/// <param name="action">文件重命名监听事件处理器</param>
119146
public FileWatcher OnRenamed( Action<object, RenamedEventArgs> action ) {
120147
_watcher.Renamed += ( source, e ) => {
121-
action( source, e );
148+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
149+
action( source, e );
122150
};
123151
return this;
124152
}
@@ -129,7 +157,8 @@ public FileWatcher OnRenamed( Action<object, RenamedEventArgs> action ) {
129157
/// <param name="action">文件重命名监听事件处理器</param>
130158
public FileWatcher OnRenamedAsync( Func<object, RenamedEventArgs, Task> action ) {
131159
_watcher.Renamed += async ( source, e ) => {
132-
await action( source, e );
160+
if ( _fileWatcherEventFilter.IsValid( e.FullPath, _debounceInterval ) )
161+
await action( source, e );
133162
};
134163
return this;
135164
}
@@ -200,4 +229,52 @@ public FileWatcher Stop() {
200229
public void Dispose() {
201230
_watcher?.Dispose();
202231
}
232+
}
233+
234+
/// <summary>
235+
/// 文件监视事件过滤器
236+
/// </summary>
237+
internal class FileWatcherEventFilter {
238+
/// <summary>
239+
/// 最后一个文件
240+
/// </summary>
241+
private WatchFile _file;
242+
243+
/// <summary>
244+
/// 监视事件是否有效
245+
/// </summary>
246+
/// <param name="path">文件路径</param>
247+
/// <param name="debounceInterval">防抖间隔</param>
248+
internal bool IsValid( string path, int debounceInterval ) {
249+
if ( _file != null && path == _file.Path && DateTime.Now - _file.Time < TimeSpan.FromMilliseconds( debounceInterval ) ) {
250+
_file = new WatchFile( path );
251+
return false;
252+
}
253+
_file = new WatchFile( path );
254+
return true;
255+
}
256+
}
257+
258+
/// <summary>
259+
/// 监视文件
260+
/// </summary>
261+
internal class WatchFile {
262+
/// <summary>
263+
/// 初始化监视文件
264+
/// </summary>
265+
/// <param name="path">文件路径</param>
266+
public WatchFile( string path ) {
267+
Path = path;
268+
Time = DateTime.Now;
269+
}
270+
271+
/// <summary>
272+
/// 文件路径
273+
/// </summary>
274+
public string Path { get; }
275+
276+
/// <summary>
277+
/// 处理时间
278+
/// </summary>
279+
public DateTime Time { get; }
203280
}

src/Util.Logging.Serilog.Exceptionless/03-Util.Logging.Serilog.Exceptionless.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Exceptionless.Extensions.Hosting" Version="6.0.3" />
31-
<PackageReference Include="Exceptionless.Extensions.Logging" Version="6.0.3" />
30+
<PackageReference Include="Exceptionless.Extensions.Hosting" Version="6.0.4" />
31+
<PackageReference Include="Exceptionless.Extensions.Logging" Version="6.0.4" />
3232
<PackageReference Include="Serilog.Sinks.Exceptionless" Version="4.0.0" />
3333
</ItemGroup>
3434

src/Util.Ui.NgZorro/AppBuilderExtensions.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public static IAppBuilder AddNgZorro( this IAppBuilder builder, Action<NgZorroOp
2727
builder.Host.ConfigureServices( ( context, services ) => {
2828
var options = new NgZorroOptions();
2929
setupAction?.Invoke( options );
30-
services.AddRazorPages().AddRazorRuntimeCompilation().AddConventions();
30+
services.AddRazorPages( razorPageOptions => {
31+
razorPageOptions.RootDirectory = options.RazorRootDirectory;
32+
} ).AddRazorRuntimeCompilation().AddConventions();
3133
services.TryAddSingleton<IRazorWatchService, RazorWatchService>();
3234
services.TryAddSingleton<IPartViewPathResolver, PartViewPathResolver>();
3335
services.TryAddSingleton<IPartViewPathFinder, PartViewPathFinder>();
@@ -53,16 +55,8 @@ private static void ConfigSpaStaticFiles( IServiceCollection services, NgZorroOp
5355
/// 配置Razor
5456
/// </summary>
5557
private static void ConfigRazorOptions( IServiceCollection services, NgZorroOptions options ) {
56-
void Action( RazorOptions t ) {
57-
t.IsGenerateHtml = options.IsGenerateHtml;
58-
t.GenerateHtmlBasePath = options.GenerateHtmlBasePath;
59-
t.GenerateHtmlFolder = options.GenerateHtmlFolder;
60-
t.GenerateHtmlSuffix = options.GenerateHtmlSuffix;
61-
t.EnableWatchRazor = options.EnableWatchRazor;
62-
t.StartInitDelay = options.StartInitDelay;
63-
t.HtmlRenderDelayOnRazorChange = options.HtmlRenderDelayOnRazorChange;
64-
t.EnablePreheat = options.EnablePreheat;
65-
t.EnableOverrideHtml = options.EnableOverrideHtml;
58+
void Action( RazorOptions razorOptions ) {
59+
options.MapTo( razorOptions );
6660
}
6761
services.Configure( (Action<RazorOptions>)Action );
6862
}

src/Util.Ui.NgZorro/Components/Descriptions/DescriptionItemTagHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.AspNetCore.Mvc.ViewFeatures;
22
using Microsoft.AspNetCore.Razor.TagHelpers;
33
using Util.Ui.Angular.TagHelpers;
4-
using Util.Ui.Configs;
54
using Util.Ui.NgZorro.Components.Descriptions.Renders;
65
using Util.Ui.NgZorro.Components.Display.Helpers;
76
using Util.Ui.Renders;

src/Util.Ui.NgZorro/Components/Links/Renders/ARender.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using Util.Ui.Builders;
2+
using Util.Ui.NgZorro.Components.Forms.Configs;
23
using Util.Ui.NgZorro.Components.Links.Builders;
34
using Util.Ui.Renders;
45

5-
namespace Util.Ui.NgZorro.Components.Links.Renders;
6+
namespace Util.Ui.NgZorro.Components.Links.Renders;
67

78
/// <summary>
89
/// 链接渲染器
@@ -25,11 +26,31 @@ public ARender( Config config ) {
2526
/// 获取标签生成器
2627
/// </summary>
2728
protected override TagBuilder GetTagBuilder() {
29+
if ( IsHide() )
30+
return new EmptyTagBuilder();
2831
var builder = new ABuilder( _config );
2932
builder.Config();
3033
return builder;
3134
}
3235

36+
/// <summary>
37+
/// 是否隐藏标签
38+
/// </summary>
39+
private bool IsHide() {
40+
var isSearch = _config.GetValue<bool?>( UiConst.IsSearch );
41+
if ( isSearch != true )
42+
return false;
43+
var formShareConfig = GetFormShareConfig();
44+
return formShareConfig.GetConditionCount() <= formShareConfig.SearchFormShowNumber;
45+
}
46+
47+
/// <summary>
48+
/// 获取表单共享配置
49+
/// </summary>
50+
public FormShareConfig GetFormShareConfig() {
51+
return _config.GetValueFromItems<FormShareConfig>() ?? new FormShareConfig();
52+
}
53+
3354
/// <inheritdoc />
3455
public override IHtmlContent Clone() {
3556
return new ARender( _config.Copy() );

src/Util.Ui.NgZorro/Components/Tables/Builders/TableBodyRowBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public override void Config() {
5555
base.Config();
5656
ConfigTableExtend();
5757
ConfigEdit();
58+
ConfigTableRowCheckedClass();
5859
ConfigContent();
5960
}
6061

@@ -88,6 +89,16 @@ protected void ConfigEdit() {
8889
Attribute( "(dblclick)", $"{EditId}.dblClickEdit(row.id)", append: true );
8990
}
9091

92+
/// <summary>
93+
/// 配置勾选样式
94+
/// </summary>
95+
protected void ConfigTableRowCheckedClass() {
96+
var options = NgZorroOptionsService.GetOptions();
97+
if ( options.EnableTableRowCheckedClass == false )
98+
return;
99+
Attribute( "[class.table-row-checked]", $"{TableShareConfig.TableExtendId}.isChecked(row)" );
100+
}
101+
91102
/// <summary>
92103
/// 配置内容
93104
/// </summary>

src/Util.Ui.NgZorro/Components/Tables/Builders/TableHeadRowBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Util.Ui.Angular.Extensions;
2-
using Util.Ui.Configs;
32
using Util.Ui.Extensions;
43
using Util.Ui.NgZorro.Components.Tables.Configs;
54
using Util.Ui.NgZorro.Components.Tables.Helpers;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Util.Ui.Razor;
2+
3+
namespace Util.Ui.NgZorro.Controllers;
4+
5+
/// <summary>
6+
/// Razor生成Html控制器
7+
/// </summary>
8+
[ApiController]
9+
[Route( "api/html" )]
10+
public class GenerateHtmlController : ControllerBase {
11+
/// <summary>
12+
/// 生成所有Razor页面的Html
13+
/// </summary>
14+
[HttpGet]
15+
public async Task<string> GenerateAsync() {
16+
var message = new StringBuilder();
17+
var result = await HtmlGenerator.GenerateAsync();
18+
message.AppendLine( "======================= 欢迎使用 Util 应用框架 - 开始生成全部Razor页面html =======================" );
19+
message.AppendLine();
20+
message.AppendLine();
21+
foreach ( var path in result )
22+
message.AppendLine( path );
23+
message.AppendLine();
24+
message.AppendLine();
25+
message.Append( "======================================== html文件生成完成 ========================================" );
26+
return message.ToString();
27+
}
28+
}

0 commit comments

Comments
 (0)