Skip to content

Commit

Permalink
按钮等组件复制到剪贴板操作时弹出提示
Browse files Browse the repository at this point in the history
  • Loading branch information
xiadao521 committed Jan 18, 2024
1 parent 7d8a8dc commit 346fffd
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 395 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>7</VersionMajor>
<VersionMinor>1</VersionMinor>
<VersionPatch>129</VersionPatch>
<VersionPatch>131</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.4" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 19 additions & 13 deletions src/Util.Ui.NgZorro/Components/Base/ButtonBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Util.Ui.NgZorro.Enums;
using Util.Ui.NgZorro.Extensions;

namespace Util.Ui.NgZorro.Components.Base;
namespace Util.Ui.NgZorro.Components.Base;

/// <summary>
/// 按钮标签生成器基类
Expand Down Expand Up @@ -685,7 +685,7 @@ public TBuilder OnClick() {
if ( IsValidateForm() ) {
var value = _config.GetValue( UiConst.OnClick );
value = $"{GetButtonExtendId()}.validateForm();{value}";
_config.SetAttribute( UiConst.OnClick,value );
_config.SetAttribute( UiConst.OnClick, value );
}
this.OnClick( _config );
return (TBuilder)this;
Expand All @@ -705,6 +705,7 @@ public TBuilder OnVisibleChange() {
protected TBuilder ConfigButton() {
var popoverRender = new PopoverRender( _config, this );
popoverRender.Config();
EnableExtend();
return Type().Size().Shape().Disabled().Danger().Loading().Ghost().Block().Icon().RouterLink()
.DropdownMenu().DropdownMenuPlacement().DropdownMenuTrigger().DropdownMenuClickHide()
.DropdownMenuVisible().DropdownMenuOverlayClassName().DropdownMenuOverlayStyle()
Expand All @@ -716,31 +717,36 @@ protected TBuilder ConfigButton() {
.TextStart().TextStop().TextAdd().TextRemove()
.TextOpen().TextClose().TextSend().TextClear()
.TextImport().TextExport().TextReset()
.Text().OnClick().OnVisibleChange()
.ValidateForm();
.Text().OnClick().OnVisibleChange();
}

/// <summary>
/// 是否验证表单
/// 启用扩展
/// </summary>
protected TBuilder ValidateForm() {
if ( IsValidateForm() == false )
return (TBuilder)this;
protected void EnableExtend() {
if ( IsEnableExtend() == false )
return;
Attribute( "x-button-extend" );
Attribute( $"#{GetButtonExtendId()}", "xButtonExtend" );
return (TBuilder)this;
}

/// <summary>
/// 是否验证表单
/// 是否启用扩展
/// </summary>
private bool IsValidateForm() {
var result = _config.GetValue<bool?>( UiConst.ValidateForm );
if ( result == true )
protected virtual bool IsEnableExtend() {
if ( IsValidateForm() )
return true;
return false;
}

/// <summary>
/// 是否验证表单
/// </summary>
protected bool IsValidateForm() {
var result = _config.GetValue<bool?>( UiConst.ValidateForm );
return result == true;
}

/// <summary>
/// 获取按钮扩展指令标识
/// </summary>
Expand Down
24 changes: 22 additions & 2 deletions src/Util.Ui.NgZorro/Components/Buttons/Builders/ButtonBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Util.Ui.NgZorro.Components.Base;
using Util.Ui.Angular.Extensions;
using Util.Ui.NgZorro.Components.Base;
using Util.Ui.NgZorro.Components.Forms.Configs;
using Util.Ui.NgZorro.Configs;
using Util.Ui.NgZorro.Directives.Tooltips;
Expand Down Expand Up @@ -47,9 +48,10 @@ public ButtonBuilder CopyToClipboard() {
var value = _config.GetValue( UiConst.CopyToClipboard );
if( value.IsEmpty() )
return this;
Attribute( "[cdkCopyToClipboard]", value );
EnableExtend();
_config.SetAttribute( UiConst.Type, Util.Ui.NgZorro.Enums.ButtonType.Text );
_config.SetAttribute( UiConst.Icon,AntDesignIcon.Copy );
this.OnClick($"{GetButtonExtendId()}.copyToClipboard({value})");
var options = NgZorroOptionsService.GetOptions();
if( options.EnableI18n ) {
this.BindTooltipTitle( $"'{I18nKeys.CopyToClipboard}'|i18n" );
Expand All @@ -68,4 +70,22 @@ public override void Config() {
base.Config();
IsSubmit().ButtonType();
}

/// <summary>
/// 是否启用扩展
/// </summary>
protected override bool IsEnableExtend() {
if ( IsValidateForm() )
return true;
if ( IsCopyToClipboard() )
return true;
return false;
}

/// <summary>
/// 是否复制到剪贴板
/// </summary>
protected bool IsCopyToClipboard() {
return _config.Contains( UiConst.CopyToClipboard );
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Util.Ui.Configs;
using Util.Ui.NgZorro.Components.Forms.Helpers;
using Util.Ui.NgZorro.Components.Forms.Helpers;

namespace Util.Ui.NgZorro.Components.Inputs.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Util.Ui.Angular.Configs;
using Util.Ui.Configs;
using Util.Ui.NgZorro.Components.Base;
using Util.Ui.NgZorro.Components.Trees.Helpers;
using Util.Ui.NgZorro.Enums;
Expand Down Expand Up @@ -312,14 +311,6 @@ public TreeSelectBuilder Width() {
return this;
}

/// <summary>
/// 配置加载标识列表
/// </summary>
public TreeSelectBuilder LoadKeys() {
AttributeIfNotEmpty( "[loadKeys]", _config.GetValue( UiConst.LoadKeys ) );
return this;
}

/// <summary>
/// 配置事件
/// </summary>
Expand Down Expand Up @@ -348,7 +339,7 @@ public override void Config() {
.DefaultExpandAll().ExpandedKeys().DisplayWith()
.MaxTagCount().MaxTagPlaceholder().TreeTemplate()
.VirtualHeight().VirtualItemSize().VirtualMaxBufferPx().VirtualMinBufferPx()
.Width().LoadKeys()
.Width()
.Events();
base.ConfigBase( _config );
_service.ConfigBuilder( this );
Expand All @@ -362,6 +353,15 @@ private void ConfigDefault() {
if ( _service.IsEnableExtend() == false )
return;
Nodes( $"{ExtendId}.dataSource" )
.LoadKeys()
.OnExpandChange( $"{ExtendId}.expandChange($event)" );
}

/// <summary>
/// 配置加载标识列表
/// </summary>
public TreeSelectBuilder LoadKeys() {
AttributeIfNotEmpty( "[loadKeys]", _config.GetValue( UiConst.LoadKeys ) );
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Util.Ui.Builders;
using Util.Ui.Configs;
using Util.Ui.Extensions;
using Util.Ui.NgZorro.Components.Base;
using Util.Ui.NgZorro.Components.TreeSelects.Builders;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using Util.Applications.Trees;
using Util.Ui.Configs;
using Util.Ui.NgZorro.Components.Base;
using Util.Ui.NgZorro.Components.Inputs.Helpers;
using Util.Ui.NgZorro.Components.TreeSelects.Renders;
Expand Down
84 changes: 57 additions & 27 deletions test/Util.Ui.NgZorro.Tests/Buttons/ButtonTagHelperTest.Extend.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,65 @@
using System.Text;
using Util.Ui.Configs;
using Util.Ui.NgZorro.Configs;
using Xunit;

namespace Util.Ui.NgZorro.Tests.Buttons {
namespace Util.Ui.NgZorro.Tests.Buttons;

/// <summary>
/// 按钮测试 - 指令扩展
/// </summary>
public partial class ButtonTagHelperTest {
/// <summary>
/// 测试是否验证表单
/// </summary>
[Fact]
public void TestValidateForm_1() {
_wrapper.SetContextAttribute( UiConst.ValidateForm, true );
_wrapper.SetContextAttribute( UiConst.OnClick, "test()" );
var result = new StringBuilder();
result.Append( "<button #x_id=\"xButtonExtend\" (click)=\"x_id.validateForm();test()\" nz-button=\"\" x-button-extend=\"\"></button>" );
Assert.Equal( result.ToString(), GetResult() );
}

/// <summary>
/// 测试是否验证表单 - 指定按钮标识
/// </summary>
[Fact]
public void TestValidateForm_2() {
_wrapper.SetContextAttribute( UiConst.ValidateForm, true );
_wrapper.SetContextAttribute( UiConst.Id, "a" );
_wrapper.SetContextAttribute( UiConst.OnClick, "test()" );
var result = new StringBuilder();
result.Append( "<button #a=\"\" #x_a=\"xButtonExtend\" (click)=\"x_a.validateForm();test()\" nz-button=\"\" x-button-extend=\"\"></button>" );
Assert.Equal( result.ToString(), GetResult() );
}

/// <summary>
/// 按钮测试 - 指令扩展
/// 测试复制到剪贴板
/// </summary>
public partial class ButtonTagHelperTest {
/// <summary>
/// 测试是否验证表单
/// </summary>
[Fact]
public void TestValidateForm_1() {
_wrapper.SetContextAttribute( UiConst.ValidateForm, true );
_wrapper.SetContextAttribute( UiConst.OnClick, "test()" );
var result = new StringBuilder();
result.Append( "<button #x_id=\"xButtonExtend\" (click)=\"x_id.validateForm();test()\" nz-button=\"\" x-button-extend=\"\"></button>" );
Assert.Equal( result.ToString(), GetResult() );
}
[Fact]
public void TestCopyToClipboard() {
_wrapper.SetContextAttribute( UiConst.CopyToClipboard, "a" );
var result = new StringBuilder();
result.Append( "<button #x_id=\"xButtonExtend\" (click)=\"x_id.copyToClipboard(a)\" " );
result.Append( "nz-button=\"\" nz-tooltip=\"\" nzTooltipTitle=\"复制到剪贴板\" nzType=\"text\" x-button-extend=\"\">" );
result.Append( "<i nz-icon=\"\" nzType=\"copy\"></i>" );
result.Append( "</button>" );
Assert.Equal( result.ToString(), GetResult() );
}

/// <summary>
/// 测试是否验证表单 - 指定按钮标识
/// </summary>
[Fact]
public void TestValidateForm_2() {
_wrapper.SetContextAttribute( UiConst.ValidateForm, true );
_wrapper.SetContextAttribute( UiConst.Id, "a" );
_wrapper.SetContextAttribute( UiConst.OnClick, "test()" );
var result = new StringBuilder();
result.Append( "<button #a=\"\" #x_a=\"xButtonExtend\" (click)=\"x_a.validateForm();test()\" nz-button=\"\" x-button-extend=\"\"></button>" );
Assert.Equal( result.ToString(), GetResult() );
}
/// <summary>
/// 测试复制到剪贴板 - 多语言
/// </summary>
[Fact]
public void TestCopyToClipboard_I18n() {
NgZorroOptionsService.SetOptions( new NgZorroOptions { EnableI18n = true } );
_wrapper.SetContextAttribute( UiConst.CopyToClipboard, "a" );
var result = new StringBuilder();
result.Append( "<button #x_id=\"xButtonExtend\" (click)=\"x_id.copyToClipboard(a)\" " );
result.Append( "nz-button=\"\" nz-tooltip=\"\" nzType=\"text\" x-button-extend=\"\" [nzTooltipTitle]=\"'util.copyToClipboard'|i18n\">" );
result.Append( "<i nz-icon=\"\" nzType=\"copy\"></i>" );
result.Append( "</button>" );
Assert.Equal( result.ToString(), GetResult() );
}
}
}
Loading

0 comments on commit 346fffd

Please sign in to comment.